@tinyweb_dev/agent-framework-llm 0.2.0 → 0.4.0
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/cache-policy.d.ts +3 -0
- package/dist/cache-policy.d.ts.map +1 -0
- package/dist/index.cjs +2968 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2843 -0
- package/dist/index.js.map +1 -0
- package/dist/llm.cjs +1718 -0
- package/dist/llm.cjs.map +1 -0
- package/dist/llm.d.ts +284 -0
- package/dist/llm.d.ts.map +1 -0
- package/dist/llm.js +1692 -0
- package/dist/llm.js.map +1 -0
- package/dist/protocols/openai-chat.cjs +2455 -0
- package/dist/protocols/openai-chat.cjs.map +1 -0
- package/dist/protocols/openai-chat.d.ts +359 -0
- package/dist/protocols/openai-chat.d.ts.map +1 -0
- package/dist/protocols/openai-chat.js +2426 -0
- package/dist/protocols/openai-chat.js.map +1 -0
- package/dist/protocols/openai-compatible-chat.cjs +2455 -0
- package/dist/protocols/openai-compatible-chat.cjs.map +1 -0
- package/dist/protocols/openai-compatible-chat.d.ts +77 -0
- package/dist/protocols/openai-compatible-chat.d.ts.map +1 -0
- package/dist/protocols/openai-compatible-chat.js +2431 -0
- package/dist/protocols/openai-compatible-chat.js.map +1 -0
- package/dist/protocols/shared.cjs +904 -0
- package/dist/protocols/shared.cjs.map +1 -0
- package/dist/protocols/shared.d.ts +51 -0
- package/dist/protocols/shared.d.ts.map +1 -0
- package/dist/protocols/shared.js +857 -0
- package/dist/protocols/shared.js.map +1 -0
- package/dist/protocols/utils/openai-options.d.ts +15 -0
- package/dist/protocols/utils/openai-options.d.ts.map +1 -0
- package/dist/protocols/utils/tool-stream.d.ts +78 -0
- package/dist/protocols/utils/tool-stream.d.ts.map +1 -0
- package/dist/provider.cjs +20 -0
- package/dist/provider.cjs.map +1 -0
- package/dist/provider.d.ts +19 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +17 -0
- package/dist/provider.js.map +1 -0
- package/{src/providers/openai-compatible-profile.ts → dist/providers/openai-compatible-profile.cjs} +12 -12
- package/dist/providers/openai-compatible-profile.cjs.map +1 -0
- package/dist/providers/openai-compatible-profile.d.ts +52 -0
- package/dist/providers/openai-compatible-profile.d.ts.map +1 -0
- package/dist/providers/openai-compatible-profile.js +21 -0
- package/dist/providers/openai-compatible-profile.js.map +1 -0
- package/dist/providers/openai-compatible.cjs +2545 -0
- package/dist/providers/openai-compatible.cjs.map +1 -0
- package/dist/providers/openai-compatible.d.ts +128 -0
- package/dist/providers/openai-compatible.d.ts.map +1 -0
- package/dist/providers/openai-compatible.js +2507 -0
- package/dist/providers/openai-compatible.js.map +1 -0
- package/dist/providers/openai-options.cjs +797 -0
- package/dist/providers/openai-options.cjs.map +1 -0
- package/dist/providers/openai-options.d.ts +29 -0
- package/dist/providers/openai-options.d.ts.map +1 -0
- package/dist/providers/openai-options.js +792 -0
- package/dist/providers/openai-options.js.map +1 -0
- package/dist/providers/openai.cjs +2529 -0
- package/dist/providers/openai.cjs.map +1 -0
- package/dist/providers/openai.d.ts +87 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +2501 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/route/auth-options.cjs +855 -0
- package/dist/route/auth-options.cjs.map +1 -0
- package/dist/route/auth-options.d.ts +25 -0
- package/dist/route/auth-options.d.ts.map +1 -0
- package/dist/route/auth-options.js +852 -0
- package/dist/route/auth-options.js.map +1 -0
- package/dist/route/auth.cjs +855 -0
- package/dist/route/auth.cjs.map +1 -0
- package/dist/route/auth.d.ts +51 -0
- package/dist/route/auth.d.ts.map +1 -0
- package/dist/route/auth.js +836 -0
- package/dist/route/auth.js.map +1 -0
- package/dist/route/client.cjs +1844 -0
- package/dist/route/client.cjs.map +1 -0
- package/dist/route/client.d.ts +268 -0
- package/dist/route/client.d.ts.map +1 -0
- package/dist/route/client.js +1830 -0
- package/dist/route/client.js.map +1 -0
- package/dist/route/endpoint.cjs +756 -0
- package/dist/route/endpoint.cjs.map +1 -0
- package/dist/route/endpoint.d.ts +13 -0
- package/dist/route/endpoint.d.ts.map +1 -0
- package/dist/route/endpoint.js +752 -0
- package/dist/route/endpoint.js.map +1 -0
- package/dist/route/executor.cjs +1077 -0
- package/dist/route/executor.cjs.map +1 -0
- package/dist/route/executor.d.ts +13 -0
- package/dist/route/executor.d.ts.map +1 -0
- package/dist/route/executor.js +1072 -0
- package/dist/route/executor.js.map +1 -0
- package/dist/route/framing.cjs +773 -0
- package/dist/route/framing.cjs.map +1 -0
- package/dist/route/framing.d.ts +9 -0
- package/dist/route/framing.d.ts.map +1 -0
- package/dist/route/framing.js +750 -0
- package/dist/route/framing.js.map +1 -0
- package/dist/route/overflow-detect.d.ts +18 -0
- package/dist/route/overflow-detect.d.ts.map +1 -0
- package/dist/route/protocol.cjs +25 -0
- package/dist/route/protocol.cjs.map +1 -0
- package/dist/route/protocol.d.ts +40 -0
- package/dist/route/protocol.d.ts.map +1 -0
- package/dist/route/protocol.js +21 -0
- package/dist/route/protocol.js.map +1 -0
- package/dist/route/transport/http.d.ts +48 -0
- package/dist/route/transport/http.d.ts.map +1 -0
- package/dist/route/transport/index.cjs +969 -0
- package/dist/route/transport/index.cjs.map +1 -0
- package/dist/route/transport/index.d.ts +13 -0
- package/dist/route/transport/index.d.ts.map +1 -0
- package/dist/route/transport/index.js +967 -0
- package/dist/route/transport/index.js.map +1 -0
- package/dist/schema/errors.d.ts +181 -0
- package/dist/schema/errors.d.ts.map +1 -0
- package/dist/schema/events.d.ts +3224 -0
- package/dist/schema/events.d.ts.map +1 -0
- package/dist/schema/ids.d.ts +31 -0
- package/dist/schema/ids.d.ts.map +1 -0
- package/dist/schema/index.cjs +847 -0
- package/dist/schema/index.cjs.map +1 -0
- package/dist/schema/index.d.ts +6 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +777 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/schema/messages.d.ts +292 -0
- package/dist/schema/messages.d.ts.map +1 -0
- package/dist/schema/options.d.ts +123 -0
- package/dist/schema/options.d.ts.map +1 -0
- package/dist/tool-runtime.cjs +907 -0
- package/dist/tool-runtime.cjs.map +1 -0
- package/dist/tool-runtime.d.ts +50 -0
- package/dist/tool-runtime.d.ts.map +1 -0
- package/dist/tool-runtime.js +901 -0
- package/dist/tool-runtime.js.map +1 -0
- package/dist/tool.cjs +802 -0
- package/dist/tool.cjs.map +1 -0
- package/dist/tool.d.ts +111 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +796 -0
- package/dist/tool.js.map +1 -0
- package/package.json +112 -29
- package/src/cache-policy.ts +0 -92
- package/src/index.ts +0 -62
- package/src/llm.ts +0 -210
- package/src/protocols/openai-chat.ts +0 -464
- package/src/protocols/openai-compatible-chat.ts +0 -29
- package/src/protocols/shared.ts +0 -204
- package/src/protocols/utils/openai-options.ts +0 -56
- package/src/protocols/utils/tool-stream.ts +0 -135
- package/src/provider.ts +0 -32
- package/src/providers/openai-compatible.ts +0 -69
- package/src/providers/openai-options.ts +0 -71
- package/src/providers/openai.ts +0 -39
- package/src/route/auth-options.ts +0 -48
- package/src/route/auth.ts +0 -198
- package/src/route/client.ts +0 -459
- package/src/route/endpoint.ts +0 -28
- package/src/route/executor.ts +0 -396
- package/src/route/framing.ts +0 -13
- package/src/route/overflow-detect.ts +0 -74
- package/src/route/protocol.ts +0 -48
- package/src/route/transport/http.ts +0 -123
- package/src/route/transport/index.ts +0 -21
- package/src/schema/errors.ts +0 -225
- package/src/schema/events.ts +0 -335
- package/src/schema/ids.ts +0 -44
- package/src/schema/index.ts +0 -6
- package/src/schema/messages.ts +0 -250
- package/src/schema/options.ts +0 -231
- package/src/tool-runtime.ts +0 -301
- package/src/tool.ts +0 -212
|
@@ -0,0 +1,792 @@
|
|
|
1
|
+
import { Schema } from 'effect';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __export = (target, all) => {
|
|
5
|
+
for (var name in all)
|
|
6
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/providers/openai-options.ts
|
|
10
|
+
var openai_options_exports = {};
|
|
11
|
+
__export(openai_options_exports, {
|
|
12
|
+
OpenAIProviderOptions: () => openai_options_exports,
|
|
13
|
+
gpt5DefaultOptions: () => gpt5DefaultOptions,
|
|
14
|
+
openAIDefaultOptions: () => openAIDefaultOptions,
|
|
15
|
+
withOpenAIOptions: () => withOpenAIOptions
|
|
16
|
+
});
|
|
17
|
+
var ProtocolID = Schema.String;
|
|
18
|
+
var RouteID = Schema.String;
|
|
19
|
+
var ModelID = Schema.String.pipe(Schema.brand("LLM.ModelID"));
|
|
20
|
+
var ProviderID = Schema.String.pipe(Schema.brand("LLM.ProviderID"));
|
|
21
|
+
var ResponseID = Schema.String;
|
|
22
|
+
var ContentBlockID = Schema.String;
|
|
23
|
+
var ToolCallID = Schema.String;
|
|
24
|
+
var ReasoningEfforts = ["none", "minimal", "low", "medium", "high", "xhigh", "max"];
|
|
25
|
+
Schema.Literals(ReasoningEfforts);
|
|
26
|
+
Schema.Literals(["low", "medium", "high"]);
|
|
27
|
+
var MessageRole = Schema.Literals(["user", "assistant", "tool"]);
|
|
28
|
+
var FinishReason = Schema.Literals(["stop", "length", "tool-calls", "content-filter", "error", "unknown"]);
|
|
29
|
+
var JsonSchema = Schema.Record(Schema.String, Schema.Unknown);
|
|
30
|
+
var ProviderMetadata = Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown));
|
|
31
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
|
+
var mergeJsonRecords = (...items) => {
|
|
33
|
+
const defined = items.filter((item) => item !== void 0);
|
|
34
|
+
if (defined.length === 0) return void 0;
|
|
35
|
+
if (defined.length === 1 && Object.values(defined[0]).every((value) => value !== void 0)) return defined[0];
|
|
36
|
+
const result = {};
|
|
37
|
+
for (const item of defined) {
|
|
38
|
+
for (const [key, value] of Object.entries(item)) {
|
|
39
|
+
if (value === void 0) continue;
|
|
40
|
+
result[key] = isRecord(result[key]) && isRecord(value) ? mergeJsonRecords(result[key], value) : value;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return Object.keys(result).length === 0 ? void 0 : result;
|
|
44
|
+
};
|
|
45
|
+
var ProviderOptions = Schema.Record(Schema.String, Schema.Record(Schema.String, Schema.Unknown));
|
|
46
|
+
var mergeProviderOptions = (...items) => {
|
|
47
|
+
const result = {};
|
|
48
|
+
for (const item of items) {
|
|
49
|
+
if (!item) continue;
|
|
50
|
+
for (const [provider, options] of Object.entries(item)) {
|
|
51
|
+
const merged = mergeJsonRecords(result[provider], options);
|
|
52
|
+
if (merged) result[provider] = merged;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return Object.keys(result).length === 0 ? void 0 : result;
|
|
56
|
+
};
|
|
57
|
+
var HttpOptions = class extends Schema.Class("LLM.HttpOptions")({
|
|
58
|
+
body: Schema.optional(JsonSchema),
|
|
59
|
+
headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
60
|
+
query: Schema.optional(Schema.Record(Schema.String, Schema.String))
|
|
61
|
+
}) {
|
|
62
|
+
};
|
|
63
|
+
((HttpOptions2) => {
|
|
64
|
+
HttpOptions2.make = (input) => input instanceof HttpOptions2 ? input : new HttpOptions2(input);
|
|
65
|
+
})(HttpOptions || (HttpOptions = {}));
|
|
66
|
+
var GenerationOptions = class extends Schema.Class("LLM.GenerationOptions")({
|
|
67
|
+
maxTokens: Schema.optional(Schema.Number),
|
|
68
|
+
temperature: Schema.optional(Schema.Number),
|
|
69
|
+
topP: Schema.optional(Schema.Number),
|
|
70
|
+
topK: Schema.optional(Schema.Number),
|
|
71
|
+
frequencyPenalty: Schema.optional(Schema.Number),
|
|
72
|
+
presencePenalty: Schema.optional(Schema.Number),
|
|
73
|
+
seed: Schema.optional(Schema.Number),
|
|
74
|
+
stop: Schema.optional(Schema.Array(Schema.String))
|
|
75
|
+
}) {
|
|
76
|
+
};
|
|
77
|
+
((GenerationOptions2) => {
|
|
78
|
+
GenerationOptions2.make = (input = {}) => input instanceof GenerationOptions2 ? input : new GenerationOptions2(input);
|
|
79
|
+
})(GenerationOptions || (GenerationOptions = {}));
|
|
80
|
+
var ModelLimits = class extends Schema.Class("LLM.ModelLimits")({
|
|
81
|
+
context: Schema.optional(Schema.Number),
|
|
82
|
+
output: Schema.optional(Schema.Number)
|
|
83
|
+
}) {
|
|
84
|
+
};
|
|
85
|
+
((ModelLimits2) => {
|
|
86
|
+
ModelLimits2.make = (input) => input instanceof ModelLimits2 ? input : new ModelLimits2(input ?? {});
|
|
87
|
+
})(ModelLimits || (ModelLimits = {}));
|
|
88
|
+
var ModelRef = class extends Schema.Class("LLM.ModelRef")({
|
|
89
|
+
id: ModelID,
|
|
90
|
+
provider: ProviderID,
|
|
91
|
+
route: RouteID,
|
|
92
|
+
baseURL: Schema.String,
|
|
93
|
+
/** Provider-specific API key convenience. Provider helpers normalize this into `auth`. */
|
|
94
|
+
apiKey: Schema.optional(Schema.String),
|
|
95
|
+
/** Optional transport auth policy. Opaque because it may contain functions. */
|
|
96
|
+
auth: Schema.optional(Schema.Any),
|
|
97
|
+
headers: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
98
|
+
/**
|
|
99
|
+
* Query params appended to the request URL by `Endpoint.baseURL`. Used for
|
|
100
|
+
* deployment-level URL-scoped settings such as Azure's `api-version` or any
|
|
101
|
+
* provider that requires a per-request key in the URL. Generic concern, so
|
|
102
|
+
* lives as a typed first-class field instead of `native`.
|
|
103
|
+
*/
|
|
104
|
+
queryParams: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
105
|
+
limits: ModelLimits,
|
|
106
|
+
/** Provider-neutral generation defaults. Request-level values override them. */
|
|
107
|
+
generation: Schema.optional(GenerationOptions),
|
|
108
|
+
/** Provider-owned typed-at-the-facade options for non-portable knobs. */
|
|
109
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
110
|
+
/** Serializable raw HTTP overlays applied to the final outgoing request. */
|
|
111
|
+
http: Schema.optional(HttpOptions),
|
|
112
|
+
/**
|
|
113
|
+
* Provider-specific opaque options. Reach for this only when the value is
|
|
114
|
+
* genuinely provider-private and does not fit a typed axis (e.g. Bedrock's
|
|
115
|
+
* `aws_credentials` / `aws_region` for SigV4). Anything used by more than
|
|
116
|
+
* one route should grow into a typed field instead.
|
|
117
|
+
*/
|
|
118
|
+
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
119
|
+
}) {
|
|
120
|
+
};
|
|
121
|
+
((ModelRef2) => {
|
|
122
|
+
ModelRef2.input = (model) => ({
|
|
123
|
+
id: model.id,
|
|
124
|
+
provider: model.provider,
|
|
125
|
+
route: model.route,
|
|
126
|
+
baseURL: model.baseURL,
|
|
127
|
+
apiKey: model.apiKey,
|
|
128
|
+
auth: model.auth,
|
|
129
|
+
headers: model.headers,
|
|
130
|
+
queryParams: model.queryParams,
|
|
131
|
+
limits: model.limits,
|
|
132
|
+
generation: model.generation,
|
|
133
|
+
providerOptions: model.providerOptions,
|
|
134
|
+
http: model.http,
|
|
135
|
+
native: model.native
|
|
136
|
+
});
|
|
137
|
+
ModelRef2.update = (model, patch) => {
|
|
138
|
+
if (Object.keys(patch).length === 0) return model;
|
|
139
|
+
return new ModelRef2({
|
|
140
|
+
...(0, ModelRef2.input)(model),
|
|
141
|
+
...patch
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
})(ModelRef || (ModelRef = {}));
|
|
145
|
+
var CacheHint = class extends Schema.Class("LLM.CacheHint")({
|
|
146
|
+
type: Schema.Literals(["ephemeral", "persistent"]),
|
|
147
|
+
ttlSeconds: Schema.optional(Schema.Number)
|
|
148
|
+
}) {
|
|
149
|
+
};
|
|
150
|
+
var CachePolicyObject = Schema.Struct({
|
|
151
|
+
tools: Schema.optional(Schema.Boolean),
|
|
152
|
+
system: Schema.optional(Schema.Boolean),
|
|
153
|
+
messages: Schema.optional(
|
|
154
|
+
Schema.Union([
|
|
155
|
+
Schema.Literal("latest-user-message"),
|
|
156
|
+
Schema.Literal("latest-assistant"),
|
|
157
|
+
Schema.Struct({ tail: Schema.Number })
|
|
158
|
+
])
|
|
159
|
+
),
|
|
160
|
+
ttlSeconds: Schema.optional(Schema.Number)
|
|
161
|
+
});
|
|
162
|
+
var CachePolicy = Schema.Union([Schema.Literal("auto"), Schema.Literal("none"), CachePolicyObject]);
|
|
163
|
+
var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
164
|
+
var systemPartSchema = Schema.Struct({
|
|
165
|
+
type: Schema.Literal("text"),
|
|
166
|
+
text: Schema.String,
|
|
167
|
+
cache: Schema.optional(CacheHint),
|
|
168
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
169
|
+
}).annotate({ identifier: "LLM.SystemPart" });
|
|
170
|
+
var makeSystemPart = (text) => ({ type: "text", text });
|
|
171
|
+
var SystemPart = Object.assign(systemPartSchema, {
|
|
172
|
+
make: makeSystemPart,
|
|
173
|
+
content: (input) => {
|
|
174
|
+
if (input === void 0) return [];
|
|
175
|
+
return typeof input === "string" ? [makeSystemPart(input)] : Array.isArray(input) ? [...input] : [input];
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
var TextPart = Schema.Struct({
|
|
179
|
+
type: Schema.Literal("text"),
|
|
180
|
+
text: Schema.String,
|
|
181
|
+
cache: Schema.optional(CacheHint),
|
|
182
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
183
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
184
|
+
}).annotate({ identifier: "LLM.Content.Text" });
|
|
185
|
+
var MediaPart = Schema.Struct({
|
|
186
|
+
type: Schema.Literal("media"),
|
|
187
|
+
mediaType: Schema.String,
|
|
188
|
+
data: Schema.Union([Schema.String, Schema.Uint8Array]),
|
|
189
|
+
filename: Schema.optional(Schema.String),
|
|
190
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
191
|
+
}).annotate({ identifier: "LLM.Content.Media" });
|
|
192
|
+
var isToolResultValue = (value) => isRecord2(value) && (value.type === "text" || value.type === "json" || value.type === "error") && "value" in value;
|
|
193
|
+
var ToolResultValue = Object.assign(
|
|
194
|
+
Schema.Struct({
|
|
195
|
+
type: Schema.Literals(["json", "text", "error"]),
|
|
196
|
+
value: Schema.Unknown,
|
|
197
|
+
/** Optional structured payload (e.g. tool-interrupt metadata). */
|
|
198
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
199
|
+
}).annotate({ identifier: "LLM.ToolResult" }),
|
|
200
|
+
{
|
|
201
|
+
make: (value, type = "json", metadata) => {
|
|
202
|
+
if (isToolResultValue(value)) {
|
|
203
|
+
return metadata ? { ...value, metadata: { ...value.metadata ?? {}, ...metadata } } : value;
|
|
204
|
+
}
|
|
205
|
+
return metadata ? { type, value, metadata } : { type, value };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
);
|
|
209
|
+
var ToolCallPart = Object.assign(
|
|
210
|
+
Schema.Struct({
|
|
211
|
+
type: Schema.Literal("tool-call"),
|
|
212
|
+
id: Schema.String,
|
|
213
|
+
name: Schema.String,
|
|
214
|
+
input: Schema.Unknown,
|
|
215
|
+
providerExecuted: Schema.optional(Schema.Boolean),
|
|
216
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
217
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
218
|
+
}).annotate({ identifier: "LLM.Content.ToolCall" }),
|
|
219
|
+
{
|
|
220
|
+
make: (input) => ({ type: "tool-call", ...input })
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
var ToolResultPart = Object.assign(
|
|
224
|
+
Schema.Struct({
|
|
225
|
+
type: Schema.Literal("tool-result"),
|
|
226
|
+
id: Schema.String,
|
|
227
|
+
name: Schema.String,
|
|
228
|
+
result: ToolResultValue,
|
|
229
|
+
providerExecuted: Schema.optional(Schema.Boolean),
|
|
230
|
+
cache: Schema.optional(CacheHint),
|
|
231
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
232
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
233
|
+
}).annotate({ identifier: "LLM.Content.ToolResult" }),
|
|
234
|
+
{
|
|
235
|
+
make: (input) => ({
|
|
236
|
+
type: "tool-result",
|
|
237
|
+
id: input.id,
|
|
238
|
+
name: input.name,
|
|
239
|
+
result: ToolResultValue.make(input.result, input.resultType),
|
|
240
|
+
providerExecuted: input.providerExecuted,
|
|
241
|
+
cache: input.cache,
|
|
242
|
+
metadata: input.metadata,
|
|
243
|
+
providerMetadata: input.providerMetadata
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
);
|
|
247
|
+
var ReasoningPart = Schema.Struct({
|
|
248
|
+
type: Schema.Literal("reasoning"),
|
|
249
|
+
text: Schema.String,
|
|
250
|
+
encrypted: Schema.optional(Schema.String),
|
|
251
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
252
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
253
|
+
}).annotate({ identifier: "LLM.Content.Reasoning" });
|
|
254
|
+
var ContentPart = Schema.Union([TextPart, MediaPart, ToolCallPart, ToolResultPart, ReasoningPart]).pipe(
|
|
255
|
+
Schema.toTaggedUnion("type")
|
|
256
|
+
);
|
|
257
|
+
var Message = class extends Schema.Class("LLM.Message")({
|
|
258
|
+
id: Schema.optional(Schema.String),
|
|
259
|
+
role: MessageRole,
|
|
260
|
+
content: Schema.Array(ContentPart),
|
|
261
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
262
|
+
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
263
|
+
}) {
|
|
264
|
+
};
|
|
265
|
+
((Message2) => {
|
|
266
|
+
Message2.text = (value) => ({ type: "text", text: value });
|
|
267
|
+
Message2.content = (input) => typeof input === "string" ? [(0, Message2.text)(input)] : Array.isArray(input) ? [...input] : [input];
|
|
268
|
+
Message2.make = (input) => {
|
|
269
|
+
if (input instanceof Message2) return input;
|
|
270
|
+
return new Message2({ ...input, content: (0, Message2.content)(input.content) });
|
|
271
|
+
};
|
|
272
|
+
Message2.user = (content2) => (0, Message2.make)({ role: "user", content: content2 });
|
|
273
|
+
Message2.assistant = (content2) => (0, Message2.make)({ role: "assistant", content: content2 });
|
|
274
|
+
Message2.tool = (result) => (0, Message2.make)({ role: "tool", content: ["type" in result ? result : ToolResultPart.make(result)] });
|
|
275
|
+
})(Message || (Message = {}));
|
|
276
|
+
var ToolDefinition = class extends Schema.Class("LLM.ToolDefinition")({
|
|
277
|
+
name: Schema.String,
|
|
278
|
+
description: Schema.String,
|
|
279
|
+
inputSchema: JsonSchema,
|
|
280
|
+
cache: Schema.optional(CacheHint),
|
|
281
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
282
|
+
native: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
283
|
+
}) {
|
|
284
|
+
};
|
|
285
|
+
((ToolDefinition2) => {
|
|
286
|
+
ToolDefinition2.make = (input) => input instanceof ToolDefinition2 ? input : new ToolDefinition2(input);
|
|
287
|
+
})(ToolDefinition || (ToolDefinition = {}));
|
|
288
|
+
var ToolChoice = class extends Schema.Class("LLM.ToolChoice")({
|
|
289
|
+
type: Schema.Literals(["auto", "none", "required", "tool"]),
|
|
290
|
+
name: Schema.optional(Schema.String)
|
|
291
|
+
}) {
|
|
292
|
+
};
|
|
293
|
+
((ToolChoice2) => {
|
|
294
|
+
const isMode = (value) => value === "auto" || value === "none" || value === "required";
|
|
295
|
+
ToolChoice2.named = (value) => new ToolChoice2({ type: "tool", name: value });
|
|
296
|
+
ToolChoice2.make = (input) => {
|
|
297
|
+
if (input instanceof ToolChoice2) return input;
|
|
298
|
+
if (input instanceof ToolDefinition) return (0, ToolChoice2.named)(input.name);
|
|
299
|
+
if (typeof input === "string") return isMode(input) ? new ToolChoice2({ type: input }) : (0, ToolChoice2.named)(input);
|
|
300
|
+
return new ToolChoice2(input);
|
|
301
|
+
};
|
|
302
|
+
})(ToolChoice || (ToolChoice = {}));
|
|
303
|
+
var ResponseFormat = Schema.Union([
|
|
304
|
+
Schema.Struct({ type: Schema.Literal("text") }),
|
|
305
|
+
Schema.Struct({ type: Schema.Literal("json"), schema: JsonSchema }),
|
|
306
|
+
Schema.Struct({ type: Schema.Literal("tool"), tool: ToolDefinition })
|
|
307
|
+
]).pipe(Schema.toTaggedUnion("type"));
|
|
308
|
+
var LLMRequest = class extends Schema.Class("LLM.Request")({
|
|
309
|
+
id: Schema.optional(Schema.String),
|
|
310
|
+
model: ModelRef,
|
|
311
|
+
system: Schema.Array(SystemPart),
|
|
312
|
+
messages: Schema.Array(Message),
|
|
313
|
+
tools: Schema.Array(ToolDefinition),
|
|
314
|
+
toolChoice: Schema.optional(ToolChoice),
|
|
315
|
+
generation: Schema.optional(GenerationOptions),
|
|
316
|
+
providerOptions: Schema.optional(ProviderOptions),
|
|
317
|
+
http: Schema.optional(HttpOptions),
|
|
318
|
+
responseFormat: Schema.optional(ResponseFormat),
|
|
319
|
+
cache: Schema.optional(CachePolicy),
|
|
320
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
321
|
+
}) {
|
|
322
|
+
};
|
|
323
|
+
((LLMRequest2) => {
|
|
324
|
+
LLMRequest2.input = (request) => ({
|
|
325
|
+
id: request.id,
|
|
326
|
+
model: request.model,
|
|
327
|
+
system: request.system,
|
|
328
|
+
messages: request.messages,
|
|
329
|
+
tools: request.tools,
|
|
330
|
+
toolChoice: request.toolChoice,
|
|
331
|
+
generation: request.generation,
|
|
332
|
+
providerOptions: request.providerOptions,
|
|
333
|
+
http: request.http,
|
|
334
|
+
responseFormat: request.responseFormat,
|
|
335
|
+
cache: request.cache,
|
|
336
|
+
metadata: request.metadata
|
|
337
|
+
});
|
|
338
|
+
LLMRequest2.update = (request, patch) => {
|
|
339
|
+
if (Object.keys(patch).length === 0) return request;
|
|
340
|
+
return new LLMRequest2({
|
|
341
|
+
...(0, LLMRequest2.input)(request),
|
|
342
|
+
...patch,
|
|
343
|
+
model: patch.model ?? request.model
|
|
344
|
+
});
|
|
345
|
+
};
|
|
346
|
+
})(LLMRequest || (LLMRequest = {}));
|
|
347
|
+
var Usage = class extends Schema.Class("LLM.Usage")({
|
|
348
|
+
inputTokens: Schema.optional(Schema.Number),
|
|
349
|
+
outputTokens: Schema.optional(Schema.Number),
|
|
350
|
+
nonCachedInputTokens: Schema.optional(Schema.Number),
|
|
351
|
+
cacheReadInputTokens: Schema.optional(Schema.Number),
|
|
352
|
+
cacheWriteInputTokens: Schema.optional(Schema.Number),
|
|
353
|
+
reasoningTokens: Schema.optional(Schema.Number),
|
|
354
|
+
totalTokens: Schema.optional(Schema.Number),
|
|
355
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
356
|
+
}) {
|
|
357
|
+
/**
|
|
358
|
+
* Visible output tokens — `outputTokens` minus `reasoningTokens`, clamped
|
|
359
|
+
* to zero. The one place subtraction happens in this contract; the clamp
|
|
360
|
+
* means a provider reporting `reasoningTokens > outputTokens` produces a
|
|
361
|
+
* harmless zero rather than a negative that crashes downstream schemas.
|
|
362
|
+
*/
|
|
363
|
+
get visibleOutputTokens() {
|
|
364
|
+
return Math.max(0, (this.outputTokens ?? 0) - (this.reasoningTokens ?? 0));
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var RequestStart = Schema.Struct({
|
|
368
|
+
type: Schema.tag("request-start"),
|
|
369
|
+
id: ResponseID,
|
|
370
|
+
model: ModelRef
|
|
371
|
+
}).annotate({ identifier: "LLM.Event.RequestStart" });
|
|
372
|
+
var StepStart = Schema.Struct({
|
|
373
|
+
type: Schema.tag("step-start"),
|
|
374
|
+
index: Schema.Number
|
|
375
|
+
}).annotate({ identifier: "LLM.Event.StepStart" });
|
|
376
|
+
var TextStart = Schema.Struct({
|
|
377
|
+
type: Schema.tag("text-start"),
|
|
378
|
+
id: ContentBlockID,
|
|
379
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
380
|
+
}).annotate({ identifier: "LLM.Event.TextStart" });
|
|
381
|
+
var TextDelta = Schema.Struct({
|
|
382
|
+
type: Schema.tag("text-delta"),
|
|
383
|
+
id: ContentBlockID,
|
|
384
|
+
text: Schema.String
|
|
385
|
+
}).annotate({ identifier: "LLM.Event.TextDelta" });
|
|
386
|
+
var TextEnd = Schema.Struct({
|
|
387
|
+
type: Schema.tag("text-end"),
|
|
388
|
+
id: ContentBlockID,
|
|
389
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
390
|
+
}).annotate({ identifier: "LLM.Event.TextEnd" });
|
|
391
|
+
var ReasoningStart = Schema.Struct({
|
|
392
|
+
type: Schema.tag("reasoning-start"),
|
|
393
|
+
id: ContentBlockID,
|
|
394
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
395
|
+
}).annotate({ identifier: "LLM.Event.ReasoningStart" });
|
|
396
|
+
var ReasoningDelta = Schema.Struct({
|
|
397
|
+
type: Schema.tag("reasoning-delta"),
|
|
398
|
+
id: ContentBlockID,
|
|
399
|
+
text: Schema.String
|
|
400
|
+
}).annotate({ identifier: "LLM.Event.ReasoningDelta" });
|
|
401
|
+
var ReasoningEnd = Schema.Struct({
|
|
402
|
+
type: Schema.tag("reasoning-end"),
|
|
403
|
+
id: ContentBlockID,
|
|
404
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
405
|
+
}).annotate({ identifier: "LLM.Event.ReasoningEnd" });
|
|
406
|
+
var ToolInputStart = Schema.Struct({
|
|
407
|
+
type: Schema.tag("tool-input-start"),
|
|
408
|
+
id: ToolCallID,
|
|
409
|
+
name: Schema.String,
|
|
410
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
411
|
+
}).annotate({ identifier: "LLM.Event.ToolInputStart" });
|
|
412
|
+
var ToolInputDelta = Schema.Struct({
|
|
413
|
+
type: Schema.tag("tool-input-delta"),
|
|
414
|
+
id: ToolCallID,
|
|
415
|
+
name: Schema.String,
|
|
416
|
+
text: Schema.String
|
|
417
|
+
}).annotate({ identifier: "LLM.Event.ToolInputDelta" });
|
|
418
|
+
var ToolInputEnd = Schema.Struct({
|
|
419
|
+
type: Schema.tag("tool-input-end"),
|
|
420
|
+
id: ToolCallID,
|
|
421
|
+
name: Schema.String,
|
|
422
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
423
|
+
}).annotate({ identifier: "LLM.Event.ToolInputEnd" });
|
|
424
|
+
var ToolCall = Schema.Struct({
|
|
425
|
+
type: Schema.tag("tool-call"),
|
|
426
|
+
id: ToolCallID,
|
|
427
|
+
name: Schema.String,
|
|
428
|
+
input: Schema.Unknown,
|
|
429
|
+
providerExecuted: Schema.optional(Schema.Boolean),
|
|
430
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
431
|
+
}).annotate({ identifier: "LLM.Event.ToolCall" });
|
|
432
|
+
var ToolResult = Schema.Struct({
|
|
433
|
+
type: Schema.tag("tool-result"),
|
|
434
|
+
id: ToolCallID,
|
|
435
|
+
name: Schema.String,
|
|
436
|
+
result: ToolResultValue,
|
|
437
|
+
providerExecuted: Schema.optional(Schema.Boolean),
|
|
438
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
439
|
+
}).annotate({ identifier: "LLM.Event.ToolResult" });
|
|
440
|
+
var ToolError = Schema.Struct({
|
|
441
|
+
type: Schema.tag("tool-error"),
|
|
442
|
+
id: ToolCallID,
|
|
443
|
+
name: Schema.String,
|
|
444
|
+
message: Schema.String,
|
|
445
|
+
/** Optional structured payload (e.g. tool-interrupt metadata for approval). */
|
|
446
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown)),
|
|
447
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
448
|
+
}).annotate({ identifier: "LLM.Event.ToolError" });
|
|
449
|
+
var StepFinish = Schema.Struct({
|
|
450
|
+
type: Schema.tag("step-finish"),
|
|
451
|
+
index: Schema.Number,
|
|
452
|
+
reason: FinishReason,
|
|
453
|
+
usage: Schema.optional(Usage),
|
|
454
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
455
|
+
}).annotate({ identifier: "LLM.Event.StepFinish" });
|
|
456
|
+
var RequestFinish = Schema.Struct({
|
|
457
|
+
type: Schema.tag("request-finish"),
|
|
458
|
+
reason: FinishReason,
|
|
459
|
+
usage: Schema.optional(Usage),
|
|
460
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
461
|
+
}).annotate({ identifier: "LLM.Event.RequestFinish" });
|
|
462
|
+
var ProviderErrorEvent = Schema.Struct({
|
|
463
|
+
type: Schema.tag("provider-error"),
|
|
464
|
+
message: Schema.String,
|
|
465
|
+
retryable: Schema.optional(Schema.Boolean),
|
|
466
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
467
|
+
}).annotate({ identifier: "LLM.Event.ProviderError" });
|
|
468
|
+
var llmEventTagged = Schema.Union([
|
|
469
|
+
RequestStart,
|
|
470
|
+
StepStart,
|
|
471
|
+
TextStart,
|
|
472
|
+
TextDelta,
|
|
473
|
+
TextEnd,
|
|
474
|
+
ReasoningStart,
|
|
475
|
+
ReasoningDelta,
|
|
476
|
+
ReasoningEnd,
|
|
477
|
+
ToolInputStart,
|
|
478
|
+
ToolInputDelta,
|
|
479
|
+
ToolInputEnd,
|
|
480
|
+
ToolCall,
|
|
481
|
+
ToolResult,
|
|
482
|
+
ToolError,
|
|
483
|
+
StepFinish,
|
|
484
|
+
RequestFinish,
|
|
485
|
+
ProviderErrorEvent
|
|
486
|
+
]).pipe(Schema.toTaggedUnion("type"));
|
|
487
|
+
var responseID = (value) => ResponseID.make(value);
|
|
488
|
+
var contentBlockID = (value) => ContentBlockID.make(value);
|
|
489
|
+
var toolCallID = (value) => ToolCallID.make(value);
|
|
490
|
+
var LLMEvent = Object.assign(llmEventTagged, {
|
|
491
|
+
requestStart: (input) => RequestStart.make({ ...input, id: responseID(input.id) }),
|
|
492
|
+
stepStart: StepStart.make,
|
|
493
|
+
textStart: (input) => TextStart.make({ ...input, id: contentBlockID(input.id) }),
|
|
494
|
+
textDelta: (input) => TextDelta.make({ ...input, id: contentBlockID(input.id) }),
|
|
495
|
+
textEnd: (input) => TextEnd.make({ ...input, id: contentBlockID(input.id) }),
|
|
496
|
+
reasoningStart: (input) => ReasoningStart.make({ ...input, id: contentBlockID(input.id) }),
|
|
497
|
+
reasoningDelta: (input) => ReasoningDelta.make({ ...input, id: contentBlockID(input.id) }),
|
|
498
|
+
reasoningEnd: (input) => ReasoningEnd.make({ ...input, id: contentBlockID(input.id) }),
|
|
499
|
+
toolInputStart: (input) => ToolInputStart.make({ ...input, id: toolCallID(input.id) }),
|
|
500
|
+
toolInputDelta: (input) => ToolInputDelta.make({ ...input, id: toolCallID(input.id) }),
|
|
501
|
+
toolInputEnd: (input) => ToolInputEnd.make({ ...input, id: toolCallID(input.id) }),
|
|
502
|
+
toolCall: (input) => ToolCall.make({ ...input, id: toolCallID(input.id) }),
|
|
503
|
+
toolResult: (input) => ToolResult.make({ ...input, id: toolCallID(input.id) }),
|
|
504
|
+
toolError: (input) => ToolError.make({ ...input, id: toolCallID(input.id) }),
|
|
505
|
+
stepFinish: StepFinish.make,
|
|
506
|
+
requestFinish: RequestFinish.make,
|
|
507
|
+
providerError: ProviderErrorEvent.make,
|
|
508
|
+
is: {
|
|
509
|
+
requestStart: llmEventTagged.guards["request-start"],
|
|
510
|
+
stepStart: llmEventTagged.guards["step-start"],
|
|
511
|
+
textStart: llmEventTagged.guards["text-start"],
|
|
512
|
+
textDelta: llmEventTagged.guards["text-delta"],
|
|
513
|
+
textEnd: llmEventTagged.guards["text-end"],
|
|
514
|
+
reasoningStart: llmEventTagged.guards["reasoning-start"],
|
|
515
|
+
reasoningDelta: llmEventTagged.guards["reasoning-delta"],
|
|
516
|
+
reasoningEnd: llmEventTagged.guards["reasoning-end"],
|
|
517
|
+
toolInputStart: llmEventTagged.guards["tool-input-start"],
|
|
518
|
+
toolInputDelta: llmEventTagged.guards["tool-input-delta"],
|
|
519
|
+
toolInputEnd: llmEventTagged.guards["tool-input-end"],
|
|
520
|
+
toolCall: llmEventTagged.guards["tool-call"],
|
|
521
|
+
toolResult: llmEventTagged.guards["tool-result"],
|
|
522
|
+
toolError: llmEventTagged.guards["tool-error"],
|
|
523
|
+
stepFinish: llmEventTagged.guards["step-finish"],
|
|
524
|
+
requestFinish: llmEventTagged.guards["request-finish"],
|
|
525
|
+
providerError: llmEventTagged.guards["provider-error"]
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
(class extends Schema.Class("LLM.PreparedRequest")({
|
|
529
|
+
id: Schema.String,
|
|
530
|
+
route: RouteID,
|
|
531
|
+
protocol: ProtocolID,
|
|
532
|
+
model: ModelRef,
|
|
533
|
+
body: Schema.Unknown,
|
|
534
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
535
|
+
}) {
|
|
536
|
+
});
|
|
537
|
+
var responseText = (events) => events.filter(LLMEvent.is.textDelta).map((event) => event.text).join("");
|
|
538
|
+
var responseReasoning = (events) => events.filter(LLMEvent.is.reasoningDelta).map((event) => event.text).join("");
|
|
539
|
+
var responseUsage = (events) => events.reduce(
|
|
540
|
+
(usage, event) => "usage" in event && event.usage !== void 0 ? event.usage : usage,
|
|
541
|
+
void 0
|
|
542
|
+
);
|
|
543
|
+
var LLMResponse = class extends Schema.Class("LLM.Response")({
|
|
544
|
+
events: Schema.Array(LLMEvent),
|
|
545
|
+
usage: Schema.optional(Usage)
|
|
546
|
+
}) {
|
|
547
|
+
/** Concatenated assistant text assembled from streamed `text-delta` events. */
|
|
548
|
+
get text() {
|
|
549
|
+
return responseText(this.events);
|
|
550
|
+
}
|
|
551
|
+
/** Concatenated reasoning text assembled from streamed `reasoning-delta` events. */
|
|
552
|
+
get reasoning() {
|
|
553
|
+
return responseReasoning(this.events);
|
|
554
|
+
}
|
|
555
|
+
/** Completed tool calls emitted by the provider. */
|
|
556
|
+
get toolCalls() {
|
|
557
|
+
return this.events.filter(LLMEvent.is.toolCall);
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
((LLMResponse2) => {
|
|
561
|
+
LLMResponse2.text = (response) => responseText(response.events);
|
|
562
|
+
LLMResponse2.usage = (response) => response.usage ?? responseUsage(response.events);
|
|
563
|
+
LLMResponse2.toolCalls = (response) => response.events.filter(LLMEvent.is.toolCall);
|
|
564
|
+
LLMResponse2.reasoning = (response) => responseReasoning(response.events);
|
|
565
|
+
})(LLMResponse || (LLMResponse = {}));
|
|
566
|
+
var HttpRequestDetails = class extends Schema.Class("LLM.HttpRequestDetails")({
|
|
567
|
+
method: Schema.String,
|
|
568
|
+
url: Schema.String,
|
|
569
|
+
headers: Schema.Record(Schema.String, Schema.String)
|
|
570
|
+
}) {
|
|
571
|
+
};
|
|
572
|
+
var HttpResponseDetails = class extends Schema.Class("LLM.HttpResponseDetails")({
|
|
573
|
+
status: Schema.Number,
|
|
574
|
+
headers: Schema.Record(Schema.String, Schema.String)
|
|
575
|
+
}) {
|
|
576
|
+
};
|
|
577
|
+
var HttpRateLimitDetails = class extends Schema.Class("LLM.HttpRateLimitDetails")({
|
|
578
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
579
|
+
limit: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
580
|
+
remaining: Schema.optional(Schema.Record(Schema.String, Schema.String)),
|
|
581
|
+
reset: Schema.optional(Schema.Record(Schema.String, Schema.String))
|
|
582
|
+
}) {
|
|
583
|
+
};
|
|
584
|
+
var HttpContext = class extends Schema.Class("LLM.HttpContext")({
|
|
585
|
+
request: HttpRequestDetails,
|
|
586
|
+
response: Schema.optional(HttpResponseDetails),
|
|
587
|
+
body: Schema.optional(Schema.String),
|
|
588
|
+
bodyTruncated: Schema.optional(Schema.Boolean),
|
|
589
|
+
requestId: Schema.optional(Schema.String),
|
|
590
|
+
rateLimit: Schema.optional(HttpRateLimitDetails)
|
|
591
|
+
}) {
|
|
592
|
+
};
|
|
593
|
+
var InvalidRequestReason = class extends Schema.Class("LLM.Error.InvalidRequest")({
|
|
594
|
+
_tag: Schema.tag("InvalidRequest"),
|
|
595
|
+
message: Schema.String,
|
|
596
|
+
parameter: Schema.optional(Schema.String),
|
|
597
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
598
|
+
http: Schema.optional(HttpContext)
|
|
599
|
+
}) {
|
|
600
|
+
get retryable() {
|
|
601
|
+
return false;
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
var ContextOverflowReason = class extends Schema.Class("LLM.Error.ContextOverflow")({
|
|
605
|
+
_tag: Schema.tag("ContextOverflow"),
|
|
606
|
+
message: Schema.String,
|
|
607
|
+
/** Provider-reported prompt token count when present in the error body. */
|
|
608
|
+
promptTokens: Schema.optional(Schema.Number),
|
|
609
|
+
/** Provider-reported context window size when present in the error body. */
|
|
610
|
+
contextWindow: Schema.optional(Schema.Number),
|
|
611
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
612
|
+
http: Schema.optional(HttpContext)
|
|
613
|
+
}) {
|
|
614
|
+
get retryable() {
|
|
615
|
+
return false;
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
var NoRouteReason = class extends Schema.Class("LLM.Error.NoRoute")({
|
|
619
|
+
_tag: Schema.tag("NoRoute"),
|
|
620
|
+
route: RouteID,
|
|
621
|
+
provider: ProviderID,
|
|
622
|
+
model: ModelID
|
|
623
|
+
}) {
|
|
624
|
+
get retryable() {
|
|
625
|
+
return false;
|
|
626
|
+
}
|
|
627
|
+
get message() {
|
|
628
|
+
return `No LLM route for ${this.provider}/${this.model} using ${this.route}`;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
var AuthenticationReason = class extends Schema.Class("LLM.Error.Authentication")({
|
|
632
|
+
_tag: Schema.tag("Authentication"),
|
|
633
|
+
message: Schema.String,
|
|
634
|
+
kind: Schema.Literals(["missing", "invalid", "expired", "insufficient-permissions", "unknown"]),
|
|
635
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
636
|
+
http: Schema.optional(HttpContext)
|
|
637
|
+
}) {
|
|
638
|
+
get retryable() {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
};
|
|
642
|
+
var RateLimitReason = class extends Schema.Class("LLM.Error.RateLimit")({
|
|
643
|
+
_tag: Schema.tag("RateLimit"),
|
|
644
|
+
message: Schema.String,
|
|
645
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
646
|
+
rateLimit: Schema.optional(HttpRateLimitDetails),
|
|
647
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
648
|
+
http: Schema.optional(HttpContext)
|
|
649
|
+
}) {
|
|
650
|
+
get retryable() {
|
|
651
|
+
return true;
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
var QuotaExceededReason = class extends Schema.Class("LLM.Error.QuotaExceeded")({
|
|
655
|
+
_tag: Schema.tag("QuotaExceeded"),
|
|
656
|
+
message: Schema.String,
|
|
657
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
658
|
+
http: Schema.optional(HttpContext)
|
|
659
|
+
}) {
|
|
660
|
+
get retryable() {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
var ContentPolicyReason = class extends Schema.Class("LLM.Error.ContentPolicy")({
|
|
665
|
+
_tag: Schema.tag("ContentPolicy"),
|
|
666
|
+
message: Schema.String,
|
|
667
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
668
|
+
http: Schema.optional(HttpContext)
|
|
669
|
+
}) {
|
|
670
|
+
get retryable() {
|
|
671
|
+
return false;
|
|
672
|
+
}
|
|
673
|
+
};
|
|
674
|
+
var ProviderInternalReason = class extends Schema.Class("LLM.Error.ProviderInternal")({
|
|
675
|
+
_tag: Schema.tag("ProviderInternal"),
|
|
676
|
+
message: Schema.String,
|
|
677
|
+
status: Schema.Number,
|
|
678
|
+
retryAfterMs: Schema.optional(Schema.Number),
|
|
679
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
680
|
+
http: Schema.optional(HttpContext)
|
|
681
|
+
}) {
|
|
682
|
+
get retryable() {
|
|
683
|
+
return true;
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
var TransportReason = class extends Schema.Class("LLM.Error.Transport")({
|
|
687
|
+
_tag: Schema.tag("Transport"),
|
|
688
|
+
message: Schema.String,
|
|
689
|
+
kind: Schema.optional(Schema.String),
|
|
690
|
+
url: Schema.optional(Schema.String),
|
|
691
|
+
http: Schema.optional(HttpContext)
|
|
692
|
+
}) {
|
|
693
|
+
get retryable() {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var InvalidProviderOutputReason = class extends Schema.Class(
|
|
698
|
+
"LLM.Error.InvalidProviderOutput"
|
|
699
|
+
)({
|
|
700
|
+
_tag: Schema.tag("InvalidProviderOutput"),
|
|
701
|
+
message: Schema.String,
|
|
702
|
+
route: Schema.optional(Schema.String),
|
|
703
|
+
raw: Schema.optional(Schema.String),
|
|
704
|
+
providerMetadata: Schema.optional(ProviderMetadata)
|
|
705
|
+
}) {
|
|
706
|
+
get retryable() {
|
|
707
|
+
return false;
|
|
708
|
+
}
|
|
709
|
+
};
|
|
710
|
+
var UnknownProviderReason = class extends Schema.Class("LLM.Error.UnknownProvider")({
|
|
711
|
+
_tag: Schema.tag("UnknownProvider"),
|
|
712
|
+
message: Schema.String,
|
|
713
|
+
status: Schema.optional(Schema.Number),
|
|
714
|
+
providerMetadata: Schema.optional(ProviderMetadata),
|
|
715
|
+
http: Schema.optional(HttpContext)
|
|
716
|
+
}) {
|
|
717
|
+
get retryable() {
|
|
718
|
+
return false;
|
|
719
|
+
}
|
|
720
|
+
};
|
|
721
|
+
var LLMErrorReason = Schema.Union([
|
|
722
|
+
InvalidRequestReason,
|
|
723
|
+
ContextOverflowReason,
|
|
724
|
+
NoRouteReason,
|
|
725
|
+
AuthenticationReason,
|
|
726
|
+
RateLimitReason,
|
|
727
|
+
QuotaExceededReason,
|
|
728
|
+
ContentPolicyReason,
|
|
729
|
+
ProviderInternalReason,
|
|
730
|
+
TransportReason,
|
|
731
|
+
InvalidProviderOutputReason,
|
|
732
|
+
UnknownProviderReason
|
|
733
|
+
]).pipe(Schema.toTaggedUnion("_tag"));
|
|
734
|
+
(class extends Schema.TaggedErrorClass()("LLM.Error", {
|
|
735
|
+
module: Schema.String,
|
|
736
|
+
method: Schema.String,
|
|
737
|
+
reason: LLMErrorReason
|
|
738
|
+
}) {
|
|
739
|
+
cause = this.reason;
|
|
740
|
+
get retryable() {
|
|
741
|
+
return this.reason.retryable;
|
|
742
|
+
}
|
|
743
|
+
get retryAfterMs() {
|
|
744
|
+
return "retryAfterMs" in this.reason ? this.reason.retryAfterMs : void 0;
|
|
745
|
+
}
|
|
746
|
+
get message() {
|
|
747
|
+
return `${this.module}.${this.method}: ${this.reason.message}`;
|
|
748
|
+
}
|
|
749
|
+
});
|
|
750
|
+
(class extends Schema.TaggedErrorClass()("LLM.ToolFailure", {
|
|
751
|
+
message: Schema.String,
|
|
752
|
+
metadata: Schema.optional(Schema.Record(Schema.String, Schema.Unknown))
|
|
753
|
+
}) {
|
|
754
|
+
});
|
|
755
|
+
|
|
756
|
+
// src/providers/openai-options.ts
|
|
757
|
+
var definedEntries = (input) => Object.entries(input).filter((entry) => entry[1] !== void 0);
|
|
758
|
+
var openAIProviderOptions = (options) => {
|
|
759
|
+
const openai = Object.fromEntries(
|
|
760
|
+
definedEntries({
|
|
761
|
+
store: options?.store,
|
|
762
|
+
promptCacheKey: options?.promptCacheKey,
|
|
763
|
+
reasoningEffort: options?.reasoningEffort,
|
|
764
|
+
reasoningSummary: options?.reasoningSummary,
|
|
765
|
+
includeEncryptedReasoning: options?.includeEncryptedReasoning,
|
|
766
|
+
textVerbosity: options?.textVerbosity
|
|
767
|
+
})
|
|
768
|
+
);
|
|
769
|
+
if (Object.keys(openai).length === 0) return void 0;
|
|
770
|
+
return { openai };
|
|
771
|
+
};
|
|
772
|
+
var gpt5DefaultOptions = (modelID, options = {}) => {
|
|
773
|
+
const id = modelID.toLowerCase();
|
|
774
|
+
if (!id.includes("gpt-5") || id.includes("gpt-5-chat") || id.includes("gpt-5-pro")) return void 0;
|
|
775
|
+
return openAIProviderOptions({
|
|
776
|
+
reasoningEffort: "medium",
|
|
777
|
+
reasoningSummary: "auto",
|
|
778
|
+
textVerbosity: options.textVerbosity === true && id.includes("gpt-5.") && !id.includes("codex") && !id.includes("-chat") ? "low" : void 0
|
|
779
|
+
});
|
|
780
|
+
};
|
|
781
|
+
var openAIDefaultOptions = (modelID, options = {}) => mergeProviderOptions(openAIProviderOptions({ store: false }), gpt5DefaultOptions(modelID, options));
|
|
782
|
+
var withOpenAIOptions = (modelID, options, defaults = {}) => {
|
|
783
|
+
return {
|
|
784
|
+
...options,
|
|
785
|
+
id: modelID,
|
|
786
|
+
providerOptions: mergeProviderOptions(openAIDefaultOptions(modelID, defaults), options.providerOptions)
|
|
787
|
+
};
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
export { openai_options_exports as OpenAIProviderOptions, gpt5DefaultOptions, openAIDefaultOptions, withOpenAIOptions };
|
|
791
|
+
//# sourceMappingURL=openai-options.js.map
|
|
792
|
+
//# sourceMappingURL=openai-options.js.map
|