@jaypie/llm 1.3.5 → 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 +227 -20
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +53 -3
- package/dist/cjs/src/constants.d.ts +1 -1
- 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/operate/types.d.ts +2 -0
- package/dist/cjs/src/types/LlmProvider.interface.d.ts +50 -0
- package/dist/cjs/src/util/index.d.ts +1 -0
- package/dist/cjs/src/util/maxOutputTokens.d.ts +12 -0
- package/dist/esm/index.d.ts +53 -3
- package/dist/esm/index.js +228 -21
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/src/constants.d.ts +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/operate/types.d.ts +2 -0
- package/dist/esm/src/types/LlmProvider.interface.d.ts +50 -0
- package/dist/esm/src/util/index.d.ts +1 -0
- package/dist/esm/src/util/maxOutputTokens.d.ts +12 -0
- package/package.json +1 -1
package/dist/esm/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";
|
|
@@ -70,6 +70,8 @@ export interface OperateRequest {
|
|
|
70
70
|
format?: JsonObject;
|
|
71
71
|
/** Provider-specific options */
|
|
72
72
|
providerOptions?: JsonObject;
|
|
73
|
+
/** Whether the request will execute over a streaming transport */
|
|
74
|
+
stream?: boolean;
|
|
73
75
|
/** Sampling temperature (0-2 for most providers) */
|
|
74
76
|
temperature?: number;
|
|
75
77
|
/** User identifier for tracking */
|
|
@@ -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;
|
|
@@ -6,6 +6,7 @@ export * from "./formatOperateMessage.js";
|
|
|
6
6
|
export * from "./jsonSchema.js";
|
|
7
7
|
export * from "./jsonSchemaToOpenApi3.js";
|
|
8
8
|
export * from "./logger.js";
|
|
9
|
+
export * from "./maxOutputTokens.js";
|
|
9
10
|
export * from "./maxTurnsFromOptions.js";
|
|
10
11
|
export * from "./naturalZodSchema.js";
|
|
11
12
|
export * from "./random.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum output tokens the model supports, or undefined when unknown.
|
|
3
|
+
*/
|
|
4
|
+
export declare function maxOutputTokens(model: string): number | undefined;
|
|
5
|
+
/**
|
|
6
|
+
* Default output token limit for a request: the model maximum when
|
|
7
|
+
* streaming, capped at the non-streaming maximum otherwise. Returns
|
|
8
|
+
* undefined when the model's maximum is unknown.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolveMaxOutputTokens(model: string, { stream }?: {
|
|
11
|
+
stream?: boolean;
|
|
12
|
+
}): number | undefined;
|