@jaypie/llm 1.2.29 → 1.2.32
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/constants.d.ts +5 -5
- package/dist/cjs/index.cjs +692 -132
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/operate/adapters/AnthropicAdapter.d.ts +29 -2
- package/dist/cjs/operate/adapters/GeminiAdapter.d.ts +11 -1
- package/dist/cjs/operate/adapters/OpenAiAdapter.d.ts +4 -0
- package/dist/cjs/operate/adapters/OpenRouterAdapter.d.ts +32 -4
- package/dist/esm/constants.d.ts +5 -5
- package/dist/esm/index.js +692 -132
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/operate/adapters/AnthropicAdapter.d.ts +29 -2
- package/dist/esm/operate/adapters/GeminiAdapter.d.ts +11 -1
- package/dist/esm/operate/adapters/OpenAiAdapter.d.ts +4 -0
- package/dist/esm/operate/adapters/OpenRouterAdapter.d.ts +32 -4
- package/package.json +2 -1
|
@@ -6,6 +6,22 @@ import { LlmHistory, LlmOperateOptions, LlmUsageItem } from "../../types/LlmProv
|
|
|
6
6
|
import { LlmStreamChunk } from "../../types/LlmStreamChunk.interface.js";
|
|
7
7
|
import { ClassifiedError, OperateRequest, ParsedResponse, ProviderToolDefinition, StandardToolCall, StandardToolResult } from "../types.js";
|
|
8
8
|
import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
|
|
9
|
+
/**
|
|
10
|
+
* Local extension of the SDK's `MessageCreateParams` to carry
|
|
11
|
+
* `output_config.format` (Anthropic native structured outputs). The SDK 0.71
|
|
12
|
+
* shipped with the older `output_format` field which the API has since
|
|
13
|
+
* deprecated in favor of `output_config.format`. We send the new shape via
|
|
14
|
+
* an untyped passthrough so callers don't need a newer SDK; remove this
|
|
15
|
+
* extension once the SDK types `output_config` directly.
|
|
16
|
+
*/
|
|
17
|
+
type AnthropicRequestParams = Anthropic.MessageCreateParams & {
|
|
18
|
+
output_config?: {
|
|
19
|
+
format: {
|
|
20
|
+
type: "json_schema";
|
|
21
|
+
schema: JsonObject;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
};
|
|
9
25
|
/**
|
|
10
26
|
* AnthropicAdapter implements the ProviderAdapter interface for Anthropic's API.
|
|
11
27
|
* It handles request building, response parsing, and error classification
|
|
@@ -15,13 +31,23 @@ export declare class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
15
31
|
readonly name: "anthropic";
|
|
16
32
|
readonly defaultModel: "claude-sonnet-4-6";
|
|
17
33
|
private runtimeNoTemperatureModels;
|
|
34
|
+
private runtimeNoStructuredOutputModels;
|
|
18
35
|
rememberModelRejectsTemperature(model: string): void;
|
|
19
36
|
clearRuntimeNoTemperatureModels(): void;
|
|
37
|
+
rememberModelRejectsStructuredOutput(model: string): void;
|
|
38
|
+
clearRuntimeNoStructuredOutputModels(): void;
|
|
20
39
|
private supportsTemperature;
|
|
21
|
-
|
|
22
|
-
|
|
40
|
+
private supportsStructuredOutput;
|
|
41
|
+
buildRequest(request: OperateRequest): AnthropicRequestParams;
|
|
42
|
+
formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
|
|
23
43
|
formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
|
|
24
44
|
executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<Anthropic.Message>;
|
|
45
|
+
/**
|
|
46
|
+
* Rebuild a structured-output request without `output_format`, swapping in
|
|
47
|
+
* the legacy fake-tool emulation. Used as a runtime fallback when a model
|
|
48
|
+
* rejects native `output_config.format`.
|
|
49
|
+
*/
|
|
50
|
+
private toFallbackStructuredOutputRequest;
|
|
25
51
|
executeStreamRequest(client: unknown, request: unknown, signal?: AbortSignal): AsyncIterable<LlmStreamChunk>;
|
|
26
52
|
parseResponse(response: unknown, _options?: LlmOperateOptions): ParsedResponse;
|
|
27
53
|
extractToolCalls(response: unknown): StandardToolCall[];
|
|
@@ -36,3 +62,4 @@ export declare class AnthropicAdapter extends BaseProviderAdapter {
|
|
|
36
62
|
private extractContent;
|
|
37
63
|
}
|
|
38
64
|
export declare const anthropicAdapter: AnthropicAdapter;
|
|
65
|
+
export {};
|
|
@@ -14,10 +14,20 @@ import { GeminiPart, GeminiRawResponse, GeminiRequest } from "../../providers/ge
|
|
|
14
14
|
export declare class GeminiAdapter extends BaseProviderAdapter {
|
|
15
15
|
readonly name: "google";
|
|
16
16
|
readonly defaultModel: "gemini-3.1-pro-preview";
|
|
17
|
+
private runtimeNoStructuredOutputComboModels;
|
|
18
|
+
rememberModelRejectsStructuredOutputCombo(model: string): void;
|
|
19
|
+
clearRuntimeNoStructuredOutputComboModels(): void;
|
|
20
|
+
private supportsStructuredOutputCombo;
|
|
17
21
|
buildRequest(request: OperateRequest): GeminiRequest;
|
|
18
|
-
formatTools(toolkit: Toolkit,
|
|
22
|
+
formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
|
|
19
23
|
formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
|
|
20
24
|
executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<GeminiRawResponse>;
|
|
25
|
+
/**
|
|
26
|
+
* Rebuild a Gemini 3 native-combo request without `responseJsonSchema`/
|
|
27
|
+
* `responseMimeType`, swapping in the legacy fake-tool emulation. Used as
|
|
28
|
+
* a runtime fallback when a Gemini 3 model rejects the combo.
|
|
29
|
+
*/
|
|
30
|
+
private toFallbackStructuredOutputRequest;
|
|
21
31
|
executeStreamRequest(client: unknown, request: unknown, signal?: AbortSignal): AsyncIterable<LlmStreamChunk>;
|
|
22
32
|
parseResponse(response: unknown, options?: LlmOperateOptions): ParsedResponse;
|
|
23
33
|
extractToolCalls(response: unknown): StandardToolCall[];
|
|
@@ -13,6 +13,10 @@ import { BaseProviderAdapter } from "./ProviderAdapter.interface.js";
|
|
|
13
13
|
export declare class OpenAiAdapter extends BaseProviderAdapter {
|
|
14
14
|
readonly name: "openai";
|
|
15
15
|
readonly defaultModel: "gpt-5.4";
|
|
16
|
+
private runtimeNoTemperatureModels;
|
|
17
|
+
rememberModelRejectsTemperature(model: string): void;
|
|
18
|
+
clearRuntimeNoTemperatureModels(): void;
|
|
19
|
+
private supportsTemperature;
|
|
16
20
|
buildRequest(request: OperateRequest): unknown;
|
|
17
21
|
formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
|
|
18
22
|
formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
|
|
@@ -59,14 +59,26 @@ interface OpenRouterTool {
|
|
|
59
59
|
parameters: JsonObject;
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
interface OpenRouterJsonSchemaConfig {
|
|
63
|
+
name: string;
|
|
64
|
+
description?: string;
|
|
65
|
+
schema: JsonObject;
|
|
66
|
+
strict?: boolean;
|
|
67
|
+
}
|
|
68
|
+
type OpenRouterResponseFormat = {
|
|
69
|
+
type: "json_schema";
|
|
70
|
+
json_schema: OpenRouterJsonSchemaConfig;
|
|
71
|
+
} | {
|
|
72
|
+
type: "json_object";
|
|
73
|
+
} | {
|
|
74
|
+
type: "text";
|
|
75
|
+
};
|
|
62
76
|
interface OpenRouterRequest {
|
|
63
77
|
model: string;
|
|
64
78
|
messages: OpenRouterMessage[];
|
|
65
79
|
tools?: OpenRouterTool[];
|
|
66
80
|
tool_choice?: "auto" | "none" | "required";
|
|
67
|
-
response_format?:
|
|
68
|
-
type: "json_object" | "text";
|
|
69
|
-
};
|
|
81
|
+
response_format?: OpenRouterResponseFormat;
|
|
70
82
|
user?: string;
|
|
71
83
|
}
|
|
72
84
|
/**
|
|
@@ -85,10 +97,26 @@ type OpenRouterContentPart = {
|
|
|
85
97
|
export declare class OpenRouterAdapter extends BaseProviderAdapter {
|
|
86
98
|
readonly name: "openrouter";
|
|
87
99
|
readonly defaultModel: "anthropic/claude-sonnet-4-6";
|
|
100
|
+
private runtimeNoStructuredOutputModels;
|
|
101
|
+
rememberModelRejectsStructuredOutput(model: string): void;
|
|
102
|
+
clearRuntimeNoStructuredOutputModels(): void;
|
|
103
|
+
private supportsStructuredOutput;
|
|
88
104
|
buildRequest(request: OperateRequest): OpenRouterRequest;
|
|
89
|
-
formatTools(toolkit: Toolkit,
|
|
105
|
+
formatTools(toolkit: Toolkit, _outputSchema?: JsonObject): ProviderToolDefinition[];
|
|
90
106
|
formatOutputSchema(schema: JsonObject | NaturalSchema | z.ZodType): JsonObject;
|
|
91
107
|
executeRequest(client: unknown, request: unknown, signal?: AbortSignal): Promise<OpenRouterResponse>;
|
|
108
|
+
/**
|
|
109
|
+
* Translate our internal snake_case `OpenRouterRequest` into the SDK's
|
|
110
|
+
* camelCase shape, forwarding only the fields we care about (the SDK
|
|
111
|
+
* silently strips unknown fields).
|
|
112
|
+
*/
|
|
113
|
+
private toSdkChatParams;
|
|
114
|
+
/**
|
|
115
|
+
* Rebuild a structured-output request without `response_format`, swapping in
|
|
116
|
+
* the legacy fake-tool emulation. Used as a runtime fallback when a model
|
|
117
|
+
* rejects native json_schema.
|
|
118
|
+
*/
|
|
119
|
+
private toFallbackStructuredOutputRequest;
|
|
92
120
|
executeStreamRequest(client: unknown, request: unknown, signal?: AbortSignal): AsyncIterable<LlmStreamChunk>;
|
|
93
121
|
parseResponse(response: unknown, _options?: LlmOperateOptions): ParsedResponse;
|
|
94
122
|
extractToolCalls(response: unknown): StandardToolCall[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jaypie/llm",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.32",
|
|
4
4
|
"description": "Large language model utilities",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
"format": "eslint . --fix",
|
|
29
29
|
"lint": "eslint .",
|
|
30
30
|
"test": "vitest run .",
|
|
31
|
+
"test:matrix": "tsx test/matrix.ts",
|
|
31
32
|
"test:watch": "vitest",
|
|
32
33
|
"typecheck": "tsc --noEmit"
|
|
33
34
|
},
|