@carlonicora/nestjs-neo4jsonapi 1.64.0 → 1.65.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agents/agents.modules.js +3 -3
- package/dist/agents/agents.modules.js.map +1 -1
- package/dist/agents/graph/graph.module.d.ts +3 -0
- package/dist/agents/graph/graph.module.d.ts.map +1 -0
- package/dist/agents/{chatbot/chatbot.module.js → graph/graph.module.js} +12 -16
- package/dist/agents/graph/graph.module.js.map +1 -0
- package/dist/agents/{chatbot → graph}/interfaces/graph.catalog.interface.d.ts +4 -0
- package/dist/agents/graph/interfaces/graph.catalog.interface.d.ts.map +1 -0
- package/dist/agents/graph/interfaces/graph.catalog.interface.js.map +1 -0
- package/dist/agents/graph/interfaces/graph.node.output.interface.d.ts +30 -0
- package/dist/agents/graph/interfaces/graph.node.output.interface.d.ts.map +1 -0
- package/dist/agents/graph/interfaces/graph.node.output.interface.js +3 -0
- package/dist/agents/graph/interfaces/graph.node.output.interface.js.map +1 -0
- package/dist/agents/graph/prompts/graph.node.system.prompt.d.ts +3 -0
- package/dist/agents/graph/prompts/graph.node.system.prompt.d.ts.map +1 -0
- package/dist/agents/graph/prompts/graph.node.system.prompt.js +66 -0
- package/dist/agents/graph/prompts/graph.node.system.prompt.js.map +1 -0
- package/dist/agents/graph/repositories/user-modules.repository.d.ts.map +1 -0
- package/dist/agents/graph/repositories/user-modules.repository.js.map +1 -0
- package/dist/agents/{chatbot → graph}/services/descriptor.source.d.ts +2 -0
- package/dist/agents/graph/services/descriptor.source.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/services/descriptor.source.js +18 -3
- package/dist/agents/graph/services/descriptor.source.js.map +1 -0
- package/dist/agents/graph/services/field-formatting.d.ts.map +1 -0
- package/dist/agents/graph/services/field-formatting.js.map +1 -0
- package/dist/agents/{chatbot → graph}/services/graph.catalog.service.d.ts +16 -0
- package/dist/agents/graph/services/graph.catalog.service.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/services/graph.catalog.service.js +63 -1
- package/dist/agents/graph/services/graph.catalog.service.js.map +1 -0
- package/dist/agents/{chatbot/services/chatbot.index.manager.d.ts → graph/services/graph.index.manager.d.ts} +2 -2
- package/dist/agents/graph/services/graph.index.manager.d.ts.map +1 -0
- package/dist/agents/{chatbot/services/chatbot.index.manager.js → graph/services/graph.index.manager.js} +9 -9
- package/dist/agents/graph/services/graph.index.manager.js.map +1 -0
- package/dist/agents/graph/services/graph.search.service.d.ts +69 -0
- package/dist/agents/graph/services/graph.search.service.d.ts.map +1 -0
- package/dist/agents/graph/services/graph.search.service.js +230 -0
- package/dist/agents/graph/services/graph.search.service.js.map +1 -0
- package/dist/agents/graph/services/humanize-tool.d.ts.map +1 -0
- package/dist/agents/graph/services/humanize-tool.js.map +1 -0
- package/dist/agents/graph/services/materialise-bridge.d.ts +36 -0
- package/dist/agents/graph/services/materialise-bridge.d.ts.map +1 -0
- package/dist/agents/graph/services/materialise-bridge.js +69 -0
- package/dist/agents/graph/services/materialise-bridge.js.map +1 -0
- package/dist/agents/graph/tools/describe-entity.tool.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/describe-entity.tool.js +1 -0
- package/dist/agents/graph/tools/describe-entity.tool.js.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/read-entity.tool.d.ts +5 -1
- package/dist/agents/graph/tools/read-entity.tool.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/read-entity.tool.js +37 -8
- package/dist/agents/graph/tools/read-entity.tool.js.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/resolve-entity.tool.d.ts +2 -2
- package/dist/agents/graph/tools/resolve-entity.tool.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/resolve-entity.tool.js +2 -2
- package/dist/agents/graph/tools/resolve-entity.tool.js.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/search-entities.tool.d.ts +6 -2
- package/dist/agents/graph/tools/search-entities.tool.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/search-entities.tool.js +36 -12
- package/dist/agents/graph/tools/search-entities.tool.js.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/tool.factory.d.ts +7 -0
- package/dist/agents/graph/tools/tool.factory.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/tool.factory.js +57 -3
- package/dist/agents/graph/tools/tool.factory.js.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/traverse.tool.d.ts +5 -1
- package/dist/agents/graph/tools/traverse.tool.d.ts.map +1 -0
- package/dist/agents/{chatbot → graph}/tools/traverse.tool.js +38 -15
- package/dist/agents/graph/tools/traverse.tool.js.map +1 -0
- package/dist/agents/index.d.ts +6 -9
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +13 -15
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/responder/contexts/responder.context.d.ts +75 -1
- package/dist/agents/responder/contexts/responder.context.d.ts.map +1 -1
- package/dist/agents/responder/contexts/responder.context.js +29 -4
- package/dist/agents/responder/contexts/responder.context.js.map +1 -1
- package/dist/agents/responder/factories/responder.context.factory.d.ts +4 -5
- package/dist/agents/responder/factories/responder.context.factory.d.ts.map +1 -1
- package/dist/agents/responder/factories/responder.context.factory.js +28 -8
- package/dist/agents/responder/factories/responder.context.factory.js.map +1 -1
- package/dist/agents/responder/interfaces/entity.reference.interface.d.ts +7 -0
- package/dist/agents/responder/interfaces/entity.reference.interface.d.ts.map +1 -0
- package/dist/agents/{chatbot/interfaces/chatbot.response.interface.js → responder/interfaces/entity.reference.interface.js} +1 -1
- package/dist/agents/responder/interfaces/entity.reference.interface.js.map +1 -0
- package/dist/agents/responder/interfaces/responder.response.interface.d.ts +12 -3
- package/dist/agents/responder/interfaces/responder.response.interface.d.ts.map +1 -1
- package/dist/agents/responder/interfaces/unified.trace.interface.d.ts +64 -0
- package/dist/agents/responder/interfaces/unified.trace.interface.d.ts.map +1 -0
- package/dist/agents/responder/interfaces/unified.trace.interface.js +3 -0
- package/dist/agents/responder/interfaces/unified.trace.interface.js.map +1 -0
- package/dist/agents/responder/nodes/graph.node.service.d.ts +31 -0
- package/dist/agents/responder/nodes/graph.node.service.d.ts.map +1 -0
- package/dist/agents/responder/nodes/graph.node.service.js +319 -0
- package/dist/agents/responder/nodes/graph.node.service.js.map +1 -0
- package/dist/agents/responder/nodes/planner.node.service.d.ts +14 -0
- package/dist/agents/responder/nodes/planner.node.service.d.ts.map +1 -0
- package/dist/agents/responder/nodes/planner.node.service.js +121 -0
- package/dist/agents/responder/nodes/planner.node.service.js.map +1 -0
- package/dist/agents/responder/nodes/responder.answer.node.service.d.ts +5 -23
- package/dist/agents/responder/nodes/responder.answer.node.service.d.ts.map +1 -1
- package/dist/agents/responder/nodes/responder.answer.node.service.js +257 -432
- package/dist/agents/responder/nodes/responder.answer.node.service.js.map +1 -1
- package/dist/agents/responder/responder.module.d.ts.map +1 -1
- package/dist/agents/responder/responder.module.js +12 -3
- package/dist/agents/responder/responder.module.js.map +1 -1
- package/dist/agents/responder/services/responder.service.d.ts +15 -22
- package/dist/agents/responder/services/responder.service.d.ts.map +1 -1
- package/dist/agents/responder/services/responder.service.js +116 -89
- package/dist/agents/responder/services/responder.service.js.map +1 -1
- package/dist/common/helpers/define-entity.d.ts.map +1 -1
- package/dist/common/helpers/define-entity.js +16 -1
- package/dist/common/helpers/define-entity.js.map +1 -1
- package/dist/common/interfaces/entity.schema.interface.d.ts +15 -0
- package/dist/common/interfaces/entity.schema.interface.d.ts.map +1 -1
- package/dist/core/llm/interfaces/llm-call-metadata.interface.d.ts +19 -0
- package/dist/core/llm/interfaces/llm-call-metadata.interface.d.ts.map +1 -0
- package/dist/core/llm/interfaces/llm-call-metadata.interface.js +3 -0
- package/dist/core/llm/interfaces/llm-call-metadata.interface.js.map +1 -0
- package/dist/core/llm/llm.module.d.ts +1 -0
- package/dist/core/llm/llm.module.d.ts.map +1 -1
- package/dist/core/llm/llm.module.js +3 -1
- package/dist/core/llm/llm.module.js.map +1 -1
- package/dist/core/llm/services/llm-call-dumper.service.d.ts +64 -0
- package/dist/core/llm/services/llm-call-dumper.service.d.ts.map +1 -0
- package/dist/core/llm/services/llm-call-dumper.service.js +204 -0
- package/dist/core/llm/services/llm-call-dumper.service.js.map +1 -0
- package/dist/core/llm/services/llm.service.d.ts +4 -1
- package/dist/core/llm/services/llm.service.d.ts.map +1 -1
- package/dist/core/llm/services/llm.service.js +304 -220
- package/dist/core/llm/services/llm.service.js.map +1 -1
- package/dist/foundations/assistant/assistant.module.d.ts.map +1 -1
- package/dist/foundations/assistant/assistant.module.js +3 -2
- package/dist/foundations/assistant/assistant.module.js.map +1 -1
- package/dist/foundations/assistant/entities/assistant.d.ts +15 -16
- package/dist/foundations/assistant/entities/assistant.d.ts.map +1 -1
- package/dist/foundations/assistant/entities/assistant.js +21 -9
- package/dist/foundations/assistant/entities/assistant.js.map +1 -1
- package/dist/foundations/assistant/repositories/assistant.repository.d.ts +13 -0
- package/dist/foundations/assistant/repositories/assistant.repository.d.ts.map +1 -1
- package/dist/foundations/assistant/services/assistant.service.d.ts +35 -10
- package/dist/foundations/assistant/services/assistant.service.d.ts.map +1 -1
- package/dist/foundations/assistant/services/assistant.service.js +132 -17
- package/dist/foundations/assistant/services/assistant.service.js.map +1 -1
- package/dist/foundations/assistant-message/entities/assistant-message.d.ts +30 -10
- package/dist/foundations/assistant-message/entities/assistant-message.d.ts.map +1 -1
- package/dist/foundations/assistant-message/entities/assistant-message.js +19 -4
- package/dist/foundations/assistant-message/entities/assistant-message.js.map +1 -1
- package/dist/foundations/assistant-message/repositories/assistant-message.repository.d.ts +53 -4
- package/dist/foundations/assistant-message/repositories/assistant-message.repository.d.ts.map +1 -1
- package/dist/foundations/assistant-message/repositories/assistant-message.repository.js +43 -3
- package/dist/foundations/assistant-message/repositories/assistant-message.repository.js.map +1 -1
- package/dist/foundations/assistant-message/services/assistant-message.service.d.ts +26 -0
- package/dist/foundations/assistant-message/services/assistant-message.service.d.ts.map +1 -1
- package/dist/foundations/chunk/chunk.module.d.ts.map +1 -1
- package/dist/foundations/chunk/chunk.module.js +4 -5
- package/dist/foundations/chunk/chunk.module.js.map +1 -1
- package/dist/foundations/chunk/entities/chunk.entity.d.ts +19 -4
- package/dist/foundations/chunk/entities/chunk.entity.d.ts.map +1 -1
- package/dist/foundations/chunk/entities/chunk.entity.js +48 -0
- package/dist/foundations/chunk/entities/chunk.entity.js.map +1 -1
- package/dist/foundations/chunk/index.d.ts +1 -2
- package/dist/foundations/chunk/index.d.ts.map +1 -1
- package/dist/foundations/chunk/index.js +3 -3
- package/dist/foundations/chunk/index.js.map +1 -1
- package/dist/foundations/chunk/repositories/chunk.repository.d.ts.map +1 -1
- package/dist/foundations/chunk/repositories/chunk.repository.js +8 -8
- package/dist/foundations/chunk/repositories/chunk.repository.js.map +1 -1
- package/dist/foundations/chunk/services/chunk.service.d.ts.map +1 -1
- package/dist/foundations/chunk/services/chunk.service.js +2 -2
- package/dist/foundations/chunk/services/chunk.service.js.map +1 -1
- package/package.json +1 -1
- package/dist/agents/chatbot/chatbot.module.d.ts +0 -3
- package/dist/agents/chatbot/chatbot.module.d.ts.map +0 -1
- package/dist/agents/chatbot/chatbot.module.js.map +0 -1
- package/dist/agents/chatbot/interfaces/chatbot.response.interface.d.ts +0 -25
- package/dist/agents/chatbot/interfaces/chatbot.response.interface.d.ts.map +0 -1
- package/dist/agents/chatbot/interfaces/chatbot.response.interface.js.map +0 -1
- package/dist/agents/chatbot/interfaces/graph.catalog.interface.d.ts.map +0 -1
- package/dist/agents/chatbot/interfaces/graph.catalog.interface.js.map +0 -1
- package/dist/agents/chatbot/prompts/chatbot.system.prompt.d.ts +0 -3
- package/dist/agents/chatbot/prompts/chatbot.system.prompt.d.ts.map +0 -1
- package/dist/agents/chatbot/prompts/chatbot.system.prompt.js +0 -60
- package/dist/agents/chatbot/prompts/chatbot.system.prompt.js.map +0 -1
- package/dist/agents/chatbot/repositories/user-modules.repository.d.ts.map +0 -1
- package/dist/agents/chatbot/repositories/user-modules.repository.js.map +0 -1
- package/dist/agents/chatbot/services/chatbot.index.manager.d.ts.map +0 -1
- package/dist/agents/chatbot/services/chatbot.index.manager.js.map +0 -1
- package/dist/agents/chatbot/services/chatbot.search.service.d.ts +0 -46
- package/dist/agents/chatbot/services/chatbot.search.service.d.ts.map +0 -1
- package/dist/agents/chatbot/services/chatbot.search.service.js +0 -148
- package/dist/agents/chatbot/services/chatbot.search.service.js.map +0 -1
- package/dist/agents/chatbot/services/chatbot.service.d.ts +0 -36
- package/dist/agents/chatbot/services/chatbot.service.d.ts.map +0 -1
- package/dist/agents/chatbot/services/chatbot.service.js +0 -220
- package/dist/agents/chatbot/services/chatbot.service.js.map +0 -1
- package/dist/agents/chatbot/services/descriptor.source.d.ts.map +0 -1
- package/dist/agents/chatbot/services/descriptor.source.js.map +0 -1
- package/dist/agents/chatbot/services/field-formatting.d.ts.map +0 -1
- package/dist/agents/chatbot/services/field-formatting.js.map +0 -1
- package/dist/agents/chatbot/services/graph.catalog.service.d.ts.map +0 -1
- package/dist/agents/chatbot/services/graph.catalog.service.js.map +0 -1
- package/dist/agents/chatbot/services/humanize-tool.d.ts.map +0 -1
- package/dist/agents/chatbot/services/humanize-tool.js.map +0 -1
- package/dist/agents/chatbot/tools/describe-entity.tool.d.ts.map +0 -1
- package/dist/agents/chatbot/tools/describe-entity.tool.js.map +0 -1
- package/dist/agents/chatbot/tools/read-entity.tool.d.ts.map +0 -1
- package/dist/agents/chatbot/tools/read-entity.tool.js.map +0 -1
- package/dist/agents/chatbot/tools/resolve-entity.tool.d.ts.map +0 -1
- package/dist/agents/chatbot/tools/resolve-entity.tool.js.map +0 -1
- package/dist/agents/chatbot/tools/search-entities.tool.d.ts.map +0 -1
- package/dist/agents/chatbot/tools/search-entities.tool.js.map +0 -1
- package/dist/agents/chatbot/tools/tool.factory.d.ts.map +0 -1
- package/dist/agents/chatbot/tools/tool.factory.js.map +0 -1
- package/dist/agents/chatbot/tools/traverse.tool.d.ts.map +0 -1
- package/dist/agents/chatbot/tools/traverse.tool.js.map +0 -1
- package/dist/foundations/chunk/entities/chunk.map.d.ts +0 -8
- package/dist/foundations/chunk/entities/chunk.map.d.ts.map +0 -1
- package/dist/foundations/chunk/entities/chunk.map.js +0 -31
- package/dist/foundations/chunk/entities/chunk.map.js.map +0 -1
- package/dist/foundations/chunk/entities/chunk.model.d.ts +0 -4
- package/dist/foundations/chunk/entities/chunk.model.d.ts.map +0 -1
- package/dist/foundations/chunk/entities/chunk.model.js +0 -13
- package/dist/foundations/chunk/entities/chunk.model.js.map +0 -1
- package/dist/foundations/chunk/serialisers/chunk.serialiser.d.ts +0 -14
- package/dist/foundations/chunk/serialisers/chunk.serialiser.d.ts.map +0 -1
- package/dist/foundations/chunk/serialisers/chunk.serialiser.js +0 -54
- package/dist/foundations/chunk/serialisers/chunk.serialiser.js.map +0 -1
- /package/dist/agents/{chatbot → graph}/interfaces/graph.catalog.interface.js +0 -0
- /package/dist/agents/{chatbot → graph}/repositories/user-modules.repository.d.ts +0 -0
- /package/dist/agents/{chatbot → graph}/repositories/user-modules.repository.js +0 -0
- /package/dist/agents/{chatbot → graph}/services/field-formatting.d.ts +0 -0
- /package/dist/agents/{chatbot → graph}/services/field-formatting.js +0 -0
- /package/dist/agents/{chatbot → graph}/services/humanize-tool.d.ts +0 -0
- /package/dist/agents/{chatbot → graph}/services/humanize-tool.js +0 -0
- /package/dist/agents/{chatbot → graph}/tools/describe-entity.tool.d.ts +0 -0
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var GraphNodeService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.GraphNodeService = exports.GRAPH_NODE_WALL_CLOCK_MS = exports.MAX_TOOL_ITERATIONS = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const zod_1 = require("zod");
|
|
19
|
+
const tools_1 = require("@langchain/core/tools");
|
|
20
|
+
const websocket_service_1 = require("../../../core/websocket/services/websocket.service");
|
|
21
|
+
const llm_service_1 = require("../../../core/llm/services/llm.service");
|
|
22
|
+
const graph_catalog_service_1 = require("../../graph/services/graph.catalog.service");
|
|
23
|
+
const tool_factory_1 = require("../../graph/tools/tool.factory");
|
|
24
|
+
const resolve_entity_tool_1 = require("../../graph/tools/resolve-entity.tool");
|
|
25
|
+
const describe_entity_tool_1 = require("../../graph/tools/describe-entity.tool");
|
|
26
|
+
const search_entities_tool_1 = require("../../graph/tools/search-entities.tool");
|
|
27
|
+
const read_entity_tool_1 = require("../../graph/tools/read-entity.tool");
|
|
28
|
+
const traverse_tool_1 = require("../../graph/tools/traverse.tool");
|
|
29
|
+
const graph_node_system_prompt_1 = require("../../graph/prompts/graph.node.system.prompt");
|
|
30
|
+
const humanize_tool_1 = require("../../graph/services/humanize-tool");
|
|
31
|
+
exports.MAX_TOOL_ITERATIONS = 15;
|
|
32
|
+
exports.GRAPH_NODE_WALL_CLOCK_MS = 60_000;
|
|
33
|
+
const RETRY_INSTRUCTION = `Your previous attempt did not call any tools. You cannot answer a question about the company's data without first looking it up.
|
|
34
|
+
|
|
35
|
+
You must call at least one tool BEFORE producing a final answer. For a question that names an entity (a customer, person, product, project, work order, anything that could correspond to a record in the graph), the first tool call is always:
|
|
36
|
+
|
|
37
|
+
resolve_entity({ text: "<the user's literal phrase>" })
|
|
38
|
+
|
|
39
|
+
Inspect the returned candidates, pick a type, then call describe_entity and proceed with the typed tools (read_entity, search_entities, traverse) until you have the data the answer needs. Do not respond with prose alone — call the tool now.`;
|
|
40
|
+
const APOLOGY_REGEX = /^\s*(i am sorry|i'm sorry|i am unable|i cannot|please provide|could you (please )?specify)/i;
|
|
41
|
+
const graphOutputSchema = zod_1.z.object({
|
|
42
|
+
answer: zod_1.z.string(),
|
|
43
|
+
entities: zod_1.z.array(zod_1.z.object({
|
|
44
|
+
type: zod_1.z.string(),
|
|
45
|
+
id: zod_1.z.string(),
|
|
46
|
+
reason: zod_1.z.string(),
|
|
47
|
+
fields: zod_1.z.record(zod_1.z.string(), zod_1.z.any()).optional(),
|
|
48
|
+
})),
|
|
49
|
+
stop: zod_1.z.boolean(),
|
|
50
|
+
});
|
|
51
|
+
let GraphNodeService = GraphNodeService_1 = class GraphNodeService {
|
|
52
|
+
constructor(llm, graph,
|
|
53
|
+
// Preserved for DI shape compatibility with the (deleted) ChatbotService.
|
|
54
|
+
// Task 9.2 will decide whether to keep it. Do not remove.
|
|
55
|
+
factory, resolveTool, describeTool, searchTool, readTool, traverseTool, ws) {
|
|
56
|
+
this.llm = llm;
|
|
57
|
+
this.graph = graph;
|
|
58
|
+
this.factory = factory;
|
|
59
|
+
this.resolveTool = resolveTool;
|
|
60
|
+
this.describeTool = describeTool;
|
|
61
|
+
this.searchTool = searchTool;
|
|
62
|
+
this.readTool = readTool;
|
|
63
|
+
this.traverseTool = traverseTool;
|
|
64
|
+
this.ws = ws;
|
|
65
|
+
this.logger = new common_1.Logger(GraphNodeService_1.name);
|
|
66
|
+
}
|
|
67
|
+
async execute(params) {
|
|
68
|
+
const state = params.state;
|
|
69
|
+
const ctx = {
|
|
70
|
+
companyId: state.companyId,
|
|
71
|
+
userId: state.userId,
|
|
72
|
+
userModuleIds: state.userModuleIds ?? [],
|
|
73
|
+
};
|
|
74
|
+
if (ctx.userModuleIds.length === 0) {
|
|
75
|
+
const out = {
|
|
76
|
+
answer: "",
|
|
77
|
+
entities: [],
|
|
78
|
+
toolCalls: [],
|
|
79
|
+
tokens: { input: 0, output: 0 },
|
|
80
|
+
status: "skipped_no_modules",
|
|
81
|
+
};
|
|
82
|
+
return { graphContext: out, graphError: null, trace: { graph: this.traceFromOutput(out) } };
|
|
83
|
+
}
|
|
84
|
+
const recorder = [];
|
|
85
|
+
const typeIndex = this.graph.getTypeIndexFor(ctx.userModuleIds);
|
|
86
|
+
const systemPrompt = (0, graph_node_system_prompt_1.renderGraphNodeSystemPrompt)(typeIndex);
|
|
87
|
+
let tools = [
|
|
88
|
+
this.resolveTool.build(ctx, recorder),
|
|
89
|
+
this.describeTool.build(ctx, recorder),
|
|
90
|
+
this.searchTool.build(ctx, recorder),
|
|
91
|
+
this.readTool.build(ctx, recorder),
|
|
92
|
+
this.traverseTool.build(ctx, recorder),
|
|
93
|
+
];
|
|
94
|
+
if (this.ws) {
|
|
95
|
+
const ws = this.ws;
|
|
96
|
+
const userId = state.userId;
|
|
97
|
+
tools = tools.map((t) => new tools_1.DynamicStructuredTool({
|
|
98
|
+
name: t.name,
|
|
99
|
+
description: t.description,
|
|
100
|
+
schema: t.schema,
|
|
101
|
+
func: async (input) => {
|
|
102
|
+
try {
|
|
103
|
+
await ws.sendMessageToUser(userId, "assistant:status", {
|
|
104
|
+
status: (0, humanize_tool_1.humanizeTool)(t.name, input),
|
|
105
|
+
at: new Date().toISOString(),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch (err) {
|
|
109
|
+
this.logger.warn(`assistant:status emit failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
110
|
+
}
|
|
111
|
+
return t.func(input);
|
|
112
|
+
},
|
|
113
|
+
}));
|
|
114
|
+
}
|
|
115
|
+
const history = (state.chatHistory ?? []).map((m) => ({
|
|
116
|
+
role: (m.role ?? m.type),
|
|
117
|
+
content: m.content,
|
|
118
|
+
}));
|
|
119
|
+
const startedAt = Date.now();
|
|
120
|
+
try {
|
|
121
|
+
let response = await this.llm.call({
|
|
122
|
+
systemPrompts: [systemPrompt],
|
|
123
|
+
history,
|
|
124
|
+
outputSchema: graphOutputSchema,
|
|
125
|
+
inputParams: {
|
|
126
|
+
question: state.question,
|
|
127
|
+
contentScope: state.contentId && state.contentType ? `${state.contentType}:${state.contentId}` : null,
|
|
128
|
+
},
|
|
129
|
+
tools,
|
|
130
|
+
maxToolIterations: exports.MAX_TOOL_ITERATIONS,
|
|
131
|
+
temperature: 0.1,
|
|
132
|
+
metadata: this.buildMetadata(state),
|
|
133
|
+
});
|
|
134
|
+
// Zero-tool-call retry: the first attempt produced no searches at all.
|
|
135
|
+
// Re-invoke with an explicit instruction that data must be looked up
|
|
136
|
+
// before answering.
|
|
137
|
+
if (recorder.length === 0) {
|
|
138
|
+
this.logger.warn(`graph node: zero tool calls on first attempt — retrying with RETRY_INSTRUCTION`);
|
|
139
|
+
response = await this.llm.call({
|
|
140
|
+
systemPrompts: [systemPrompt, RETRY_INSTRUCTION],
|
|
141
|
+
history,
|
|
142
|
+
outputSchema: graphOutputSchema,
|
|
143
|
+
inputParams: {
|
|
144
|
+
question: state.question,
|
|
145
|
+
contentScope: state.contentId && state.contentType ? `${state.contentType}:${state.contentId}` : null,
|
|
146
|
+
},
|
|
147
|
+
tools,
|
|
148
|
+
maxToolIterations: exports.MAX_TOOL_ITERATIONS,
|
|
149
|
+
temperature: 0.1,
|
|
150
|
+
metadata: this.buildMetadata(state),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Error-recovery retry: at least one tool call failed AND the model
|
|
154
|
+
// bounced an apology to the user instead of correcting and retrying.
|
|
155
|
+
// Force another pass with the failing call's error message in context.
|
|
156
|
+
const erroredCalls = recorder.filter((c) => c.error);
|
|
157
|
+
const answerSoundsApologetic = APOLOGY_REGEX.test(typeof response.answer === "string" ? response.answer : "");
|
|
158
|
+
if (erroredCalls.length > 0 && answerSoundsApologetic) {
|
|
159
|
+
const lastError = erroredCalls[erroredCalls.length - 1];
|
|
160
|
+
const recoveryInstruction = `A previous tool call failed and you responded to the user with an apology instead of retrying. That is wrong — the user did not cause the error. Read the error message carefully, correct the arguments, and call the tool again.
|
|
161
|
+
|
|
162
|
+
Most recent failing call:
|
|
163
|
+
tool: ${lastError.tool}
|
|
164
|
+
input: ${JSON.stringify(lastError.input)}
|
|
165
|
+
error: ${lastError.error}
|
|
166
|
+
|
|
167
|
+
If the error lists valid fields or relationships, pick one of those and retry now. Do not respond to the user until the tool succeeds or you have exhausted sensible options. Do not open your final answer with "I am sorry" or "I cannot".`;
|
|
168
|
+
this.logger.warn(`graph node: ${erroredCalls.length} tool error(s) + apologetic answer — retrying with recovery prompt`);
|
|
169
|
+
response = await this.llm.call({
|
|
170
|
+
systemPrompts: [systemPrompt, recoveryInstruction],
|
|
171
|
+
history,
|
|
172
|
+
outputSchema: graphOutputSchema,
|
|
173
|
+
inputParams: {
|
|
174
|
+
question: state.question,
|
|
175
|
+
contentScope: state.contentId && state.contentType ? `${state.contentType}:${state.contentId}` : null,
|
|
176
|
+
},
|
|
177
|
+
tools,
|
|
178
|
+
maxToolIterations: exports.MAX_TOOL_ITERATIONS,
|
|
179
|
+
temperature: 0.1,
|
|
180
|
+
metadata: this.buildMetadata(state),
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
// Structural data-loading retry: the LLM made tool calls but none of
|
|
184
|
+
// them successfully loaded data (read_entity / search_entities /
|
|
185
|
+
// traverse), AND returned no entities. This catches the most common
|
|
186
|
+
// laziness mode: the LLM resolves an entity, sees ambiguity or
|
|
187
|
+
// missing relationships, and gives up before fetching the records.
|
|
188
|
+
// Detected structurally — no regex on answer text.
|
|
189
|
+
const dataLoadingTools = new Set(["read_entity", "search_entities", "traverse"]);
|
|
190
|
+
const dataToolCallsBefore = recorder.filter((c) => dataLoadingTools.has(c.tool) && !c.error).length;
|
|
191
|
+
if (recorder.length > 0 && dataToolCallsBefore === 0) {
|
|
192
|
+
const triedTools = Array.from(new Set(recorder.map((c) => c.tool))).join(", ");
|
|
193
|
+
const dataLoadingRetry = `Your previous attempt called ${triedTools} but never successfully loaded data with read_entity, search_entities, or traverse. The user asked a data question; you must answer it.
|
|
194
|
+
|
|
195
|
+
Steps to take now:
|
|
196
|
+
1. Re-read your previous resolve_entity results. Pick the most plausible candidate by name match — an item whose name equals the user's literal phrase is the right pick.
|
|
197
|
+
2. Call describe_entity on the type(s) the question is about (both the resolved entity's type AND any target type the user is asking about).
|
|
198
|
+
3. Call traverse from the resolved entity along the relationship that leads to the records the user wants. If no direct relationship is listed, use search_entities on the target type with appropriate filters.
|
|
199
|
+
4. Call read_entity on each result to get the full fields.
|
|
200
|
+
5. Return the records in entities, with their fields populated.
|
|
201
|
+
|
|
202
|
+
Proceed now. Do not refuse, do not ask the user to clarify, do not apologise.`;
|
|
203
|
+
this.logger.warn(`graph node: ${recorder.length} tool call(s), 0 successful data loads — retrying with data-loading instruction`);
|
|
204
|
+
response = await this.llm.call({
|
|
205
|
+
systemPrompts: [systemPrompt, dataLoadingRetry],
|
|
206
|
+
history,
|
|
207
|
+
outputSchema: graphOutputSchema,
|
|
208
|
+
inputParams: {
|
|
209
|
+
question: state.question,
|
|
210
|
+
contentScope: state.contentId && state.contentType ? `${state.contentType}:${state.contentId}` : null,
|
|
211
|
+
},
|
|
212
|
+
tools,
|
|
213
|
+
maxToolIterations: exports.MAX_TOOL_ITERATIONS,
|
|
214
|
+
temperature: 0.1,
|
|
215
|
+
metadata: this.buildMetadata(state),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
// Honesty rewrite: even after the zero-tool retry the model produced no
|
|
219
|
+
// tool calls. Replace its `answer` with an explicit failure message
|
|
220
|
+
// rather than letting the synthesizer downstream see prose pretending
|
|
221
|
+
// to have looked something up.
|
|
222
|
+
if (recorder.length === 0) {
|
|
223
|
+
this.logger.warn(`graph node: still 0 tool calls after retry — rewriting answer to honest failure`);
|
|
224
|
+
response = {
|
|
225
|
+
...response,
|
|
226
|
+
answer: "I was unable to answer this question — I did not call any tool to look up data for it, so I cannot provide a real response. Please try rephrasing, or ask about a specific entity by name.",
|
|
227
|
+
entities: [],
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
const wallclockHit = Date.now() - startedAt > exports.GRAPH_NODE_WALL_CLOCK_MS;
|
|
231
|
+
const iterationsHit = recorder.length >= exports.MAX_TOOL_ITERATIONS;
|
|
232
|
+
const status = wallclockHit || iterationsHit ? "partial" : "success";
|
|
233
|
+
const entities = (response.entities ?? []).map((e, idx) => ({
|
|
234
|
+
type: e.type,
|
|
235
|
+
id: e.id,
|
|
236
|
+
reason: e.reason ?? "",
|
|
237
|
+
foundAtHop: idx,
|
|
238
|
+
...(e.fields && Object.keys(e.fields).length > 0 ? { fields: e.fields } : {}),
|
|
239
|
+
}));
|
|
240
|
+
const answerText = typeof response.answer === "string" ? response.answer : "";
|
|
241
|
+
this.logger.log(`graph node done: status=${status} toolCalls=${recorder.length} entities=${entities.length} ` +
|
|
242
|
+
`withFields=${entities.filter((e) => e.fields).length} ` +
|
|
243
|
+
`answerChars=${answerText.length} ` +
|
|
244
|
+
`tokens=${JSON.stringify(response.tokenUsage ?? { input: 0, output: 0 })}`);
|
|
245
|
+
this.logger.debug(`graph node tool sequence: ${recorder.map((r) => r.tool).join(" → ") || "(none)"}`);
|
|
246
|
+
this.logger.debug(`graph node entities returned: ${JSON.stringify(entities.map((e) => ({
|
|
247
|
+
type: e.type,
|
|
248
|
+
id: e.id,
|
|
249
|
+
reason: e.reason,
|
|
250
|
+
fieldKeys: e.fields ? Object.keys(e.fields) : [],
|
|
251
|
+
})))}`);
|
|
252
|
+
const out = {
|
|
253
|
+
answer: answerText,
|
|
254
|
+
entities,
|
|
255
|
+
toolCalls: recorder,
|
|
256
|
+
tokens: response.tokenUsage ?? { input: 0, output: 0 },
|
|
257
|
+
status,
|
|
258
|
+
};
|
|
259
|
+
return { graphContext: out, graphError: null, trace: { graph: this.traceFromOutput(out) } };
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
263
|
+
this.logger.warn(`graph node failed: ${message}`);
|
|
264
|
+
const out = {
|
|
265
|
+
answer: "",
|
|
266
|
+
entities: [],
|
|
267
|
+
toolCalls: recorder,
|
|
268
|
+
tokens: { input: 0, output: 0 },
|
|
269
|
+
status: "failed",
|
|
270
|
+
errorMessage: message,
|
|
271
|
+
};
|
|
272
|
+
return { graphContext: out, graphError: message, trace: { graph: this.traceFromOutput(out) } };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
traceFromOutput(out) {
|
|
276
|
+
const materialisedBridges = [];
|
|
277
|
+
for (const c of out.toolCalls) {
|
|
278
|
+
if (!c.materialised?.length)
|
|
279
|
+
continue;
|
|
280
|
+
const total = c.materialised.reduce((acc, m) => acc + m.count, 0);
|
|
281
|
+
const inputType = typeof c.input.type === "string"
|
|
282
|
+
? c.input.type
|
|
283
|
+
: typeof c.input.fromType === "string"
|
|
284
|
+
? c.input.fromType
|
|
285
|
+
: "?";
|
|
286
|
+
materialisedBridges.push({ tool: c.tool, type: inputType, count: total });
|
|
287
|
+
}
|
|
288
|
+
return {
|
|
289
|
+
toolCalls: out.toolCalls,
|
|
290
|
+
entitiesDiscovered: out.entities.length,
|
|
291
|
+
status: out.status,
|
|
292
|
+
errorMessage: out.errorMessage,
|
|
293
|
+
tokens: out.tokens,
|
|
294
|
+
...(materialisedBridges.length ? { materialisedBridges } : {}),
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
buildMetadata(state) {
|
|
298
|
+
return {
|
|
299
|
+
nodeName: "graph",
|
|
300
|
+
agentName: "responder",
|
|
301
|
+
userQuestion: state.question,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
exports.GraphNodeService = GraphNodeService;
|
|
306
|
+
exports.GraphNodeService = GraphNodeService = GraphNodeService_1 = __decorate([
|
|
307
|
+
(0, common_1.Injectable)(),
|
|
308
|
+
__param(8, (0, common_1.Optional)()),
|
|
309
|
+
__metadata("design:paramtypes", [llm_service_1.LLMService,
|
|
310
|
+
graph_catalog_service_1.GraphCatalogService,
|
|
311
|
+
tool_factory_1.ToolFactory,
|
|
312
|
+
resolve_entity_tool_1.ResolveEntityTool,
|
|
313
|
+
describe_entity_tool_1.DescribeEntityTool,
|
|
314
|
+
search_entities_tool_1.SearchEntitiesTool,
|
|
315
|
+
read_entity_tool_1.ReadEntityTool,
|
|
316
|
+
traverse_tool_1.TraverseTool,
|
|
317
|
+
websocket_service_1.WebSocketService])
|
|
318
|
+
], GraphNodeService);
|
|
319
|
+
//# sourceMappingURL=graph.node.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.node.service.js","sourceRoot":"","sources":["../../../../src/agents/responder/nodes/graph.node.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA8D;AAC9D,6BAAwB;AACxB,iDAA8D;AAC9D,0FAAsF;AACtF,wEAAoE;AACpE,sFAAiF;AACjF,iEAA6E;AAC7E,+EAA0E;AAC1E,iFAA4E;AAC5E,iFAA4E;AAC5E,yEAAoE;AACpE,mEAA+D;AAC/D,2FAA2F;AAC3F,sEAAkE;AAIrD,QAAA,mBAAmB,GAAG,EAAE,CAAC;AACzB,QAAA,wBAAwB,GAAG,MAAM,CAAC;AAE/C,MAAM,iBAAiB,GAAG;;;;;;iPAMuN,CAAC;AAElP,MAAM,aAAa,GAAG,6FAA6F,CAAC;AAEpH,MAAM,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACjC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE;IA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,GAAG,CAAC;YACZ,mBAAmB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5E,CAAC;QACD,OAAO;YACL,SAAS,EAAE,GAAG,CAAC,SAAS;YACxB,kBAAkB,EAAE,GAAG,CAAC,QAAQ,CAAC,MAAM;YACvC,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,YAAY,EAAE,GAAG,CAAC,YAAY;YAC9B,MAAM,EAAE,GAAG,CAAC,MAAM;YAClB,GAAG,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/D,CAAC;IACJ,CAAC;IAEO,aAAa,CAAC,KAA4B;QAChD,OAAO;YACL,QAAQ,EAAE,OAAO;YACjB,SAAS,EAAE,WAAW;YACtB,YAAY,EAAE,KAAK,CAAC,QAAQ;SAC7B,CAAC;IACJ,CAAC;CACF,CAAA;AA5RY,4CAAgB;2BAAhB,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAgBR,WAAA,IAAA,iBAAQ,GAAE,CAAA;qCAXW,wBAAU;QACR,2CAAmB;QAIjB,0BAAW;QACP,uCAAiB;QAChB,yCAAkB;QACpB,yCAAkB;QACpB,iCAAc;QACV,4BAAY;QACT,oCAAgB;GAfzC,gBAAgB,CA4R5B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { LLMService } from "../../../core/llm/services/llm.service";
|
|
2
|
+
import { GraphCatalogService } from "../../graph/services/graph.catalog.service";
|
|
3
|
+
import { ResponderContextState } from "../contexts/responder.context";
|
|
4
|
+
export declare const PLANNER_SYSTEM_PROMPT = "\nYou decide which retrieval branches a unified assistant should run for a single user turn.\n\nYou have three branches to choose from (subset, not exclusive):\n- runGraph \u2192 traverses entities (accounts, orders, etc.) the user has access to via tools\n- runContextualiser \u2192 multi-hop document retrieval (chunks, atomic facts, key concepts)\n- runDrift \u2192 community-level summary search\n\nDecide based on the user's question, prior chat history, the available entity catalog, and any content scope.\nYou MUST select at least one branch. Prefer multiple branches in parallel when the question could plausibly draw on more than one.\n\nRefine the question into a single canonical form that all chosen branches can use.\n\nWhen you produce `refinedQuestion`, preserve every proper-noun-looking span in the user's question verbatim. Do not change \"and\" to \"or\" (or vice versa) inside what could be a name; do not collapse, expand, split, or pluralise names. The graph branch uses `refinedQuestion` as the user's literal phrase to look up records \u2014 paraphrasing breaks the lookup. If you must restructure the question, do so around the names, not over them.\n\nReturn STRICTLY: { runGraph, runContextualiser, runDrift, reasoning, refinedQuestion }.\n";
|
|
5
|
+
export declare class PlannerNodeService {
|
|
6
|
+
private readonly llm;
|
|
7
|
+
private readonly catalog;
|
|
8
|
+
private readonly logger;
|
|
9
|
+
constructor(llm: LLMService, catalog: GraphCatalogService);
|
|
10
|
+
execute(params: {
|
|
11
|
+
state: ResponderContextState;
|
|
12
|
+
}): Promise<Partial<ResponderContextState>>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=planner.node.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.node.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/responder/nodes/planner.node.service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,4CAA4C,CAAC;AACjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAiBtE,eAAO,MAAM,qBAAqB,uwCAgBjC,CAAC;AAEF,qBACa,kBAAkB;IAI3B,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuC;gBAG3C,GAAG,EAAE,UAAU,EACf,OAAO,EAAE,mBAAmB;IAGzC,OAAO,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,qBAAqB,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CA+DjG"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var PlannerNodeService_1;
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.PlannerNodeService = exports.PLANNER_SYSTEM_PROMPT = void 0;
|
|
14
|
+
const common_1 = require("@nestjs/common");
|
|
15
|
+
const zod_1 = require("zod");
|
|
16
|
+
const llm_service_1 = require("../../../core/llm/services/llm.service");
|
|
17
|
+
const graph_catalog_service_1 = require("../../graph/services/graph.catalog.service");
|
|
18
|
+
const PlannerOutputSchema = zod_1.z.object({
|
|
19
|
+
runGraph: zod_1.z.boolean(),
|
|
20
|
+
runContextualiser: zod_1.z.boolean(),
|
|
21
|
+
runDrift: zod_1.z.boolean(),
|
|
22
|
+
reasoning: zod_1.z.string(),
|
|
23
|
+
refinedQuestion: zod_1.z.string(),
|
|
24
|
+
});
|
|
25
|
+
const PlannerInputSchema = zod_1.z.object({
|
|
26
|
+
rawQuestion: zod_1.z.string(),
|
|
27
|
+
catalog: zod_1.z.string(),
|
|
28
|
+
history: zod_1.z.array(zod_1.z.object({ role: zod_1.z.string(), content: zod_1.z.string() })),
|
|
29
|
+
contentScope: zod_1.z.object({ contentType: zod_1.z.string(), contentId: zod_1.z.string() }).nullable(),
|
|
30
|
+
});
|
|
31
|
+
exports.PLANNER_SYSTEM_PROMPT = `
|
|
32
|
+
You decide which retrieval branches a unified assistant should run for a single user turn.
|
|
33
|
+
|
|
34
|
+
You have three branches to choose from (subset, not exclusive):
|
|
35
|
+
- runGraph → traverses entities (accounts, orders, etc.) the user has access to via tools
|
|
36
|
+
- runContextualiser → multi-hop document retrieval (chunks, atomic facts, key concepts)
|
|
37
|
+
- runDrift → community-level summary search
|
|
38
|
+
|
|
39
|
+
Decide based on the user's question, prior chat history, the available entity catalog, and any content scope.
|
|
40
|
+
You MUST select at least one branch. Prefer multiple branches in parallel when the question could plausibly draw on more than one.
|
|
41
|
+
|
|
42
|
+
Refine the question into a single canonical form that all chosen branches can use.
|
|
43
|
+
|
|
44
|
+
When you produce \`refinedQuestion\`, preserve every proper-noun-looking span in the user's question verbatim. Do not change "and" to "or" (or vice versa) inside what could be a name; do not collapse, expand, split, or pluralise names. The graph branch uses \`refinedQuestion\` as the user's literal phrase to look up records — paraphrasing breaks the lookup. If you must restructure the question, do so around the names, not over them.
|
|
45
|
+
|
|
46
|
+
Return STRICTLY: { runGraph, runContextualiser, runDrift, reasoning, refinedQuestion }.
|
|
47
|
+
`;
|
|
48
|
+
let PlannerNodeService = PlannerNodeService_1 = class PlannerNodeService {
|
|
49
|
+
constructor(llm, catalog) {
|
|
50
|
+
this.llm = llm;
|
|
51
|
+
this.catalog = catalog;
|
|
52
|
+
this.logger = new common_1.Logger(PlannerNodeService_1.name);
|
|
53
|
+
}
|
|
54
|
+
async execute(params) {
|
|
55
|
+
const state = params.state;
|
|
56
|
+
const catalogText = this.catalog.getTypeIndexFor(state.userModuleIds ?? []);
|
|
57
|
+
const history = (state.chatHistory ?? []).map((m) => ({ role: String(m.type), content: m.content }));
|
|
58
|
+
const contentScope = state.contentId && state.contentType ? { contentType: state.contentType, contentId: state.contentId } : null;
|
|
59
|
+
try {
|
|
60
|
+
const out = await this.llm.call({
|
|
61
|
+
systemPrompts: [exports.PLANNER_SYSTEM_PROMPT],
|
|
62
|
+
inputSchema: PlannerInputSchema,
|
|
63
|
+
inputParams: {
|
|
64
|
+
rawQuestion: state.rawQuestion,
|
|
65
|
+
catalog: catalogText,
|
|
66
|
+
history,
|
|
67
|
+
contentScope,
|
|
68
|
+
},
|
|
69
|
+
outputSchema: PlannerOutputSchema,
|
|
70
|
+
temperature: 0.0,
|
|
71
|
+
metadata: {
|
|
72
|
+
nodeName: "planner",
|
|
73
|
+
agentName: "responder",
|
|
74
|
+
userQuestion: state.rawQuestion,
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
const branchPlan = {
|
|
78
|
+
runGraph: out.runGraph,
|
|
79
|
+
runContextualiser: out.runContextualiser,
|
|
80
|
+
runDrift: out.runDrift,
|
|
81
|
+
reasoning: out.reasoning,
|
|
82
|
+
};
|
|
83
|
+
const tokens = out.tokenUsage ?? { input: 0, output: 0 };
|
|
84
|
+
return {
|
|
85
|
+
branchPlan,
|
|
86
|
+
question: out.refinedQuestion,
|
|
87
|
+
plannerError: null,
|
|
88
|
+
trace: {
|
|
89
|
+
planner: { reasoning: out.reasoning, branchPlan, tokens },
|
|
90
|
+
totalTokens: tokens,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
catch (err) {
|
|
95
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
96
|
+
this.logger.warn(`planner LLM failed — fallback engaged: ${message}`);
|
|
97
|
+
const branchPlan = {
|
|
98
|
+
runGraph: true,
|
|
99
|
+
runContextualiser: true,
|
|
100
|
+
runDrift: false,
|
|
101
|
+
reasoning: "planner_fallback",
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
branchPlan,
|
|
105
|
+
question: state.rawQuestion,
|
|
106
|
+
plannerError: message,
|
|
107
|
+
trace: {
|
|
108
|
+
planner: { reasoning: "planner_fallback", branchPlan, tokens: { input: 0, output: 0 } },
|
|
109
|
+
totalTokens: { input: 0, output: 0 },
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
exports.PlannerNodeService = PlannerNodeService;
|
|
116
|
+
exports.PlannerNodeService = PlannerNodeService = PlannerNodeService_1 = __decorate([
|
|
117
|
+
(0, common_1.Injectable)(),
|
|
118
|
+
__metadata("design:paramtypes", [llm_service_1.LLMService,
|
|
119
|
+
graph_catalog_service_1.GraphCatalogService])
|
|
120
|
+
], PlannerNodeService);
|
|
121
|
+
//# sourceMappingURL=planner.node.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.node.service.js","sourceRoot":"","sources":["../../../../src/agents/responder/nodes/planner.node.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,2CAAoD;AACpD,6BAAwB;AACxB,wEAAoE;AACpE,sFAAiF;AAGjF,MAAM,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IACnC,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE;IACrB,iBAAiB,EAAE,OAAC,CAAC,OAAO,EAAE;IAC9B,QAAQ,EAAE,OAAC,CAAC,OAAO,EAAE;IACrB,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE;IACrB,eAAe,EAAE,OAAC,CAAC,MAAM,EAAE;CAC5B,CAAC,CAAC;AAEH,MAAM,kBAAkB,GAAG,OAAC,CAAC,MAAM,CAAC;IAClC,WAAW,EAAE,OAAC,CAAC,MAAM,EAAE;IACvB,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,OAAO,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE,EAAE,OA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AAS,EAAE,kBAAkB;aAC9B,CAAC;YACF,OAAO;gBACL,UAAU;gBACV,QAAQ,EAAE,KAAK,CAAC,WAAW;gBAC3B,YAAY,EAAE,OAAO;gBACrB,KAAK,EAAE;oBACL,OAAO,EAAE,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE;oBACvF,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE;iBAC9B;aACT,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAA;AAvEY,gDAAkB;6BAAlB,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAKa,wBAAU;QACN,2CAAmB;GALpC,kBAAkB,CAuE9B"}
|
|
@@ -2,7 +2,7 @@ import { ConfigService } from "@nestjs/config";
|
|
|
2
2
|
import { BaseConfigInterface } from "../../../config/interfaces";
|
|
3
3
|
import { LLMService } from "../../../core/llm/services/llm.service";
|
|
4
4
|
import { ResponderContext, ResponderContextState } from "../../responder/contexts/responder.context";
|
|
5
|
-
export declare const defaultAnswerPrompt = "\nAs an intelligent assistant, your primary objective is to answer questions based on information within a text.\nYou have explored multiple paths from various starting nodes on a graph, recording key information for each path in a **notebook**.\nYour task now is to **analyze these memories and reason to answer the question**. \n\n---\n\n### **Strategy:**\n\n1. **Provide a Title**:\n - Create a short **title** that the user can read as a quick reference.\n\n2. **Analyze Notebook Content**:\n - Carefully review each entry in your notebook before providing a final answer.\n - Consider complementary information from different notes.\n\n3. **Assess Availability of Information**:\n - Determine whether the notebook contains **explicit and sufficient information** to answer the question.\n - **Do not infer or assume information** not explicitly present in the notebook.\n - **If the notebook contains sufficient information**, proceed to formulate the final answer using only the information provided.\n - **If the notebook does NOT contain enough information**, clearly state that the answer to the question is not available in the company knowledge.\n - **Do not use any external information, prior knowledge, or make assumptions beyond what is in the notebook.**\n\n4. **Citations with Relevance Scores**:\n - For each line in your notebook, consider the **chunkId** at the beginning of the line.\n - **ChunkIds are valid UUIDs** (e.g., '123e4567-e89b-12d3-a456-426614174000').\n - **Use only the chunkIds provided in the notebook**. **Do not invent or make up chunkIds**.\n - **Do not use line numbers or indices as chunkIds**.\n - Assign a **percentage relevance score** to indicate how much each line influenced your final answer.\n - This relevance score reflects the parts of your thought process used to generate the answer and will be used for citations.\n - **If the notebook is empty or lacks relevant information, the citations section should be empty.**\n\n5. **Generate Follow-up Questions**:\n - **If sufficient information is available**, provide a list of **5 follow-up or refinement questions** based on the final answer.\n - **If the answer is not available**, **do not generate any follow-up questions**.\n\n6. **Provide a Comprehensive Final Answer**:\n - **When sufficient information is available**, create a thorough, detailed, and well-structured response that goes beyond minimal explanations.\n - **Expand on concepts thoroughly**: Don't just state facts - explain them, provide context, and help users understand the complete picture.\n - **Use structured formatting**: Organize content with headers, subheadings, bullet points, and numbered lists to make complex information digestible.\n - **Be educational and informative**: Treat each answer as an opportunity to teach and provide comprehensive understanding of the topic.\n - **If the answer is not available**, clearly inform the user that the information is not present in the company knowledge.\n - **Format Requirements for Comprehensive Answers**:\n - Use proper markdown formatting with headers (##, ###) to organize different sections\n - Include bullet points or numbered lists when presenting multiple items or steps\n - Expand on concepts with detailed explanations rather than brief summaries\n - Use subheadings to break down complex topics into digestible sections\n - Provide context and background information when relevant to help users understand the full picture\n - Include examples or specific details from the notebook when available\n - Ensure the answer flows logically from one section to another\n - Make the response comprehensive, detailed, and educational rather than minimalistic\n - **Do not include any technical terms** such as \"nodes,\" \"text chunks,\" or \"atomic facts\" in your final answer or title.\n - Avoid using technical jargon and ensure the response is user-friendly while being comprehensive.\n\n---\n\n### **Important Notes:**\n\n- **Use Only Notebook Information**:\n - Do not use any external sources, prior knowledge, or make up information not present in the notebook.\n - Do not provide definitions, explanations, or details that are not explicitly stated in the notebook.\n\n- **No Paraphrasing Beyond Notebook Content**:\n - Do not restate or rephrase the notebook content as the final answer unless it directly and explicitly answers the question.\n\n- **Do Not Infer or Assume**:\n - Avoid making inferences or assumptions based on partial information.\n - If the notebook does not explicitly provide the answer, acknowledge that the information is not available.\n\n- **Do Not guess the presume to know the acronyms**:\n - If your notebook contains the definition of an acronym, you can use it, but if the precise definition of the acronym does NOT exist in the notebook, you must not use it.\n - NEVER GUESS an ACRONYM. If you don't have a clear definition in the notebook, use only the acronym and don't try to explain it.\n - **NEVER** write your own definitions or explanations for acronyms. An acronym is a word on its own, and you don't have to explain it.\n\n- **ChunkIds Must Match Exactly**:\n - Use only the actual chunkIds provided in the notebook entries.\n - **ChunkIds are valid UUIDs**. Do not use line numbers, indices, or any other placeholders.\n - **Do not invent or make up chunkIds**.\n\n- **Empty or Insufficient Notebook Handling**:\n - If the notebook is empty or lacks sufficient information, acknowledge this in your analysis and final answer.\n - **Do not provide a final answer based on assumptions or external knowledge**.\n - **Do not generate any follow-up questions if the answer is not available**.\n\n- **Provide Clear and User-Friendly Responses**:\n - Communicate clearly without technical jargon.\n - Do not include any technical terms such as \"nodes,\" \"text chunks,\" or \"atomic facts\" in your final answer or title.\n\n---\n\n### **Expected Output Format:**\n\nYour output should include the following fields in the order specified:\n\n- **Title**: A short title providing the user with a quick reference to the answer.\n\n- **Analyse**:\n - An analysis of the notebook content, considering complementary information and resolving inconsistencies.\n - State whether the notebook contains sufficient information to answer the question.\n - If not, acknowledge that the information is not available.\n\n- **Citations**:\n - A list of citations for the information you used to generate the final answer.\n - Each citation includes:\n - **chunkId**: The ID of the line in your notebook.\n - **relevance**: The relevance of the information in that line (as a percentage).\n - **If the notebook is empty or lacks relevant information, the citations section should be empty**.\n\n- **Questions**:\n - **If sufficient information is available**, provide a list of **5 follow-up or refinement questions** based on the final answer.\n - **If the answer is not available**, **do not generate any follow-up questions**.\n\n- **Final Answer**:\n - **If sufficient information is available**, provide a comprehensive, detailed, and well-structured answer, strictly using only the information from the notebook.\n - The answer should be thorough and educational, expanding on concepts with proper explanations.\n - Use markdown formatting with appropriate headers, subheadings, lists, and sections to organize the content clearly.\n - **If insufficient information is available**, state that the answer is not available in the company knowledge.\n\n---\n\n### **Example When Information Is Available:**\n\n**User:**\n\nQuestion: What is project management?\n\nNotebook of different exploration paths:\n\n- 123e4567-e89b-12d3-a456-426614174000: Project management is the application of processes, methods, skills, knowledge and experience to achieve specific project objectives.\n- 987f6543-e21a-34c5-b678-539725841901: Project management involves planning, organizing, securing, managing, leading, and controlling resources to achieve specific goals.\n- 456a1234-f56b-78c9-d012-345678901234: The primary challenge of project management is to achieve all project goals within the given constraints like time, budget, and scope.\n\n**Assistant:**\n\n**Title:**\n\nUnderstanding Project Management: Processes, Goals, and Constraints\n\n**Analyse:**\n\nThe notebook contains comprehensive information about project management, covering its definition, key activities, and primary challenges. The information is consistent across different sources and provides a complete foundation for explaining what project management entails.\n\n**Citations:**\n\n- chunkId: \"123e4567-e89b-12d3-a456-426614174000\", relevance: 95\n- chunkId: \"987f6543-e21a-34c5-b678-539725841901\", relevance: 90\n- chunkId: \"456a1234-f56b-78c9-d012-345678901234\", relevance: 85\n\n**Questions:**\n\n1. What specific methodologies are commonly used in project management?\n2. How do project managers handle scope creep and changing requirements?\n3. What tools and software are most effective for project planning and tracking?\n4. How does project management differ across various industries?\n5. What skills are essential for becoming an effective project manager?\n\n**Final Answer:**\n\n## What is Project Management?\n\nProject management is a comprehensive discipline that involves **the application of processes, methods, skills, knowledge, and experience to achieve specific project objectives**. It represents a structured approach to turning ideas and goals into tangible results within defined parameters.\n\n### Core Components of Project Management\n\nProject management encompasses several critical activities that work together to ensure project success:\n\n- **Planning**: Establishing clear objectives, timelines, and resource requirements\n- **Organizing**: Structuring teams, workflows, and project elements efficiently\n- **Securing**: Obtaining necessary resources, approvals, and stakeholder buy-in\n- **Managing**: Overseeing day-to-day operations and progress monitoring\n- **Leading**: Guiding teams and stakeholders toward common goals\n- **Controlling**: Monitoring performance and making necessary adjustments\n\n### The Primary Challenge\n\nThe fundamental challenge of project management lies in **achieving all project goals within the given constraints**. These constraints typically include:\n\n- **Time**: Meeting established deadlines and milestones\n- **Budget**: Staying within allocated financial resources\n- **Scope**: Delivering all required features and functionality without exceeding boundaries\n\n### Why Project Management Matters\n\nProject management serves as the bridge between conceptual ideas and practical implementation. By applying systematic approaches and proven methodologies, project managers help organizations transform vision into reality while minimizing risks and maximizing efficiency.\n\nThe discipline ensures that resources are used effectively, stakeholders remain aligned, and deliverables meet quality standards within the established timeframe and budget constraints.\n\n---\n\n### **Example When Information Is Not Available:**\n\n**User:**\n\nQuestion: What is Ontology?\n\nNotebook of different exploration paths:\n\n- *(Notebook is empty or does not contain relevant information.)*\n\n**Assistant:**\n\n**Title:**\n\nInformation on Ontology\n\n**Analyse:**\n\n- After reviewing the notebook, there is no information available regarding the definition or explanation of ontology.\n- The notebook does not contain sufficient information to answer the question.\n\n**Citations:**\n\n*(No citations since the notebook is empty or lacks relevant information.)*\n\n**Questions:**\n\n*(No questions since the answer is not available.)*\n\n**Final Answer:**\n\nThe answer to your question is not available in the company knowledge. There is insufficient information to explain what ontology is based on the provided data.\n\n---\n\n### **Please Proceed by Following These Instructions Carefully:**\n\n- **Use Only Information Provided in the Notebook**:\n - Do not incorporate any external knowledge or make assumptions.\n - Do not provide definitions or explanations that are not explicitly in the notebook.\n\n- **Do Not Restate Notebook Content as Answer**:\n - Unless the notebook explicitly answers the question, do not restate the notebook content as the final answer.\n\n- **ChunkIds are Valid UUIDs**:\n - Use only the chunkIds provided in the notebook, which are valid UUIDs (e.g., '123e4567-e89b-12d3-a456-426614174000').\n - **Do not invent or make up chunkIds**.\n - **Do not use line numbers or indices as chunkIds**.\n\n- **Handle Empty or Insufficient Notebooks Appropriately**:\n - If the notebook is empty or lacks sufficient information, acknowledge this in your analysis and final answer.\n - **Do not generate any follow-up questions if the answer is not available**.\n\n- **Provide Clear and User-Friendly Responses**:\n - Communicate clearly without technical jargon.\n\n---\n\nBy emphasizing that ChunkIds are valid UUIDs and that you should not invent or make up any chunkIds, as well as specifying that no follow-up questions should be generated if the answer is not available, this updated prompt should help prevent the LLM from including information from outside the notebook or making up chunkIds. It also clarifies how to handle situations where the notebook does not contain sufficient information to answer the question.\n";
|
|
5
|
+
export declare const defaultAnswerPrompt = "\nYou are the synthesizer of a unified ERP assistant. You are given a user\nquestion and the results of up to three retrieval branches that ran in\nparallel before you. Your job is to write a clear, useful answer using\nONLY the data those branches returned.\n\n## What you receive\n\nEach turn arrives with these inputs:\n\n- `question` \u2014 the user's refined question.\n- `graphSection` \u2014 the graph branch's own prose reply about the records it\n loaded, followed by an \"--- entities for citation ---\" block listing each\n cited entity as `[ref:N] type \u2014 reason` plus an optional JSON block of\n field values. Treat the prose at the top of `graphSection` as the\n authoritative graph result; weave it into the unified answer rather than\n restating the entity list line-by-line. The `[ref:N]` handles are opaque\n reference tokens \u2014 use them only inside the `references` array, never\n inside `finalAnswer` or `title`.\n- `notebookSection` \u2014 chunks the contextualiser branch retrieved from the\n document store, each prefixed with its chunkId followed by a snippet of\n text.\n- `driftSection` \u2014 community-level summaries (when the drift branch ran).\n- `scopeSection` \u2014 optional scope hint when the conversation is bound to a\n single content.\n- `branchesUsed` \u2014 list of branches that produced data this turn.\n\nA section is the empty string `\"\"` when its branch did not run. When all\ndata sections are empty, you have no information for this turn \u2014 say so\nplainly without referencing \"company knowledge\", \"notebook\", or other\nsystem internals.\n\n## How to write the answer\n\n1. **Identify the user's intent.** Are they asking for a list, a single\n fact, a procedure, a status, or a comparison? Match the answer's shape\n to the question.\n\n2. **Use the graph branch's prose as authoritative graph data.** The\n prose at the top of `graphSection` was written by the same component\n that loaded the records; it already contains the field values, names,\n and statuses. Weave it into `finalAnswer`. You may reorganise it,\n merge it with material from `notebookSection` or `driftSection`, or\n tighten the wording \u2014 but do not invent values that are not in the\n prose, the entity field blocks, or the chunks.\n\n3. **Quote chunk content faithfully.** When you draw from\n `notebookSection`, quote or paraphrase the snippet rather than\n substituting your own restatement.\n\n4. **Cite the chunks that grounded a document answer.** When you quote or\n paraphrase from `notebookSection`, add the chunkId to `citations` with\n a relevance score 0\u2013100. Use only chunkIds that actually appear in\n `notebookSection`. If `notebookSection` is empty, `citations` MUST be\n `[]`.\n\n5. **Cite the entities that grounded a graph answer.** Every entity whose\n information the answer relies on goes into `references` as\n `{ ref, relevance, reason }`, with the `ref` handle copied verbatim\n from the \"entities for citation\" block (e.g. `\"ref:0\"`). Never invent\n a handle. Never put a chunk into `references`; never put an entity\n into `citations`. If `graphSection` is empty, `references` MUST be\n `[]`.\n\n6. **No handles, no UUIDs in user-facing text.** `title` and\n `finalAnswer` must not contain the word \"ref\", the bracketed handle,\n or any UUID. The handles are translated back to real (type, id) pairs\n after you return.\n\n7. **Suggested questions are optional.** If the answer is solid and\n obvious next-step questions exist, propose 3\u20135; otherwise return `[]`.\n Do not return suggestions when you had no data.\n\n8. **No-data case.** If every data section is empty (or together they do\n not cover what the user asked), say so directly. Do not say \"answer\n is not available in the company knowledge\" \u2014 that is a bad system\n phrase. Return `citations: []` and `references: []` in this case.\n\n## Output schema\n\nReturn strictly:\n\n- `title` \u2014 short headline for the UI (under ~70 chars). No handles, no UUIDs.\n- `analyse` \u2014 one to three sentences describing how you derived the answer\n (which branches you used, which records you compared). Internal-facing.\n No handles.\n- `finalAnswer` \u2014 the user-facing markdown answer. Use headings sparingly,\n bullet lists where they help, and field values from the graph branch's\n prose and entity field blocks. No handles, no UUIDs.\n- `citations` \u2014 array of `{ chunkId, relevance }` for chunks you used.\n- `references` \u2014 array of `{ ref, relevance, reason }` for entities you used.\n- `questions` \u2014 array of follow-up question strings.\n";
|
|
6
6
|
export declare class ResponderAnswerNodeService {
|
|
7
7
|
private readonly llmService;
|
|
8
8
|
private readonly configService;
|
|
@@ -12,27 +12,9 @@ export declare class ResponderAnswerNodeService {
|
|
|
12
12
|
execute(params: {
|
|
13
13
|
state: typeof ResponderContext.State;
|
|
14
14
|
}): Promise<ResponderContextState>;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
/**
|
|
20
|
-
* Execute answer generation using both DRIFT (global) and Contextualiser (local) data
|
|
21
|
-
* Combines community-level insights with chunk-level citations
|
|
22
|
-
*/
|
|
23
|
-
private executeHybridMode;
|
|
24
|
-
/**
|
|
25
|
-
* Build global context section from DRIFT search results
|
|
26
|
-
*/
|
|
27
|
-
private buildGlobalContextSection;
|
|
28
|
-
/**
|
|
29
|
-
* Execute answer generation using DRIFT search data
|
|
30
|
-
* DRIFT already provides a synthesized answer, so we format it for the response
|
|
31
|
-
*/
|
|
32
|
-
private executeDriftMode;
|
|
33
|
-
/**
|
|
34
|
-
* Build analysis text from DRIFT context
|
|
35
|
-
*/
|
|
36
|
-
private buildDriftAnalysis;
|
|
15
|
+
private buildNotebookSection;
|
|
16
|
+
private buildGraphSection;
|
|
17
|
+
private buildDriftSection;
|
|
18
|
+
private deduplicateByChunkId;
|
|
37
19
|
}
|
|
38
20
|
//# sourceMappingURL=responder.answer.node.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responder.answer.node.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/responder/nodes/responder.answer.node.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;
|
|
1
|
+
{"version":3,"file":"responder.answer.node.service.d.ts","sourceRoot":"","sources":["../../../../src/agents/responder/nodes/responder.answer.node.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,mBAAmB,EAA0B,MAAM,4BAA4B,CAAC;AACzF,OAAO,EAAE,UAAU,EAAE,MAAM,wCAAwC,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAC;AAGrG,eAAO,MAAM,mBAAmB,olJA4F/B,CAAC;AAqEF,qBACa,0BAA0B;IAKnC,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,aAAa;IALhC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+C;IACtE,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;gBAGnB,UAAU,EAAE,UAAU,EACtB,aAAa,EAAE,aAAa,CAAC,mBAAmB,CAAC;IAM9D,OAAO,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,OAAO,gBAAgB,CAAC,KAAK,CAAA;KAAE,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAuI/F,OAAO,CAAC,oBAAoB;IAO5B,OAAO,CAAC,iBAAiB;IAkBzB,OAAO,CAAC,iBAAiB;IAgBzB,OAAO,CAAC,oBAAoB;CAc7B"}
|