@jaypie/llm 1.3.13 → 1.3.15
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 +813 -344
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +112 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/observability/exchangeStore.d.ts +20 -0
- package/dist/cjs/operate/adapters/BedrockAdapter.d.ts +6 -0
- package/dist/cjs/operate/adapters/OpenAiAdapter.d.ts +5 -0
- package/dist/cjs/operate/adapters/OpenRouterAdapter.d.ts +11 -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 +10 -1
- package/dist/cjs/providers/anthropic/types.d.ts +14 -1
- package/dist/cjs/types/LlmProvider.interface.d.ts +106 -1
- package/dist/cjs/util/cacheControl.d.ts +21 -0
- package/dist/cjs/util/index.d.ts +1 -0
- package/dist/esm/Llm.d.ts +6 -0
- package/dist/esm/index.d.ts +112 -1
- package/dist/esm/index.js +813 -344
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/observability/exchangeStore.d.ts +20 -0
- package/dist/esm/operate/adapters/BedrockAdapter.d.ts +6 -0
- package/dist/esm/operate/adapters/OpenAiAdapter.d.ts +5 -0
- package/dist/esm/operate/adapters/OpenRouterAdapter.d.ts +11 -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 +10 -1
- package/dist/esm/providers/anthropic/types.d.ts +14 -1
- package/dist/esm/types/LlmProvider.interface.d.ts +106 -1
- package/dist/esm/util/cacheControl.d.ts +21 -0
- package/dist/esm/util/index.d.ts +1 -0
- package/package.json +5 -1
package/dist/esm/index.d.ts
CHANGED
|
@@ -525,7 +525,97 @@ 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
|
+
cache?: LlmCache;
|
|
534
|
+
data?: NaturalMap;
|
|
535
|
+
effort?: LlmEffort;
|
|
536
|
+
explain?: boolean;
|
|
537
|
+
/** Format normalized to JSON Schema (Zod/Natural already rendered) */
|
|
538
|
+
format?: JsonObject;
|
|
539
|
+
input: string | LlmHistory | LlmInputMessage | LlmOperateInput;
|
|
540
|
+
instructions?: string;
|
|
541
|
+
/** Requested model (pre-fallback) */
|
|
542
|
+
model?: string;
|
|
543
|
+
placeholders?: {
|
|
544
|
+
input?: boolean;
|
|
545
|
+
instructions?: boolean;
|
|
546
|
+
system?: boolean;
|
|
547
|
+
};
|
|
548
|
+
providerOptions?: JsonObject;
|
|
549
|
+
system?: string;
|
|
550
|
+
temperature?: number;
|
|
551
|
+
/** Names of tools offered to the model */
|
|
552
|
+
tools?: string[];
|
|
553
|
+
turns?: boolean | number;
|
|
554
|
+
user?: string;
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* Serializable snapshot of the response side of one operate() call.
|
|
558
|
+
*/
|
|
559
|
+
interface LlmExchangeResponse {
|
|
560
|
+
content?: string | JsonObject;
|
|
561
|
+
error?: LlmError$1;
|
|
562
|
+
/** Turns this call added to history (tool calls/results included); never the resent history */
|
|
563
|
+
historyDelta: LlmHistory;
|
|
564
|
+
reasoning?: string[];
|
|
565
|
+
status: LlmResponseStatus;
|
|
566
|
+
stopReason?: string;
|
|
567
|
+
/** Per-model-call usage items (provider/model on each item) */
|
|
568
|
+
usage: LlmUsage;
|
|
569
|
+
/** Cumulative usage keyed `provider:model` */
|
|
570
|
+
usageTotals?: Record<string, LlmUsageItem>;
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* How the call was actually served after fallback and retry resolution.
|
|
574
|
+
*/
|
|
575
|
+
interface LlmExchangeResolution {
|
|
576
|
+
fallbackAttempts?: number;
|
|
577
|
+
fallbackUsed?: boolean;
|
|
578
|
+
/** Served model */
|
|
579
|
+
model?: string;
|
|
580
|
+
/** Served provider */
|
|
581
|
+
provider?: string;
|
|
582
|
+
/** Model-request retries within the served attempt */
|
|
583
|
+
retries?: number;
|
|
584
|
+
}
|
|
585
|
+
interface LlmExchangeTiming {
|
|
586
|
+
/** Milliseconds from start to settlement */
|
|
587
|
+
duration: number;
|
|
588
|
+
/** ISO 8601 */
|
|
589
|
+
startedAt: string;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* One serializable request/response envelope per operate() settlement
|
|
593
|
+
* (success or failure). Contains no functions.
|
|
594
|
+
*/
|
|
595
|
+
interface LlmExchangeEnvelope {
|
|
596
|
+
/** Provider response id(s) per model turn, when available */
|
|
597
|
+
ids?: string[];
|
|
598
|
+
request: LlmExchangeRequest;
|
|
599
|
+
resolution: LlmExchangeResolution;
|
|
600
|
+
response: LlmExchangeResponse;
|
|
601
|
+
timing: LlmExchangeTiming;
|
|
602
|
+
}
|
|
603
|
+
type LlmExchangeCallback = (envelope: LlmExchangeEnvelope) => unknown | Promise<unknown>;
|
|
604
|
+
/**
|
|
605
|
+
* Prompt-caching control for operate()/stream().
|
|
606
|
+
* - `true` / omitted → caching enabled at the default `"5m"` TTL
|
|
607
|
+
* - `false` / `0` → caching disabled
|
|
608
|
+
* - `"5m"` / `"1h"` → enabled at that TTL (TTL honored by Anthropic/OpenRouter;
|
|
609
|
+
* other providers ignore it and cache with their own defaults)
|
|
610
|
+
*/
|
|
611
|
+
type LlmCache = boolean | 0 | "5m" | "1h";
|
|
528
612
|
interface LlmOperateOptions {
|
|
613
|
+
/**
|
|
614
|
+
* Prompt caching for the stable request prefix (system prompt + tools).
|
|
615
|
+
* Enabled by default; pass `false`/`0` to opt out, or `"5m"`/`"1h"` to set
|
|
616
|
+
* the TTL. See {@link LlmCache}.
|
|
617
|
+
*/
|
|
618
|
+
cache?: LlmCache;
|
|
529
619
|
data?: NaturalMap;
|
|
530
620
|
/**
|
|
531
621
|
* Provider-neutral reasoning effort (lowest | low | medium | high | highest).
|
|
@@ -589,6 +679,12 @@ interface LlmOperateOptions {
|
|
|
589
679
|
};
|
|
590
680
|
instructions?: string;
|
|
591
681
|
model?: string;
|
|
682
|
+
/**
|
|
683
|
+
* Fires once per operate() settlement (success or failure) with a fully
|
|
684
|
+
* serializable request/response envelope. Errors thrown by the callback
|
|
685
|
+
* are logged and never interrupt the call.
|
|
686
|
+
*/
|
|
687
|
+
onExchange?: LlmExchangeCallback;
|
|
592
688
|
/**
|
|
593
689
|
* Receives lightweight progress events as the operate loop runs:
|
|
594
690
|
* start, model_request, model_response, tool_call, tool_result,
|
|
@@ -628,6 +724,10 @@ interface LlmUsageItem {
|
|
|
628
724
|
output: number;
|
|
629
725
|
reasoning: number;
|
|
630
726
|
total: number;
|
|
727
|
+
/** Prompt-cache tokens served from cache this call (billed at ~0.1x input) */
|
|
728
|
+
cacheRead?: number;
|
|
729
|
+
/** Prompt-cache tokens written to cache this call (billed at ~1.25x input) */
|
|
730
|
+
cacheWrite?: number;
|
|
631
731
|
provider?: string;
|
|
632
732
|
model?: string;
|
|
633
733
|
}
|
|
@@ -635,6 +735,11 @@ type LlmUsage = LlmUsageItem[];
|
|
|
635
735
|
interface LlmOperateResponse {
|
|
636
736
|
content?: string | JsonObject;
|
|
637
737
|
error?: LlmError$1;
|
|
738
|
+
/**
|
|
739
|
+
* Serializable exchange envelope for this call. Present only when
|
|
740
|
+
* `onExchange` was passed or exchange persistence is enabled.
|
|
741
|
+
*/
|
|
742
|
+
exchange?: LlmExchangeEnvelope;
|
|
638
743
|
/** Number of providers attempted (1 = primary only, >1 = fallback(s) used) */
|
|
639
744
|
fallbackAttempts?: number;
|
|
640
745
|
/** Whether a fallback provider was used instead of the primary */
|
|
@@ -680,6 +785,12 @@ declare class Llm implements LlmProvider {
|
|
|
680
785
|
operate(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
681
786
|
model?: LlmModelOption;
|
|
682
787
|
}): Promise<LlmOperateResponse>;
|
|
788
|
+
/**
|
|
789
|
+
* Stamp fallback resolution onto the envelope the operate loop attached to
|
|
790
|
+
* the response and deliver it to the caller's onExchange. Fires once per
|
|
791
|
+
* operate() settlement; callback errors are logged and never thrown.
|
|
792
|
+
*/
|
|
793
|
+
private settleExchange;
|
|
683
794
|
stream(input: string | LlmHistory | LlmInputMessage | LlmOperateInput, options?: Omit<LlmOperateOptions, "model"> & {
|
|
684
795
|
model?: LlmModelOption;
|
|
685
796
|
}): AsyncIterable<LlmStreamChunk>;
|
|
@@ -931,4 +1042,4 @@ declare class XaiProvider implements LlmProvider {
|
|
|
931
1042
|
}
|
|
932
1043
|
|
|
933
1044
|
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 };
|
|
1045
|
+
export type { LlmCache, 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 };
|