@illuma-ai/agents 1.1.21 → 1.1.23
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/cjs/graphs/Graph.cjs +12 -1
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs +105 -1
- package/dist/cjs/graphs/MultiAgentGraph.cjs.map +1 -1
- package/dist/cjs/run.cjs +20 -9
- package/dist/cjs/run.cjs.map +1 -1
- package/dist/cjs/utils/llm.cjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +12 -1
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs +105 -1
- package/dist/esm/graphs/MultiAgentGraph.mjs.map +1 -1
- package/dist/esm/run.mjs +20 -9
- package/dist/esm/run.mjs.map +1 -1
- package/dist/esm/utils/llm.mjs.map +1 -1
- package/dist/types/graphs/MultiAgentGraph.d.ts +17 -0
- package/package.json +1 -1
- package/src/graphs/Graph.ts +13 -1
- package/src/graphs/MultiAgentGraph.ts +128 -1
- package/src/graphs/__tests__/multi-agent-delegate.test.ts +205 -0
- package/src/run.ts +20 -11
- package/src/scripts/test-bedrock-handoff-autonomous.ts +231 -0
- package/src/utils/llm.ts +1 -0
- package/src/agents/AgentContext.js +0 -782
- package/src/agents/AgentContext.test.js +0 -421
- package/src/agents/__tests__/AgentContext.test.js +0 -678
- package/src/agents/__tests__/resolveStructuredOutputMode.test.js +0 -117
- package/src/common/enum.js +0 -192
- package/src/common/index.js +0 -3
- package/src/events.js +0 -166
- package/src/graphs/Graph.js +0 -1857
- package/src/graphs/MultiAgentGraph.js +0 -1092
- package/src/graphs/__tests__/structured-output.integration.test.js +0 -624
- package/src/graphs/__tests__/structured-output.test.js +0 -144
- package/src/graphs/contextManagement.e2e.test.js +0 -718
- package/src/graphs/contextManagement.test.js +0 -485
- package/src/graphs/handoffValidation.test.js +0 -276
- package/src/graphs/index.js +0 -3
- package/src/index.js +0 -28
- package/src/instrumentation.js +0 -21
- package/src/llm/anthropic/index.js +0 -319
- package/src/llm/anthropic/types.js +0 -46
- package/src/llm/anthropic/utils/message_inputs.js +0 -627
- package/src/llm/anthropic/utils/message_outputs.js +0 -290
- package/src/llm/anthropic/utils/output_parsers.js +0 -89
- package/src/llm/anthropic/utils/tools.js +0 -25
- package/src/llm/bedrock/__tests__/bedrock-caching.test.js +0 -392
- package/src/llm/bedrock/index.js +0 -303
- package/src/llm/bedrock/types.js +0 -2
- package/src/llm/bedrock/utils/index.js +0 -6
- package/src/llm/bedrock/utils/message_inputs.js +0 -463
- package/src/llm/bedrock/utils/message_outputs.js +0 -269
- package/src/llm/fake.js +0 -92
- package/src/llm/google/index.js +0 -215
- package/src/llm/google/types.js +0 -12
- package/src/llm/google/utils/common.js +0 -670
- package/src/llm/google/utils/tools.js +0 -111
- package/src/llm/google/utils/zod_to_genai_parameters.js +0 -47
- package/src/llm/openai/index.js +0 -1033
- package/src/llm/openai/types.js +0 -2
- package/src/llm/openai/utils/index.js +0 -756
- package/src/llm/openai/utils/isReasoningModel.test.js +0 -79
- package/src/llm/openrouter/index.js +0 -261
- package/src/llm/openrouter/reasoning.test.js +0 -181
- package/src/llm/providers.js +0 -36
- package/src/llm/text.js +0 -65
- package/src/llm/vertexai/index.js +0 -402
- package/src/messages/__tests__/tools.test.js +0 -392
- package/src/messages/cache.js +0 -404
- package/src/messages/cache.test.js +0 -1167
- package/src/messages/content.js +0 -48
- package/src/messages/content.test.js +0 -314
- package/src/messages/core.js +0 -359
- package/src/messages/ensureThinkingBlock.test.js +0 -997
- package/src/messages/format.js +0 -973
- package/src/messages/formatAgentMessages.test.js +0 -2278
- package/src/messages/formatAgentMessages.tools.test.js +0 -362
- package/src/messages/formatMessage.test.js +0 -608
- package/src/messages/ids.js +0 -18
- package/src/messages/index.js +0 -9
- package/src/messages/labelContentByAgent.test.js +0 -725
- package/src/messages/prune.js +0 -438
- package/src/messages/reducer.js +0 -60
- package/src/messages/shiftIndexTokenCountMap.test.js +0 -63
- package/src/messages/summarize.js +0 -146
- package/src/messages/summarize.test.js +0 -332
- package/src/messages/tools.js +0 -90
- package/src/mockStream.js +0 -81
- package/src/prompts/collab.js +0 -7
- package/src/prompts/index.js +0 -3
- package/src/prompts/taskmanager.js +0 -58
- package/src/run.js +0 -427
- package/src/schemas/index.js +0 -3
- package/src/schemas/schema-preparation.test.js +0 -370
- package/src/schemas/validate.js +0 -314
- package/src/schemas/validate.test.js +0 -264
- package/src/scripts/abort.js +0 -127
- package/src/scripts/ant_web_search.js +0 -130
- package/src/scripts/ant_web_search_edge_case.js +0 -133
- package/src/scripts/ant_web_search_error_edge_case.js +0 -119
- package/src/scripts/args.js +0 -41
- package/src/scripts/bedrock-cache-debug.js +0 -186
- package/src/scripts/bedrock-content-aggregation-test.js +0 -195
- package/src/scripts/bedrock-merge-test.js +0 -80
- package/src/scripts/bedrock-parallel-tools-test.js +0 -150
- package/src/scripts/caching.js +0 -106
- package/src/scripts/cli.js +0 -152
- package/src/scripts/cli2.js +0 -119
- package/src/scripts/cli3.js +0 -163
- package/src/scripts/cli4.js +0 -165
- package/src/scripts/cli5.js +0 -165
- package/src/scripts/code_exec.js +0 -171
- package/src/scripts/code_exec_files.js +0 -180
- package/src/scripts/code_exec_multi_session.js +0 -185
- package/src/scripts/code_exec_ptc.js +0 -265
- package/src/scripts/code_exec_session.js +0 -217
- package/src/scripts/code_exec_simple.js +0 -120
- package/src/scripts/content.js +0 -111
- package/src/scripts/empty_input.js +0 -125
- package/src/scripts/handoff-test.js +0 -96
- package/src/scripts/image.js +0 -138
- package/src/scripts/memory.js +0 -83
- package/src/scripts/multi-agent-chain.js +0 -271
- package/src/scripts/multi-agent-conditional.js +0 -185
- package/src/scripts/multi-agent-document-review-chain.js +0 -171
- package/src/scripts/multi-agent-hybrid-flow.js +0 -264
- package/src/scripts/multi-agent-parallel-start.js +0 -214
- package/src/scripts/multi-agent-parallel.js +0 -346
- package/src/scripts/multi-agent-sequence.js +0 -184
- package/src/scripts/multi-agent-supervisor.js +0 -324
- package/src/scripts/multi-agent-test.js +0 -147
- package/src/scripts/parallel-asymmetric-tools-test.js +0 -202
- package/src/scripts/parallel-full-metadata-test.js +0 -176
- package/src/scripts/parallel-tools-test.js +0 -256
- package/src/scripts/programmatic_exec.js +0 -277
- package/src/scripts/programmatic_exec_agent.js +0 -168
- package/src/scripts/search.js +0 -118
- package/src/scripts/sequential-full-metadata-test.js +0 -143
- package/src/scripts/simple.js +0 -174
- package/src/scripts/single-agent-metadata-test.js +0 -152
- package/src/scripts/stream.js +0 -113
- package/src/scripts/test-custom-prompt-key.js +0 -132
- package/src/scripts/test-handoff-input.js +0 -143
- package/src/scripts/test-handoff-preamble.js +0 -227
- package/src/scripts/test-handoff-steering.js +0 -353
- package/src/scripts/test-multi-agent-list-handoff.js +0 -318
- package/src/scripts/test-parallel-agent-labeling.js +0 -253
- package/src/scripts/test-parallel-handoffs.js +0 -229
- package/src/scripts/test-thinking-handoff-bedrock.js +0 -132
- package/src/scripts/test-thinking-handoff.js +0 -132
- package/src/scripts/test-thinking-to-thinking-handoff-bedrock.js +0 -140
- package/src/scripts/test-tool-before-handoff-role-order.js +0 -223
- package/src/scripts/test-tools-before-handoff.js +0 -187
- package/src/scripts/test_code_api.js +0 -263
- package/src/scripts/thinking-bedrock.js +0 -128
- package/src/scripts/thinking-vertexai.js +0 -130
- package/src/scripts/thinking.js +0 -134
- package/src/scripts/tool_search.js +0 -114
- package/src/scripts/tools.js +0 -125
- package/src/specs/agent-handoffs-bedrock.integration.test.js +0 -280
- package/src/specs/agent-handoffs.test.js +0 -924
- package/src/specs/anthropic.simple.test.js +0 -287
- package/src/specs/azure.simple.test.js +0 -381
- package/src/specs/cache.simple.test.js +0 -282
- package/src/specs/custom-event-await.test.js +0 -148
- package/src/specs/deepseek.simple.test.js +0 -189
- package/src/specs/emergency-prune.test.js +0 -308
- package/src/specs/moonshot.simple.test.js +0 -237
- package/src/specs/observability.integration.test.js +0 -1337
- package/src/specs/openai.simple.test.js +0 -233
- package/src/specs/openrouter.simple.test.js +0 -202
- package/src/specs/prune.test.js +0 -733
- package/src/specs/reasoning.test.js +0 -144
- package/src/specs/spec.utils.js +0 -4
- package/src/specs/thinking-handoff.test.js +0 -486
- package/src/specs/thinking-prune.test.js +0 -600
- package/src/specs/token-distribution-edge-case.test.js +0 -246
- package/src/specs/token-memoization.test.js +0 -32
- package/src/specs/tokens.test.js +0 -49
- package/src/specs/tool-error.test.js +0 -139
- package/src/splitStream.js +0 -204
- package/src/splitStream.test.js +0 -504
- package/src/stream.js +0 -650
- package/src/stream.test.js +0 -225
- package/src/test/mockTools.js +0 -340
- package/src/tools/BrowserTools.js +0 -245
- package/src/tools/Calculator.js +0 -38
- package/src/tools/Calculator.test.js +0 -225
- package/src/tools/CodeExecutor.js +0 -233
- package/src/tools/ProgrammaticToolCalling.js +0 -602
- package/src/tools/StreamingToolCallBuffer.js +0 -179
- package/src/tools/ToolNode.js +0 -930
- package/src/tools/ToolSearch.js +0 -904
- package/src/tools/__tests__/BrowserTools.test.js +0 -306
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.js +0 -276
- package/src/tools/__tests__/ProgrammaticToolCalling.test.js +0 -807
- package/src/tools/__tests__/StreamingToolCallBuffer.test.js +0 -175
- package/src/tools/__tests__/ToolApproval.test.js +0 -675
- package/src/tools/__tests__/ToolNode.recovery.test.js +0 -200
- package/src/tools/__tests__/ToolNode.session.test.js +0 -319
- package/src/tools/__tests__/ToolSearch.integration.test.js +0 -125
- package/src/tools/__tests__/ToolSearch.test.js +0 -812
- package/src/tools/__tests__/handlers.test.js +0 -799
- package/src/tools/__tests__/truncation-recovery.integration.test.js +0 -362
- package/src/tools/handlers.js +0 -306
- package/src/tools/schema.js +0 -25
- package/src/tools/search/anthropic.js +0 -34
- package/src/tools/search/content.js +0 -116
- package/src/tools/search/content.test.js +0 -133
- package/src/tools/search/firecrawl.js +0 -173
- package/src/tools/search/format.js +0 -198
- package/src/tools/search/highlights.js +0 -241
- package/src/tools/search/index.js +0 -3
- package/src/tools/search/jina-reranker.test.js +0 -106
- package/src/tools/search/rerankers.js +0 -165
- package/src/tools/search/schema.js +0 -102
- package/src/tools/search/search.js +0 -561
- package/src/tools/search/serper-scraper.js +0 -126
- package/src/tools/search/test.js +0 -129
- package/src/tools/search/tool.js +0 -453
- package/src/tools/search/types.js +0 -2
- package/src/tools/search/utils.js +0 -59
- package/src/types/graph.js +0 -24
- package/src/types/graph.test.js +0 -192
- package/src/types/index.js +0 -7
- package/src/types/llm.js +0 -2
- package/src/types/messages.js +0 -2
- package/src/types/run.js +0 -2
- package/src/types/stream.js +0 -2
- package/src/types/tools.js +0 -2
- package/src/utils/contextAnalytics.js +0 -79
- package/src/utils/contextAnalytics.test.js +0 -166
- package/src/utils/events.js +0 -26
- package/src/utils/graph.js +0 -11
- package/src/utils/handlers.js +0 -65
- package/src/utils/index.js +0 -10
- package/src/utils/llm.js +0 -21
- package/src/utils/llmConfig.js +0 -205
- package/src/utils/logging.js +0 -37
- package/src/utils/misc.js +0 -51
- package/src/utils/run.js +0 -69
- package/src/utils/schema.js +0 -21
- package/src/utils/title.js +0 -119
- package/src/utils/tokens.js +0 -92
- package/src/utils/toonFormat.js +0 -379
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { HumanMessage } from '@langchain/core/messages';
|
|
2
|
-
const MAX_MESSAGE_CHARS = 4000;
|
|
3
|
-
const MAX_TRUNCATED_CHARS = 500;
|
|
4
|
-
const SIMPLE_MAX_TOKENS = 512;
|
|
5
|
-
export const FULL_SUMMARY_TEMPLATE = `Analyze this conversation and produce a structured summary covering each section below. Be precise and preserve actionable details.
|
|
6
|
-
|
|
7
|
-
## 1. Task Overview & User Intent
|
|
8
|
-
What the user originally asked for and their high-level goal.
|
|
9
|
-
|
|
10
|
-
## 2. Technical Context
|
|
11
|
-
Languages, frameworks, libraries, APIs, and architectural patterns involved.
|
|
12
|
-
|
|
13
|
-
## 3. Files & Code State
|
|
14
|
-
All file paths mentioned, their current state, and any pending modifications.
|
|
15
|
-
|
|
16
|
-
## 4. Problem Resolution History
|
|
17
|
-
Problems encountered, debugging steps taken, and their outcomes.
|
|
18
|
-
|
|
19
|
-
## 5. Agent Workflow State
|
|
20
|
-
{agent_workflow}
|
|
21
|
-
|
|
22
|
-
## 6. Tool Results Summary
|
|
23
|
-
Tools called, their inputs, and key outputs (omit verbose raw data).
|
|
24
|
-
|
|
25
|
-
## 7. Progress Tracking
|
|
26
|
-
What has been completed, what remains, and any blockers.
|
|
27
|
-
|
|
28
|
-
## 8. Active Working State
|
|
29
|
-
Variables, configurations, and runtime state that must be preserved.
|
|
30
|
-
|
|
31
|
-
## 9. Continuation Plan
|
|
32
|
-
Immediate next steps and the order in which they should be executed.
|
|
33
|
-
|
|
34
|
-
## 10. Critical Context
|
|
35
|
-
Any constraints, warnings, edge cases, or decisions that must not be lost.
|
|
36
|
-
|
|
37
|
-
Conversation:
|
|
38
|
-
{conversation}
|
|
39
|
-
|
|
40
|
-
Structured Summary:`;
|
|
41
|
-
export const SIMPLE_SUMMARY_TEMPLATE = 'Summarize this conversation preserving: user\'s original request, key decisions, current task state, and any file paths mentioned.\n\nConversation:\n{conversation}\n\nSummary:';
|
|
42
|
-
export function formatMessagesForSummary(messages) {
|
|
43
|
-
const parts = [];
|
|
44
|
-
for (const message of messages) {
|
|
45
|
-
const role = message.getType();
|
|
46
|
-
const raw = typeof message.content === 'string'
|
|
47
|
-
? message.content
|
|
48
|
-
: JSON.stringify(message.content);
|
|
49
|
-
const content = raw.length > MAX_MESSAGE_CHARS
|
|
50
|
-
? raw.slice(0, MAX_MESSAGE_CHARS) + '...'
|
|
51
|
-
: raw;
|
|
52
|
-
parts.push(`${role}: ${content}`);
|
|
53
|
-
}
|
|
54
|
-
return parts.join('\n');
|
|
55
|
-
}
|
|
56
|
-
export function buildFullSummaryPrompt(conversation, config) {
|
|
57
|
-
let agentWorkflow = 'N/A (single-agent conversation)';
|
|
58
|
-
if (config?.isMultiAgent === true && config.agentWorkflowState != null) {
|
|
59
|
-
const { currentAgentId, agentChain, pendingAgents } = config.agentWorkflowState;
|
|
60
|
-
agentWorkflow = [
|
|
61
|
-
`Current agent: ${currentAgentId}`,
|
|
62
|
-
`Agent chain: ${agentChain.join(' -> ')}`,
|
|
63
|
-
`Pending agents: ${pendingAgents.length > 0 ? pendingAgents.join(', ') : 'none'}`,
|
|
64
|
-
].join('\n');
|
|
65
|
-
}
|
|
66
|
-
return FULL_SUMMARY_TEMPLATE
|
|
67
|
-
.replace('{agent_workflow}', agentWorkflow)
|
|
68
|
-
.replace('{conversation}', conversation);
|
|
69
|
-
}
|
|
70
|
-
export function buildSimpleSummaryPrompt(conversation) {
|
|
71
|
-
return SIMPLE_SUMMARY_TEMPLATE.replace('{conversation}', conversation);
|
|
72
|
-
}
|
|
73
|
-
export function createEmergencySummary(messages) {
|
|
74
|
-
let firstUserContent = '';
|
|
75
|
-
let lastAIContent = '';
|
|
76
|
-
const toolNames = new Set();
|
|
77
|
-
for (const message of messages) {
|
|
78
|
-
const type = message.getType();
|
|
79
|
-
const content = typeof message.content === 'string'
|
|
80
|
-
? message.content
|
|
81
|
-
: JSON.stringify(message.content);
|
|
82
|
-
if (type === 'human' && firstUserContent.length === 0) {
|
|
83
|
-
firstUserContent = content.slice(0, MAX_TRUNCATED_CHARS);
|
|
84
|
-
}
|
|
85
|
-
if (type === 'ai') {
|
|
86
|
-
lastAIContent = content.slice(0, MAX_TRUNCATED_CHARS);
|
|
87
|
-
}
|
|
88
|
-
if (type === 'tool') {
|
|
89
|
-
const name = message.name;
|
|
90
|
-
if (name != null && name.length > 0) {
|
|
91
|
-
toolNames.add(name);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const toolList = toolNames.size > 0 ? [...toolNames].join(', ') : 'none';
|
|
96
|
-
return [
|
|
97
|
-
'[Emergency Context Summary]',
|
|
98
|
-
`Original request: ${firstUserContent}`,
|
|
99
|
-
`Last response: ${lastAIContent}`,
|
|
100
|
-
`Tools used: ${toolList}`,
|
|
101
|
-
`Messages compacted: ${messages.length}`,
|
|
102
|
-
].join('\n');
|
|
103
|
-
}
|
|
104
|
-
export function validateSummarySize(summary, budget, tokenCounter) {
|
|
105
|
-
const count = tokenCounter(new HumanMessage(summary));
|
|
106
|
-
return count <= budget;
|
|
107
|
-
}
|
|
108
|
-
export async function summarize(messages, callback, config) {
|
|
109
|
-
const messageCount = messages.length;
|
|
110
|
-
const maxOutputTokens = config?.maxOutputTokens ?? 1024;
|
|
111
|
-
// Tier 1: Full structured summary
|
|
112
|
-
try {
|
|
113
|
-
const conversation = formatMessagesForSummary(messages);
|
|
114
|
-
const prompt = buildFullSummaryPrompt(conversation, config);
|
|
115
|
-
const result = await callback(prompt, maxOutputTokens);
|
|
116
|
-
if (result != null && result.length > 0) {
|
|
117
|
-
if (config?.summaryBudget != null && config.summaryBudget > 0 && config.tokenCounter != null) {
|
|
118
|
-
if (validateSummarySize(result, config.summaryBudget, config.tokenCounter)) {
|
|
119
|
-
return { summary: result, tier: 'full', messagesCompacted: messageCount };
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
return { summary: result, tier: 'full', messagesCompacted: messageCount };
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// Fall through to Tier 2
|
|
129
|
-
}
|
|
130
|
-
// Tier 2: Simple summary
|
|
131
|
-
try {
|
|
132
|
-
const conversation = formatMessagesForSummary(messages);
|
|
133
|
-
const prompt = buildSimpleSummaryPrompt(conversation);
|
|
134
|
-
const result = await callback(prompt, SIMPLE_MAX_TOKENS);
|
|
135
|
-
if (result != null && result.length > 0) {
|
|
136
|
-
return { summary: result, tier: 'simple', messagesCompacted: messageCount };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
// Fall through to Tier 3
|
|
141
|
-
}
|
|
142
|
-
// Tier 3: Emergency (no LLM)
|
|
143
|
-
const summary = createEmergencySummary(messages);
|
|
144
|
-
return { summary, tier: 'emergency', messagesCompacted: messageCount };
|
|
145
|
-
}
|
|
146
|
-
//# sourceMappingURL=summarize.js.map
|
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
import { HumanMessage, AIMessage, SystemMessage, ToolMessage, } from '@langchain/core/messages';
|
|
2
|
-
import { formatMessagesForSummary, buildFullSummaryPrompt, buildSimpleSummaryPrompt, createEmergencySummary, validateSummarySize, summarize, } from './summarize';
|
|
3
|
-
/**
|
|
4
|
-
* Simple token counter that approximates 1 token per 4 characters.
|
|
5
|
-
* Used across all tests that need a TokenCounter.
|
|
6
|
-
*/
|
|
7
|
-
const simpleTokenCounter = (msg) => {
|
|
8
|
-
const content = typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content);
|
|
9
|
-
return Math.ceil(content.length / 4);
|
|
10
|
-
};
|
|
11
|
-
describe('formatMessagesForSummary', () => {
|
|
12
|
-
it('formats messages as "role: content" pairs', () => {
|
|
13
|
-
const messages = [
|
|
14
|
-
new HumanMessage('Hello there'),
|
|
15
|
-
new AIMessage('Hi! How can I help?'),
|
|
16
|
-
new SystemMessage('You are a helpful assistant'),
|
|
17
|
-
];
|
|
18
|
-
const result = formatMessagesForSummary(messages);
|
|
19
|
-
expect(result).toBe('human: Hello there\nai: Hi! How can I help?\nsystem: You are a helpful assistant');
|
|
20
|
-
});
|
|
21
|
-
it('truncates long content (>4000 chars) with ellipsis', () => {
|
|
22
|
-
const longContent = 'x'.repeat(5000);
|
|
23
|
-
const messages = [new HumanMessage(longContent)];
|
|
24
|
-
const result = formatMessagesForSummary(messages);
|
|
25
|
-
// 4000 chars of content + "..." + "human: " prefix
|
|
26
|
-
expect(result).toBe(`human: ${'x'.repeat(4000)}...`);
|
|
27
|
-
expect(result.length).toBe(4000 + 3 + 7); // content + ellipsis + "human: "
|
|
28
|
-
});
|
|
29
|
-
it('does not truncate content at exactly 4000 chars', () => {
|
|
30
|
-
const exactContent = 'y'.repeat(4000);
|
|
31
|
-
const messages = [new HumanMessage(exactContent)];
|
|
32
|
-
const result = formatMessagesForSummary(messages);
|
|
33
|
-
expect(result).toBe(`human: ${exactContent}`);
|
|
34
|
-
expect(result).not.toContain('...');
|
|
35
|
-
});
|
|
36
|
-
it('handles empty messages array', () => {
|
|
37
|
-
const result = formatMessagesForSummary([]);
|
|
38
|
-
expect(result).toBe('');
|
|
39
|
-
});
|
|
40
|
-
it('handles messages with complex (array) content', () => {
|
|
41
|
-
const messages = [
|
|
42
|
-
new HumanMessage({
|
|
43
|
-
content: [
|
|
44
|
-
{ type: 'text', text: 'Look at this image' },
|
|
45
|
-
{ type: 'image_url', image_url: { url: 'data:image/png;base64,abc123' } },
|
|
46
|
-
],
|
|
47
|
-
}),
|
|
48
|
-
];
|
|
49
|
-
const result = formatMessagesForSummary(messages);
|
|
50
|
-
// Array content gets JSON.stringified
|
|
51
|
-
expect(result).toContain('human: ');
|
|
52
|
-
expect(result).toContain('Look at this image');
|
|
53
|
-
expect(result).toContain('image_url');
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
describe('buildFullSummaryPrompt', () => {
|
|
57
|
-
const conversation = 'human: Hello\nai: Hi there!';
|
|
58
|
-
it('contains all 10 section headers', () => {
|
|
59
|
-
const prompt = buildFullSummaryPrompt(conversation);
|
|
60
|
-
const expectedSections = [
|
|
61
|
-
'## 1. Task Overview & User Intent',
|
|
62
|
-
'## 2. Technical Context',
|
|
63
|
-
'## 3. Files & Code State',
|
|
64
|
-
'## 4. Problem Resolution History',
|
|
65
|
-
'## 5. Agent Workflow State',
|
|
66
|
-
'## 6. Tool Results Summary',
|
|
67
|
-
'## 7. Progress Tracking',
|
|
68
|
-
'## 8. Active Working State',
|
|
69
|
-
'## 9. Continuation Plan',
|
|
70
|
-
'## 10. Critical Context',
|
|
71
|
-
];
|
|
72
|
-
for (const section of expectedSections) {
|
|
73
|
-
expect(prompt).toContain(section);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
it('includes conversation text', () => {
|
|
77
|
-
const prompt = buildFullSummaryPrompt(conversation);
|
|
78
|
-
expect(prompt).toContain(conversation);
|
|
79
|
-
});
|
|
80
|
-
it('includes agent workflow state when isMultiAgent=true', () => {
|
|
81
|
-
const prompt = buildFullSummaryPrompt(conversation, {
|
|
82
|
-
isMultiAgent: true,
|
|
83
|
-
agentWorkflowState: {
|
|
84
|
-
currentAgentId: 'coder',
|
|
85
|
-
agentChain: ['planner', 'coder'],
|
|
86
|
-
pendingAgents: ['reviewer'],
|
|
87
|
-
},
|
|
88
|
-
});
|
|
89
|
-
expect(prompt).toContain('Current agent: coder');
|
|
90
|
-
expect(prompt).toContain('Agent chain: planner -> coder');
|
|
91
|
-
expect(prompt).toContain('Pending agents: reviewer');
|
|
92
|
-
expect(prompt).not.toContain('N/A (single-agent conversation)');
|
|
93
|
-
});
|
|
94
|
-
it('shows "none" for empty pendingAgents in multi-agent mode', () => {
|
|
95
|
-
const prompt = buildFullSummaryPrompt(conversation, {
|
|
96
|
-
isMultiAgent: true,
|
|
97
|
-
agentWorkflowState: {
|
|
98
|
-
currentAgentId: 'coder',
|
|
99
|
-
agentChain: ['coder'],
|
|
100
|
-
pendingAgents: [],
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
expect(prompt).toContain('Pending agents: none');
|
|
104
|
-
});
|
|
105
|
-
it('omits agent workflow when not multi-agent', () => {
|
|
106
|
-
const prompt = buildFullSummaryPrompt(conversation);
|
|
107
|
-
expect(prompt).toContain('N/A (single-agent conversation)');
|
|
108
|
-
});
|
|
109
|
-
it('omits agent workflow when isMultiAgent is true but no state provided', () => {
|
|
110
|
-
const prompt = buildFullSummaryPrompt(conversation, { isMultiAgent: true });
|
|
111
|
-
expect(prompt).toContain('N/A (single-agent conversation)');
|
|
112
|
-
});
|
|
113
|
-
});
|
|
114
|
-
describe('buildSimpleSummaryPrompt', () => {
|
|
115
|
-
it('contains "Summarize this conversation" directive', () => {
|
|
116
|
-
const prompt = buildSimpleSummaryPrompt('human: test');
|
|
117
|
-
expect(prompt).toContain('Summarize this conversation');
|
|
118
|
-
});
|
|
119
|
-
it('includes conversation text', () => {
|
|
120
|
-
const conversation = 'human: What is 2+2?\nai: 4';
|
|
121
|
-
const prompt = buildSimpleSummaryPrompt(conversation);
|
|
122
|
-
expect(prompt).toContain(conversation);
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
describe('createEmergencySummary', () => {
|
|
126
|
-
it('extracts first user message', () => {
|
|
127
|
-
const messages = [
|
|
128
|
-
new HumanMessage('First question'),
|
|
129
|
-
new HumanMessage('Second question'),
|
|
130
|
-
];
|
|
131
|
-
const result = createEmergencySummary(messages);
|
|
132
|
-
expect(result).toContain('Original request: First question');
|
|
133
|
-
});
|
|
134
|
-
it('extracts last AI message', () => {
|
|
135
|
-
const messages = [
|
|
136
|
-
new AIMessage('First answer'),
|
|
137
|
-
new AIMessage('Second answer'),
|
|
138
|
-
];
|
|
139
|
-
const result = createEmergencySummary(messages);
|
|
140
|
-
// Should contain the LAST AI message, not the first
|
|
141
|
-
expect(result).toContain('Last response: Second answer');
|
|
142
|
-
});
|
|
143
|
-
it('extracts tool names from tool messages', () => {
|
|
144
|
-
const messages = [
|
|
145
|
-
new ToolMessage({ content: 'result1', tool_call_id: 'tc1', name: 'search' }),
|
|
146
|
-
new ToolMessage({ content: 'result2', tool_call_id: 'tc2', name: 'calculator' }),
|
|
147
|
-
new ToolMessage({ content: 'result3', tool_call_id: 'tc3', name: 'search' }), // duplicate
|
|
148
|
-
];
|
|
149
|
-
const result = createEmergencySummary(messages);
|
|
150
|
-
expect(result).toContain('Tools used: search, calculator');
|
|
151
|
-
});
|
|
152
|
-
it('reports correct message count', () => {
|
|
153
|
-
const messages = [
|
|
154
|
-
new HumanMessage('q1'),
|
|
155
|
-
new AIMessage('a1'),
|
|
156
|
-
new HumanMessage('q2'),
|
|
157
|
-
new AIMessage('a2'),
|
|
158
|
-
new ToolMessage({ content: 'r', tool_call_id: 'tc1', name: 'tool1' }),
|
|
159
|
-
];
|
|
160
|
-
const result = createEmergencySummary(messages);
|
|
161
|
-
expect(result).toContain('Messages compacted: 5');
|
|
162
|
-
});
|
|
163
|
-
it('handles empty array', () => {
|
|
164
|
-
const result = createEmergencySummary([]);
|
|
165
|
-
expect(result).toContain('[Emergency Context Summary]');
|
|
166
|
-
expect(result).toContain('Original request: ');
|
|
167
|
-
expect(result).toContain('Last response: ');
|
|
168
|
-
expect(result).toContain('Tools used: none');
|
|
169
|
-
expect(result).toContain('Messages compacted: 0');
|
|
170
|
-
});
|
|
171
|
-
it('handles messages with no user or AI messages', () => {
|
|
172
|
-
const messages = [
|
|
173
|
-
new SystemMessage('You are helpful'),
|
|
174
|
-
new ToolMessage({ content: 'ok', tool_call_id: 'tc1', name: 'ping' }),
|
|
175
|
-
];
|
|
176
|
-
const result = createEmergencySummary(messages);
|
|
177
|
-
expect(result).toContain('Original request: ');
|
|
178
|
-
expect(result).toContain('Last response: ');
|
|
179
|
-
expect(result).toContain('Tools used: ping');
|
|
180
|
-
expect(result).toContain('Messages compacted: 2');
|
|
181
|
-
});
|
|
182
|
-
it('truncates long content to 500 chars', () => {
|
|
183
|
-
const longContent = 'a'.repeat(1000);
|
|
184
|
-
const messages = [new HumanMessage(longContent)];
|
|
185
|
-
const result = createEmergencySummary(messages);
|
|
186
|
-
// The original request should be truncated to 500 chars
|
|
187
|
-
expect(result).toContain(`Original request: ${'a'.repeat(500)}`);
|
|
188
|
-
expect(result).not.toContain('a'.repeat(501));
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
describe('validateSummarySize', () => {
|
|
192
|
-
it('returns true when summary fits in budget', () => {
|
|
193
|
-
const summary = 'Short summary';
|
|
194
|
-
// simpleTokenCounter: ceil(13/4) = 4 tokens
|
|
195
|
-
const result = validateSummarySize(summary, 100, simpleTokenCounter);
|
|
196
|
-
expect(result).toBe(true);
|
|
197
|
-
});
|
|
198
|
-
it('returns false when summary exceeds budget', () => {
|
|
199
|
-
const summary = 'This is a summary that should exceed a tiny budget';
|
|
200
|
-
// simpleTokenCounter: ceil(50/4) = 13 tokens
|
|
201
|
-
const result = validateSummarySize(summary, 1, simpleTokenCounter);
|
|
202
|
-
expect(result).toBe(false);
|
|
203
|
-
});
|
|
204
|
-
it('uses the provided tokenCounter', () => {
|
|
205
|
-
const customCounter = jest.fn().mockReturnValue(50);
|
|
206
|
-
validateSummarySize('any text', 100, customCounter);
|
|
207
|
-
expect(customCounter).toHaveBeenCalledTimes(1);
|
|
208
|
-
// Should be called with a HumanMessage wrapping the summary text
|
|
209
|
-
const arg = customCounter.mock.calls[0][0];
|
|
210
|
-
expect(arg).toBeInstanceOf(HumanMessage);
|
|
211
|
-
expect(arg.content).toBe('any text');
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
describe('summarize', () => {
|
|
215
|
-
const sampleMessages = [
|
|
216
|
-
new HumanMessage('What is TypeScript?'),
|
|
217
|
-
new AIMessage('TypeScript is a typed superset of JavaScript.'),
|
|
218
|
-
new ToolMessage({ content: 'tool result', tool_call_id: 'tc1', name: 'search' }),
|
|
219
|
-
];
|
|
220
|
-
it('Tier 1 success: callback returns valid summary -> result.tier === "full"', async () => {
|
|
221
|
-
const mockCallback = jest.fn().mockResolvedValueOnce('## Summary\nThis is a valid summary');
|
|
222
|
-
const result = await summarize(sampleMessages, mockCallback);
|
|
223
|
-
expect(result.tier).toBe('full');
|
|
224
|
-
expect(result.summary).toBe('## Summary\nThis is a valid summary');
|
|
225
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
226
|
-
});
|
|
227
|
-
it('Tier 1 fails -> Tier 2 success: first callback throws, second succeeds', async () => {
|
|
228
|
-
const mockCallback = jest.fn()
|
|
229
|
-
.mockRejectedValueOnce(new Error('LLM overloaded'))
|
|
230
|
-
.mockResolvedValueOnce('Simple summary');
|
|
231
|
-
const result = await summarize(sampleMessages, mockCallback);
|
|
232
|
-
expect(result.tier).toBe('simple');
|
|
233
|
-
expect(result.summary).toBe('Simple summary');
|
|
234
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
235
|
-
});
|
|
236
|
-
it('Tier 1 + 2 fail -> Tier 3: callback always throws', async () => {
|
|
237
|
-
const mockCallback = jest.fn().mockRejectedValue(new Error('LLM down'));
|
|
238
|
-
const result = await summarize(sampleMessages, mockCallback);
|
|
239
|
-
expect(result.tier).toBe('emergency');
|
|
240
|
-
expect(result.summary).toContain('[Emergency Context Summary]');
|
|
241
|
-
expect(result.summary).toContain('What is TypeScript?');
|
|
242
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
243
|
-
});
|
|
244
|
-
it('Callback returns undefined -> falls to Tier 2', async () => {
|
|
245
|
-
const mockCallback = jest.fn()
|
|
246
|
-
.mockResolvedValueOnce(undefined)
|
|
247
|
-
.mockResolvedValueOnce('Tier 2 summary');
|
|
248
|
-
const result = await summarize(sampleMessages, mockCallback);
|
|
249
|
-
expect(result.tier).toBe('simple');
|
|
250
|
-
expect(result.summary).toBe('Tier 2 summary');
|
|
251
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
252
|
-
});
|
|
253
|
-
it('Callback returns empty string -> falls to Tier 2', async () => {
|
|
254
|
-
const mockCallback = jest.fn()
|
|
255
|
-
.mockResolvedValueOnce('')
|
|
256
|
-
.mockResolvedValueOnce('Tier 2 result');
|
|
257
|
-
const result = await summarize(sampleMessages, mockCallback);
|
|
258
|
-
expect(result.tier).toBe('simple');
|
|
259
|
-
expect(result.summary).toBe('Tier 2 result');
|
|
260
|
-
});
|
|
261
|
-
it('Empty messages: returns emergency summary immediately', async () => {
|
|
262
|
-
const mockCallback = jest.fn().mockResolvedValue('should not matter');
|
|
263
|
-
const result = await summarize([], mockCallback);
|
|
264
|
-
// With empty messages, tier 1 still runs (formatMessagesForSummary returns ''),
|
|
265
|
-
// but callback returns content so it should succeed as tier 1
|
|
266
|
-
// unless the callback result is validated against budget.
|
|
267
|
-
// Actually, empty messages still go through the normal flow.
|
|
268
|
-
// The callback returns a valid string, so it should be 'full'.
|
|
269
|
-
expect(result.messagesCompacted).toBe(0);
|
|
270
|
-
});
|
|
271
|
-
it('Token budget validation: summary exceeds budget -> falls to next tier', async () => {
|
|
272
|
-
const longSummary = 'x'.repeat(2000);
|
|
273
|
-
const mockCallback = jest.fn()
|
|
274
|
-
.mockResolvedValueOnce(longSummary) // Tier 1: exceeds budget
|
|
275
|
-
.mockResolvedValueOnce('Short tier 2 summary'); // Tier 2: no budget check
|
|
276
|
-
const result = await summarize(sampleMessages, mockCallback, {
|
|
277
|
-
summaryBudget: 10, // Very small budget: 10 tokens
|
|
278
|
-
tokenCounter: simpleTokenCounter,
|
|
279
|
-
});
|
|
280
|
-
expect(result.tier).toBe('simple');
|
|
281
|
-
expect(result.summary).toBe('Short tier 2 summary');
|
|
282
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
283
|
-
});
|
|
284
|
-
it('Token budget validation: summary fits within budget -> stays at Tier 1', async () => {
|
|
285
|
-
const mockCallback = jest.fn().mockResolvedValueOnce('Short summary');
|
|
286
|
-
const result = await summarize(sampleMessages, mockCallback, {
|
|
287
|
-
summaryBudget: 1000,
|
|
288
|
-
tokenCounter: simpleTokenCounter,
|
|
289
|
-
});
|
|
290
|
-
expect(result.tier).toBe('full');
|
|
291
|
-
expect(result.summary).toBe('Short summary');
|
|
292
|
-
expect(mockCallback).toHaveBeenCalledTimes(1);
|
|
293
|
-
});
|
|
294
|
-
it('messagesCompacted count matches input length', async () => {
|
|
295
|
-
const mockCallback = jest.fn().mockResolvedValueOnce('Valid summary');
|
|
296
|
-
const messages = [
|
|
297
|
-
new HumanMessage('q1'),
|
|
298
|
-
new AIMessage('a1'),
|
|
299
|
-
new HumanMessage('q2'),
|
|
300
|
-
new AIMessage('a2'),
|
|
301
|
-
new HumanMessage('q3'),
|
|
302
|
-
];
|
|
303
|
-
const result = await summarize(messages, mockCallback);
|
|
304
|
-
expect(result.messagesCompacted).toBe(5);
|
|
305
|
-
});
|
|
306
|
-
it('messagesCompacted count is correct even for emergency tier', async () => {
|
|
307
|
-
const mockCallback = jest.fn().mockRejectedValue(new Error('fail'));
|
|
308
|
-
const result = await summarize(sampleMessages, mockCallback);
|
|
309
|
-
expect(result.tier).toBe('emergency');
|
|
310
|
-
expect(result.messagesCompacted).toBe(3);
|
|
311
|
-
});
|
|
312
|
-
it('passes maxOutputTokens to Tier 1 callback', async () => {
|
|
313
|
-
const mockCallback = jest.fn().mockResolvedValueOnce('Summary');
|
|
314
|
-
await summarize(sampleMessages, mockCallback, { maxOutputTokens: 2048 });
|
|
315
|
-
expect(mockCallback).toHaveBeenCalledWith(expect.any(String), 2048);
|
|
316
|
-
});
|
|
317
|
-
it('defaults maxOutputTokens to 1024 for Tier 1', async () => {
|
|
318
|
-
const mockCallback = jest.fn().mockResolvedValueOnce('Summary');
|
|
319
|
-
await summarize(sampleMessages, mockCallback);
|
|
320
|
-
expect(mockCallback).toHaveBeenCalledWith(expect.any(String), 1024);
|
|
321
|
-
});
|
|
322
|
-
it('passes 512 as maxTokens for Tier 2 (simple) callback', async () => {
|
|
323
|
-
const mockCallback = jest.fn()
|
|
324
|
-
.mockRejectedValueOnce(new Error('Tier 1 fail'))
|
|
325
|
-
.mockResolvedValueOnce('Simple summary');
|
|
326
|
-
await summarize(sampleMessages, mockCallback);
|
|
327
|
-
// Second call (Tier 2) should use SIMPLE_MAX_TOKENS = 512
|
|
328
|
-
expect(mockCallback).toHaveBeenCalledTimes(2);
|
|
329
|
-
expect(mockCallback.mock.calls[1][1]).toBe(512);
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
//# sourceMappingURL=summarize.test.js.map
|
package/src/messages/tools.js
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
// src/messages/toolDiscovery.ts
|
|
2
|
-
import { AIMessageChunk } from '@langchain/core/messages';
|
|
3
|
-
import { Constants, MessageTypes } from '@/common';
|
|
4
|
-
import { findLastIndex } from './core';
|
|
5
|
-
/**
|
|
6
|
-
* Extracts discovered tool names from tool search results in the current turn.
|
|
7
|
-
* Only processes tool search messages after the latest AI message with tool calls.
|
|
8
|
-
*
|
|
9
|
-
* Similar pattern to formatArtifactPayload - finds relevant messages efficiently
|
|
10
|
-
* by identifying the latest AI parent and only processing subsequent tool messages.
|
|
11
|
-
*
|
|
12
|
-
* @param messages - All messages in the conversation
|
|
13
|
-
* @returns Array of discovered tool names (empty if no new discoveries)
|
|
14
|
-
*/
|
|
15
|
-
export function extractToolDiscoveries(messages) {
|
|
16
|
-
if (messages.length === 0)
|
|
17
|
-
return [];
|
|
18
|
-
const lastMessage = messages[messages.length - 1];
|
|
19
|
-
// Use getType() instead of instanceof to avoid module mismatch issues
|
|
20
|
-
if (lastMessage.getType() !== MessageTypes.TOOL)
|
|
21
|
-
return [];
|
|
22
|
-
const lastToolMessage = lastMessage;
|
|
23
|
-
// Find the latest AIMessage with tool_calls that this tool message belongs to
|
|
24
|
-
const latestAIParentIndex = findLastIndex(messages, (msg) => (msg instanceof AIMessageChunk &&
|
|
25
|
-
(msg.tool_calls?.length ?? 0) > 0 &&
|
|
26
|
-
msg.tool_calls?.some((tc) => tc.id === lastToolMessage.tool_call_id)) ??
|
|
27
|
-
false);
|
|
28
|
-
if (latestAIParentIndex === -1)
|
|
29
|
-
return [];
|
|
30
|
-
// Collect tool_call_ids from the AI message
|
|
31
|
-
const aiMessage = messages[latestAIParentIndex];
|
|
32
|
-
const toolCallIds = new Set(aiMessage.tool_calls?.map((tc) => tc.id) ?? []);
|
|
33
|
-
// Only process tool search results after the AI message that belong to this turn
|
|
34
|
-
const discoveredNames = [];
|
|
35
|
-
for (let i = latestAIParentIndex + 1; i < messages.length; i++) {
|
|
36
|
-
const msg = messages[i];
|
|
37
|
-
// Use getType() instead of instanceof to avoid module mismatch issues
|
|
38
|
-
if (msg.getType() !== MessageTypes.TOOL)
|
|
39
|
-
continue;
|
|
40
|
-
const toolMsg = msg;
|
|
41
|
-
if (toolMsg.name !== Constants.TOOL_SEARCH)
|
|
42
|
-
continue;
|
|
43
|
-
if (!toolCallIds.has(toolMsg.tool_call_id))
|
|
44
|
-
continue;
|
|
45
|
-
// This is a tool search result from the current turn
|
|
46
|
-
if (typeof toolMsg.artifact === 'object' && toolMsg.artifact != null) {
|
|
47
|
-
const artifact = toolMsg.artifact;
|
|
48
|
-
if (artifact.tool_references && artifact.tool_references.length > 0) {
|
|
49
|
-
for (const ref of artifact.tool_references) {
|
|
50
|
-
discoveredNames.push(ref.tool_name);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return discoveredNames;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Checks if the current turn has any tool search results.
|
|
59
|
-
* Quick check to avoid full extraction when not needed.
|
|
60
|
-
*/
|
|
61
|
-
export function hasToolSearchInCurrentTurn(messages) {
|
|
62
|
-
if (messages.length === 0)
|
|
63
|
-
return false;
|
|
64
|
-
const lastMessage = messages[messages.length - 1];
|
|
65
|
-
// Use getType() instead of instanceof to avoid module mismatch issues
|
|
66
|
-
if (lastMessage.getType() !== MessageTypes.TOOL)
|
|
67
|
-
return false;
|
|
68
|
-
const lastToolMessage = lastMessage;
|
|
69
|
-
// Find the latest AIMessage with tool_calls
|
|
70
|
-
const latestAIParentIndex = findLastIndex(messages, (msg) => (msg instanceof AIMessageChunk &&
|
|
71
|
-
(msg.tool_calls?.length ?? 0) > 0 &&
|
|
72
|
-
msg.tool_calls?.some((tc) => tc.id === lastToolMessage.tool_call_id)) ??
|
|
73
|
-
false);
|
|
74
|
-
if (latestAIParentIndex === -1)
|
|
75
|
-
return false;
|
|
76
|
-
const aiMessage = messages[latestAIParentIndex];
|
|
77
|
-
const toolCallIds = new Set(aiMessage.tool_calls?.map((tc) => tc.id) ?? []);
|
|
78
|
-
// Check if any tool search results exist after the AI message
|
|
79
|
-
// Use getType() instead of instanceof to avoid module mismatch issues
|
|
80
|
-
for (let i = latestAIParentIndex + 1; i < messages.length; i++) {
|
|
81
|
-
const msg = messages[i];
|
|
82
|
-
if (msg.getType() === MessageTypes.TOOL &&
|
|
83
|
-
msg.name === Constants.TOOL_SEARCH &&
|
|
84
|
-
toolCallIds.has(msg.tool_call_id)) {
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return false;
|
|
89
|
-
}
|
|
90
|
-
//# sourceMappingURL=tools.js.map
|
package/src/mockStream.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// import { SplitStreamHandler } from '@/splitStream';
|
|
2
|
-
// import { GraphEvents } from '@/common';
|
|
3
|
-
import { sleep } from '@/utils';
|
|
4
|
-
const choiceProps = { finish_reason: null, index: 0, delta: {} };
|
|
5
|
-
const reasoningSplitRegex = /(?<=\s+)|(?=\s+)/;
|
|
6
|
-
const contentSplitRegex = /(?<=<\/?think>)|(?=<\/?think>)|(?<=\s+)|(?=\s+)/;
|
|
7
|
-
export const createMockStream = (options = {}) => {
|
|
8
|
-
const { text, reasoningText, streamRate = 25, reasoningKey = 'reasoning_content' } = options;
|
|
9
|
-
return async function* mockOpenAIStream() {
|
|
10
|
-
const content = text ?? `Here's a sample message that includes code:
|
|
11
|
-
\`\`\`python
|
|
12
|
-
def hello_world():
|
|
13
|
-
print("Hello, World!")
|
|
14
|
-
# This is a long code block
|
|
15
|
-
# That shouldn't be split
|
|
16
|
-
return True
|
|
17
|
-
\`\`\`
|
|
18
|
-
Now we're back to regular text. This is a very long sentence that should probably be split at some point because it exceeds our threshold and contains multiple natural breaking points. Let's see how it handles this case properly.
|
|
19
|
-
|
|
20
|
-
Here's another code block:
|
|
21
|
-
\`\`\`javascript
|
|
22
|
-
console.log("Another test");
|
|
23
|
-
// More code here
|
|
24
|
-
\`\`\`
|
|
25
|
-
And finally some more regular text to test our splitting logic.`;
|
|
26
|
-
if (reasoningText != null && reasoningText) {
|
|
27
|
-
// Split reasoning text into "token-like" chunks
|
|
28
|
-
const reasoningTokens = reasoningText.split(reasoningSplitRegex);
|
|
29
|
-
for (const token of reasoningTokens) {
|
|
30
|
-
yield {
|
|
31
|
-
choices: [{
|
|
32
|
-
...choiceProps,
|
|
33
|
-
delta: {
|
|
34
|
-
[reasoningKey]: token,
|
|
35
|
-
},
|
|
36
|
-
}]
|
|
37
|
-
};
|
|
38
|
-
await sleep(streamRate);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Split main content into "token-like" chunks
|
|
42
|
-
const tokens = content.split(contentSplitRegex);
|
|
43
|
-
for (const token of tokens) {
|
|
44
|
-
yield {
|
|
45
|
-
choices: [{
|
|
46
|
-
...choiceProps,
|
|
47
|
-
delta: {
|
|
48
|
-
content: token
|
|
49
|
-
}
|
|
50
|
-
}]
|
|
51
|
-
};
|
|
52
|
-
await sleep(streamRate);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
(async function testStream(): Promise<void> {
|
|
58
|
-
const runId = nanoid();
|
|
59
|
-
|
|
60
|
-
const streamHandler = new SplitStreamHandler({
|
|
61
|
-
runId,
|
|
62
|
-
handlers: {
|
|
63
|
-
[GraphEvents.ON_RUN_STEP]: (data): void => {
|
|
64
|
-
console.dir(data, { depth: null });
|
|
65
|
-
},
|
|
66
|
-
[GraphEvents.ON_MESSAGE_DELTA]: (): void => {
|
|
67
|
-
// console.dir(data, { depth: null });
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
const stream = createMockStream({
|
|
72
|
-
reasoningText: 'This is a test reasoning text.',
|
|
73
|
-
streamRate: 5,
|
|
74
|
-
})();
|
|
75
|
-
|
|
76
|
-
for await (const chunk of stream) {
|
|
77
|
-
streamHandler.handle(chunk);
|
|
78
|
-
}
|
|
79
|
-
})();
|
|
80
|
-
*/
|
|
81
|
-
//# sourceMappingURL=mockStream.js.map
|
package/src/prompts/collab.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// src/prompts/collab.ts
|
|
2
|
-
export const supervisorPrompt = `You are a supervisor tasked with managing a conversation between the
|
|
3
|
-
following workers: {members}. Given the following user request,
|
|
4
|
-
respond with the worker to act next. Each worker will perform a
|
|
5
|
-
task and respond with their results and status. Multiple workers can work at once, and they can use multiple tools at once. Each worker can run their tools multiple times per task. When finished,
|
|
6
|
-
respond with FINISH.`;
|
|
7
|
-
//# sourceMappingURL=collab.js.map
|
package/src/prompts/index.js
DELETED