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