@jaypie/llm 1.3.12 → 1.3.14
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/Llm.d.ts +6 -0
- package/dist/cjs/index.cjs +703 -333
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +93 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/observability/exchangeStore.d.ts +20 -0
- package/dist/cjs/operate/adapters/FireworksAdapter.d.ts +1 -0
- package/dist/cjs/operate/adapters/ProviderAdapter.interface.d.ts +13 -0
- package/dist/cjs/operate/exchange/buildExchangeEnvelope.d.ts +16 -0
- package/dist/cjs/operate/exchange/emitExchange.d.ts +20 -0
- package/dist/cjs/operate/exchange/index.d.ts +2 -0
- package/dist/cjs/operate/types.d.ts +13 -0
- package/dist/cjs/types/LlmProvider.interface.d.ts +87 -1
- package/dist/esm/Llm.d.ts +6 -0
- package/dist/esm/index.d.ts +93 -1
- package/dist/esm/index.js +703 -333
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/observability/exchangeStore.d.ts +20 -0
- package/dist/esm/operate/adapters/FireworksAdapter.d.ts +1 -0
- package/dist/esm/operate/adapters/ProviderAdapter.interface.d.ts +13 -0
- package/dist/esm/operate/exchange/buildExchangeEnvelope.d.ts +16 -0
- package/dist/esm/operate/exchange/emitExchange.d.ts +20 -0
- package/dist/esm/operate/exchange/index.d.ts +2 -0
- package/dist/esm/operate/types.d.ts +13 -0
- package/dist/esm/types/LlmProvider.interface.d.ts +87 -1
- package/package.json +5 -1
package/dist/cjs/index.d.cts
CHANGED
|
@@ -525,6 +525,81 @@ interface LlmProgressEvent {
|
|
|
525
525
|
usage?: LlmUsage;
|
|
526
526
|
}
|
|
527
527
|
type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
528
|
+
/**
|
|
529
|
+
* Serializable snapshot of the request side of one operate() call.
|
|
530
|
+
* `input` is the raw, pre-interpolation input with multimodal parts preserved.
|
|
531
|
+
*/
|
|
532
|
+
interface LlmExchangeRequest {
|
|
533
|
+
data?: NaturalMap;
|
|
534
|
+
effort?: LlmEffort;
|
|
535
|
+
explain?: boolean;
|
|
536
|
+
/** Format normalized to JSON Schema (Zod/Natural already rendered) */
|
|
537
|
+
format?: JsonObject;
|
|
538
|
+
input: string | LlmHistory | LlmInputMessage | LlmOperateInput;
|
|
539
|
+
instructions?: string;
|
|
540
|
+
/** Requested model (pre-fallback) */
|
|
541
|
+
model?: string;
|
|
542
|
+
placeholders?: {
|
|
543
|
+
input?: boolean;
|
|
544
|
+
instructions?: boolean;
|
|
545
|
+
system?: boolean;
|
|
546
|
+
};
|
|
547
|
+
providerOptions?: JsonObject;
|
|
548
|
+
system?: string;
|
|
549
|
+
temperature?: number;
|
|
550
|
+
/** Names of tools offered to the model */
|
|
551
|
+
tools?: string[];
|
|
552
|
+
turns?: boolean | number;
|
|
553
|
+
user?: string;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Serializable snapshot of the response side of one operate() call.
|
|
557
|
+
*/
|
|
558
|
+
interface LlmExchangeResponse {
|
|
559
|
+
content?: string | JsonObject;
|
|
560
|
+
error?: LlmError$1;
|
|
561
|
+
/** Turns this call added to history (tool calls/results included); never the resent history */
|
|
562
|
+
historyDelta: LlmHistory;
|
|
563
|
+
reasoning?: string[];
|
|
564
|
+
status: LlmResponseStatus;
|
|
565
|
+
stopReason?: string;
|
|
566
|
+
/** Per-model-call usage items (provider/model on each item) */
|
|
567
|
+
usage: LlmUsage;
|
|
568
|
+
/** Cumulative usage keyed `provider:model` */
|
|
569
|
+
usageTotals?: Record<string, LlmUsageItem>;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* How the call was actually served after fallback and retry resolution.
|
|
573
|
+
*/
|
|
574
|
+
interface LlmExchangeResolution {
|
|
575
|
+
fallbackAttempts?: number;
|
|
576
|
+
fallbackUsed?: boolean;
|
|
577
|
+
/** Served model */
|
|
578
|
+
model?: string;
|
|
579
|
+
/** Served provider */
|
|
580
|
+
provider?: string;
|
|
581
|
+
/** Model-request retries within the served attempt */
|
|
582
|
+
retries?: number;
|
|
583
|
+
}
|
|
584
|
+
interface LlmExchangeTiming {
|
|
585
|
+
/** Milliseconds from start to settlement */
|
|
586
|
+
duration: number;
|
|
587
|
+
/** ISO 8601 */
|
|
588
|
+
startedAt: string;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* One serializable request/response envelope per operate() settlement
|
|
592
|
+
* (success or failure). Contains no functions.
|
|
593
|
+
*/
|
|
594
|
+
interface LlmExchangeEnvelope {
|
|
595
|
+
/** Provider response id(s) per model turn, when available */
|
|
596
|
+
ids?: string[];
|
|
597
|
+
request: LlmExchangeRequest;
|
|
598
|
+
resolution: LlmExchangeResolution;
|
|
599
|
+
response: LlmExchangeResponse;
|
|
600
|
+
timing: LlmExchangeTiming;
|
|
601
|
+
}
|
|
602
|
+
type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
|
|
528
603
|
interface LlmOperateOptions {
|
|
529
604
|
data?: NaturalMap;
|
|
530
605
|
/**
|
|
@@ -589,6 +664,12 @@ interface LlmOperateOptions {
|
|
|
589
664
|
};
|
|
590
665
|
instructions?: string;
|
|
591
666
|
model?: string;
|
|
667
|
+
/**
|
|
668
|
+
* Fires once per operate() settlement (success or failure) with a fully
|
|
669
|
+
* serializable request/response envelope. Errors thrown by the callback
|
|
670
|
+
* are logged and never interrupt the call.
|
|
671
|
+
*/
|
|
672
|
+
onExchange?: LlmExchangeCallback;
|
|
592
673
|
/**
|
|
593
674
|
* Receives lightweight progress events as the operate loop runs:
|
|
594
675
|
* start, model_request, model_response, tool_call, tool_result,
|
|
@@ -635,6 +716,11 @@ type LlmUsage = LlmUsageItem[];
|
|
|
635
716
|
interface LlmOperateResponse {
|
|
636
717
|
content?: string | JsonObject;
|
|
637
718
|
error?: LlmError$1;
|
|
719
|
+
/**
|
|
720
|
+
* Serializable exchange envelope for this call. Present only when
|
|
721
|
+
* `onExchange` was passed or exchange persistence is enabled.
|
|
722
|
+
*/
|
|
723
|
+
exchange?: LlmExchangeEnvelope;
|
|
638
724
|
/** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
|
|
639
725
|
fallbackAttempts?: number;
|
|
640
726
|
/** Whether a fallback provider was used instead of the primary */
|
|
@@ -680,6 +766,12 @@ declare class Llm implements LlmProvider {
|
|
|
680
766
|
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
681
767
|
model?: LlmModelOption;
|
|
682
768
|
}): Promise<LlmOperateResponse>;
|
|
769
|
+
/**
|
|
770
|
+
* Stamp fallback resolution onto the envelope the operate loop attached to
|
|
771
|
+
* the response and deliver it to the caller's onExchange. Fires once per
|
|
772
|
+
* operate() settlement; callback errors are logged and never thrown.
|
|
773
|
+
*/
|
|
774
|
+
private settleExchange;
|
|
683
775
|
stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
684
776
|
model?: LlmModelOption;
|
|
685
777
|
}): AsyncIterable<LlmStreamChunk>;
|
|
@@ -931,4 +1023,4 @@ declare class XaiProvider implements LlmProvider {
|
|
|
931
1023
|
}
|
|
932
1024
|
|
|
933
1025
|
export { BedrockProvider, ErrorCategory, FireworksProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmError, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmQuotaError, LlmRateLimitError, LlmStreamChunkType, LlmTransientError, LlmUnrecoverableError, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
934
|
-
export type { LlmEffort, LlmErrorOptions, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
|
1026
|
+
export type { LlmEffort, LlmErrorOptions, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
package/dist/cjs/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
3
|
export type { LlmEffort } from "./constants.js";
|
|
4
|
-
export type { LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.js";
|
|
4
|
+
export type { LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, } from "./types/LlmProvider.interface.js";
|
|
5
5
|
export { LlmMessageRole, LlmMessageType, LlmProgressEventType, } from "./types/LlmProvider.interface.js";
|
|
6
6
|
export { isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, } from "./types/LlmOperateInput.guards.js";
|
|
7
7
|
export type { LlmTool } from "./types/LlmTool.interface.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LlmExchangeEnvelope } from "../types/LlmProvider.interface.js";
|
|
2
|
+
/** Minimal shape of the @jaypie/dynamodb surface this module uses. */
|
|
3
|
+
interface ExchangeStoreSdk {
|
|
4
|
+
storeExchange: (envelope: LlmExchangeEnvelope) => Promise<unknown>;
|
|
5
|
+
}
|
|
6
|
+
/** Reset the cached resolution. Exposed for tests. */
|
|
7
|
+
export declare function _resetExchangeStore(): void;
|
|
8
|
+
/**
|
|
9
|
+
* Inject a store to bypass @jaypie/dynamodb resolution. Test-only: the peer
|
|
10
|
+
* is optional, so the enabled path cannot otherwise be exercised in unit
|
|
11
|
+
* tests without it installed.
|
|
12
|
+
*/
|
|
13
|
+
export declare function _setExchangeStore(sdk: ExchangeStoreSdk | null): void;
|
|
14
|
+
/**
|
|
15
|
+
* Persist an exchange envelope via @jaypie/dynamodb when
|
|
16
|
+
* LLM_EXCHANGE_ENABLED is set. Silent no-op when the flag is unset or the
|
|
17
|
+
* peer is absent; persister failures are logged and never thrown.
|
|
18
|
+
*/
|
|
19
|
+
export declare function persistExchange(envelope: LlmExchangeEnvelope): Promise<void>;
|
|
20
|
+
export {};
|
|
@@ -106,6 +106,7 @@ type FireworksContentPart = {
|
|
|
106
106
|
export declare class FireworksAdapter extends BaseProviderAdapter {
|
|
107
107
|
readonly name: "fireworks";
|
|
108
108
|
readonly defaultModel: string;
|
|
109
|
+
readonly supportsStructuredOutputRetry = true;
|
|
109
110
|
private runtimeNoStructuredOutputModels;
|
|
110
111
|
rememberModelRejectsStructuredOutput(model: string): void;
|
|
111
112
|
clearRuntimeNoStructuredOutputModels(): void;
|
|
@@ -20,6 +20,12 @@ export interface ProviderAdapter {
|
|
|
20
20
|
* Default model for this provider
|
|
21
21
|
*/
|
|
22
22
|
readonly defaultModel: string;
|
|
23
|
+
/**
|
|
24
|
+
* Whether OperateLoop may take a corrective turn when a `format` request
|
|
25
|
+
* completes with prose instead of structured output (tool-emulation
|
|
26
|
+
* providers opt in).
|
|
27
|
+
*/
|
|
28
|
+
readonly supportsStructuredOutputRetry?: boolean;
|
|
23
29
|
/**
|
|
24
30
|
* Build a provider-specific request from the standardized format
|
|
25
31
|
*
|
|
@@ -169,6 +175,13 @@ export declare abstract class BaseProviderAdapter implements ProviderAdapter {
|
|
|
169
175
|
abstract responseToHistoryItems(response: unknown): LlmHistory;
|
|
170
176
|
abstract classifyError(error: unknown): ClassifiedError;
|
|
171
177
|
abstract isComplete(response: unknown): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Whether OperateLoop may take a corrective turn when a `format` request
|
|
180
|
+
* completes with prose instead of structured output. Providers whose
|
|
181
|
+
* structured output rides a tool emulation (where compliance is a model
|
|
182
|
+
* decision) opt in; native grammar-constrained providers do not need it.
|
|
183
|
+
*/
|
|
184
|
+
readonly supportsStructuredOutputRetry: boolean;
|
|
172
185
|
/**
|
|
173
186
|
* Default implementation checks if error is retryable via classifyError
|
|
174
187
|
*/
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LlmExchangeEnvelope, LlmHistory, LlmInputMessage, LlmOperateInput, LlmOperateOptions, LlmOperateResponse } from "../../types/LlmProvider.interface.js";
|
|
2
|
+
import { OperateLoopState } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Assemble the serializable exchange envelope for one operate() settlement.
|
|
5
|
+
* The `resolution` block is stamped by the Llm facade, which is the layer
|
|
6
|
+
* that knows fallback outcome; the loop fills provider/model best-effort.
|
|
7
|
+
*/
|
|
8
|
+
export declare function buildExchangeEnvelope({ duration, initialHistoryLength, input, options, response, startedAt, state, }: {
|
|
9
|
+
duration: number;
|
|
10
|
+
initialHistoryLength: number;
|
|
11
|
+
input: string | LlmHistory | LlmInputMessage | LlmOperateInput;
|
|
12
|
+
options: LlmOperateOptions;
|
|
13
|
+
response: LlmOperateResponse;
|
|
14
|
+
startedAt: string;
|
|
15
|
+
state: OperateLoopState;
|
|
16
|
+
}): LlmExchangeEnvelope;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { LlmExchangeCallback, LlmExchangeEnvelope } from "../../types/LlmProvider.interface.js";
|
|
2
|
+
/**
|
|
3
|
+
* Truthy-except-"false"/"0" gate on LLM_EXCHANGE_ENABLED, matching the
|
|
4
|
+
* DD_LLMOBS_ENABLED convention in observability/llmobs.ts.
|
|
5
|
+
*/
|
|
6
|
+
export declare function isExchangeStoreEnabled(): boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Whether the loop should assemble an exchange envelope at settlement.
|
|
9
|
+
*/
|
|
10
|
+
export declare function isExchangeRequested({ onExchange, }: {
|
|
11
|
+
onExchange?: LlmExchangeCallback;
|
|
12
|
+
}): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Deliver an exchange envelope to a callback. Errors thrown by the callback
|
|
15
|
+
* are logged and swallowed — exchange capture must never interrupt the call.
|
|
16
|
+
*/
|
|
17
|
+
export declare function emitExchange({ envelope, onExchange, }: {
|
|
18
|
+
envelope: LlmExchangeEnvelope;
|
|
19
|
+
onExchange?: LlmExchangeCallback;
|
|
20
|
+
}): Promise<void>;
|
|
@@ -77,6 +77,13 @@ export interface OperateRequest {
|
|
|
77
77
|
stream?: boolean;
|
|
78
78
|
/** Sampling temperature (0-2 for most providers) */
|
|
79
79
|
temperature?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Set by OperateLoop on a corrective turn after a format request came back
|
|
82
|
+
* as prose. Adapters that support the retry (see
|
|
83
|
+
* `ProviderAdapter.supportsStructuredOutputRetry`) should offer only the
|
|
84
|
+
* structured-output mechanism on this turn.
|
|
85
|
+
*/
|
|
86
|
+
structuredOutputRetry?: boolean;
|
|
80
87
|
/** User identifier for tracking */
|
|
81
88
|
user?: string;
|
|
82
89
|
}
|
|
@@ -135,12 +142,18 @@ import type { ResponseBuilder } from "./response/ResponseBuilder.js";
|
|
|
135
142
|
export interface OperateLoopState {
|
|
136
143
|
/** Count of consecutive tool errors (resets on success) */
|
|
137
144
|
consecutiveToolErrors: number;
|
|
145
|
+
/** Set when the loop has taken a corrective structured-output turn */
|
|
146
|
+
structuredOutputRetry?: boolean;
|
|
138
147
|
/** Current conversation input/messages */
|
|
139
148
|
currentInput: LlmHistory;
|
|
140
149
|
/** Current turn number (0-indexed, incremented at start of each turn) */
|
|
141
150
|
currentTurn: number;
|
|
142
151
|
/** Formatted output schema for structured output */
|
|
143
152
|
formattedFormat?: JsonObject;
|
|
153
|
+
/** Stop reason from the most recent model response */
|
|
154
|
+
lastStopReason?: string;
|
|
155
|
+
/** Model-request retries across all turns (exchange envelope) */
|
|
156
|
+
retries: number;
|
|
144
157
|
/** Formatted tools for the provider */
|
|
145
158
|
formattedTools?: ProviderToolDefinition[];
|
|
146
159
|
/** Maximum allowed turns */
|
|
@@ -26,7 +26,7 @@ export declare enum LlmResponseStatus {
|
|
|
26
26
|
Incomplete = "incomplete",
|
|
27
27
|
InProgress = "in_progress"
|
|
28
28
|
}
|
|
29
|
-
interface LlmError {
|
|
29
|
+
export interface LlmError {
|
|
30
30
|
detail?: string;
|
|
31
31
|
status: number | string;
|
|
32
32
|
title: string;
|
|
@@ -212,6 +212,81 @@ export interface LlmProgressEvent {
|
|
|
212
212
|
usage?: LlmUsage;
|
|
213
213
|
}
|
|
214
214
|
export type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
215
|
+
/**
|
|
216
|
+
* Serializable snapshot of the request side of one operate() call.
|
|
217
|
+
* `input` is the raw, pre-interpolation input with multimodal parts preserved.
|
|
218
|
+
*/
|
|
219
|
+
export interface LlmExchangeRequest {
|
|
220
|
+
data?: NaturalMap;
|
|
221
|
+
effort?: LlmEffort;
|
|
222
|
+
explain?: boolean;
|
|
223
|
+
/** Format normalized to JSON Schema (Zod/Natural already rendered) */
|
|
224
|
+
format?: JsonObject;
|
|
225
|
+
input: string | LlmHistory | LlmInputMessage | LlmOperateInput;
|
|
226
|
+
instructions?: string;
|
|
227
|
+
/** Requested model (pre-fallback) */
|
|
228
|
+
model?: string;
|
|
229
|
+
placeholders?: {
|
|
230
|
+
input?: boolean;
|
|
231
|
+
instructions?: boolean;
|
|
232
|
+
system?: boolean;
|
|
233
|
+
};
|
|
234
|
+
providerOptions?: JsonObject;
|
|
235
|
+
system?: string;
|
|
236
|
+
temperature?: number;
|
|
237
|
+
/** Names of tools offered to the model */
|
|
238
|
+
tools?: string[];
|
|
239
|
+
turns?: boolean | number;
|
|
240
|
+
user?: string;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Serializable snapshot of the response side of one operate() call.
|
|
244
|
+
*/
|
|
245
|
+
export interface LlmExchangeResponse {
|
|
246
|
+
content?: string | JsonObject;
|
|
247
|
+
error?: LlmError;
|
|
248
|
+
/** Turns this call added to history (tool calls/results included); never the resent history */
|
|
249
|
+
historyDelta: LlmHistory;
|
|
250
|
+
reasoning?: string[];
|
|
251
|
+
status: LlmResponseStatus;
|
|
252
|
+
stopReason?: string;
|
|
253
|
+
/** Per-model-call usage items (provider/model on each item) */
|
|
254
|
+
usage: LlmUsage;
|
|
255
|
+
/** Cumulative usage keyed `provider:model` */
|
|
256
|
+
usageTotals?: Record<string, LlmUsageItem>;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* How the call was actually served after fallback and retry resolution.
|
|
260
|
+
*/
|
|
261
|
+
export interface LlmExchangeResolution {
|
|
262
|
+
fallbackAttempts?: number;
|
|
263
|
+
fallbackUsed?: boolean;
|
|
264
|
+
/** Served model */
|
|
265
|
+
model?: string;
|
|
266
|
+
/** Served provider */
|
|
267
|
+
provider?: string;
|
|
268
|
+
/** Model-request retries within the served attempt */
|
|
269
|
+
retries?: number;
|
|
270
|
+
}
|
|
271
|
+
export interface LlmExchangeTiming {
|
|
272
|
+
/** Milliseconds from start to settlement */
|
|
273
|
+
duration: number;
|
|
274
|
+
/** ISO 8601 */
|
|
275
|
+
startedAt: string;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* One serializable request/response envelope per operate() settlement
|
|
279
|
+
* (success or failure). Contains no functions.
|
|
280
|
+
*/
|
|
281
|
+
export interface LlmExchangeEnvelope {
|
|
282
|
+
/** Provider response id(s) per model turn, when available */
|
|
283
|
+
ids?: string[];
|
|
284
|
+
request: LlmExchangeRequest;
|
|
285
|
+
resolution: LlmExchangeResolution;
|
|
286
|
+
response: LlmExchangeResponse;
|
|
287
|
+
timing: LlmExchangeTiming;
|
|
288
|
+
}
|
|
289
|
+
export type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
|
|
215
290
|
export interface LlmOperateOptions {
|
|
216
291
|
data?: NaturalMap;
|
|
217
292
|
/**
|
|
@@ -276,6 +351,12 @@ export interface LlmOperateOptions {
|
|
|
276
351
|
};
|
|
277
352
|
instructions?: string;
|
|
278
353
|
model?: string;
|
|
354
|
+
/**
|
|
355
|
+
* Fires once per operate() settlement (success or failure) with a fully
|
|
356
|
+
* serializable request/response envelope. Errors thrown by the callback
|
|
357
|
+
* are logged and never interrupt the call.
|
|
358
|
+
*/
|
|
359
|
+
onExchange?: LlmExchangeCallback;
|
|
279
360
|
/**
|
|
280
361
|
* Receives lightweight progress events as the operate loop runs:
|
|
281
362
|
* start, model_request, model_response, tool_call, tool_result,
|
|
@@ -322,6 +403,11 @@ export type LlmUsage = LlmUsageItem[];
|
|
|
322
403
|
export interface LlmOperateResponse {
|
|
323
404
|
content?: string | JsonObject;
|
|
324
405
|
error?: LlmError;
|
|
406
|
+
/**
|
|
407
|
+
* Serializable exchange envelope for this call. Present only when
|
|
408
|
+
* `onExchange` was passed or exchange persistence is enabled.
|
|
409
|
+
*/
|
|
410
|
+
exchange?: LlmExchangeEnvelope;
|
|
325
411
|
/** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
|
|
326
412
|
fallbackAttempts?: number;
|
|
327
413
|
/** Whether a fallback provider was used instead of the primary */
|
package/dist/esm/Llm.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ declare class Llm implements LlmProvider {
|
|
|
27
27
|
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
28
28
|
model?: LlmModelOption;
|
|
29
29
|
}): Promise<LlmOperateResponse>;
|
|
30
|
+
/**
|
|
31
|
+
* Stamp fallback resolution onto the envelope the operate loop attached to
|
|
32
|
+
* the response and deliver it to the caller's onExchange. Fires once per
|
|
33
|
+
* operate() settlement; callback errors are logged and never thrown.
|
|
34
|
+
*/
|
|
35
|
+
private settleExchange;
|
|
30
36
|
stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
31
37
|
model?: LlmModelOption;
|
|
32
38
|
}): AsyncIterable<LlmStreamChunk>;
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -525,6 +525,81 @@ interface LlmProgressEvent {
|
|
|
525
525
|
usage?: LlmUsage;
|
|
526
526
|
}
|
|
527
527
|
type LlmProgressCallback = (event: LlmProgressEvent) => unknown | Promise<unknown>;
|
|
528
|
+
/**
|
|
529
|
+
* Serializable snapshot of the request side of one operate() call.
|
|
530
|
+
* `input` is the raw, pre-interpolation input with multimodal parts preserved.
|
|
531
|
+
*/
|
|
532
|
+
interface LlmExchangeRequest {
|
|
533
|
+
data?: NaturalMap;
|
|
534
|
+
effort?: LlmEffort;
|
|
535
|
+
explain?: boolean;
|
|
536
|
+
/** Format normalized to JSON Schema (Zod/Natural already rendered) */
|
|
537
|
+
format?: JsonObject;
|
|
538
|
+
input: string | LlmHistory | LlmInputMessage | LlmOperateInput;
|
|
539
|
+
instructions?: string;
|
|
540
|
+
/** Requested model (pre-fallback) */
|
|
541
|
+
model?: string;
|
|
542
|
+
placeholders?: {
|
|
543
|
+
input?: boolean;
|
|
544
|
+
instructions?: boolean;
|
|
545
|
+
system?: boolean;
|
|
546
|
+
};
|
|
547
|
+
providerOptions?: JsonObject;
|
|
548
|
+
system?: string;
|
|
549
|
+
temperature?: number;
|
|
550
|
+
/** Names of tools offered to the model */
|
|
551
|
+
tools?: string[];
|
|
552
|
+
turns?: boolean | number;
|
|
553
|
+
user?: string;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Serializable snapshot of the response side of one operate() call.
|
|
557
|
+
*/
|
|
558
|
+
interface LlmExchangeResponse {
|
|
559
|
+
content?: string | JsonObject;
|
|
560
|
+
error?: LlmError$1;
|
|
561
|
+
/** Turns this call added to history (tool calls/results included); never the resent history */
|
|
562
|
+
historyDelta: LlmHistory;
|
|
563
|
+
reasoning?: string[];
|
|
564
|
+
status: LlmResponseStatus;
|
|
565
|
+
stopReason?: string;
|
|
566
|
+
/** Per-model-call usage items (provider/model on each item) */
|
|
567
|
+
usage: LlmUsage;
|
|
568
|
+
/** Cumulative usage keyed `provider:model` */
|
|
569
|
+
usageTotals?: Record<string, LlmUsageItem>;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* How the call was actually served after fallback and retry resolution.
|
|
573
|
+
*/
|
|
574
|
+
interface LlmExchangeResolution {
|
|
575
|
+
fallbackAttempts?: number;
|
|
576
|
+
fallbackUsed?: boolean;
|
|
577
|
+
/** Served model */
|
|
578
|
+
model?: string;
|
|
579
|
+
/** Served provider */
|
|
580
|
+
provider?: string;
|
|
581
|
+
/** Model-request retries within the served attempt */
|
|
582
|
+
retries?: number;
|
|
583
|
+
}
|
|
584
|
+
interface LlmExchangeTiming {
|
|
585
|
+
/** Milliseconds from start to settlement */
|
|
586
|
+
duration: number;
|
|
587
|
+
/** ISO 8601 */
|
|
588
|
+
startedAt: string;
|
|
589
|
+
}
|
|
590
|
+
/**
|
|
591
|
+
* One serializable request/response envelope per operate() settlement
|
|
592
|
+
* (success or failure). Contains no functions.
|
|
593
|
+
*/
|
|
594
|
+
interface LlmExchangeEnvelope {
|
|
595
|
+
/** Provider response id(s) per model turn, when available */
|
|
596
|
+
ids?: string[];
|
|
597
|
+
request: LlmExchangeRequest;
|
|
598
|
+
resolution: LlmExchangeResolution;
|
|
599
|
+
response: LlmExchangeResponse;
|
|
600
|
+
timing: LlmExchangeTiming;
|
|
601
|
+
}
|
|
602
|
+
type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
|
|
528
603
|
interface LlmOperateOptions {
|
|
529
604
|
data?: NaturalMap;
|
|
530
605
|
/**
|
|
@@ -589,6 +664,12 @@ interface LlmOperateOptions {
|
|
|
589
664
|
};
|
|
590
665
|
instructions?: string;
|
|
591
666
|
model?: string;
|
|
667
|
+
/**
|
|
668
|
+
* Fires once per operate() settlement (success or failure) with a fully
|
|
669
|
+
* serializable request/response envelope. Errors thrown by the callback
|
|
670
|
+
* are logged and never interrupt the call.
|
|
671
|
+
*/
|
|
672
|
+
onExchange?: LlmExchangeCallback;
|
|
592
673
|
/**
|
|
593
674
|
* Receives lightweight progress events as the operate loop runs:
|
|
594
675
|
* start, model_request, model_response, tool_call, tool_result,
|
|
@@ -635,6 +716,11 @@ type LlmUsage = LlmUsageItem[];
|
|
|
635
716
|
interface LlmOperateResponse {
|
|
636
717
|
content?: string | JsonObject;
|
|
637
718
|
error?: LlmError$1;
|
|
719
|
+
/**
|
|
720
|
+
* Serializable exchange envelope for this call. Present only when
|
|
721
|
+
* `onExchange` was passed or exchange persistence is enabled.
|
|
722
|
+
*/
|
|
723
|
+
exchange?: LlmExchangeEnvelope;
|
|
638
724
|
/** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
|
|
639
725
|
fallbackAttempts?: number;
|
|
640
726
|
/** Whether a fallback provider was used instead of the primary */
|
|
@@ -680,6 +766,12 @@ declare class Llm implements LlmProvider {
|
|
|
680
766
|
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
681
767
|
model?: LlmModelOption;
|
|
682
768
|
}): Promise<LlmOperateResponse>;
|
|
769
|
+
/**
|
|
770
|
+
* Stamp fallback resolution onto the envelope the operate loop attached to
|
|
771
|
+
* the response and deliver it to the caller's onExchange. Fires once per
|
|
772
|
+
* operate() settlement; callback errors are logged and never thrown.
|
|
773
|
+
*/
|
|
774
|
+
private settleExchange;
|
|
683
775
|
stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
684
776
|
model?: LlmModelOption;
|
|
685
777
|
}): AsyncIterable<LlmStreamChunk>;
|
|
@@ -931,4 +1023,4 @@ declare class XaiProvider implements LlmProvider {
|
|
|
931
1023
|
}
|
|
932
1024
|
|
|
933
1025
|
export { BedrockProvider, ErrorCategory, FireworksProvider, GoogleProvider as GeminiProvider, GoogleProvider, JaypieToolkit, constants as LLM, Llm, LlmError, LlmMessageRole, LlmMessageType, LlmProgressEventType, LlmQuotaError, LlmRateLimitError, LlmStreamChunkType, LlmTransientError, LlmUnrecoverableError, OpenRouterProvider, Toolkit, XaiProvider, extractReasoning, isLlmOperateInput, isLlmOperateInputContent, isLlmOperateInputFile, isLlmOperateInputImage, jsonSchemaToNaturalSchema, naturalSchemaToJsonSchema, toolkit, tools };
|
|
934
|
-
export type { LlmEffort, LlmErrorOptions, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|
|
1026
|
+
export type { LlmEffort, LlmErrorOptions, LlmExchangeCallback, LlmExchangeEnvelope, LlmExchangeRequest, LlmExchangeResolution, LlmExchangeResponse, LlmExchangeTiming, LlmFallbackConfig, LlmHistory, LlmInputContent, LlmInputContentFile, LlmInputContentImage, LlmInputContentText, LlmInputMessage, LlmMessageOptions, LlmModelOption, LlmOperateInput, LlmOperateInputContent, LlmOperateInputFile, LlmOperateInputImage, LlmOperateOptions, LlmOperateResponse, LlmOptions, LlmProgressCallback, LlmProgressEvent, LlmProgressToolCall, LlmProvider, LlmStreamChunk, LlmStreamChunkDone, LlmStreamChunkError, LlmStreamChunkText, LlmStreamChunkToolCall, LlmStreamChunkToolResult, LlmTool };
|