@jaypie/llm 1.3.6 → 1.3.7
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/index.cjs +158 -11
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +52 -2
- package/dist/cjs/src/index.d.ts +2 -2
- package/dist/cjs/src/operate/OperateLoop.d.ts +5 -0
- package/dist/cjs/src/operate/progress/emitProgress.d.ts +10 -0
- package/dist/cjs/src/operate/progress/index.d.ts +1 -0
- package/dist/cjs/src/types/LlmProvider.interface.d.ts +50 -0
- package/dist/esm/index.d.ts +52 -2
- package/dist/esm/index.js +159 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/index.d.ts +2 -2
- package/dist/esm/src/operate/OperateLoop.d.ts +5 -0
- package/dist/esm/src/operate/progress/emitProgress.d.ts +10 -0
- package/dist/esm/src/operate/progress/index.d.ts +1 -0
- package/dist/esm/src/types/LlmProvider.interface.d.ts +50 -0
- package/package.json +1 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -402,6 +402,49 @@ interface LlmMessageOptions {
|
|
|
402
402
|
response?: NaturalSchema | z.ZodType;
|
|
403
403
|
system?: string;
|
|
404
404
|
}
|
|
405
|
+
declare enum LlmProgressEventType {
|
|
406
|
+
Done = "done",
|
|
407
|
+
ModelRequest = "model_request",
|
|
408
|
+
ModelResponse = "model_response",
|
|
409
|
+
Retry = "retry",
|
|
410
|
+
Start = "start",
|
|
411
|
+
ToolCall = "tool_call",
|
|
412
|
+
ToolError = "tool_error",
|
|
413
|
+
ToolResult = "tool_result"
|
|
414
|
+
}
|
|
415
|
+
interface LlmProgressToolCall {
|
|
416
|
+
/** JSON string of arguments (tool_call events only) */
|
|
417
|
+
arguments?: string;
|
|
418
|
+
/** Tool name */
|
|
419
|
+
name: string;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Lightweight, serializable progress event emitted by the operate loop.
|
|
423
|
+
* Suitable for forwarding directly to websockets, queues, or UI updates.
|
|
424
|
+
*/
|
|
425
|
+
interface LlmProgressEvent {
|
|
426
|
+
/** Text or structured content (model_response, done) */
|
|
427
|
+
content?: string | JsonObject;
|
|
428
|
+
/** Error message (tool_error, retry) */
|
|
429
|
+
error?: string;
|
|
430
|
+
/** Maximum turns allowed for the loop (start) */
|
|
431
|
+
maxTurns?: number;
|
|
432
|
+
/** Model handling the request (start, model_request) */
|
|
433
|
+
model?: string;
|
|
434
|
+
/** Provider name (start) */
|
|
435
|
+
provider?: string;
|
|
436
|
+
/** The tool involved (tool_call, tool_result, tool_error) */
|
|
437
|
+
tool?: LlmProgressToolCall;
|
|
438
|
+
/** Tools the model requested (model_response) */
|
|
439
|
+
toolCalls?: LlmProgressToolCall[];
|
|
440
|
+
/** Current turn, 1-indexed */
|
|
441
|
+
turn?: number;
|
|
442
|
+
/** Event type */
|
|
443
|
+
type: LlmProgressEventType;
|
|
444
|
+
/** Usage: this turn for model_response, cumulative for done */
|
|
445
|
+
usage?: LlmUsage;
|
|
446
|
+
}
|
|
447
|
+
type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
405
448
|
interface LlmOperateOptions {
|
|
406
449
|
data?: NaturalMap;
|
|
407
450
|
explain?: boolean;
|
|
@@ -452,6 +495,13 @@ interface LlmOperateOptions {
|
|
|
452
495
|
};
|
|
453
496
|
instructions?: string;
|
|
454
497
|
model?: string;
|
|
498
|
+
/**
|
|
499
|
+
* Receives lightweight progress events as the operate loop runs:
|
|
500
|
+
* start, model_request, model_response, tool_call, tool_result,
|
|
501
|
+
* tool_error, retry, done. Errors thrown by the callback are logged
|
|
502
|
+
* and never interrupt the loop.
|
|
503
|
+
*/
|
|
504
|
+
onProgress?: LlmProgressCallback;
|
|
455
505
|
placeholders?: {
|
|
456
506
|
input?: boolean;
|
|
457
507
|
instructions?: boolean;
|
|
@@ -669,5 +719,5 @@ declare class XaiProvider implements LlmProvider {
|
|
|
669
719
|
stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
|
|
670
720
|
}
|
|
671
721
|
|
|
672
|
-
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
673
|
-
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
|
722
|
+
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
723
|
+
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
package/dist/cjs/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { default as Llm } from "./Llm.js";
|
|
2
2
|
export * as LLM from "./constants.js";
|
|
3
|
-
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProvider, } from "./types/LlmProvider.interface.js";
|
|
4
|
-
export { LlmMessageRole, LlmMessageType, } from "./types/LlmProvider.interface.js";
|
|
3
|
+
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.js";
|
|
4
|
+
export { LlmMessageRole, LlmMessageType, LlmProgressEventType, } from "./types/LlmProvider.interface.js";
|
|
5
5
|
export { isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, } from "./types/LlmOperateInput.guards.js";
|
|
6
6
|
export type { LlmTool } from "./types/LlmTool.interface.js";
|
|
7
7
|
export type { LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, } from "./types/LlmStreamChunk.interface.js";
|
|
@@ -34,6 +34,11 @@ export declare class OperateLoop {
|
|
|
34
34
|
private createContext;
|
|
35
35
|
private buildInitialRequest;
|
|
36
36
|
private executeOneTurn;
|
|
37
|
+
/**
|
|
38
|
+
* Draconian summary of a history item for trace logging: string message
|
|
39
|
+
* content is kept; everything else is reduced to its type.
|
|
40
|
+
*/
|
|
41
|
+
private summarizeHistoryItem;
|
|
37
42
|
/**
|
|
38
43
|
* Reconcile structured output against the declared `format` contract. A
|
|
39
44
|
* declared `format` is a schema contract: returned keys should match the
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LlmProgressCallback, LlmProgressEvent } from "../../types/LlmProvider.interface.js";
|
|
2
|
+
/**
|
|
3
|
+
* Deliver a progress event to the caller's onProgress callback.
|
|
4
|
+
* Errors thrown by the callback are logged and swallowed — progress
|
|
5
|
+
* reporting must never interrupt the operate loop.
|
|
6
|
+
*/
|
|
7
|
+
export declare function emitProgress({ event, onProgress, }: {
|
|
8
|
+
event: LlmProgressEvent;
|
|
9
|
+
onProgress?: LlmProgressCallback;
|
|
10
|
+
}): Promise<void>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { emitProgress } from "./emitProgress.js";
|
|
@@ -166,6 +166,49 @@ export interface LlmMessageOptions {
|
|
|
166
166
|
response?: NaturalSchema | z.ZodType;
|
|
167
167
|
system?: string;
|
|
168
168
|
}
|
|
169
|
+
export declare enum LlmProgressEventType {
|
|
170
|
+
Done = "done",
|
|
171
|
+
ModelRequest = "model_request",
|
|
172
|
+
ModelResponse = "model_response",
|
|
173
|
+
Retry = "retry",
|
|
174
|
+
Start = "start",
|
|
175
|
+
ToolCall = "tool_call",
|
|
176
|
+
ToolError = "tool_error",
|
|
177
|
+
ToolResult = "tool_result"
|
|
178
|
+
}
|
|
179
|
+
export interface LlmProgressToolCall {
|
|
180
|
+
/** JSON string of arguments (tool_call events only) */
|
|
181
|
+
arguments?: string;
|
|
182
|
+
/** Tool name */
|
|
183
|
+
name: string;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Lightweight, serializable progress event emitted by the operate loop.
|
|
187
|
+
* Suitable for forwarding directly to websockets, queues, or UI updates.
|
|
188
|
+
*/
|
|
189
|
+
export interface LlmProgressEvent {
|
|
190
|
+
/** Text or structured content (model_response, done) */
|
|
191
|
+
content?: string | JsonObject;
|
|
192
|
+
/** Error message (tool_error, retry) */
|
|
193
|
+
error?: string;
|
|
194
|
+
/** Maximum turns allowed for the loop (start) */
|
|
195
|
+
maxTurns?: number;
|
|
196
|
+
/** Model handling the request (start, model_request) */
|
|
197
|
+
model?: string;
|
|
198
|
+
/** Provider name (start) */
|
|
199
|
+
provider?: string;
|
|
200
|
+
/** The tool involved (tool_call, tool_result, tool_error) */
|
|
201
|
+
tool?: LlmProgressToolCall;
|
|
202
|
+
/** Tools the model requested (model_response) */
|
|
203
|
+
toolCalls?: LlmProgressToolCall[];
|
|
204
|
+
/** Current turn, 1-indexed */
|
|
205
|
+
turn?: number;
|
|
206
|
+
/** Event type */
|
|
207
|
+
type: LlmProgressEventType;
|
|
208
|
+
/** Usage: this turn for model_response, cumulative for done */
|
|
209
|
+
usage?: LlmUsage;
|
|
210
|
+
}
|
|
211
|
+
export type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
169
212
|
export interface LlmOperateOptions {
|
|
170
213
|
data?: NaturalMap;
|
|
171
214
|
explain?: boolean;
|
|
@@ -216,6 +259,13 @@ export interface LlmOperateOptions {
|
|
|
216
259
|
};
|
|
217
260
|
instructions?: string;
|
|
218
261
|
model?: string;
|
|
262
|
+
/**
|
|
263
|
+
* Receives lightweight progress events as the operate loop runs:
|
|
264
|
+
* start, model_request, model_response, tool_call, tool_result,
|
|
265
|
+
* tool_error, retry, done. Errors thrown by the callback are logged
|
|
266
|
+
* and never interrupt the loop.
|
|
267
|
+
*/
|
|
268
|
+
onProgress?: LlmProgressCallback;
|
|
219
269
|
placeholders?: {
|
|
220
270
|
input?: boolean;
|
|
221
271
|
instructions?: boolean;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -402,6 +402,49 @@ interface LlmMessageOptions {
|
|
|
402
402
|
response?: NaturalSchema | z.ZodType;
|
|
403
403
|
system?: string;
|
|
404
404
|
}
|
|
405
|
+
declare enum LlmProgressEventType {
|
|
406
|
+
Done = "done",
|
|
407
|
+
ModelRequest = "model_request",
|
|
408
|
+
ModelResponse = "model_response",
|
|
409
|
+
Retry = "retry",
|
|
410
|
+
Start = "start",
|
|
411
|
+
ToolCall = "tool_call",
|
|
412
|
+
ToolError = "tool_error",
|
|
413
|
+
ToolResult = "tool_result"
|
|
414
|
+
}
|
|
415
|
+
interface LlmProgressToolCall {
|
|
416
|
+
/** JSON string of arguments (tool_call events only) */
|
|
417
|
+
arguments?: string;
|
|
418
|
+
/** Tool name */
|
|
419
|
+
name: string;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Lightweight, serializable progress event emitted by the operate loop.
|
|
423
|
+
* Suitable for forwarding directly to websockets, queues, or UI updates.
|
|
424
|
+
*/
|
|
425
|
+
interface LlmProgressEvent {
|
|
426
|
+
/** Text or structured content (model_response, done) */
|
|
427
|
+
content?: string | JsonObject;
|
|
428
|
+
/** Error message (tool_error, retry) */
|
|
429
|
+
error?: string;
|
|
430
|
+
/** Maximum turns allowed for the loop (start) */
|
|
431
|
+
maxTurns?: number;
|
|
432
|
+
/** Model handling the request (start, model_request) */
|
|
433
|
+
model?: string;
|
|
434
|
+
/** Provider name (start) */
|
|
435
|
+
provider?: string;
|
|
436
|
+
/** The tool involved (tool_call, tool_result, tool_error) */
|
|
437
|
+
tool?: LlmProgressToolCall;
|
|
438
|
+
/** Tools the model requested (model_response) */
|
|
439
|
+
toolCalls?: LlmProgressToolCall[];
|
|
440
|
+
/** Current turn, 1-indexed */
|
|
441
|
+
turn?: number;
|
|
442
|
+
/** Event type */
|
|
443
|
+
type: LlmProgressEventType;
|
|
444
|
+
/** Usage: this turn for model_response, cumulative for done */
|
|
445
|
+
usage?: LlmUsage;
|
|
446
|
+
}
|
|
447
|
+
type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
405
448
|
interface LlmOperateOptions {
|
|
406
449
|
data?: NaturalMap;
|
|
407
450
|
explain?: boolean;
|
|
@@ -452,6 +495,13 @@ interface LlmOperateOptions {
|
|
|
452
495
|
};
|
|
453
496
|
instructions?: string;
|
|
454
497
|
model?: string;
|
|
498
|
+
/**
|
|
499
|
+
* Receives lightweight progress events as the operate loop runs:
|
|
500
|
+
* start, model_request, model_response, tool_call, tool_result,
|
|
501
|
+
* tool_error, retry, done. Errors thrown by the callback are logged
|
|
502
|
+
* and never interrupt the loop.
|
|
503
|
+
*/
|
|
504
|
+
onProgress?: LlmProgressCallback;
|
|
455
505
|
placeholders?: {
|
|
456
506
|
input?: boolean;
|
|
457
507
|
instructions?: boolean;
|
|
@@ -669,5 +719,5 @@ declare class XaiProvider implements LlmProvider {
|
|
|
669
719
|
stream(input: string | LlmHistory | LlmInputMessage, options?: LlmOperateOptions): AsyncIterable<LlmStreamChunk>;
|
|
670
720
|
}
|
|
671
721
|
|
|
672
|
-
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
673
|
-
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
|
722
|
+
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
723
|
+
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
package/dist/esm/index.js
CHANGED
|
@@ -487,6 +487,18 @@ var LlmResponseStatus;
|
|
|
487
487
|
LlmResponseStatus["Incomplete"] = "incomplete";
|
|
488
488
|
LlmResponseStatus["InProgress"] = "in_progress";
|
|
489
489
|
})(LlmResponseStatus || (LlmResponseStatus = {}));
|
|
490
|
+
// Progress
|
|
491
|
+
var LlmProgressEventType;
|
|
492
|
+
(function (LlmProgressEventType) {
|
|
493
|
+
LlmProgressEventType["Done"] = "done";
|
|
494
|
+
LlmProgressEventType["ModelRequest"] = "model_request";
|
|
495
|
+
LlmProgressEventType["ModelResponse"] = "model_response";
|
|
496
|
+
LlmProgressEventType["Retry"] = "retry";
|
|
497
|
+
LlmProgressEventType["Start"] = "start";
|
|
498
|
+
LlmProgressEventType["ToolCall"] = "tool_call";
|
|
499
|
+
LlmProgressEventType["ToolError"] = "tool_error";
|
|
500
|
+
LlmProgressEventType["ToolResult"] = "tool_result";
|
|
501
|
+
})(LlmProgressEventType || (LlmProgressEventType = {}));
|
|
490
502
|
|
|
491
503
|
//
|
|
492
504
|
//
|
|
@@ -6130,6 +6142,25 @@ class InputProcessor {
|
|
|
6130
6142
|
// Export singleton instance for convenience
|
|
6131
6143
|
const inputProcessor = new InputProcessor();
|
|
6132
6144
|
|
|
6145
|
+
/**
|
|
6146
|
+
* Deliver a progress event to the caller's onProgress callback.
|
|
6147
|
+
* Errors thrown by the callback are logged and swallowed — progress
|
|
6148
|
+
* reporting must never interrupt the operate loop.
|
|
6149
|
+
*/
|
|
6150
|
+
async function emitProgress({ event, onProgress, }) {
|
|
6151
|
+
if (!onProgress) {
|
|
6152
|
+
return;
|
|
6153
|
+
}
|
|
6154
|
+
try {
|
|
6155
|
+
await onProgress(event);
|
|
6156
|
+
}
|
|
6157
|
+
catch (error) {
|
|
6158
|
+
const log = getLogger$6();
|
|
6159
|
+
log.warn(`[operate] onProgress callback threw on "${event.type}" event`);
|
|
6160
|
+
log.var({ error });
|
|
6161
|
+
}
|
|
6162
|
+
}
|
|
6163
|
+
|
|
6133
6164
|
//
|
|
6134
6165
|
//
|
|
6135
6166
|
// Main
|
|
@@ -6555,12 +6586,21 @@ class OperateLoop {
|
|
|
6555
6586
|
const log = getLogger$6();
|
|
6556
6587
|
// Log what was passed to operate
|
|
6557
6588
|
log.trace("[operate] Starting operate loop");
|
|
6558
|
-
log.var({ "operate.input": input });
|
|
6559
|
-
log.var({ "operate.options": options });
|
|
6589
|
+
log.trace.var({ "operate.input": input });
|
|
6590
|
+
log.trace.var({ "operate.options": options });
|
|
6560
6591
|
// Initialize state
|
|
6561
6592
|
const state = await this.initializeState(input, options);
|
|
6562
6593
|
const context = this.createContext(options);
|
|
6563
6594
|
const modelName = options.model ?? this.adapter.defaultModel;
|
|
6595
|
+
await emitProgress({
|
|
6596
|
+
event: {
|
|
6597
|
+
maxTurns: state.maxTurns,
|
|
6598
|
+
model: modelName,
|
|
6599
|
+
provider: this.adapter.name,
|
|
6600
|
+
type: LlmProgressEventType.Start,
|
|
6601
|
+
},
|
|
6602
|
+
onProgress: options.onProgress,
|
|
6603
|
+
});
|
|
6564
6604
|
// Enclosing LLM Observability span (no-op when DD_LLMOBS_ENABLED is unset).
|
|
6565
6605
|
// Child llm/tool spans nest under it via the SDK's active-span context.
|
|
6566
6606
|
return withLlmObsSpan({
|
|
@@ -6598,6 +6638,15 @@ class OperateLoop {
|
|
|
6598
6638
|
metrics: usageToLlmObsMetrics(response.usage),
|
|
6599
6639
|
outputData: response.content,
|
|
6600
6640
|
});
|
|
6641
|
+
await emitProgress({
|
|
6642
|
+
event: {
|
|
6643
|
+
content: response.content,
|
|
6644
|
+
turn: state.currentTurn,
|
|
6645
|
+
type: LlmProgressEventType.Done,
|
|
6646
|
+
usage: response.usage,
|
|
6647
|
+
},
|
|
6648
|
+
onProgress: options.onProgress,
|
|
6649
|
+
});
|
|
6601
6650
|
return response;
|
|
6602
6651
|
});
|
|
6603
6652
|
}
|
|
@@ -6692,18 +6741,54 @@ class OperateLoop {
|
|
|
6692
6741
|
});
|
|
6693
6742
|
// Build provider-specific request
|
|
6694
6743
|
const providerRequest = this.adapter.buildRequest(request);
|
|
6695
|
-
// Log
|
|
6744
|
+
// Log a draconian subset of the request; the full payload is available
|
|
6745
|
+
// via the beforeEachModelRequest hook
|
|
6696
6746
|
log.trace("[operate] Calling model");
|
|
6697
|
-
log.var({
|
|
6747
|
+
log.trace.var({
|
|
6748
|
+
"operate.request": {
|
|
6749
|
+
latest: this.summarizeHistoryItem(request.messages[request.messages.length - 1]),
|
|
6750
|
+
messages: request.messages.length,
|
|
6751
|
+
model: request.model,
|
|
6752
|
+
turn: state.currentTurn,
|
|
6753
|
+
},
|
|
6754
|
+
});
|
|
6755
|
+
await emitProgress({
|
|
6756
|
+
event: {
|
|
6757
|
+
model: request.model,
|
|
6758
|
+
turn: state.currentTurn,
|
|
6759
|
+
type: LlmProgressEventType.ModelRequest,
|
|
6760
|
+
},
|
|
6761
|
+
onProgress: options.onProgress,
|
|
6762
|
+
});
|
|
6698
6763
|
// Execute beforeEachModelRequest hook
|
|
6699
6764
|
await this.hookRunnerInstance.runBeforeModelRequest(context.hooks, {
|
|
6700
6765
|
input: state.currentInput,
|
|
6701
6766
|
options,
|
|
6702
6767
|
providerRequest,
|
|
6703
6768
|
});
|
|
6769
|
+
// Emit retry progress alongside the caller's onRetryableModelError hook
|
|
6770
|
+
const hooks = context.hooks;
|
|
6771
|
+
const hooksWithProgress = options.onProgress
|
|
6772
|
+
? {
|
|
6773
|
+
...hooks,
|
|
6774
|
+
onRetryableModelError: async (retryContext) => {
|
|
6775
|
+
await emitProgress({
|
|
6776
|
+
event: {
|
|
6777
|
+
error: retryContext.error instanceof Error
|
|
6778
|
+
? retryContext.error.message
|
|
6779
|
+
: String(retryContext.error),
|
|
6780
|
+
turn: state.currentTurn,
|
|
6781
|
+
type: LlmProgressEventType.Retry,
|
|
6782
|
+
},
|
|
6783
|
+
onProgress: options.onProgress,
|
|
6784
|
+
});
|
|
6785
|
+
return hooks?.onRetryableModelError?.(retryContext);
|
|
6786
|
+
},
|
|
6787
|
+
}
|
|
6788
|
+
: hooks;
|
|
6704
6789
|
// Execute with retry inside a child llm span (no-op when llmobs disabled).
|
|
6705
6790
|
// RetryExecutor handles error hooks and throws appropriate errors.
|
|
6706
|
-
const { parsed, response } = await withLlmObsSpan({
|
|
6791
|
+
const { parsed, response, toolCalls } = await withLlmObsSpan({
|
|
6707
6792
|
kind: "llm",
|
|
6708
6793
|
modelName: options.model ?? this.adapter.defaultModel,
|
|
6709
6794
|
modelProvider: this.adapter.name,
|
|
@@ -6715,19 +6800,43 @@ class OperateLoop {
|
|
|
6715
6800
|
options,
|
|
6716
6801
|
providerRequest,
|
|
6717
6802
|
},
|
|
6718
|
-
hooks:
|
|
6803
|
+
hooks: hooksWithProgress,
|
|
6719
6804
|
});
|
|
6720
|
-
// Log what was returned from the model
|
|
6721
|
-
log.trace("[operate] Model response received");
|
|
6722
|
-
log.var({ "operate.response": response });
|
|
6723
6805
|
// Parse response
|
|
6724
6806
|
const parsed = this.adapter.parseResponse(response, options);
|
|
6807
|
+
const toolCalls = parsed.hasToolCalls
|
|
6808
|
+
? this.adapter.extractToolCalls(response)
|
|
6809
|
+
: [];
|
|
6810
|
+
// Log only the text or tool calls; the full payload is available
|
|
6811
|
+
// via the afterEachModelResponse hook
|
|
6812
|
+
log.trace("[operate] Model response received");
|
|
6813
|
+
log.trace.var({
|
|
6814
|
+
"operate.response": toolCalls.length > 0
|
|
6815
|
+
? toolCalls.map(({ arguments: args, name }) => ({
|
|
6816
|
+
arguments: args,
|
|
6817
|
+
name,
|
|
6818
|
+
}))
|
|
6819
|
+
: parsed.content,
|
|
6820
|
+
});
|
|
6725
6821
|
annotateLlmObs({
|
|
6726
6822
|
inputData: state.currentInput,
|
|
6727
6823
|
metrics: usageToLlmObsMetrics(parsed.usage ? [parsed.usage] : undefined),
|
|
6728
6824
|
outputData: parsed.content ?? "",
|
|
6729
6825
|
});
|
|
6730
|
-
return { parsed, response };
|
|
6826
|
+
return { parsed, response, toolCalls };
|
|
6827
|
+
});
|
|
6828
|
+
await emitProgress({
|
|
6829
|
+
event: {
|
|
6830
|
+
content: parsed.content,
|
|
6831
|
+
toolCalls: toolCalls.map(({ arguments: args, name }) => ({
|
|
6832
|
+
arguments: args,
|
|
6833
|
+
name,
|
|
6834
|
+
})),
|
|
6835
|
+
turn: state.currentTurn,
|
|
6836
|
+
type: LlmProgressEventType.ModelResponse,
|
|
6837
|
+
usage: parsed.usage ? [parsed.usage] : undefined,
|
|
6838
|
+
},
|
|
6839
|
+
onProgress: options.onProgress,
|
|
6731
6840
|
});
|
|
6732
6841
|
// Track usage
|
|
6733
6842
|
if (parsed.usage) {
|
|
@@ -6756,7 +6865,6 @@ class OperateLoop {
|
|
|
6756
6865
|
}
|
|
6757
6866
|
// Handle tool calls
|
|
6758
6867
|
if (parsed.hasToolCalls) {
|
|
6759
|
-
const toolCalls = this.adapter.extractToolCalls(response);
|
|
6760
6868
|
if (toolCalls.length > 0 && state.toolkit && state.maxTurns > 1) {
|
|
6761
6869
|
// Track updated provider request for tool results
|
|
6762
6870
|
let currentProviderRequest = providerRequest;
|
|
@@ -6768,6 +6876,14 @@ class OperateLoop {
|
|
|
6768
6876
|
// Process each tool call
|
|
6769
6877
|
for (const toolCall of toolCalls) {
|
|
6770
6878
|
try {
|
|
6879
|
+
await emitProgress({
|
|
6880
|
+
event: {
|
|
6881
|
+
tool: { arguments: toolCall.arguments, name: toolCall.name },
|
|
6882
|
+
turn: state.currentTurn,
|
|
6883
|
+
type: LlmProgressEventType.ToolCall,
|
|
6884
|
+
},
|
|
6885
|
+
onProgress: options.onProgress,
|
|
6886
|
+
});
|
|
6771
6887
|
// Execute beforeEachTool hook
|
|
6772
6888
|
await this.hookRunnerInstance.runBeforeTool(context.hooks, {
|
|
6773
6889
|
args: toolCall.arguments,
|
|
@@ -6787,6 +6903,14 @@ class OperateLoop {
|
|
|
6787
6903
|
});
|
|
6788
6904
|
return result;
|
|
6789
6905
|
});
|
|
6906
|
+
await emitProgress({
|
|
6907
|
+
event: {
|
|
6908
|
+
tool: { name: toolCall.name },
|
|
6909
|
+
turn: state.currentTurn,
|
|
6910
|
+
type: LlmProgressEventType.ToolResult,
|
|
6911
|
+
},
|
|
6912
|
+
onProgress: options.onProgress,
|
|
6913
|
+
});
|
|
6790
6914
|
// Execute afterEachTool hook
|
|
6791
6915
|
await this.hookRunnerInstance.runAfterTool(context.hooks, {
|
|
6792
6916
|
args: toolCall.arguments,
|
|
@@ -6810,6 +6934,15 @@ class OperateLoop {
|
|
|
6810
6934
|
state.responseBuilder.appendToHistory(toolResultFormatted);
|
|
6811
6935
|
}
|
|
6812
6936
|
catch (error) {
|
|
6937
|
+
await emitProgress({
|
|
6938
|
+
event: {
|
|
6939
|
+
error: error.message,
|
|
6940
|
+
tool: { name: toolCall.name },
|
|
6941
|
+
turn: state.currentTurn,
|
|
6942
|
+
type: LlmProgressEventType.ToolError,
|
|
6943
|
+
},
|
|
6944
|
+
onProgress: options.onProgress,
|
|
6945
|
+
});
|
|
6813
6946
|
// Execute onToolError hook
|
|
6814
6947
|
await this.hookRunnerInstance.runOnToolError(context.hooks, {
|
|
6815
6948
|
args: toolCall.arguments,
|
|
@@ -6883,6 +7016,20 @@ class OperateLoop {
|
|
|
6883
7016
|
}
|
|
6884
7017
|
return false; // Stop loop
|
|
6885
7018
|
}
|
|
7019
|
+
/**
|
|
7020
|
+
* Draconian summary of a history item for trace logging: string message
|
|
7021
|
+
* content is kept; everything else is reduced to its type.
|
|
7022
|
+
*/
|
|
7023
|
+
summarizeHistoryItem(item) {
|
|
7024
|
+
if (!item) {
|
|
7025
|
+
return undefined;
|
|
7026
|
+
}
|
|
7027
|
+
const record = item;
|
|
7028
|
+
if (typeof record.content === "string") {
|
|
7029
|
+
return { content: record.content, role: record.role };
|
|
7030
|
+
}
|
|
7031
|
+
return { type: record.type ?? "message" };
|
|
7032
|
+
}
|
|
6886
7033
|
/**
|
|
6887
7034
|
* Reconcile structured output against the declared `format` contract. A
|
|
6888
7035
|
* declared `format` is a schema contract: returned keys should match the
|
|
@@ -9220,5 +9367,5 @@ const toolkit = new JaypieToolkit(tools);
|
|
|
9220
9367
|
[LlmMessageRole.Developer]: "user",
|
|
9221
9368
|
});
|
|
9222
9369
|
|
|
9223
|
-
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
9370
|
+
export { BedrockProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmStreamChunkType, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
9224
9371
|
//# sourceMappingURL=index.js.map
|