@n8n/ai-workflow-builder 1.7.0 → 1.8.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/planner.agent.d.ts +80 -0
- package/dist/agents/planner.agent.js +133 -0
- package/dist/agents/planner.agent.js.map +1 -0
- package/dist/agents/responder.agent.d.ts +44 -9
- package/dist/agents/responder.agent.js +123 -85
- package/dist/agents/responder.agent.js.map +1 -1
- package/dist/agents/supervisor.agent.d.ts +5 -3
- package/dist/agents/supervisor.agent.js +6 -5
- package/dist/agents/supervisor.agent.js.map +1 -1
- package/dist/ai-workflow-builder-agent.service.d.ts +3 -0
- package/dist/ai-workflow-builder-agent.service.js +93 -3
- package/dist/ai-workflow-builder-agent.service.js.map +1 -1
- package/dist/build.tsbuildinfo +1 -1
- package/dist/constants.d.ts +3 -2
- package/dist/constants.js +5 -4
- package/dist/constants.js.map +1 -1
- package/dist/llm-config.d.ts +2 -1
- package/dist/llm-config.js +25 -1
- package/dist/llm-config.js.map +1 -1
- package/dist/multi-agent-workflow-subgraphs.d.ts +90 -6
- package/dist/multi-agent-workflow-subgraphs.js +94 -17
- package/dist/multi-agent-workflow-subgraphs.js.map +1 -1
- package/dist/parent-graph-state.d.ts +6 -0
- package/dist/parent-graph-state.js +20 -0
- package/dist/parent-graph-state.js.map +1 -1
- package/dist/prompts/agents/builder.prompt.d.ts +6 -1
- package/dist/prompts/agents/builder.prompt.js +535 -387
- package/dist/prompts/agents/builder.prompt.js.map +1 -1
- package/dist/prompts/agents/discovery.prompt.d.ts +1 -0
- package/dist/prompts/agents/discovery.prompt.js +334 -349
- package/dist/prompts/agents/discovery.prompt.js.map +1 -1
- package/dist/prompts/agents/index.d.ts +6 -0
- package/dist/prompts/agents/index.js +21 -0
- package/dist/prompts/agents/index.js.map +1 -0
- package/dist/prompts/agents/planner.prompt.d.ts +14 -0
- package/dist/prompts/agents/planner.prompt.js +77 -0
- package/dist/prompts/agents/planner.prompt.js.map +1 -0
- package/dist/prompts/agents/responder.prompt.js +35 -2
- package/dist/prompts/agents/responder.prompt.js.map +1 -1
- package/dist/prompts/agents/supervisor.prompt.js +3 -4
- package/dist/prompts/agents/supervisor.prompt.js.map +1 -1
- package/dist/prompts/index.d.ts +4 -4
- package/dist/prompts/index.js +11 -4
- package/dist/prompts/index.js.map +1 -1
- package/dist/session-manager.service.d.ts +18 -0
- package/dist/session-manager.service.js +154 -1
- package/dist/session-manager.service.js.map +1 -1
- package/dist/subgraphs/builder.subgraph.d.ts +31 -2
- package/dist/subgraphs/builder.subgraph.js +141 -35
- package/dist/subgraphs/builder.subgraph.js.map +1 -1
- package/dist/subgraphs/discovery.subgraph.d.ts +87 -27
- package/dist/subgraphs/discovery.subgraph.js +204 -24
- package/dist/subgraphs/discovery.subgraph.js.map +1 -1
- package/dist/tools/add-node.tool.d.ts +36 -0
- package/dist/tools/add-node.tool.js +28 -8
- package/dist/tools/add-node.tool.js.map +1 -1
- package/dist/tools/best-practices/triage.js +5 -5
- package/dist/tools/builder-tools.js +6 -1
- package/dist/tools/builder-tools.js.map +1 -1
- package/dist/tools/connect-nodes.tool.js +16 -3
- package/dist/tools/connect-nodes.tool.js.map +1 -1
- package/dist/tools/get-execution-logs.tool.d.ts +4 -0
- package/dist/tools/get-execution-logs.tool.js +104 -0
- package/dist/tools/get-execution-logs.tool.js.map +1 -0
- package/dist/tools/get-execution-schema.tool.d.ts +4 -0
- package/dist/tools/get-execution-schema.tool.js +81 -0
- package/dist/tools/get-execution-schema.tool.js.map +1 -0
- package/dist/tools/get-expression-data-mapping.tool.d.ts +4 -0
- package/dist/tools/get-expression-data-mapping.tool.js +85 -0
- package/dist/tools/get-expression-data-mapping.tool.js.map +1 -0
- package/dist/tools/get-node-context.tool.d.ts +13 -0
- package/dist/tools/get-node-context.tool.js +227 -0
- package/dist/tools/get-node-context.tool.js.map +1 -0
- package/dist/tools/get-node-parameter.tool.js +1 -2
- package/dist/tools/get-node-parameter.tool.js.map +1 -1
- package/dist/tools/get-workflow-overview.tool.d.ts +11 -0
- package/dist/tools/get-workflow-overview.tool.js +158 -0
- package/dist/tools/get-workflow-overview.tool.js.map +1 -0
- package/dist/tools/helpers/state.d.ts +1 -0
- package/dist/tools/helpers/state.js +10 -0
- package/dist/tools/helpers/state.js.map +1 -1
- package/dist/tools/submit-questions.tool.d.ts +71 -0
- package/dist/tools/submit-questions.tool.js +74 -0
- package/dist/tools/submit-questions.tool.js.map +1 -0
- package/dist/tools/update-node-parameters.tool.js +2 -3
- package/dist/tools/update-node-parameters.tool.js.map +1 -1
- package/dist/tools/utils/mermaid.utils.d.ts +9 -1
- package/dist/tools/utils/mermaid.utils.js +9 -5
- package/dist/tools/utils/mermaid.utils.js.map +1 -1
- package/dist/tools/utils/node-creation.utils.d.ts +6 -2
- package/dist/tools/utils/node-creation.utils.js +2 -1
- package/dist/tools/utils/node-creation.utils.js.map +1 -1
- package/dist/tools/validate-configuration.tool.js +15 -7
- package/dist/tools/validate-configuration.tool.js.map +1 -1
- package/dist/tools/validate-structure.tool.js +3 -3
- package/dist/tools/validate-structure.tool.js.map +1 -1
- package/dist/types/coordination.d.ts +9 -9
- package/dist/types/coordination.js +14 -4
- package/dist/types/coordination.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/planning.d.ts +48 -0
- package/dist/types/planning.js +3 -0
- package/dist/types/planning.js.map +1 -0
- package/dist/types/streaming.d.ts +14 -1
- package/dist/types/tools.d.ts +16 -0
- package/dist/utils/context-builders.d.ts +8 -0
- package/dist/utils/context-builders.js +249 -8
- package/dist/utils/context-builders.js.map +1 -1
- package/dist/utils/coordination-log.d.ts +2 -4
- package/dist/utils/coordination-log.js +0 -8
- package/dist/utils/coordination-log.js.map +1 -1
- package/dist/utils/node-helpers.d.ts +1 -0
- package/dist/utils/node-helpers.js +7 -0
- package/dist/utils/node-helpers.js.map +1 -1
- package/dist/utils/plan-helpers.d.ts +2 -0
- package/dist/utils/plan-helpers.js +26 -0
- package/dist/utils/plan-helpers.js.map +1 -0
- package/dist/utils/stream-processor.js +137 -8
- package/dist/utils/stream-processor.js.map +1 -1
- package/dist/utils/subgraph-helpers.js +7 -1
- package/dist/utils/subgraph-helpers.js.map +1 -1
- package/dist/utils/truncate-json.d.ts +5 -0
- package/dist/utils/truncate-json.js +18 -0
- package/dist/utils/truncate-json.js.map +1 -0
- package/dist/validation/checks/credentials.js +2 -6
- package/dist/validation/checks/credentials.js.map +1 -1
- package/dist/validation/checks/index.d.ts +1 -0
- package/dist/validation/checks/index.js +3 -1
- package/dist/validation/checks/index.js.map +1 -1
- package/dist/validation/checks/parameters.d.ts +4 -0
- package/dist/validation/checks/parameters.js +165 -0
- package/dist/validation/checks/parameters.js.map +1 -0
- package/dist/validation/programmatic.js +2 -0
- package/dist/validation/programmatic.js.map +1 -1
- package/dist/validation/types.d.ts +3 -1
- package/dist/validation/types.js +2 -0
- package/dist/validation/types.js.map +1 -1
- package/dist/workflow-builder-agent.d.ts +7 -1
- package/dist/workflow-builder-agent.js +43 -11
- package/dist/workflow-builder-agent.js.map +1 -1
- package/package.json +8 -7
- package/dist/prompts/agents/configurator.prompt.d.ts +0 -3
- package/dist/prompts/agents/configurator.prompt.js +0 -260
- package/dist/prompts/agents/configurator.prompt.js.map +0 -1
- package/dist/subgraphs/configurator.subgraph.d.ts +0 -158
- package/dist/subgraphs/configurator.subgraph.js +0 -234
- package/dist/subgraphs/configurator.subgraph.js.map +0 -1
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import type { StructuredTool } from '@langchain/core/tools';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { DiscoveryContext } from '../types/discovery-types';
|
|
7
|
+
import type { PlanDecision, PlanOutput } from '../types/planning';
|
|
8
|
+
import type { SimpleWorkflow } from '../types/workflow';
|
|
9
|
+
export declare const plannerOutputSchema: z.ZodObject<{
|
|
10
|
+
summary: z.ZodString;
|
|
11
|
+
trigger: z.ZodString;
|
|
12
|
+
steps: z.ZodArray<z.ZodObject<{
|
|
13
|
+
description: z.ZodString;
|
|
14
|
+
subSteps: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
15
|
+
suggestedNodes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
description: string;
|
|
18
|
+
subSteps?: string[] | undefined;
|
|
19
|
+
suggestedNodes?: string[] | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
description: string;
|
|
22
|
+
subSteps?: string[] | undefined;
|
|
23
|
+
suggestedNodes?: string[] | undefined;
|
|
24
|
+
}>, "many">;
|
|
25
|
+
additionalSpecs: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
summary: string;
|
|
28
|
+
trigger: string;
|
|
29
|
+
steps: {
|
|
30
|
+
description: string;
|
|
31
|
+
subSteps?: string[] | undefined;
|
|
32
|
+
suggestedNodes?: string[] | undefined;
|
|
33
|
+
}[];
|
|
34
|
+
additionalSpecs?: string[] | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
summary: string;
|
|
37
|
+
trigger: string;
|
|
38
|
+
steps: {
|
|
39
|
+
description: string;
|
|
40
|
+
subSteps?: string[] | undefined;
|
|
41
|
+
suggestedNodes?: string[] | undefined;
|
|
42
|
+
}[];
|
|
43
|
+
additionalSpecs?: string[] | undefined;
|
|
44
|
+
}>;
|
|
45
|
+
export type PlannerOutput = z.infer<typeof plannerOutputSchema>;
|
|
46
|
+
export interface PlannerAgentConfig {
|
|
47
|
+
llm: BaseChatModel;
|
|
48
|
+
tools?: StructuredTool[];
|
|
49
|
+
}
|
|
50
|
+
export declare function createPlannerAgent(config: PlannerAgentConfig): import("langchain").ReactAgent<{
|
|
51
|
+
summary: string;
|
|
52
|
+
trigger: string;
|
|
53
|
+
steps: {
|
|
54
|
+
description: string;
|
|
55
|
+
subSteps?: string[] | undefined;
|
|
56
|
+
suggestedNodes?: string[] | undefined;
|
|
57
|
+
}[];
|
|
58
|
+
additionalSpecs?: string[] | undefined;
|
|
59
|
+
}, undefined, import("langchain").AnyAnnotationRoot, readonly import("langchain").AgentMiddleware<any, any, any>[]>;
|
|
60
|
+
export type PlannerAgentType = ReturnType<typeof createPlannerAgent>;
|
|
61
|
+
export interface PlannerNodeInput {
|
|
62
|
+
userRequest: string;
|
|
63
|
+
discoveryContext: DiscoveryContext;
|
|
64
|
+
workflowJSON: SimpleWorkflow;
|
|
65
|
+
planPrevious?: PlanOutput | null;
|
|
66
|
+
planFeedback?: string | null;
|
|
67
|
+
}
|
|
68
|
+
export interface PlannerNodeResult {
|
|
69
|
+
planDecision?: PlanDecision;
|
|
70
|
+
planOutput?: PlanOutput | null;
|
|
71
|
+
planFeedback?: string | null;
|
|
72
|
+
planPrevious?: PlanOutput | null;
|
|
73
|
+
mode?: 'build';
|
|
74
|
+
messages?: BaseMessage[];
|
|
75
|
+
}
|
|
76
|
+
export declare function parsePlanDecision(value: unknown): {
|
|
77
|
+
action: PlanDecision;
|
|
78
|
+
feedback?: string;
|
|
79
|
+
};
|
|
80
|
+
export declare function invokePlannerNode(agent: PlannerAgentType, input: PlannerNodeInput, config?: RunnableConfig): Promise<PlannerNodeResult>;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plannerOutputSchema = void 0;
|
|
4
|
+
exports.createPlannerAgent = createPlannerAgent;
|
|
5
|
+
exports.parsePlanDecision = parsePlanDecision;
|
|
6
|
+
exports.invokePlannerNode = invokePlannerNode;
|
|
7
|
+
const messages_1 = require("@langchain/core/messages");
|
|
8
|
+
const langgraph_1 = require("@langchain/langgraph");
|
|
9
|
+
const langchain_1 = require("langchain");
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const prompts_1 = require("../prompts");
|
|
12
|
+
const context_builders_1 = require("../utils/context-builders");
|
|
13
|
+
const plan_helpers_1 = require("../utils/plan-helpers");
|
|
14
|
+
exports.plannerOutputSchema = zod_1.z.object({
|
|
15
|
+
summary: zod_1.z.string().describe('1-2 sentence description of the workflow outcome'),
|
|
16
|
+
trigger: zod_1.z.string().describe('What starts the workflow (manual, schedule, webhook, etc.)'),
|
|
17
|
+
steps: zod_1.z
|
|
18
|
+
.array(zod_1.z.object({
|
|
19
|
+
description: zod_1.z.string().describe('What this step does'),
|
|
20
|
+
subSteps: zod_1.z.array(zod_1.z.string()).optional(),
|
|
21
|
+
suggestedNodes: zod_1.z
|
|
22
|
+
.array(zod_1.z.string())
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('Suggested internal n8n node type names (when known)'),
|
|
25
|
+
}))
|
|
26
|
+
.min(1)
|
|
27
|
+
.describe('Ordered list of workflow steps'),
|
|
28
|
+
additionalSpecs: zod_1.z
|
|
29
|
+
.array(zod_1.z.string())
|
|
30
|
+
.optional()
|
|
31
|
+
.describe('Optional assumptions, edge cases, or notes'),
|
|
32
|
+
});
|
|
33
|
+
function createPlannerAgent(config) {
|
|
34
|
+
const tools = config.tools ?? [];
|
|
35
|
+
const hasDocumentationTool = tools.some((t) => t.name === 'get_documentation');
|
|
36
|
+
const plannerPromptText = (0, prompts_1.buildPlannerPrompt)({ hasDocumentationTool });
|
|
37
|
+
const systemPrompt = new messages_1.SystemMessage({
|
|
38
|
+
content: [
|
|
39
|
+
{
|
|
40
|
+
type: 'text',
|
|
41
|
+
text: plannerPromptText,
|
|
42
|
+
cache_control: { type: 'ephemeral' },
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
});
|
|
46
|
+
return (0, langchain_1.createAgent)({
|
|
47
|
+
model: config.llm,
|
|
48
|
+
tools,
|
|
49
|
+
systemPrompt,
|
|
50
|
+
responseFormat: exports.plannerOutputSchema,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function parsePlanDecision(value) {
|
|
54
|
+
if (typeof value !== 'object' || value === null) {
|
|
55
|
+
return {
|
|
56
|
+
action: 'reject',
|
|
57
|
+
feedback: `Invalid response: expected an object, got ${typeof value}.`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
const obj = value;
|
|
61
|
+
const action = obj.action;
|
|
62
|
+
if (action !== 'approve' && action !== 'reject' && action !== 'modify') {
|
|
63
|
+
return {
|
|
64
|
+
action: 'reject',
|
|
65
|
+
feedback: `Invalid response: expected action to be approve/reject/modify, got '${String(action)}'.`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const feedback = typeof obj.feedback === 'string' ? obj.feedback : undefined;
|
|
69
|
+
return { action, ...(feedback ? { feedback } : {}) };
|
|
70
|
+
}
|
|
71
|
+
const MAX_PLANNER_RETRIES = 1;
|
|
72
|
+
async function invokePlannerNode(agent, input, config) {
|
|
73
|
+
const contextContent = (0, prompts_1.buildPlannerContext)({
|
|
74
|
+
userRequest: input.userRequest,
|
|
75
|
+
discoveryContext: input.discoveryContext,
|
|
76
|
+
workflowJSON: input.workflowJSON,
|
|
77
|
+
planPrevious: input.planPrevious,
|
|
78
|
+
planFeedback: input.planFeedback,
|
|
79
|
+
});
|
|
80
|
+
const contextMessage = (0, context_builders_1.createContextMessage)([contextContent]);
|
|
81
|
+
let lastError;
|
|
82
|
+
let plan;
|
|
83
|
+
for (let attempt = 0; attempt <= MAX_PLANNER_RETRIES; attempt++) {
|
|
84
|
+
const messages = attempt === 0
|
|
85
|
+
? [contextMessage]
|
|
86
|
+
: [
|
|
87
|
+
contextMessage,
|
|
88
|
+
new messages_1.HumanMessage(`Your previous output was invalid: ${lastError}. Please output a valid JSON plan with summary, trigger, and steps fields.`),
|
|
89
|
+
];
|
|
90
|
+
const output = await agent.invoke({ messages }, config);
|
|
91
|
+
const parsedPlan = exports.plannerOutputSchema.safeParse(output.structuredResponse);
|
|
92
|
+
if (parsedPlan.success) {
|
|
93
|
+
plan = parsedPlan.data;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
lastError = parsedPlan.error.message;
|
|
97
|
+
}
|
|
98
|
+
if (!plan) {
|
|
99
|
+
throw new Error(`Planner produced invalid output after ${MAX_PLANNER_RETRIES + 1} attempts: ${lastError}`);
|
|
100
|
+
}
|
|
101
|
+
const decisionValue = (0, langgraph_1.interrupt)({ type: 'plan', plan });
|
|
102
|
+
const decision = parsePlanDecision(decisionValue);
|
|
103
|
+
if (decision.action === 'approve') {
|
|
104
|
+
return {
|
|
105
|
+
planDecision: 'approve',
|
|
106
|
+
planOutput: plan,
|
|
107
|
+
mode: 'build',
|
|
108
|
+
planFeedback: null,
|
|
109
|
+
planPrevious: null,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
if (decision.action === 'reject') {
|
|
113
|
+
return {
|
|
114
|
+
planDecision: 'reject',
|
|
115
|
+
planOutput: null,
|
|
116
|
+
planFeedback: null,
|
|
117
|
+
planPrevious: null,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
const feedback = decision.feedback ?? 'User requested changes without additional details.';
|
|
121
|
+
const feedbackMessage = (0, context_builders_1.createContextMessage)([
|
|
122
|
+
`<plan_feedback>\n${feedback}\n</plan_feedback>`,
|
|
123
|
+
`<previous_plan>\n${(0, plan_helpers_1.formatPlanAsText)(plan)}\n</previous_plan>`,
|
|
124
|
+
]);
|
|
125
|
+
return {
|
|
126
|
+
planDecision: 'modify',
|
|
127
|
+
planOutput: null,
|
|
128
|
+
planFeedback: feedback,
|
|
129
|
+
planPrevious: plan,
|
|
130
|
+
messages: [feedbackMessage],
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=planner.agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"planner.agent.js","sourceRoot":"","sources":["../../src/agents/planner.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EAAE,CAAC,CAAC;IACjE,MAAM,QAAQ,GAAG,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAElD,IAAI,QAAQ,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;QACnC,OAAO;YACN,YAAY,EAAE,SAAS;YACvB,UAAU,EAAE,IAAI;YAChB,IAAI,EAAE,OAAO;YACb,YAAY,EAAE,IAAI;YAClB,YAAY,EAAE,IAAI;SAClB,CAAC;IACH,CAAC;IAED,IAAI,QAAQ,CAAC,MAAM,KAAK,QAAQ,EAAE,CAAC;QAClC,OAAO;YACN,YAAY,EAAE,QAAQ;YACtB,UAAU,EAAE,IAAI;YAChB,YAAY,EAAE,IAAI;YAClB,YAAY,EAAE,IAAI;SAClB,CAAC;IACH,CAAC;IAGD,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,IAAI,oDAAoD,CAAC;IAC3F,MAAM,eAAe,GAAG,IAAA,uCAAoB,EAAC;QAC5C,oBAAoB,QAAQ,oBAAoB;QAChD,oBAAoB,IAAA,+BAAgB,EAAC,IAAI,CAAC,oBAAoB;KAC9D,CAAC,CAAC;IAEH,OAAO;QACN,YAAY,EAAE,QAAQ;QACtB,UAAU,EAAE,IAAI;QAChB,YAAY,EAAE,QAAQ;QACtB,YAAY,EAAE,IAAI;QAClB,QAAQ,EAAE,CAAC,eAAe,CAAC;KAC3B,CAAC;AACH,CAAC"}
|
|
@@ -1,23 +1,58 @@
|
|
|
1
1
|
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
2
|
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
-
import { AIMessage } from '@langchain/core/messages';
|
|
4
3
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
4
|
+
import { z } from 'zod';
|
|
5
5
|
import type { CoordinationLogEntry } from '../types/coordination';
|
|
6
6
|
import type { DiscoveryContext } from '../types/discovery-types';
|
|
7
7
|
import type { SimpleWorkflow } from '../types/workflow';
|
|
8
|
-
|
|
9
|
-
llm: BaseChatModel;
|
|
10
|
-
}
|
|
8
|
+
import type { ChatPayload } from '../workflow-builder-agent';
|
|
11
9
|
export interface ResponderContext {
|
|
12
10
|
messages: BaseMessage[];
|
|
13
11
|
coordinationLog: CoordinationLogEntry[];
|
|
14
12
|
discoveryContext?: DiscoveryContext | null;
|
|
15
13
|
workflowJSON: SimpleWorkflow;
|
|
16
14
|
previousSummary?: string;
|
|
15
|
+
workflowContext?: ChatPayload['workflowContext'];
|
|
17
16
|
}
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
constructor(config: ResponderAgentConfig);
|
|
21
|
-
private buildContextMessage;
|
|
22
|
-
invoke(context: ResponderContext, config?: RunnableConfig): Promise<AIMessage>;
|
|
17
|
+
export interface ResponderAgentConfig {
|
|
18
|
+
llm: BaseChatModel;
|
|
23
19
|
}
|
|
20
|
+
export declare function createResponderAgent(config: ResponderAgentConfig): import("langchain").ReactAgent<import("langchain").ResponseFormatUndefined, undefined, z.ZodObject<{
|
|
21
|
+
coordinationLog: z.ZodArray<z.ZodAny, "many">;
|
|
22
|
+
discoveryContext: z.ZodNullable<z.ZodOptional<z.ZodAny>>;
|
|
23
|
+
workflowJSON: z.ZodAny;
|
|
24
|
+
previousSummary: z.ZodOptional<z.ZodString>;
|
|
25
|
+
workflowContext: z.ZodOptional<z.ZodAny>;
|
|
26
|
+
}, "strip", z.ZodTypeAny, {
|
|
27
|
+
coordinationLog: any[];
|
|
28
|
+
workflowJSON?: any;
|
|
29
|
+
workflowContext?: any;
|
|
30
|
+
previousSummary?: string | undefined;
|
|
31
|
+
discoveryContext?: any;
|
|
32
|
+
}, {
|
|
33
|
+
coordinationLog: any[];
|
|
34
|
+
workflowJSON?: any;
|
|
35
|
+
workflowContext?: any;
|
|
36
|
+
previousSummary?: string | undefined;
|
|
37
|
+
discoveryContext?: any;
|
|
38
|
+
}>, readonly [import("langchain").AgentMiddleware<undefined, z.ZodObject<{
|
|
39
|
+
coordinationLog: z.ZodArray<z.ZodAny, "many">;
|
|
40
|
+
discoveryContext: z.ZodNullable<z.ZodOptional<z.ZodAny>>;
|
|
41
|
+
workflowJSON: z.ZodAny;
|
|
42
|
+
previousSummary: z.ZodOptional<z.ZodString>;
|
|
43
|
+
workflowContext: z.ZodOptional<z.ZodAny>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
coordinationLog: any[];
|
|
46
|
+
workflowJSON?: any;
|
|
47
|
+
workflowContext?: any;
|
|
48
|
+
previousSummary?: string | undefined;
|
|
49
|
+
discoveryContext?: any;
|
|
50
|
+
}, {
|
|
51
|
+
coordinationLog: any[];
|
|
52
|
+
workflowJSON?: any;
|
|
53
|
+
workflowContext?: any;
|
|
54
|
+
previousSummary?: string | undefined;
|
|
55
|
+
discoveryContext?: any;
|
|
56
|
+
}>, any>]>;
|
|
57
|
+
export type ResponderAgentType = ReturnType<typeof createResponderAgent>;
|
|
58
|
+
export declare function invokeResponderAgent(agent: ResponderAgentType, context: ResponderContext, config?: RunnableConfig): Promise<BaseMessage>;
|
|
@@ -1,100 +1,138 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createResponderAgent = createResponderAgent;
|
|
4
|
+
exports.invokeResponderAgent = invokeResponderAgent;
|
|
4
5
|
const messages_1 = require("@langchain/core/messages");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const langchain_1 = require("langchain");
|
|
7
|
+
const zod_1 = require("zod");
|
|
8
|
+
const prompts_1 = require("../prompts");
|
|
9
|
+
const context_builders_1 = require("../utils/context-builders");
|
|
8
10
|
const coordination_log_1 = require("../utils/coordination-log");
|
|
9
11
|
const data_table_helpers_1 = require("../utils/data-table-helpers");
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
['placeholder', '{messages}'],
|
|
22
|
-
]);
|
|
23
|
-
class ResponderAgent {
|
|
24
|
-
llm;
|
|
25
|
-
constructor(config) {
|
|
26
|
-
this.llm = config.llm;
|
|
12
|
+
const responderContextSchema = zod_1.z.object({
|
|
13
|
+
coordinationLog: zod_1.z.array(zod_1.z.any()),
|
|
14
|
+
discoveryContext: zod_1.z.any().optional().nullable(),
|
|
15
|
+
workflowJSON: zod_1.z.any(),
|
|
16
|
+
previousSummary: zod_1.z.string().optional(),
|
|
17
|
+
workflowContext: zod_1.z.any().optional(),
|
|
18
|
+
});
|
|
19
|
+
function buildContextContent(context) {
|
|
20
|
+
const contextParts = [];
|
|
21
|
+
if (context.previousSummary) {
|
|
22
|
+
contextParts.push(`**Previous Conversation Summary:**\n${context.previousSummary}`);
|
|
27
23
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
errorMessage.includes('iteration limit');
|
|
45
|
-
contextParts.push(`**Error:** An error occurred in the ${errorEntry.phase} phase: ${errorEntry.summary}`);
|
|
46
|
-
if (isRecursionError && hasWorkflow) {
|
|
47
|
-
const guidance = (0, responder_prompt_1.buildRecursionErrorWithWorkflowGuidance)(context.workflowJSON.nodes.length);
|
|
48
|
-
contextParts.push(...guidance);
|
|
49
|
-
}
|
|
50
|
-
else if (isRecursionError && !hasWorkflow) {
|
|
51
|
-
const guidance = (0, responder_prompt_1.buildRecursionErrorNoWorkflowGuidance)();
|
|
52
|
-
contextParts.push(...guidance);
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
contextParts.push((0, responder_prompt_1.buildGeneralErrorGuidance)());
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (context.discoveryContext?.nodesFound.length) {
|
|
59
|
-
contextParts.push(`**Discovery:** Found ${context.discoveryContext.nodesFound.length} relevant nodes`);
|
|
60
|
-
}
|
|
61
|
-
const builderOutput = (0, coordination_log_1.getBuilderOutput)(context.coordinationLog);
|
|
62
|
-
if (builderOutput) {
|
|
63
|
-
contextParts.push(`**Builder:** ${builderOutput}`);
|
|
24
|
+
const stateManagementEntry = context.coordinationLog.find((e) => e.phase === 'state_management');
|
|
25
|
+
if (stateManagementEntry) {
|
|
26
|
+
contextParts.push(`**State Management:** ${stateManagementEntry.summary}`);
|
|
27
|
+
}
|
|
28
|
+
const errorEntry = (0, coordination_log_1.getErrorEntry)(context.coordinationLog);
|
|
29
|
+
const errorsCleared = (0, coordination_log_1.hasRecursionErrorsCleared)(context.coordinationLog);
|
|
30
|
+
if (errorEntry && !errorsCleared) {
|
|
31
|
+
const hasWorkflow = context.workflowJSON.nodes.length > 0;
|
|
32
|
+
const errorMessage = errorEntry.summary.toLowerCase();
|
|
33
|
+
const isRecursionError = errorMessage.includes('recursion') ||
|
|
34
|
+
errorMessage.includes('maximum number of steps') ||
|
|
35
|
+
errorMessage.includes('iteration limit');
|
|
36
|
+
contextParts.push(`**Error:** An error occurred in the ${errorEntry.phase} phase: ${errorEntry.summary}`);
|
|
37
|
+
if (isRecursionError && hasWorkflow) {
|
|
38
|
+
const guidance = (0, prompts_1.buildRecursionErrorWithWorkflowGuidance)(context.workflowJSON.nodes.length);
|
|
39
|
+
contextParts.push(...guidance);
|
|
64
40
|
}
|
|
65
|
-
else if (
|
|
66
|
-
|
|
41
|
+
else if (isRecursionError && !hasWorkflow) {
|
|
42
|
+
const guidance = (0, prompts_1.buildRecursionErrorNoWorkflowGuidance)();
|
|
43
|
+
contextParts.push(...guidance);
|
|
67
44
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
contextParts.push(`**Configuration:**\n${configuratorOutput}`);
|
|
45
|
+
else {
|
|
46
|
+
contextParts.push((0, prompts_1.buildGeneralErrorGuidance)());
|
|
71
47
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
48
|
+
}
|
|
49
|
+
if (context.discoveryContext?.nodesFound.length) {
|
|
50
|
+
contextParts.push(`**Discovery:** Found ${context.discoveryContext.nodesFound.length} relevant nodes`);
|
|
51
|
+
}
|
|
52
|
+
const builderOutput = (0, coordination_log_1.getBuilderOutput)(context.coordinationLog);
|
|
53
|
+
if (builderOutput) {
|
|
54
|
+
contextParts.push(`**Builder:** ${builderOutput}`);
|
|
55
|
+
}
|
|
56
|
+
else if (context.workflowJSON.nodes.length) {
|
|
57
|
+
contextParts.push(`**Workflow:**\n${(0, context_builders_1.buildWorkflowOverview)(context.workflowJSON)}`);
|
|
58
|
+
}
|
|
59
|
+
const dataTableInfo = (0, data_table_helpers_1.extractDataTableInfo)(context.workflowJSON);
|
|
60
|
+
if (dataTableInfo.length > 0) {
|
|
61
|
+
const dataTableGuidance = (0, prompts_1.buildDataTableCreationGuidance)(dataTableInfo);
|
|
62
|
+
contextParts.push(dataTableGuidance);
|
|
63
|
+
}
|
|
64
|
+
if (context.workflowContext) {
|
|
65
|
+
const executionStatus = (0, context_builders_1.buildSimplifiedExecutionContext)(context.workflowContext, context.workflowJSON.nodes);
|
|
66
|
+
contextParts.push(`**Execution Status:**\n${executionStatus}`);
|
|
67
|
+
}
|
|
68
|
+
if (contextParts.length === 0) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
return `[Internal Context - Use this to craft your response]\n${contextParts.join('\n\n')}`;
|
|
72
|
+
}
|
|
73
|
+
const contextInjectionMiddleware = (0, langchain_1.createMiddleware)({
|
|
74
|
+
name: 'ResponderContextInjection',
|
|
75
|
+
contextSchema: responderContextSchema,
|
|
76
|
+
wrapModelCall: async (request, handler) => {
|
|
77
|
+
const context = request.runtime.context;
|
|
78
|
+
if (!context) {
|
|
79
|
+
return await handler(request);
|
|
76
80
|
}
|
|
77
|
-
|
|
78
|
-
|
|
81
|
+
const responderContext = {
|
|
82
|
+
messages: request.messages,
|
|
83
|
+
coordinationLog: (context.coordinationLog ?? []),
|
|
84
|
+
discoveryContext: context.discoveryContext,
|
|
85
|
+
workflowJSON: (context.workflowJSON ?? { nodes: [], connections: {} }),
|
|
86
|
+
previousSummary: context.previousSummary,
|
|
87
|
+
workflowContext: context.workflowContext,
|
|
88
|
+
};
|
|
89
|
+
const contextContent = buildContextContent(responderContext);
|
|
90
|
+
if (!contextContent) {
|
|
91
|
+
return await handler(request);
|
|
79
92
|
}
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
const contextMessage = new messages_1.HumanMessage({ content: contextContent });
|
|
94
|
+
return await handler({
|
|
95
|
+
...request,
|
|
96
|
+
messages: [...request.messages, contextMessage],
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
function createResponderAgent(config) {
|
|
101
|
+
const systemPromptText = (0, prompts_1.buildResponderPrompt)();
|
|
102
|
+
const systemPrompt = new messages_1.SystemMessage({
|
|
103
|
+
content: [
|
|
104
|
+
{
|
|
105
|
+
type: 'text',
|
|
106
|
+
text: systemPromptText,
|
|
107
|
+
cache_control: { type: 'ephemeral' },
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
});
|
|
111
|
+
return (0, langchain_1.createAgent)({
|
|
112
|
+
model: config.llm,
|
|
113
|
+
tools: [],
|
|
114
|
+
systemPrompt,
|
|
115
|
+
middleware: [contextInjectionMiddleware],
|
|
116
|
+
contextSchema: responderContextSchema,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
async function invokeResponderAgent(agent, context, config) {
|
|
120
|
+
const result = await agent.invoke({ messages: context.messages }, {
|
|
121
|
+
...config,
|
|
122
|
+
context: {
|
|
123
|
+
coordinationLog: context.coordinationLog,
|
|
124
|
+
discoveryContext: context.discoveryContext,
|
|
125
|
+
workflowJSON: context.workflowJSON,
|
|
126
|
+
previousSummary: context.previousSummary,
|
|
127
|
+
workflowContext: context.workflowContext,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
130
|
+
const messages = result.messages;
|
|
131
|
+
if (messages.length === 0) {
|
|
132
|
+
return new messages_1.AIMessage({
|
|
133
|
+
content: 'I encountered an issue generating a response. Please try again.',
|
|
82
134
|
});
|
|
83
135
|
}
|
|
84
|
-
|
|
85
|
-
const agent = systemPrompt.pipe(this.llm);
|
|
86
|
-
const contextMessage = this.buildContextMessage(context);
|
|
87
|
-
const messagesToSend = contextMessage
|
|
88
|
-
? [...context.messages, contextMessage]
|
|
89
|
-
: context.messages;
|
|
90
|
-
const result = await agent.invoke({ messages: messagesToSend }, config);
|
|
91
|
-
if (!(0, langchain_1.isAIMessage)(result)) {
|
|
92
|
-
return new messages_1.AIMessage({
|
|
93
|
-
content: 'I encountered an issue generating a response. Please try again.',
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
}
|
|
136
|
+
return messages[messages.length - 1];
|
|
98
137
|
}
|
|
99
|
-
exports.ResponderAgent = ResponderAgent;
|
|
100
138
|
//# sourceMappingURL=responder.agent.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"responder.agent.js","sourceRoot":"","sources":["../../src/agents/responder.agent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"responder.agent.js","sourceRoot":"","sources":["../../src/agents/responder.agent.ts"],"names":[],"mappings":";;AAkMA,oDAqBC;AAaD,oDA4BC;AA9PD,uDAAkF;AAElF,yCAA0D;AAC1D,6BAAwB;AAExB,uCAMmB;AAInB,+DAAkG;AAClG,+DAIkC;AAClC,mEAAkE;AAwBlE,MAAM,sBAAsB,GAAG,OAAC,CAAC,MAAM,CAAC;IACvC,eAAe,EAAE,OAAC,CAAC,KAAK,CAAC,OAAC,CAAC,GAAG,EAAE,CAAC;IACjC,gBAAgB,EAAE,OAAC,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE;IAC/C,YAAY,EAAE,OAAC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CAAC,QAAQ,CAAC;IACjC,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,IAAI,oBAAS,CAAC;YACpB,OAAO,EAAE,iEAAiE;SAC1E,CAAC,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -4,15 +4,16 @@ import type { RunnableConfig } from '@langchain/core/runnables';
|
|
|
4
4
|
import { z } from 'zod';
|
|
5
5
|
import type { CoordinationLogEntry } from '../types/coordination';
|
|
6
6
|
import type { SimpleWorkflow } from '../types/workflow';
|
|
7
|
+
import type { ChatPayload } from '../workflow-builder-agent';
|
|
7
8
|
export declare const supervisorRoutingSchema: z.ZodObject<{
|
|
8
9
|
reasoning: z.ZodString;
|
|
9
|
-
next: z.ZodEnum<["responder", "discovery", "builder"
|
|
10
|
+
next: z.ZodEnum<["responder", "discovery", "builder"]>;
|
|
10
11
|
}, "strip", z.ZodTypeAny, {
|
|
11
12
|
reasoning: string;
|
|
12
|
-
next: "responder" | "discovery" | "builder"
|
|
13
|
+
next: "responder" | "discovery" | "builder";
|
|
13
14
|
}, {
|
|
14
15
|
reasoning: string;
|
|
15
|
-
next: "responder" | "discovery" | "builder"
|
|
16
|
+
next: "responder" | "discovery" | "builder";
|
|
16
17
|
}>;
|
|
17
18
|
export type SupervisorRouting = z.infer<typeof supervisorRoutingSchema>;
|
|
18
19
|
export interface SupervisorAgentConfig {
|
|
@@ -23,6 +24,7 @@ export interface SupervisorContext {
|
|
|
23
24
|
workflowJSON: SimpleWorkflow;
|
|
24
25
|
coordinationLog: CoordinationLogEntry[];
|
|
25
26
|
previousSummary?: string;
|
|
27
|
+
workflowContext?: ChatPayload['workflowContext'];
|
|
26
28
|
}
|
|
27
29
|
export declare class SupervisorAgent {
|
|
28
30
|
private llm;
|
|
@@ -4,7 +4,7 @@ exports.SupervisorAgent = exports.supervisorRoutingSchema = void 0;
|
|
|
4
4
|
const messages_1 = require("@langchain/core/messages");
|
|
5
5
|
const prompts_1 = require("@langchain/core/prompts");
|
|
6
6
|
const zod_1 = require("zod");
|
|
7
|
-
const
|
|
7
|
+
const prompts_2 = require("../prompts");
|
|
8
8
|
const context_builders_1 = require("../utils/context-builders");
|
|
9
9
|
const coordination_log_1 = require("../utils/coordination-log");
|
|
10
10
|
const systemPrompt = prompts_1.ChatPromptTemplate.fromMessages([
|
|
@@ -13,7 +13,7 @@ const systemPrompt = prompts_1.ChatPromptTemplate.fromMessages([
|
|
|
13
13
|
[
|
|
14
14
|
{
|
|
15
15
|
type: 'text',
|
|
16
|
-
text: (0,
|
|
16
|
+
text: (0, prompts_2.buildSupervisorPrompt)(),
|
|
17
17
|
cache_control: { type: 'ephemeral' },
|
|
18
18
|
},
|
|
19
19
|
],
|
|
@@ -22,9 +22,7 @@ const systemPrompt = prompts_1.ChatPromptTemplate.fromMessages([
|
|
|
22
22
|
]);
|
|
23
23
|
exports.supervisorRoutingSchema = zod_1.z.object({
|
|
24
24
|
reasoning: zod_1.z.string().describe('One sentence explaining why this agent should act next'),
|
|
25
|
-
next: zod_1.z
|
|
26
|
-
.enum(['responder', 'discovery', 'builder', 'configurator'])
|
|
27
|
-
.describe('The next agent to call'),
|
|
25
|
+
next: zod_1.z.enum(['responder', 'discovery', 'builder']).describe('The next agent to call'),
|
|
28
26
|
});
|
|
29
27
|
class SupervisorAgent {
|
|
30
28
|
llm;
|
|
@@ -48,6 +46,9 @@ class SupervisorAgent {
|
|
|
48
46
|
contextParts.push((0, coordination_log_1.summarizeCoordinationLog)(context.coordinationLog));
|
|
49
47
|
contextParts.push('</completed_phases>');
|
|
50
48
|
}
|
|
49
|
+
if (context.workflowContext) {
|
|
50
|
+
contextParts.push((0, context_builders_1.buildSimplifiedExecutionContext)(context.workflowContext, context.workflowJSON.nodes));
|
|
51
|
+
}
|
|
51
52
|
if (contextParts.length === 0) {
|
|
52
53
|
return null;
|
|
53
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"supervisor.agent.js","sourceRoot":"","sources":["../../src/agents/supervisor.agent.ts"],"names":[],"mappings":";;;AAEA,uDAAwD;AACxD,qDAA6D;AAE7D,6BAAwB;AAExB,
|
|
1
|
+
{"version":3,"file":"supervisor.agent.js","sourceRoot":"","sources":["../../src/agents/supervisor.agent.ts"],"names":[],"mappings":";;;AAEA,uDAAwD;AACxD,qDAA6D;AAE7D,6BAAwB;AAExB,uCAAkD;AAIlD,gEAAkG;AAClG,gEAAqE;AAGrE,MAAM,YAAY,GAAG,4BAAkB,CAAC,YAAY,CAAC;IACpD;QACC,QAAQ;QACR;YACC;gBACC,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAA,+BAAqB,GAAE;gBAC7B,aAAa,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;aACpC;SACD;KACD;IACD,CAAC,aAAa,EAAE,YAAY,CAAC;CAC7B,CAAC,CAAC;AAKU,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC/C,SAAS,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,wDAAwD,CAAC;IACxF,IAAI,EAAE,OAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,wBAAwB,CAAC;CACtF,CAAC,CAAC;AA8BH,MAAa,eAAe;IACnB,GAAG,CAAgB;IAE3B,YAAY,MAA6B;QACxC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;IACvB,CAAC;IAKO,mBAAmB,CAAC,OAA0B;QACrD,MAAM,YAAY,GAAa,EAAE,CAAC;QAGlC,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;YAC7B,YAAY,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;YACrD,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;YAC3C,YAAY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C,OAAO,CAAC,CAAC;QACzD,MAAM,cAAc,GAAG,cAAc;YACpC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC;YACvC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QAEpB,OAAO,MAAM,KAAK,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,EAAE,MAAM,CAAC,CAAC;IACjE,CAAC;CACD;AAnED,0CAmEC"}
|
|
@@ -31,5 +31,8 @@ export declare class AiWorkflowBuilderService {
|
|
|
31
31
|
}>;
|
|
32
32
|
getBuilderInstanceCredits(user: IUser): Promise<AiAssistantSDK.BuilderInstanceCreditsResponse>;
|
|
33
33
|
truncateMessagesAfter(workflowId: string, user: IUser, messageId: string): Promise<boolean>;
|
|
34
|
+
private static readonly questionsInterruptSchema;
|
|
35
|
+
private static readonly planInterruptSchema;
|
|
36
|
+
private extractHitlFromStreamOutput;
|
|
34
37
|
}
|
|
35
38
|
export {};
|