feat(asset-ai): add contextual analysis and unmet-demand feedback

This commit is contained in:
shishengliang
2026-09-23 16:01:10 +08:00
parent 0a32392215
commit 7e9760f5db
23 changed files with 5160 additions and 835 deletions
@@ -84,10 +84,14 @@ test("assistant rejects unauthenticated direct calls before contacting a model",
const response = await router.request("/ask", { method: "POST", body: "{}" });
assert.equal(response.status, 401);
});
test("model only receives aggregate data; permission-filtered rows stay in the response", async (t) => {
test("model receives no business results; permission-filtered rows stay in the response", async (t) => {
const oldKey = process.env.DEEPSEEK_API_KEY;
process.env.DEEPSEEK_API_KEY = "test-only";
const oldEnabled = process.env.ASSET_AI_EXTERNAL_ENABLED;
process.env.ASSET_AI_EXTERNAL_ENABLED = "1";
t.after(() => {
if (oldEnabled === undefined) delete process.env.ASSET_AI_EXTERNAL_ENABLED;
else process.env.ASSET_AI_EXTERNAL_ENABLED = oldEnabled;
if (oldKey === undefined) delete process.env.DEEPSEEK_API_KEY;
else process.env.DEEPSEEK_API_KEY = oldKey;
});
@@ -105,7 +109,10 @@ test("model only receives aggregate data; permission-filtered rows stay in the r
message: {
content:
prompts.length === 1
? JSON.stringify(plan)
? JSON.stringify({
kind: "query",
plan,
})
: "共有 2 台库存车辆。",
},
finish_reason: "stop",
@@ -136,7 +143,7 @@ test("model only receives aggregate data; permission-filtered rows stay in the r
result.rows.map((r: { id: string }) => r.id),
["0", "2"],
);
assert.equal(prompts.length, 2);
assert.equal(prompts.length, 1);
assert.ok(
prompts.every(
(p) =>
@@ -145,5 +152,5 @@ test("model only receives aggregate data; permission-filtered rows stay in the r
!p.includes("plateNumber"),
),
);
assert.equal(events.filter((e) => e.type === "step").length, 4);
assert.equal(events.filter((e) => e.type === "step").length, 3);
});