illuma-agents 1.0.9 → 1.0.11
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/LICENSE +1 -1
- package/dist/cjs/agents/AgentContext.cjs +228 -27
- package/dist/cjs/agents/AgentContext.cjs.map +1 -1
- package/dist/cjs/common/enum.cjs +2 -0
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/events.cjs +3 -0
- package/dist/cjs/events.cjs.map +1 -1
- package/dist/cjs/graphs/Graph.cjs +29 -19
- package/dist/cjs/graphs/Graph.cjs.map +1 -1
- package/dist/cjs/instrumentation.cjs +1 -1
- package/dist/cjs/instrumentation.cjs.map +1 -1
- package/dist/cjs/llm/anthropic/index.cjs +1 -1
- package/dist/cjs/llm/anthropic/index.cjs.map +1 -1
- package/dist/cjs/llm/bedrock/index.cjs +122 -7
- package/dist/cjs/llm/bedrock/index.cjs.map +1 -1
- package/dist/cjs/llm/google/index.cjs +1 -1
- package/dist/cjs/llm/google/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/index.cjs +108 -6
- package/dist/cjs/llm/openai/index.cjs.map +1 -1
- package/dist/cjs/llm/openai/utils/index.cjs +87 -1
- package/dist/cjs/llm/openai/utils/index.cjs.map +1 -1
- package/dist/cjs/llm/openrouter/index.cjs +176 -2
- package/dist/cjs/llm/openrouter/index.cjs.map +1 -1
- package/dist/cjs/main.cjs +18 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/messages/cache.cjs +149 -54
- package/dist/cjs/messages/cache.cjs.map +1 -1
- package/dist/cjs/messages/tools.cjs +85 -0
- package/dist/cjs/messages/tools.cjs.map +1 -0
- package/dist/cjs/stream.cjs +20 -0
- package/dist/cjs/stream.cjs.map +1 -1
- package/dist/cjs/tools/CodeExecutor.cjs +4 -0
- package/dist/cjs/tools/CodeExecutor.cjs.map +1 -1
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs +438 -0
- package/dist/cjs/tools/ProgrammaticToolCalling.cjs.map +1 -0
- package/dist/cjs/tools/ToolNode.cjs +54 -6
- package/dist/cjs/tools/ToolNode.cjs.map +1 -1
- package/dist/cjs/tools/ToolSearchRegex.cjs +455 -0
- package/dist/cjs/tools/ToolSearchRegex.cjs.map +1 -0
- package/dist/cjs/tools/search/tool.cjs +21 -1
- package/dist/cjs/tools/search/tool.cjs.map +1 -1
- package/dist/cjs/utils/run.cjs +5 -1
- package/dist/cjs/utils/run.cjs.map +1 -1
- package/dist/esm/agents/AgentContext.mjs +228 -27
- package/dist/esm/agents/AgentContext.mjs.map +1 -1
- package/dist/esm/common/enum.mjs +2 -0
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/events.mjs +4 -1
- package/dist/esm/events.mjs.map +1 -1
- package/dist/esm/graphs/Graph.mjs +29 -19
- package/dist/esm/graphs/Graph.mjs.map +1 -1
- package/dist/esm/instrumentation.mjs +1 -1
- package/dist/esm/instrumentation.mjs.map +1 -1
- package/dist/esm/llm/anthropic/index.mjs +1 -1
- package/dist/esm/llm/anthropic/index.mjs.map +1 -1
- package/dist/esm/llm/bedrock/index.mjs +122 -7
- package/dist/esm/llm/bedrock/index.mjs.map +1 -1
- package/dist/esm/llm/google/index.mjs +1 -1
- package/dist/esm/llm/google/index.mjs.map +1 -1
- package/dist/esm/llm/openai/index.mjs +109 -7
- package/dist/esm/llm/openai/index.mjs.map +1 -1
- package/dist/esm/llm/openai/utils/index.mjs +88 -2
- package/dist/esm/llm/openai/utils/index.mjs.map +1 -1
- package/dist/esm/llm/openrouter/index.mjs +176 -2
- package/dist/esm/llm/openrouter/index.mjs.map +1 -1
- package/dist/esm/main.mjs +3 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/messages/cache.mjs +149 -54
- package/dist/esm/messages/cache.mjs.map +1 -1
- package/dist/esm/messages/tools.mjs +82 -0
- package/dist/esm/messages/tools.mjs.map +1 -0
- package/dist/esm/stream.mjs +20 -0
- package/dist/esm/stream.mjs.map +1 -1
- package/dist/esm/tools/CodeExecutor.mjs +4 -0
- package/dist/esm/tools/CodeExecutor.mjs.map +1 -1
- package/dist/esm/tools/ProgrammaticToolCalling.mjs +430 -0
- package/dist/esm/tools/ProgrammaticToolCalling.mjs.map +1 -0
- package/dist/esm/tools/ToolNode.mjs +54 -6
- package/dist/esm/tools/ToolNode.mjs.map +1 -1
- package/dist/esm/tools/ToolSearchRegex.mjs +448 -0
- package/dist/esm/tools/ToolSearchRegex.mjs.map +1 -0
- package/dist/esm/tools/search/tool.mjs +21 -1
- package/dist/esm/tools/search/tool.mjs.map +1 -1
- package/dist/esm/utils/run.mjs +5 -1
- package/dist/esm/utils/run.mjs.map +1 -1
- package/dist/types/agents/AgentContext.d.ts +65 -5
- package/dist/types/common/enum.d.ts +2 -0
- package/dist/types/graphs/Graph.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/llm/anthropic/index.d.ts +1 -1
- package/dist/types/llm/bedrock/index.d.ts +31 -4
- package/dist/types/llm/google/index.d.ts +1 -1
- package/dist/types/llm/openai/index.d.ts +4 -3
- package/dist/types/llm/openai/utils/index.d.ts +10 -1
- package/dist/types/llm/openrouter/index.d.ts +5 -2
- package/dist/types/messages/cache.d.ts +23 -8
- package/dist/types/messages/index.d.ts +1 -0
- package/dist/types/messages/tools.d.ts +17 -0
- package/dist/types/test/mockTools.d.ts +28 -0
- package/dist/types/tools/ProgrammaticToolCalling.d.ts +91 -0
- package/dist/types/tools/ToolNode.d.ts +10 -2
- package/dist/types/tools/ToolSearchRegex.d.ts +80 -0
- package/dist/types/types/graph.d.ts +7 -1
- package/dist/types/types/tools.d.ts +138 -0
- package/package.json +8 -3
- package/src/agents/AgentContext.ts +267 -27
- package/src/agents/__tests__/AgentContext.test.ts +805 -0
- package/src/common/enum.ts +2 -0
- package/src/events.ts +5 -1
- package/src/graphs/Graph.ts +35 -20
- package/src/index.ts +2 -0
- package/src/instrumentation.ts +1 -1
- package/src/llm/anthropic/index.ts +2 -2
- package/src/llm/bedrock/__tests__/bedrock-caching.test.ts +473 -0
- package/src/llm/bedrock/index.ts +150 -13
- package/src/llm/google/index.ts +2 -2
- package/src/llm/google/llm.spec.ts +3 -1
- package/src/llm/openai/index.ts +135 -9
- package/src/llm/openai/utils/index.ts +116 -1
- package/src/llm/openrouter/index.ts +224 -3
- package/src/messages/__tests__/tools.test.ts +473 -0
- package/src/messages/cache.ts +163 -61
- package/src/messages/index.ts +1 -0
- package/src/messages/tools.ts +99 -0
- package/src/scripts/code_exec_ptc.ts +334 -0
- package/src/scripts/programmatic_exec.ts +396 -0
- package/src/scripts/programmatic_exec_agent.ts +231 -0
- package/src/scripts/tool_search_regex.ts +162 -0
- package/src/specs/thinking-prune.test.ts +52 -118
- package/src/stream.ts +26 -0
- package/src/test/mockTools.ts +366 -0
- package/src/tools/CodeExecutor.ts +4 -0
- package/src/tools/ProgrammaticToolCalling.ts +558 -0
- package/src/tools/ToolNode.ts +60 -7
- package/src/tools/ToolSearchRegex.ts +535 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.integration.test.ts +318 -0
- package/src/tools/__tests__/ProgrammaticToolCalling.test.ts +853 -0
- package/src/tools/__tests__/ToolSearchRegex.integration.test.ts +161 -0
- package/src/tools/__tests__/ToolSearchRegex.test.ts +232 -0
- package/src/tools/search/jina-reranker.test.ts +16 -16
- package/src/tools/search/tool.ts +23 -1
- package/src/types/graph.ts +7 -1
- package/src/types/tools.ts +166 -0
- package/src/utils/llmConfig.ts +8 -2
- package/src/utils/run.ts +5 -1
- package/src/tools/search/direct-url.test.ts +0 -530
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { ChatOpenAI } from '@/llm/openai';
|
|
2
|
+
import { ChatGenerationChunk } from '@langchain/core/outputs';
|
|
3
|
+
import { CallbackManagerForLLMRun } from '@langchain/core/callbacks/manager';
|
|
4
|
+
import { AIMessageChunk as AIMessageChunkClass } from '@langchain/core/messages';
|
|
2
5
|
import type {
|
|
3
6
|
FunctionMessageChunk,
|
|
4
7
|
SystemMessageChunk,
|
|
@@ -6,12 +9,25 @@ import type {
|
|
|
6
9
|
ToolMessageChunk,
|
|
7
10
|
ChatMessageChunk,
|
|
8
11
|
AIMessageChunk,
|
|
12
|
+
BaseMessage,
|
|
9
13
|
} from '@langchain/core/messages';
|
|
10
14
|
import type {
|
|
11
15
|
ChatOpenAICallOptions,
|
|
12
16
|
OpenAIChatInput,
|
|
13
17
|
OpenAIClient,
|
|
14
18
|
} from '@langchain/openai';
|
|
19
|
+
import { _convertMessagesToOpenAIParams } from '@/llm/openai/utils';
|
|
20
|
+
|
|
21
|
+
type OpenAICompletionParam =
|
|
22
|
+
OpenAIClient.Chat.Completions.ChatCompletionMessageParam;
|
|
23
|
+
|
|
24
|
+
type OpenAIRoleEnum =
|
|
25
|
+
| 'system'
|
|
26
|
+
| 'developer'
|
|
27
|
+
| 'assistant'
|
|
28
|
+
| 'user'
|
|
29
|
+
| 'function'
|
|
30
|
+
| 'tool';
|
|
15
31
|
|
|
16
32
|
export interface ChatOpenRouterCallOptions extends ChatOpenAICallOptions {
|
|
17
33
|
include_reasoning?: boolean;
|
|
@@ -28,8 +44,8 @@ export class ChatOpenRouter extends ChatOpenAI {
|
|
|
28
44
|
},
|
|
29
45
|
});
|
|
30
46
|
}
|
|
31
|
-
static lc_name(): '
|
|
32
|
-
return '
|
|
47
|
+
static lc_name(): 'LibreChatOpenRouter' {
|
|
48
|
+
return 'LibreChatOpenRouter';
|
|
33
49
|
}
|
|
34
50
|
protected override _convertOpenAIDeltaToBaseMessageChunk(
|
|
35
51
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -54,7 +70,212 @@ export class ChatOpenRouter extends ChatOpenAI {
|
|
|
54
70
|
rawResponse,
|
|
55
71
|
defaultRole
|
|
56
72
|
);
|
|
57
|
-
|
|
73
|
+
if (delta.reasoning != null) {
|
|
74
|
+
messageChunk.additional_kwargs.reasoning = delta.reasoning;
|
|
75
|
+
}
|
|
76
|
+
if (delta.reasoning_details != null) {
|
|
77
|
+
messageChunk.additional_kwargs.reasoning_details =
|
|
78
|
+
delta.reasoning_details;
|
|
79
|
+
}
|
|
58
80
|
return messageChunk;
|
|
59
81
|
}
|
|
82
|
+
|
|
83
|
+
async *_streamResponseChunks2(
|
|
84
|
+
messages: BaseMessage[],
|
|
85
|
+
options: this['ParsedCallOptions'],
|
|
86
|
+
runManager?: CallbackManagerForLLMRun
|
|
87
|
+
): AsyncGenerator<ChatGenerationChunk> {
|
|
88
|
+
const messagesMapped: OpenAICompletionParam[] =
|
|
89
|
+
_convertMessagesToOpenAIParams(messages, this.model, {
|
|
90
|
+
includeReasoningDetails: true,
|
|
91
|
+
convertReasoningDetailsToContent: true,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const params = {
|
|
95
|
+
...this.invocationParams(options, {
|
|
96
|
+
streaming: true,
|
|
97
|
+
}),
|
|
98
|
+
messages: messagesMapped,
|
|
99
|
+
stream: true as const,
|
|
100
|
+
};
|
|
101
|
+
let defaultRole: OpenAIRoleEnum | undefined;
|
|
102
|
+
|
|
103
|
+
const streamIterable = await this.completionWithRetry(params, options);
|
|
104
|
+
let usage: OpenAIClient.Completions.CompletionUsage | undefined;
|
|
105
|
+
|
|
106
|
+
// Store reasoning_details keyed by unique identifier to prevent incorrect merging
|
|
107
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
+
const reasoningTextByIndex: Map<number, Record<string, any>> = new Map();
|
|
109
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
110
|
+
const reasoningEncryptedById: Map<string, Record<string, any>> = new Map();
|
|
111
|
+
|
|
112
|
+
for await (const data of streamIterable) {
|
|
113
|
+
const choice = data.choices[0] as
|
|
114
|
+
| Partial<OpenAIClient.Chat.Completions.ChatCompletionChunk.Choice>
|
|
115
|
+
| undefined;
|
|
116
|
+
if (data.usage) {
|
|
117
|
+
usage = data.usage;
|
|
118
|
+
}
|
|
119
|
+
if (!choice) {
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const { delta } = choice;
|
|
124
|
+
if (!delta) {
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Accumulate reasoning_details from each delta
|
|
129
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
130
|
+
const deltaAny = delta as Record<string, any>;
|
|
131
|
+
if (
|
|
132
|
+
deltaAny.reasoning_details != null &&
|
|
133
|
+
Array.isArray(deltaAny.reasoning_details)
|
|
134
|
+
) {
|
|
135
|
+
for (const detail of deltaAny.reasoning_details) {
|
|
136
|
+
// For encrypted reasoning (thought signatures), store by ID - MUST be separate
|
|
137
|
+
if (detail.type === 'reasoning.encrypted' && detail.id) {
|
|
138
|
+
reasoningEncryptedById.set(detail.id, {
|
|
139
|
+
type: detail.type,
|
|
140
|
+
id: detail.id,
|
|
141
|
+
data: detail.data,
|
|
142
|
+
format: detail.format,
|
|
143
|
+
index: detail.index,
|
|
144
|
+
});
|
|
145
|
+
} else if (detail.type === 'reasoning.text') {
|
|
146
|
+
// For text reasoning, accumulate text by index
|
|
147
|
+
const idx = detail.index ?? 0;
|
|
148
|
+
const existing = reasoningTextByIndex.get(idx);
|
|
149
|
+
if (existing) {
|
|
150
|
+
// Only append text, keep other fields from first entry
|
|
151
|
+
existing.text = (existing.text || '') + (detail.text || '');
|
|
152
|
+
} else {
|
|
153
|
+
reasoningTextByIndex.set(idx, {
|
|
154
|
+
type: detail.type,
|
|
155
|
+
text: detail.text || '',
|
|
156
|
+
format: detail.format,
|
|
157
|
+
index: idx,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const chunk = this._convertOpenAIDeltaToBaseMessageChunk(
|
|
165
|
+
delta,
|
|
166
|
+
data,
|
|
167
|
+
defaultRole
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
// IMPORTANT: Only set reasoning_details on the FINAL chunk to prevent
|
|
171
|
+
// LangChain's chunk concatenation from corrupting the array
|
|
172
|
+
// Check if this is the final chunk (has finish_reason)
|
|
173
|
+
if (choice.finish_reason != null) {
|
|
174
|
+
// Build properly structured reasoning_details array
|
|
175
|
+
// Text entries first (but we only need the encrypted ones for thought signatures)
|
|
176
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
177
|
+
const finalReasoningDetails: Record<string, any>[] = [
|
|
178
|
+
...reasoningTextByIndex.values(),
|
|
179
|
+
...reasoningEncryptedById.values(),
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
if (finalReasoningDetails.length > 0) {
|
|
183
|
+
chunk.additional_kwargs.reasoning_details = finalReasoningDetails;
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
// Clear reasoning_details from intermediate chunks to prevent concatenation issues
|
|
187
|
+
delete chunk.additional_kwargs.reasoning_details;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
defaultRole = delta.role ?? defaultRole;
|
|
191
|
+
const newTokenIndices = {
|
|
192
|
+
prompt: options.promptIndex ?? 0,
|
|
193
|
+
completion: choice.index ?? 0,
|
|
194
|
+
};
|
|
195
|
+
if (typeof chunk.content !== 'string') {
|
|
196
|
+
// eslint-disable-next-line no-console
|
|
197
|
+
console.log(
|
|
198
|
+
'[WARNING]: Received non-string content from OpenAI. This is currently not supported.'
|
|
199
|
+
);
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
+
const generationInfo: Record<string, any> = { ...newTokenIndices };
|
|
204
|
+
if (choice.finish_reason != null) {
|
|
205
|
+
generationInfo.finish_reason = choice.finish_reason;
|
|
206
|
+
generationInfo.system_fingerprint = data.system_fingerprint;
|
|
207
|
+
generationInfo.model_name = data.model;
|
|
208
|
+
generationInfo.service_tier = data.service_tier;
|
|
209
|
+
}
|
|
210
|
+
if (this.logprobs == true) {
|
|
211
|
+
generationInfo.logprobs = choice.logprobs;
|
|
212
|
+
}
|
|
213
|
+
const generationChunk = new ChatGenerationChunk({
|
|
214
|
+
message: chunk,
|
|
215
|
+
text: chunk.content,
|
|
216
|
+
generationInfo,
|
|
217
|
+
});
|
|
218
|
+
yield generationChunk;
|
|
219
|
+
if (this._lc_stream_delay != null) {
|
|
220
|
+
await new Promise((resolve) =>
|
|
221
|
+
setTimeout(resolve, this._lc_stream_delay)
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
await runManager?.handleLLMNewToken(
|
|
225
|
+
generationChunk.text || '',
|
|
226
|
+
newTokenIndices,
|
|
227
|
+
undefined,
|
|
228
|
+
undefined,
|
|
229
|
+
undefined,
|
|
230
|
+
{ chunk: generationChunk }
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (usage) {
|
|
234
|
+
const inputTokenDetails = {
|
|
235
|
+
...(usage.prompt_tokens_details?.audio_tokens != null && {
|
|
236
|
+
audio: usage.prompt_tokens_details.audio_tokens,
|
|
237
|
+
}),
|
|
238
|
+
...(usage.prompt_tokens_details?.cached_tokens != null && {
|
|
239
|
+
cache_read: usage.prompt_tokens_details.cached_tokens,
|
|
240
|
+
}),
|
|
241
|
+
};
|
|
242
|
+
const outputTokenDetails = {
|
|
243
|
+
...(usage.completion_tokens_details?.audio_tokens != null && {
|
|
244
|
+
audio: usage.completion_tokens_details.audio_tokens,
|
|
245
|
+
}),
|
|
246
|
+
...(usage.completion_tokens_details?.reasoning_tokens != null && {
|
|
247
|
+
reasoning: usage.completion_tokens_details.reasoning_tokens,
|
|
248
|
+
}),
|
|
249
|
+
};
|
|
250
|
+
const generationChunk = new ChatGenerationChunk({
|
|
251
|
+
message: new AIMessageChunkClass({
|
|
252
|
+
content: '',
|
|
253
|
+
response_metadata: {
|
|
254
|
+
usage: { ...usage },
|
|
255
|
+
},
|
|
256
|
+
usage_metadata: {
|
|
257
|
+
input_tokens: usage.prompt_tokens,
|
|
258
|
+
output_tokens: usage.completion_tokens,
|
|
259
|
+
total_tokens: usage.total_tokens,
|
|
260
|
+
...(Object.keys(inputTokenDetails).length > 0 && {
|
|
261
|
+
input_token_details: inputTokenDetails,
|
|
262
|
+
}),
|
|
263
|
+
...(Object.keys(outputTokenDetails).length > 0 && {
|
|
264
|
+
output_token_details: outputTokenDetails,
|
|
265
|
+
}),
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
text: '',
|
|
269
|
+
});
|
|
270
|
+
yield generationChunk;
|
|
271
|
+
if (this._lc_stream_delay != null) {
|
|
272
|
+
await new Promise((resolve) =>
|
|
273
|
+
setTimeout(resolve, this._lc_stream_delay)
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (options.signal?.aborted === true) {
|
|
278
|
+
throw new Error('AbortError');
|
|
279
|
+
}
|
|
280
|
+
}
|
|
60
281
|
}
|