@n8n/ai-workflow-builder 0.32.1 → 0.33.0-exp.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/responder.agent.d.ts +21 -0
- package/dist/agents/responder.agent.js +102 -0
- package/dist/agents/responder.agent.js.map +1 -0
- package/dist/agents/supervisor.agent.d.ts +31 -0
- package/dist/agents/supervisor.agent.js +104 -0
- package/dist/agents/supervisor.agent.js.map +1 -0
- package/dist/ai-workflow-builder-agent.service.d.ts +2 -1
- package/dist/ai-workflow-builder-agent.service.js +13 -4
- package/dist/ai-workflow-builder-agent.service.js.map +1 -1
- package/dist/build.tsbuildinfo +1 -1
- package/dist/chains/prompts/examples/basic/switch-node-examples.d.ts +1 -0
- package/dist/chains/prompts/examples/basic/switch-node-examples.js +128 -0
- package/dist/chains/prompts/examples/basic/switch-node-examples.js.map +1 -0
- package/dist/chains/prompts/node-types/switch-node.d.ts +1 -0
- package/dist/chains/prompts/node-types/switch-node.js +72 -0
- package/dist/chains/prompts/node-types/switch-node.js.map +1 -0
- package/dist/chains/prompts/prompt-builder.d.ts +1 -0
- package/dist/chains/prompts/prompt-builder.js +12 -0
- package/dist/chains/prompts/prompt-builder.js.map +1 -1
- package/dist/chains/prompts/prompt-config.js +1 -0
- package/dist/chains/prompts/prompt-config.js.map +1 -1
- package/dist/constants.d.ts +6 -0
- package/dist/constants.js +7 -1
- package/dist/constants.js.map +1 -1
- package/dist/llm-config.d.ts +1 -0
- package/dist/llm-config.js +20 -1
- package/dist/llm-config.js.map +1 -1
- package/dist/multi-agent-workflow-subgraphs.d.ts +122 -0
- package/dist/multi-agent-workflow-subgraphs.js +153 -0
- package/dist/multi-agent-workflow-subgraphs.js.map +1 -0
- package/dist/parent-graph-state.d.ts +27 -0
- package/dist/parent-graph-state.js +47 -0
- package/dist/parent-graph-state.js.map +1 -0
- package/dist/subgraphs/builder.subgraph.d.ts +122 -0
- package/dist/subgraphs/builder.subgraph.js +384 -0
- package/dist/subgraphs/builder.subgraph.js.map +1 -0
- package/dist/subgraphs/configurator.subgraph.d.ts +132 -0
- package/dist/subgraphs/configurator.subgraph.js +272 -0
- package/dist/subgraphs/configurator.subgraph.js.map +1 -0
- package/dist/subgraphs/discovery.subgraph.d.ts +158 -0
- package/dist/subgraphs/discovery.subgraph.js +487 -0
- package/dist/subgraphs/discovery.subgraph.js.map +1 -0
- package/dist/subgraphs/subgraph-interface.d.ts +23 -0
- package/dist/subgraphs/subgraph-interface.js +7 -0
- package/dist/subgraphs/subgraph-interface.js.map +1 -0
- package/dist/tools/best-practices/content-generation.js +38 -2
- package/dist/tools/best-practices/content-generation.js.map +1 -1
- package/dist/tools/builder-tools.d.ts +5 -2
- package/dist/tools/builder-tools.js +15 -25
- package/dist/tools/builder-tools.js.map +1 -1
- package/dist/tools/get-best-practices.tool.d.ts +1 -1
- package/dist/tools/get-workflow-examples.tool.d.ts +34 -0
- package/dist/tools/get-workflow-examples.tool.js +172 -0
- package/dist/tools/get-workflow-examples.tool.js.map +1 -0
- package/dist/tools/node-details.tool.d.ts +4 -4
- package/dist/tools/node-details.tool.js +30 -2
- package/dist/tools/node-details.tool.js.map +1 -1
- package/dist/tools/node-search.tool.d.ts +1 -1
- package/dist/tools/prompts/main-agent.prompt.d.ts +4 -0
- package/dist/tools/prompts/main-agent.prompt.js +113 -57
- package/dist/tools/prompts/main-agent.prompt.js.map +1 -1
- package/dist/tools/utils/markdown-workflow.utils.d.ts +14 -0
- package/dist/tools/utils/markdown-workflow.utils.js +174 -0
- package/dist/tools/utils/markdown-workflow.utils.js.map +1 -0
- package/dist/tools/utils/test/workflows/ai-assistant.workflow.d.ts +2 -0
- package/dist/tools/utils/test/workflows/ai-assistant.workflow.js +541 -0
- package/dist/tools/utils/test/workflows/ai-assistant.workflow.js.map +1 -0
- package/dist/tools/validate-configuration.tool.d.ts +4 -0
- package/dist/tools/validate-configuration.tool.js +70 -0
- package/dist/tools/validate-configuration.tool.js.map +1 -0
- package/dist/tools/validate-structure.tool.d.ts +4 -0
- package/dist/tools/validate-structure.tool.js +66 -0
- package/dist/tools/validate-structure.tool.js.map +1 -0
- package/dist/tools/web/templates.d.ts +7 -0
- package/dist/tools/web/templates.js +71 -0
- package/dist/tools/web/templates.js.map +1 -0
- package/dist/types/config.d.ts +1 -0
- package/dist/types/coordination.d.ts +42 -0
- package/dist/types/coordination.js +23 -0
- package/dist/types/coordination.js.map +1 -0
- package/dist/types/discovery-types.d.ts +14 -0
- package/dist/types/discovery-types.js +3 -0
- package/dist/types/discovery-types.js.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +15 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/langchain.d.ts +1 -0
- package/dist/types/langchain.js +8 -0
- package/dist/types/langchain.js.map +1 -1
- package/dist/types/tools.d.ts +20 -0
- package/dist/types/web/templates.d.ts +44 -0
- package/dist/types/web/templates.js +37 -0
- package/dist/types/web/templates.js.map +1 -0
- package/dist/utils/cache-control/helpers.d.ts +1 -0
- package/dist/utils/cache-control/helpers.js +36 -0
- package/dist/utils/cache-control/helpers.js.map +1 -1
- package/dist/utils/cache-control/index.d.ts +1 -1
- package/dist/utils/cache-control/index.js +2 -1
- package/dist/utils/cache-control/index.js.map +1 -1
- package/dist/utils/context-builders.d.ts +10 -0
- package/dist/utils/context-builders.js +71 -0
- package/dist/utils/context-builders.js.map +1 -0
- package/dist/utils/coordination-log.d.ts +15 -0
- package/dist/utils/coordination-log.js +75 -0
- package/dist/utils/coordination-log.js.map +1 -0
- package/dist/utils/operations-processor.d.ts +4 -2
- package/dist/utils/operations-processor.js.map +1 -1
- package/dist/utils/state-modifier.d.ts +32 -0
- package/dist/utils/state-modifier.js +112 -0
- package/dist/utils/state-modifier.js.map +1 -0
- package/dist/utils/state-reducers.d.ts +4 -0
- package/dist/utils/state-reducers.js +25 -0
- package/dist/utils/state-reducers.js.map +1 -0
- package/dist/utils/stream-processor.d.ts +6 -2
- package/dist/utils/stream-processor.js +138 -83
- package/dist/utils/stream-processor.js.map +1 -1
- package/dist/utils/subgraph-helpers.d.ts +16 -0
- package/dist/utils/subgraph-helpers.js +118 -0
- package/dist/utils/subgraph-helpers.js.map +1 -0
- package/dist/utils/token-usage.js +4 -1
- package/dist/utils/token-usage.js.map +1 -1
- package/dist/utils/tool-executor.js +55 -38
- package/dist/utils/tool-executor.js.map +1 -1
- package/dist/utils/workflow-validation.js +1 -0
- package/dist/utils/workflow-validation.js.map +1 -1
- package/dist/validation/checks/connections.js +6 -14
- package/dist/validation/checks/connections.js.map +1 -1
- package/dist/validation/checks/index.d.ts +2 -1
- package/dist/validation/checks/index.js +3 -1
- package/dist/validation/checks/index.js.map +1 -1
- package/dist/validation/checks/nodes.d.ts +4 -0
- package/dist/validation/checks/nodes.js +36 -0
- package/dist/validation/checks/nodes.js.map +1 -0
- package/dist/validation/checks/tools.js +0 -10
- package/dist/validation/checks/tools.js.map +1 -1
- package/dist/validation/checks/trigger.js +0 -6
- package/dist/validation/checks/trigger.js.map +1 -1
- package/dist/validation/programmatic.js +2 -0
- package/dist/validation/programmatic.js.map +1 -1
- package/dist/validation/types.d.ts +5 -1
- package/dist/validation/types.js +8 -0
- package/dist/validation/types.js.map +1 -1
- package/dist/workflow-builder-agent.d.ts +9 -0
- package/dist/workflow-builder-agent.js +44 -10
- package/dist/workflow-builder-agent.js.map +1 -1
- package/dist/workflow-state.d.ts +4 -2
- package/dist/workflow-state.js +9 -0
- package/dist/workflow-state.js.map +1 -1
- package/package.json +9 -8
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CoordinationLogEntry, SubgraphPhase, DiscoveryMetadata, BuilderMetadata, ConfiguratorMetadata, StateManagementMetadata } from '../types/coordination';
|
|
2
|
+
export type RoutingDecision = 'discovery' | 'builder' | 'configurator' | 'responder';
|
|
3
|
+
export declare function getLastCompletedPhase(log: CoordinationLogEntry[]): SubgraphPhase | null;
|
|
4
|
+
export declare function getPhaseEntry(log: CoordinationLogEntry[], phase: SubgraphPhase): CoordinationLogEntry | null;
|
|
5
|
+
export declare function hasPhaseCompleted(log: CoordinationLogEntry[], phase: SubgraphPhase): boolean;
|
|
6
|
+
export declare function getConfiguratorOutput(log: CoordinationLogEntry[]): string | null;
|
|
7
|
+
export declare function getBuilderOutput(log: CoordinationLogEntry[]): string | null;
|
|
8
|
+
export declare function getPhaseMetadata(log: CoordinationLogEntry[], phase: 'discovery'): DiscoveryMetadata | null;
|
|
9
|
+
export declare function getPhaseMetadata(log: CoordinationLogEntry[], phase: 'builder'): BuilderMetadata | null;
|
|
10
|
+
export declare function getPhaseMetadata(log: CoordinationLogEntry[], phase: 'configurator'): ConfiguratorMetadata | null;
|
|
11
|
+
export declare function getPhaseMetadata(log: CoordinationLogEntry[], phase: 'state_management'): StateManagementMetadata | null;
|
|
12
|
+
export declare function hasErrorInLog(log: CoordinationLogEntry[]): boolean;
|
|
13
|
+
export declare function getErrorEntry(log: CoordinationLogEntry[]): CoordinationLogEntry | null;
|
|
14
|
+
export declare function getNextPhaseFromLog(log: CoordinationLogEntry[]): RoutingDecision;
|
|
15
|
+
export declare function summarizeCoordinationLog(log: CoordinationLogEntry[]): string;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLastCompletedPhase = getLastCompletedPhase;
|
|
4
|
+
exports.getPhaseEntry = getPhaseEntry;
|
|
5
|
+
exports.hasPhaseCompleted = hasPhaseCompleted;
|
|
6
|
+
exports.getConfiguratorOutput = getConfiguratorOutput;
|
|
7
|
+
exports.getBuilderOutput = getBuilderOutput;
|
|
8
|
+
exports.getPhaseMetadata = getPhaseMetadata;
|
|
9
|
+
exports.hasErrorInLog = hasErrorInLog;
|
|
10
|
+
exports.getErrorEntry = getErrorEntry;
|
|
11
|
+
exports.getNextPhaseFromLog = getNextPhaseFromLog;
|
|
12
|
+
exports.summarizeCoordinationLog = summarizeCoordinationLog;
|
|
13
|
+
function getLastCompletedPhase(log) {
|
|
14
|
+
if (log.length === 0)
|
|
15
|
+
return null;
|
|
16
|
+
for (let i = log.length - 1; i >= 0; i--) {
|
|
17
|
+
if (log[i].status === 'completed') {
|
|
18
|
+
return log[i].phase;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function getPhaseEntry(log, phase) {
|
|
24
|
+
return log.find((entry) => entry.phase === phase && entry.status === 'completed') ?? null;
|
|
25
|
+
}
|
|
26
|
+
function hasPhaseCompleted(log, phase) {
|
|
27
|
+
return log.some((entry) => entry.phase === phase && entry.status === 'completed');
|
|
28
|
+
}
|
|
29
|
+
function getConfiguratorOutput(log) {
|
|
30
|
+
const entry = getPhaseEntry(log, 'configurator');
|
|
31
|
+
return entry?.output ?? null;
|
|
32
|
+
}
|
|
33
|
+
function getBuilderOutput(log) {
|
|
34
|
+
const entry = getPhaseEntry(log, 'builder');
|
|
35
|
+
return entry?.output ?? null;
|
|
36
|
+
}
|
|
37
|
+
function getPhaseMetadata(log, phase) {
|
|
38
|
+
const entry = getPhaseEntry(log, phase);
|
|
39
|
+
if (!entry)
|
|
40
|
+
return null;
|
|
41
|
+
if (entry.metadata.phase === 'error')
|
|
42
|
+
return null;
|
|
43
|
+
return entry.metadata;
|
|
44
|
+
}
|
|
45
|
+
function hasErrorInLog(log) {
|
|
46
|
+
return log.some((entry) => entry.status === 'error');
|
|
47
|
+
}
|
|
48
|
+
function getErrorEntry(log) {
|
|
49
|
+
return log.find((entry) => entry.status === 'error') ?? null;
|
|
50
|
+
}
|
|
51
|
+
function getNextPhaseFromLog(log) {
|
|
52
|
+
if (hasErrorInLog(log)) {
|
|
53
|
+
return 'responder';
|
|
54
|
+
}
|
|
55
|
+
const lastPhase = getLastCompletedPhase(log);
|
|
56
|
+
if (lastPhase === 'discovery') {
|
|
57
|
+
return 'builder';
|
|
58
|
+
}
|
|
59
|
+
if (lastPhase === 'builder') {
|
|
60
|
+
return 'configurator';
|
|
61
|
+
}
|
|
62
|
+
if (lastPhase === 'configurator') {
|
|
63
|
+
return 'responder';
|
|
64
|
+
}
|
|
65
|
+
return 'responder';
|
|
66
|
+
}
|
|
67
|
+
function summarizeCoordinationLog(log) {
|
|
68
|
+
if (log.length === 0)
|
|
69
|
+
return 'No phases completed';
|
|
70
|
+
return log
|
|
71
|
+
.filter((e) => e.status === 'completed')
|
|
72
|
+
.map((e) => `${e.phase}: ${e.summary}`)
|
|
73
|
+
.join(' → ');
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=coordination-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordination-log.js","sourceRoot":"","sources":["../../src/utils/coordination-log.ts"],"names":[],"mappings":";;AAuBA,sDAUC;AAKD,sCAKC;AAKD,8CAEC;AAKD,sDAGC;AAKD,4CAGC;AAqBD,4CAWC;AAKD,sCAEC;AAKD,sCAEC;AAMD,kDAwBC;AAKD,4DAOC;AAnID,SAAgB,qBAAqB,CAAC,GAA2B;IAChE,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IAGlC,KAAK,IAAI,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;YACnC,OAAO,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACrB,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAKD,SAAgB,aAAa,CAC5B,GAA2B,EAC3B,KAAoB;IAEpB,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,KAAK,KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,WAAW,CAAC,IAAI,IAAI,CAAC;AAC3F,CAAC;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QACxB,OAAO,WAAW,CAAC;IACpB,CAAC;IAED,MAAM,SAAS,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC;IAE7C,IAAI,SAAS,KAAK,WAAW,EAAE,CAAC;QAC/B,OAAO,SAAS,CAAC;IAClB,CAAC;IAGD,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,cAAc,CAAC;IACvB,CAAC;IAGD,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;QAClC,OAAO,WAAW,CAAC;IACpB,CAAC;IAGD,OAAO,WAAW,CAAC;AACpB,CAAC;AAKD,SAAgB,wBAAwB,CAAC,GAA2B;IACnE,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,qBAAqB,CAAC;IAEnD,OAAO,GAAG;SACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,CAAC;SACvC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC;SACtC,IAAI,CAAC,KAAK,CAAC,CAAC;AACf,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { SimpleWorkflow, WorkflowOperation } from '../types/workflow';
|
|
2
|
-
import type { WorkflowState } from '../workflow-state';
|
|
3
2
|
export declare function applyOperations(workflow: SimpleWorkflow, operations: WorkflowOperation[]): SimpleWorkflow;
|
|
4
|
-
export declare function processOperations(state:
|
|
3
|
+
export declare function processOperations(state: {
|
|
4
|
+
workflowJSON: SimpleWorkflow;
|
|
5
|
+
workflowOperations?: WorkflowOperation[] | null;
|
|
6
|
+
}): {
|
|
5
7
|
workflowJSON?: undefined;
|
|
6
8
|
workflowOperations?: undefined;
|
|
7
9
|
workflowValidation?: undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"operations-processor.js","sourceRoot":"","sources":["../../src/utils/operations-processor.ts"],"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KAAK,CAAC;QAC1B,WAAW,EAAE,EAAE,GAAG,QAAQ,CAAC,WAAW,EAAE;QACxC,IAAI,EAAE,QAAQ,CAAC,IAAI,IAAI,EAAE;KACzB,CAAC;IAGF,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;QACpC,MAAM,OAAO,GAAG,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACrC,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC;AAMD,SAAgB,iBAAiB,CAAC,KAGjC;IACA,MAAM,EAAE,YAAY,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC;IAGnD,IAAI,CAAC,kBAAkB,IAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC5D,OAAO,EAAE,CAAC;IACX,CAAC;IAGD,MAAM,WAAW,GAAG,eAAe,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;IAGtE,OAAO;QACN,YAAY,EAAE,WAAW;QACzB,kBAAkB,EAAE,IAAI;QACxB,kBAAkB,EAAE,IAAI;KACxB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { BaseMessage } from '@langchain/core/messages';
|
|
3
|
+
import { RemoveMessage } from '@langchain/core/messages';
|
|
4
|
+
import type { Logger } from '@n8n/backend-common';
|
|
5
|
+
import type { CoordinationLogEntry } from '../types/coordination';
|
|
6
|
+
import type { SimpleWorkflow } from '../types/workflow';
|
|
7
|
+
export type StateModificationAction = 'compact_messages' | 'delete_messages' | 'create_workflow_name' | 'auto_compact_messages' | 'cleanup_dangling' | 'continue';
|
|
8
|
+
export interface StateModifierInput {
|
|
9
|
+
messages: BaseMessage[];
|
|
10
|
+
workflowJSON: SimpleWorkflow;
|
|
11
|
+
previousSummary?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function determineStateAction(input: StateModifierInput, autoCompactThresholdTokens: number): StateModificationAction;
|
|
14
|
+
export declare function handleCleanupDangling(messages: BaseMessage[], logger?: Logger): {
|
|
15
|
+
messages: RemoveMessage[];
|
|
16
|
+
};
|
|
17
|
+
export declare function handleCompactMessages(messages: BaseMessage[], previousSummary: string, llm: BaseChatModel, isAutoCompact: boolean): Promise<{
|
|
18
|
+
previousSummary: string;
|
|
19
|
+
messages: BaseMessage[];
|
|
20
|
+
coordinationLog: CoordinationLogEntry[];
|
|
21
|
+
}>;
|
|
22
|
+
export declare function handleDeleteMessages(messages: BaseMessage[]): {
|
|
23
|
+
messages: RemoveMessage[];
|
|
24
|
+
workflowJSON: SimpleWorkflow;
|
|
25
|
+
previousSummary: string;
|
|
26
|
+
discoveryContext: null;
|
|
27
|
+
coordinationLog: CoordinationLogEntry[];
|
|
28
|
+
workflowOperations: [];
|
|
29
|
+
};
|
|
30
|
+
export declare function handleCreateWorkflowName(messages: BaseMessage[], workflowJSON: SimpleWorkflow, llm: BaseChatModel, logger?: Logger): Promise<{
|
|
31
|
+
workflowJSON: SimpleWorkflow;
|
|
32
|
+
}>;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.determineStateAction = determineStateAction;
|
|
4
|
+
exports.handleCleanupDangling = handleCleanupDangling;
|
|
5
|
+
exports.handleCompactMessages = handleCompactMessages;
|
|
6
|
+
exports.handleDeleteMessages = handleDeleteMessages;
|
|
7
|
+
exports.handleCreateWorkflowName = handleCreateWorkflowName;
|
|
8
|
+
const messages_1 = require("@langchain/core/messages");
|
|
9
|
+
const cleanup_dangling_tool_call_messages_1 = require("./cleanup-dangling-tool-call-messages");
|
|
10
|
+
const token_usage_1 = require("./token-usage");
|
|
11
|
+
const conversation_compact_1 = require("../chains/conversation-compact");
|
|
12
|
+
const workflow_name_1 = require("../chains/workflow-name");
|
|
13
|
+
const coordination_1 = require("../types/coordination");
|
|
14
|
+
function determineStateAction(input, autoCompactThresholdTokens) {
|
|
15
|
+
const { messages, workflowJSON } = input;
|
|
16
|
+
const danglingMessages = (0, cleanup_dangling_tool_call_messages_1.cleanupDanglingToolCallMessages)(messages);
|
|
17
|
+
if (danglingMessages.length > 0) {
|
|
18
|
+
return 'cleanup_dangling';
|
|
19
|
+
}
|
|
20
|
+
const lastHumanMessage = messages.findLast((m) => m instanceof messages_1.HumanMessage);
|
|
21
|
+
if (!lastHumanMessage)
|
|
22
|
+
return 'continue';
|
|
23
|
+
if (lastHumanMessage.content === '/compact') {
|
|
24
|
+
return 'compact_messages';
|
|
25
|
+
}
|
|
26
|
+
if (lastHumanMessage.content === '/clear') {
|
|
27
|
+
return 'delete_messages';
|
|
28
|
+
}
|
|
29
|
+
const workflowName = workflowJSON?.name;
|
|
30
|
+
const nodesLength = workflowJSON?.nodes?.length ?? 0;
|
|
31
|
+
const isDefaultName = !workflowName || /^My workflow( \d+)?$/.test(workflowName);
|
|
32
|
+
if (isDefaultName && nodesLength === 0 && messages.length === 1) {
|
|
33
|
+
return 'create_workflow_name';
|
|
34
|
+
}
|
|
35
|
+
const estimatedTokens = (0, token_usage_1.estimateTokenCountFromMessages)(messages);
|
|
36
|
+
if (estimatedTokens > autoCompactThresholdTokens) {
|
|
37
|
+
return 'auto_compact_messages';
|
|
38
|
+
}
|
|
39
|
+
return 'continue';
|
|
40
|
+
}
|
|
41
|
+
function handleCleanupDangling(messages, logger) {
|
|
42
|
+
const messagesToRemove = (0, cleanup_dangling_tool_call_messages_1.cleanupDanglingToolCallMessages)(messages);
|
|
43
|
+
if (messagesToRemove.length > 0) {
|
|
44
|
+
logger?.warn('Cleaning up dangling tool call messages', {
|
|
45
|
+
count: messagesToRemove.length,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return { messages: messagesToRemove };
|
|
49
|
+
}
|
|
50
|
+
async function handleCompactMessages(messages, previousSummary, llm, isAutoCompact) {
|
|
51
|
+
const lastHumanMessage = messages.findLast((m) => m instanceof messages_1.HumanMessage);
|
|
52
|
+
if (!lastHumanMessage) {
|
|
53
|
+
throw new Error('Cannot compact messages: no HumanMessage found');
|
|
54
|
+
}
|
|
55
|
+
const compactedMessages = await (0, conversation_compact_1.conversationCompactChain)(llm, messages, previousSummary);
|
|
56
|
+
const newMessages = [
|
|
57
|
+
...messages.map((m) => new messages_1.RemoveMessage({ id: m.id })),
|
|
58
|
+
...(isAutoCompact ? [new messages_1.HumanMessage({ content: lastHumanMessage.content })] : []),
|
|
59
|
+
];
|
|
60
|
+
return {
|
|
61
|
+
previousSummary: compactedMessages.summaryPlain,
|
|
62
|
+
messages: newMessages,
|
|
63
|
+
coordinationLog: [
|
|
64
|
+
{
|
|
65
|
+
phase: 'state_management',
|
|
66
|
+
status: 'completed',
|
|
67
|
+
timestamp: Date.now(),
|
|
68
|
+
summary: isAutoCompact
|
|
69
|
+
? 'Auto-compacted conversation due to token limit'
|
|
70
|
+
: 'Manually compacted conversation history',
|
|
71
|
+
metadata: (0, coordination_1.createStateManagementMetadata)({
|
|
72
|
+
action: 'compact',
|
|
73
|
+
messagesRemoved: messages.length,
|
|
74
|
+
}),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function handleDeleteMessages(messages) {
|
|
80
|
+
return {
|
|
81
|
+
messages: messages.map((m) => new messages_1.RemoveMessage({ id: m.id })),
|
|
82
|
+
workflowJSON: { nodes: [], connections: {}, name: '' },
|
|
83
|
+
previousSummary: '',
|
|
84
|
+
discoveryContext: null,
|
|
85
|
+
coordinationLog: [
|
|
86
|
+
{
|
|
87
|
+
phase: 'state_management',
|
|
88
|
+
status: 'completed',
|
|
89
|
+
timestamp: Date.now(),
|
|
90
|
+
summary: 'Cleared session and reset workflow',
|
|
91
|
+
metadata: (0, coordination_1.createStateManagementMetadata)({ action: 'clear' }),
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
workflowOperations: [],
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
async function handleCreateWorkflowName(messages, workflowJSON, llm, logger) {
|
|
98
|
+
if (messages.length === 1 && messages[0] instanceof messages_1.HumanMessage) {
|
|
99
|
+
const initialMessage = messages[0];
|
|
100
|
+
if (typeof initialMessage.content !== 'string') {
|
|
101
|
+
logger?.debug('Initial message content is not a string, skipping workflow name generation');
|
|
102
|
+
return { workflowJSON };
|
|
103
|
+
}
|
|
104
|
+
logger?.debug('Generating workflow name');
|
|
105
|
+
const { name } = await (0, workflow_name_1.workflowNameChain)(llm, initialMessage.content);
|
|
106
|
+
return {
|
|
107
|
+
workflowJSON: { ...workflowJSON, name },
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return { workflowJSON };
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=state-modifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-modifier.js","sourceRoot":"","sources":["../../src/utils/state-modifier.ts"],"names":[],"mappings":";;AA+BA,oDAwCC;AAMD,sDAWC;AASD,sDA0CC;AAKD,oDAwBC;AAKD,4DAqBC;AAhMD,uDAAuE;AAGvE,+FAAwF;AACxF,+CAA+D;AAC/D,yEAA0E;AAC1E,2DAA4D;AAE5D,wDAAsE;AAqBtE,SAAgB,oBAAoB,CACnC,KAAyB,EACzB,0BAAkC;IAElC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,KAAK,CAAC;IAGzC,MAAM,gBAAgB,GAAG,IAAA,qEAA+B,EAAC,QAAQ,CAAC,CAAC;IACnE,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACjC,OAAO,kBAAkB,CAAC;IAC3B,CAAC;IAED,MAAM,gBAAgB,GAAG,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,YAAY,uBAAY,CAAC,CAAC;IAC7E,IAAI,CAAC,gBA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,KAAK,EAAE,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACtD,eAAe,EAAE,EAAE;QACnB,gBAAgB,EAAE,IAAI;QACtB,eAAe,EAAE;YAChB;gBACC,KAAK,EAAE,kBAAkB;gBACzB,MAAM,EAAE,WAAW;gBACnB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;gBACrB,OAAO,EAAE,oCAAoC;gBAC7C,QAAQ,EAAE,IAAA,4CAA6B,EAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;aAC5D;SACD;QACD,kBAAkB,EAAE,EAAE;KACtB,CAAC;AACH,CAAC;AAKM,KAAK,UAAU,wBAAwB,CAC7C,QAAuB,EACvB,YAA4B,EAC5B,GAAkB,EAClB,MAAe;IAEf,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,YAAY,uBAAY,EAAE,CAAC;QAClE,MAAM,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;QACnC,IAAI,OAAO,cAAc,CAAC,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChD,MAAM,EAAE,KAAK,CAAC,4EAA4E,CAAC,CAAC;YAC5F,OAAO,EAAE,YAAY,EAAE,CAAC;QACzB,CAAC;QAED,MAAM,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC1C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAA,iCAAiB,EAAC,GAAG,EAAE,cAAc,CAAC,OAAO,CAAC,CAAC;QAEtE,OAAO;YACN,YAAY,EAAE,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE;SACvC,CAAC;IACH,CAAC;IACD,OAAO,EAAE,YAAY,EAAE,CAAC;AACzB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodeConfigurationsMap } from '../types/tools';
|
|
2
|
+
export declare function appendArrayReducer<T>(current: T[], update: T[] | undefined | null): T[];
|
|
3
|
+
export declare function mergeNodeConfigurations(target: NodeConfigurationsMap, source: NodeConfigurationsMap): void;
|
|
4
|
+
export declare function nodeConfigurationsReducer(current: NodeConfigurationsMap, update: NodeConfigurationsMap | undefined | null): NodeConfigurationsMap;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.appendArrayReducer = appendArrayReducer;
|
|
4
|
+
exports.mergeNodeConfigurations = mergeNodeConfigurations;
|
|
5
|
+
exports.nodeConfigurationsReducer = nodeConfigurationsReducer;
|
|
6
|
+
function appendArrayReducer(current, update) {
|
|
7
|
+
return update && update.length > 0 ? [...current, ...update] : current;
|
|
8
|
+
}
|
|
9
|
+
function mergeNodeConfigurations(target, source) {
|
|
10
|
+
for (const [nodeType, configs] of Object.entries(source)) {
|
|
11
|
+
if (!target[nodeType]) {
|
|
12
|
+
target[nodeType] = [];
|
|
13
|
+
}
|
|
14
|
+
target[nodeType].push(...configs);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function nodeConfigurationsReducer(current, update) {
|
|
18
|
+
if (!update || Object.keys(update).length === 0) {
|
|
19
|
+
return current;
|
|
20
|
+
}
|
|
21
|
+
const merged = { ...current };
|
|
22
|
+
mergeNodeConfigurations(merged, update);
|
|
23
|
+
return merged;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=state-reducers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state-reducers.js","sourceRoot":"","sources":["../../src/utils/state-reducers.ts"],"names":[],"mappings":";;AAMA,gDAEC;AAMD,0DAUC;AAMD,8DAUC;AAlCD,SAAgB,kBAAkB,CAAI,OAAY,EAAE,MAA8B;IACjF,OAAO,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;AACxE,CAAC;AAMD,SAAgB,uBAAuB,CACtC,MAA6B,EAC7B,MAA6B;IAE7B,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YACvB,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,CAAC;QACvB,CAAC;QACD,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC;IACnC,CAAC;AACF,CAAC;AAMD,SAAgB,yBAAyB,CACxC,OAA8B,EAC9B,MAAgD;IAEhD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACjD,OAAO,OAAO,CAAC;IAChB,CAAC;IACD,MAAM,MAAM,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;IAC9B,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,OAAO,MAAM,CAAC;AACf,CAAC"}
|
|
@@ -9,8 +9,12 @@ export interface BuilderToolBase {
|
|
|
9
9
|
export interface BuilderTool extends BuilderToolBase {
|
|
10
10
|
tool: DynamicStructuredTool;
|
|
11
11
|
}
|
|
12
|
+
type SubgraphEvent = [string[], string, unknown];
|
|
13
|
+
type ParentEvent = [string, unknown];
|
|
14
|
+
export type StreamEvent = SubgraphEvent | ParentEvent;
|
|
12
15
|
export declare const DEFAULT_WORKFLOW_UPDATE_TOOLS: string[];
|
|
13
|
-
export declare function processStreamChunk(streamMode: string, chunk: unknown): StreamOutput | null;
|
|
14
|
-
export declare function createStreamProcessor(stream: AsyncGenerator<[string, unknown], void, unknown>): AsyncGenerator<StreamOutput>;
|
|
15
16
|
export declare function cleanContextTags(text: string): string;
|
|
17
|
+
export declare function processStreamChunk(streamMode: string, chunk: unknown): StreamOutput | null;
|
|
18
|
+
export declare function createStreamProcessor(stream: AsyncIterable<StreamEvent>): AsyncGenerator<StreamOutput>;
|
|
16
19
|
export declare function formatMessages(messages: Array<AIMessage | HumanMessage | ToolMessage>, builderTools?: BuilderToolBase[]): Array<Record<string, unknown>>;
|
|
20
|
+
export {};
|
|
@@ -1,134 +1,189 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DEFAULT_WORKFLOW_UPDATE_TOOLS = void 0;
|
|
4
|
+
exports.cleanContextTags = cleanContextTags;
|
|
4
5
|
exports.processStreamChunk = processStreamChunk;
|
|
5
6
|
exports.createStreamProcessor = createStreamProcessor;
|
|
6
|
-
exports.cleanContextTags = cleanContextTags;
|
|
7
7
|
exports.formatMessages = formatMessages;
|
|
8
8
|
const messages_1 = require("@langchain/core/messages");
|
|
9
|
-
function isAgentUpdateChunk(chunk) {
|
|
10
|
-
return (typeof chunk === 'object' &&
|
|
11
|
-
chunk !== null &&
|
|
12
|
-
('agent' in chunk ||
|
|
13
|
-
'compact_messages' in chunk ||
|
|
14
|
-
'delete_messages' in chunk ||
|
|
15
|
-
'process_operations' in chunk));
|
|
16
|
-
}
|
|
17
|
-
function isToolProgressChunk(chunk) {
|
|
18
|
-
return typeof chunk === 'object' && chunk !== null && 'type' in chunk && chunk.type === 'tool';
|
|
19
|
-
}
|
|
20
9
|
exports.DEFAULT_WORKFLOW_UPDATE_TOOLS = [
|
|
21
10
|
'add_nodes',
|
|
22
11
|
'connect_nodes',
|
|
23
12
|
'update_node_parameters',
|
|
24
13
|
'remove_node',
|
|
25
14
|
];
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
const EMITTING_NODES = ['agent', 'responder'];
|
|
16
|
+
const SKIPPED_NODES = [
|
|
17
|
+
'supervisor',
|
|
18
|
+
'tools',
|
|
19
|
+
'cleanup_dangling_tool_calls',
|
|
20
|
+
'create_workflow_name',
|
|
21
|
+
'auto_compact_messages',
|
|
22
|
+
'configurator_subgraph',
|
|
23
|
+
'discovery_subgraph',
|
|
24
|
+
'builder_subgraph',
|
|
25
|
+
];
|
|
26
|
+
const SKIPPED_SUBGRAPH_PREFIXES = [
|
|
27
|
+
'discovery_subgraph',
|
|
28
|
+
'builder_subgraph',
|
|
29
|
+
'configurator_subgraph',
|
|
30
|
+
];
|
|
31
|
+
function isFromSkippedSubgraph(namespace) {
|
|
32
|
+
return namespace.some((ns) => SKIPPED_SUBGRAPH_PREFIXES.some((prefix) => ns.startsWith(prefix)));
|
|
31
33
|
}
|
|
32
|
-
function
|
|
33
|
-
|
|
34
|
-
return content
|
|
35
|
-
.filter((part) => part.type === 'text')
|
|
36
|
-
.map((part) => part.text)
|
|
37
|
-
.join('\n');
|
|
38
|
-
}
|
|
39
|
-
return content;
|
|
34
|
+
function shouldSkipNode(nodeName) {
|
|
35
|
+
return SKIPPED_NODES.includes(nodeName);
|
|
40
36
|
}
|
|
41
|
-
function
|
|
42
|
-
return
|
|
43
|
-
role: 'assistant',
|
|
44
|
-
type: 'message',
|
|
45
|
-
text,
|
|
46
|
-
};
|
|
37
|
+
function shouldEmitFromNode(nodeName) {
|
|
38
|
+
return EMITTING_NODES.includes(nodeName);
|
|
47
39
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
return { messages: [createMessageChunk('Deleted, refresh?')] };
|
|
40
|
+
function hasMessageInUpdate(update) {
|
|
41
|
+
const typed = update;
|
|
42
|
+
return Array.isArray(typed?.messages) && typed.messages.length > 0;
|
|
54
43
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
44
|
+
function shouldFilterSubgraphUpdate(namespace, data) {
|
|
45
|
+
if (!isFromSkippedSubgraph(namespace))
|
|
46
|
+
return false;
|
|
47
|
+
return Object.entries(data).some(([nodeName, update]) => {
|
|
48
|
+
if (shouldSkipNode(nodeName))
|
|
49
|
+
return false;
|
|
50
|
+
return hasMessageInUpdate(update);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function isSubgraphEvent(event) {
|
|
54
|
+
return Array.isArray(event) && event.length === 3 && Array.isArray(event[0]);
|
|
62
55
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
function isParentEvent(event) {
|
|
57
|
+
return Array.isArray(event) && event.length === 2 && typeof event[0] === 'string';
|
|
58
|
+
}
|
|
59
|
+
function extractMessageContent(messages) {
|
|
60
|
+
if (messages.length === 0)
|
|
66
61
|
return null;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if (!text) {
|
|
62
|
+
const lastMessage = messages[messages.length - 1];
|
|
63
|
+
if (!lastMessage.content)
|
|
70
64
|
return null;
|
|
65
|
+
if (Array.isArray(lastMessage.content)) {
|
|
66
|
+
const textContent = lastMessage.content
|
|
67
|
+
.filter((c) => c.type === 'text')
|
|
68
|
+
.map((c) => c.text)
|
|
69
|
+
.join('\n');
|
|
70
|
+
return textContent || null;
|
|
71
71
|
}
|
|
72
|
-
return
|
|
72
|
+
return lastMessage.content;
|
|
73
|
+
}
|
|
74
|
+
function cleanContextTags(text) {
|
|
75
|
+
return text.replace(/\n*<current_workflow_json>[\s\S]*?<\/current_execution_nodes_schemas>/, '');
|
|
73
76
|
}
|
|
74
|
-
function
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
77
|
+
function processOperationsUpdate(update) {
|
|
78
|
+
const typed = update;
|
|
79
|
+
if (!typed?.workflowJSON || typed.workflowOperations === undefined)
|
|
77
80
|
return null;
|
|
78
|
-
}
|
|
79
81
|
const workflowUpdateChunk = {
|
|
80
82
|
role: 'assistant',
|
|
81
83
|
type: 'workflow-updated',
|
|
82
|
-
codeSnippet: JSON.stringify(
|
|
84
|
+
codeSnippet: JSON.stringify(typed.workflowJSON, null, 2),
|
|
83
85
|
};
|
|
84
86
|
return { messages: [workflowUpdateChunk] };
|
|
85
87
|
}
|
|
86
|
-
function
|
|
87
|
-
if (!
|
|
88
|
+
function processAgentNodeUpdate(nodeName, update) {
|
|
89
|
+
if (!shouldEmitFromNode(nodeName))
|
|
90
|
+
return null;
|
|
91
|
+
const typed = update;
|
|
92
|
+
if (!typed?.messages?.length)
|
|
93
|
+
return null;
|
|
94
|
+
const content = extractMessageContent(typed.messages);
|
|
95
|
+
if (!content?.trim() || content.includes('<current_workflow_json>'))
|
|
96
|
+
return null;
|
|
97
|
+
const messageChunk = {
|
|
98
|
+
role: 'assistant',
|
|
99
|
+
type: 'message',
|
|
100
|
+
text: content,
|
|
101
|
+
};
|
|
102
|
+
return { messages: [messageChunk] };
|
|
103
|
+
}
|
|
104
|
+
function processToolChunk(chunk) {
|
|
105
|
+
const typed = chunk;
|
|
106
|
+
if (typed?.type !== 'tool')
|
|
107
|
+
return null;
|
|
108
|
+
return { messages: [typed] };
|
|
109
|
+
}
|
|
110
|
+
function processUpdatesChunk(nodeUpdate) {
|
|
111
|
+
if (!nodeUpdate || typeof nodeUpdate !== 'object')
|
|
112
|
+
return null;
|
|
113
|
+
if (nodeUpdate.delete_messages || nodeUpdate.compact_messages) {
|
|
88
114
|
return null;
|
|
89
115
|
}
|
|
90
|
-
|
|
116
|
+
if (nodeUpdate.process_operations) {
|
|
117
|
+
return processOperationsUpdate(nodeUpdate.process_operations);
|
|
118
|
+
}
|
|
119
|
+
for (const [nodeName, update] of Object.entries(nodeUpdate)) {
|
|
120
|
+
if (shouldSkipNode(nodeName))
|
|
121
|
+
continue;
|
|
122
|
+
const result = processAgentNodeUpdate(nodeName, update);
|
|
123
|
+
if (result)
|
|
124
|
+
return result;
|
|
125
|
+
}
|
|
126
|
+
return null;
|
|
91
127
|
}
|
|
92
128
|
function processStreamChunk(streamMode, chunk) {
|
|
93
129
|
if (streamMode === 'updates') {
|
|
94
|
-
|
|
95
|
-
return null;
|
|
96
|
-
}
|
|
97
|
-
return (processDeleteMessages(chunk) ??
|
|
98
|
-
processCompactMessages(chunk) ??
|
|
99
|
-
processAgentMessages(chunk) ??
|
|
100
|
-
processOperations(chunk));
|
|
130
|
+
return processUpdatesChunk(chunk);
|
|
101
131
|
}
|
|
102
132
|
if (streamMode === 'custom') {
|
|
103
|
-
return
|
|
133
|
+
return processToolChunk(chunk);
|
|
134
|
+
}
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
function processSubgraphEvent(event) {
|
|
138
|
+
const [namespace, streamMode, data] = event;
|
|
139
|
+
if (streamMode === 'updates' &&
|
|
140
|
+
shouldFilterSubgraphUpdate(namespace, data)) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
return processStreamChunk(streamMode, data);
|
|
144
|
+
}
|
|
145
|
+
function processParentEvent(event) {
|
|
146
|
+
const [streamMode, chunk] = event;
|
|
147
|
+
if (!streamMode || typeof streamMode !== 'string')
|
|
148
|
+
return null;
|
|
149
|
+
return processStreamChunk(streamMode, chunk);
|
|
150
|
+
}
|
|
151
|
+
function processEvent(event) {
|
|
152
|
+
if (isSubgraphEvent(event)) {
|
|
153
|
+
return processSubgraphEvent(event);
|
|
154
|
+
}
|
|
155
|
+
if (isParentEvent(event)) {
|
|
156
|
+
return processParentEvent(event);
|
|
104
157
|
}
|
|
105
158
|
return null;
|
|
106
159
|
}
|
|
107
160
|
async function* createStreamProcessor(stream) {
|
|
108
|
-
for await (const
|
|
109
|
-
const
|
|
110
|
-
if (
|
|
111
|
-
yield
|
|
161
|
+
for await (const event of stream) {
|
|
162
|
+
const result = processEvent(event);
|
|
163
|
+
if (result) {
|
|
164
|
+
yield result;
|
|
112
165
|
}
|
|
113
166
|
}
|
|
114
167
|
}
|
|
115
|
-
function
|
|
116
|
-
|
|
168
|
+
function extractHumanMessageText(content) {
|
|
169
|
+
if (typeof content === 'string') {
|
|
170
|
+
return content;
|
|
171
|
+
}
|
|
172
|
+
if (Array.isArray(content)) {
|
|
173
|
+
return content
|
|
174
|
+
.filter((c) => typeof c === 'object' && c !== null && 'type' in c && c.type === 'text' && 'text' in c)
|
|
175
|
+
.map((c) => c.text)
|
|
176
|
+
.join('\n');
|
|
177
|
+
}
|
|
178
|
+
return '';
|
|
117
179
|
}
|
|
118
180
|
function formatHumanMessage(msg) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const text = textParts.map((part) => cleanContextTags(part.text)).join('\n');
|
|
122
|
-
return {
|
|
123
|
-
role: 'user',
|
|
124
|
-
type: 'message',
|
|
125
|
-
text,
|
|
126
|
-
};
|
|
127
|
-
}
|
|
181
|
+
const rawText = extractHumanMessageText(msg.content);
|
|
182
|
+
const cleanedText = cleanContextTags(rawText);
|
|
128
183
|
return {
|
|
129
184
|
role: 'user',
|
|
130
185
|
type: 'message',
|
|
131
|
-
text:
|
|
186
|
+
text: cleanedText,
|
|
132
187
|
};
|
|
133
188
|
}
|
|
134
189
|
function processArrayContent(content) {
|