@yolk-sdk/agent 0.1.0-canary.111 → 0.1.0-canary.112
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/README.md +7 -1
- package/dist/client/state.d.mts +63 -63
- package/dist/client/state.d.mts.map +1 -1
- package/dist/providers/openai/provider.d.mts +18 -1
- package/dist/providers/openai/provider.d.mts.map +1 -1
- package/dist/providers/openai/provider.mjs +112 -38
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/opencode/conformance/cases.d.mts +2 -2
- package/dist/providers/opencode/conformance/cases.mjs +6 -6
- package/dist/providers/opencode/conformance/cases.mjs.map +1 -1
- package/dist/providers/opencode/conformance/chat-plain-text.mjs +2 -2
- package/dist/providers/opencode/conformance/chat-plain-text.mjs.map +1 -1
- package/dist/providers/opencode/conformance/messages-plain-text.mjs +2 -2
- package/dist/providers/opencode/conformance/messages-plain-text.mjs.map +1 -1
- package/dist/providers/opencode/conformance/responses-commentary-replay.mjs +2 -2
- package/dist/providers/opencode/conformance/responses-commentary-replay.mjs.map +1 -1
- package/dist/providers/opencode/conformance/responses-plain-text.mjs +2 -2
- package/dist/providers/opencode/conformance/responses-plain-text.mjs.map +1 -1
- package/dist/providers/opencode/conformance/usage-snapshot.d.mts +1 -1
- package/dist/providers/opencode/conformance/usage-snapshot.mjs +3 -3
- package/dist/providers/opencode/conformance/usage-snapshot.mjs.map +1 -1
- package/dist/providers/opencode/go-provider.d.mts +1 -1
- package/dist/providers/opencode/go-provider.d.mts.map +1 -1
- package/dist/providers/opencode/go-provider.mjs +43 -5
- package/dist/providers/opencode/go-provider.mjs.map +1 -1
- package/dist/providers/opencode/usage.d.mts +1 -1
- package/dist/providers/opencode/usage.mjs +2 -2
- package/dist/providers/opencode/usage.mjs.map +1 -1
- package/dist/react/chat-actions.d.mts +45 -45
- package/dist/react/chat-actions.d.mts.map +1 -1
- package/dist/react/chat-items.d.mts +57 -57
- package/dist/react/chat-items.d.mts.map +1 -1
- package/dist/react/chat-messages.d.mts +73 -73
- package/dist/react/chat-messages.d.mts.map +1 -1
- package/package.json +2 -2
- package/src/providers/openai/provider.ts +158 -66
- package/src/providers/opencode/conformance/cases.ts +6 -6
- package/src/providers/opencode/conformance/chat-plain-text.ts +2 -2
- package/src/providers/opencode/conformance/messages-plain-text.ts +2 -2
- package/src/providers/opencode/conformance/responses-commentary-replay.ts +2 -2
- package/src/providers/opencode/conformance/responses-plain-text.ts +2 -2
- package/src/providers/opencode/conformance/usage-snapshot.ts +3 -3
- package/src/providers/opencode/go-provider.ts +92 -5
- package/src/providers/opencode/usage.ts +1 -1
package/README.md
CHANGED
|
@@ -233,13 +233,19 @@ const GoLayer = makeOpenCodeGoProviderLayer({
|
|
|
233
233
|
}).pipe(Layer.provide(FetchHttpClient.layer))
|
|
234
234
|
```
|
|
235
235
|
|
|
236
|
-
The default base URL is `https://opencode.ai/
|
|
236
|
+
The default base URL is `https://opencode.ai/inference/go/v1`. Chat streams SSE (the Go adapter sets
|
|
237
237
|
`streaming: true`) with Bearer auth; Messages uses SSE and `x-api-key`; Responses uses SSE and Bearer
|
|
238
238
|
auth. All normalize to `LLMEvent`s.
|
|
239
239
|
Messages retains native tool names and system instructions, without Claude OAuth fingerprinting.
|
|
240
240
|
Responses sends `max_output_tokens`, unlike Codex. Go requires a nonempty key and positive safe-integer
|
|
241
241
|
limit at layer construction. `extraHeaders` cannot override required protocol headers, regardless of
|
|
242
242
|
case. Only override `baseUrl` with a trusted proxy because it receives the credential.
|
|
243
|
+
A chat parser rejection (for example a stream payload that is not JSON), a chat response that is not
|
|
244
|
+
SSE, or a chat or Responses stream ending before its terminal event is retried once, before any
|
|
245
|
+
event, under `<session>.reroute` so Go routes it to another upstream. The session is the request
|
|
246
|
+
`cacheKey`, else the `x-opencode-session` extra header; without either the request is resent
|
|
247
|
+
unchanged. Messages failures are not re-routed. Errors carrying provider metadata read
|
|
248
|
+
`OpenCode Go <cause>`, with the failed check in `provider.providerCode`.
|
|
243
249
|
|
|
244
250
|
Request `reasoningEffort` becomes chat `reasoning_effort`, Messages `output_config.effort` (omitting
|
|
245
251
|
`minimal`), or Responses `reasoning.effort` with `summary: 'auto'`. `reasoningSummary` changes the
|
package/dist/client/state.d.mts
CHANGED
|
@@ -80,26 +80,6 @@ type AgentToolRun = {
|
|
|
80
80
|
readonly result: ToolResult;
|
|
81
81
|
};
|
|
82
82
|
declare const AgentToolRun: {
|
|
83
|
-
readonly InputStreaming: Data.TaggedEnum.ConstructorFrom<{
|
|
84
|
-
readonly _tag: "InputStreaming";
|
|
85
|
-
readonly id: string;
|
|
86
|
-
readonly name?: string;
|
|
87
|
-
readonly input: string;
|
|
88
|
-
}, "_tag">;
|
|
89
|
-
readonly InputReady: Data.TaggedEnum.ConstructorFrom<{
|
|
90
|
-
readonly _tag: "InputReady";
|
|
91
|
-
readonly call: ToolCall;
|
|
92
|
-
}, "_tag">;
|
|
93
|
-
readonly ApprovalRequested: Data.TaggedEnum.ConstructorFrom<{
|
|
94
|
-
readonly _tag: "ApprovalRequested";
|
|
95
|
-
readonly call: ToolCall;
|
|
96
|
-
readonly request?: ToolApprovalRequest;
|
|
97
|
-
}, "_tag">;
|
|
98
|
-
readonly Denied: Data.TaggedEnum.ConstructorFrom<{
|
|
99
|
-
readonly _tag: "Denied";
|
|
100
|
-
readonly toolCallId: string;
|
|
101
|
-
readonly reason: string;
|
|
102
|
-
}, "_tag">;
|
|
103
83
|
readonly QuestionRequested: Data.TaggedEnum.ConstructorFrom<{
|
|
104
84
|
readonly _tag: "QuestionRequested";
|
|
105
85
|
readonly request: QuestionRequest;
|
|
@@ -142,6 +122,26 @@ declare const AgentToolRun: {
|
|
|
142
122
|
readonly response: InteractionResponse;
|
|
143
123
|
readonly request?: InteractionRequest;
|
|
144
124
|
}, "_tag">;
|
|
125
|
+
readonly InputStreaming: Data.TaggedEnum.ConstructorFrom<{
|
|
126
|
+
readonly _tag: "InputStreaming";
|
|
127
|
+
readonly id: string;
|
|
128
|
+
readonly name?: string;
|
|
129
|
+
readonly input: string;
|
|
130
|
+
}, "_tag">;
|
|
131
|
+
readonly InputReady: Data.TaggedEnum.ConstructorFrom<{
|
|
132
|
+
readonly _tag: "InputReady";
|
|
133
|
+
readonly call: ToolCall;
|
|
134
|
+
}, "_tag">;
|
|
135
|
+
readonly ApprovalRequested: Data.TaggedEnum.ConstructorFrom<{
|
|
136
|
+
readonly _tag: "ApprovalRequested";
|
|
137
|
+
readonly call: ToolCall;
|
|
138
|
+
readonly request?: ToolApprovalRequest;
|
|
139
|
+
}, "_tag">;
|
|
140
|
+
readonly Denied: Data.TaggedEnum.ConstructorFrom<{
|
|
141
|
+
readonly _tag: "Denied";
|
|
142
|
+
readonly toolCallId: string;
|
|
143
|
+
readonly reason: string;
|
|
144
|
+
}, "_tag">;
|
|
145
145
|
readonly Executing: Data.TaggedEnum.ConstructorFrom<{
|
|
146
146
|
readonly _tag: "Executing";
|
|
147
147
|
readonly call: ToolCall;
|
|
@@ -173,7 +173,7 @@ declare const AgentToolRun: {
|
|
|
173
173
|
readonly call: ToolCall;
|
|
174
174
|
readonly result: ToolResult;
|
|
175
175
|
}, "_tag">;
|
|
176
|
-
readonly $is: <Tag extends "
|
|
176
|
+
readonly $is: <Tag extends "QuestionRequested" | "QuestionAnswered" | "QuestionCancelled" | "InputRequested" | "InputSubmitted" | "InputCancelled" | "InteractionRequested" | "InteractionSubmitted" | "InteractionCancelled" | "InputStreaming" | "InputReady" | "ApprovalRequested" | "Denied" | "Executing" | "Completed" | "Accepted" | "Errored" | "ProviderCompleted">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
177
177
|
readonly _tag: "InputStreaming";
|
|
178
178
|
readonly id: string;
|
|
179
179
|
readonly name?: string;
|
|
@@ -287,26 +287,6 @@ declare const AgentToolRun: {
|
|
|
287
287
|
}>;
|
|
288
288
|
readonly $match: {
|
|
289
289
|
<Cases extends {
|
|
290
|
-
readonly InputStreaming: (args: {
|
|
291
|
-
readonly _tag: "InputStreaming";
|
|
292
|
-
readonly id: string;
|
|
293
|
-
readonly name?: string;
|
|
294
|
-
readonly input: string;
|
|
295
|
-
}) => any;
|
|
296
|
-
readonly InputReady: (args: {
|
|
297
|
-
readonly _tag: "InputReady";
|
|
298
|
-
readonly call: ToolCall;
|
|
299
|
-
}) => any;
|
|
300
|
-
readonly ApprovalRequested: (args: {
|
|
301
|
-
readonly _tag: "ApprovalRequested";
|
|
302
|
-
readonly call: ToolCall;
|
|
303
|
-
readonly request?: ToolApprovalRequest;
|
|
304
|
-
}) => any;
|
|
305
|
-
readonly Denied: (args: {
|
|
306
|
-
readonly _tag: "Denied";
|
|
307
|
-
readonly toolCallId: string;
|
|
308
|
-
readonly reason: string;
|
|
309
|
-
}) => any;
|
|
310
290
|
readonly QuestionRequested: (args: {
|
|
311
291
|
readonly _tag: "QuestionRequested";
|
|
312
292
|
readonly request: QuestionRequest;
|
|
@@ -349,6 +329,26 @@ declare const AgentToolRun: {
|
|
|
349
329
|
readonly response: InteractionResponse;
|
|
350
330
|
readonly request?: InteractionRequest;
|
|
351
331
|
}) => any;
|
|
332
|
+
readonly InputStreaming: (args: {
|
|
333
|
+
readonly _tag: "InputStreaming";
|
|
334
|
+
readonly id: string;
|
|
335
|
+
readonly name?: string;
|
|
336
|
+
readonly input: string;
|
|
337
|
+
}) => any;
|
|
338
|
+
readonly InputReady: (args: {
|
|
339
|
+
readonly _tag: "InputReady";
|
|
340
|
+
readonly call: ToolCall;
|
|
341
|
+
}) => any;
|
|
342
|
+
readonly ApprovalRequested: (args: {
|
|
343
|
+
readonly _tag: "ApprovalRequested";
|
|
344
|
+
readonly call: ToolCall;
|
|
345
|
+
readonly request?: ToolApprovalRequest;
|
|
346
|
+
}) => any;
|
|
347
|
+
readonly Denied: (args: {
|
|
348
|
+
readonly _tag: "Denied";
|
|
349
|
+
readonly toolCallId: string;
|
|
350
|
+
readonly reason: string;
|
|
351
|
+
}) => any;
|
|
352
352
|
readonly Executing: (args: {
|
|
353
353
|
readonly _tag: "Executing";
|
|
354
354
|
readonly call: ToolCall;
|
|
@@ -380,28 +380,8 @@ declare const AgentToolRun: {
|
|
|
380
380
|
readonly call: ToolCall;
|
|
381
381
|
readonly result: ToolResult;
|
|
382
382
|
}) => any;
|
|
383
|
-
}>(cases: Cases): (value: AgentToolRun) => import("effect/Unify").Unify<ReturnType<Cases["
|
|
383
|
+
}>(cases: Cases): (value: AgentToolRun) => import("effect/Unify").Unify<ReturnType<Cases["QuestionRequested" | "QuestionAnswered" | "QuestionCancelled" | "InputRequested" | "InputSubmitted" | "InputCancelled" | "InteractionRequested" | "InteractionSubmitted" | "InteractionCancelled" | "InputStreaming" | "InputReady" | "ApprovalRequested" | "Denied" | "Executing" | "Completed" | "Accepted" | "Errored" | "ProviderCompleted"]>>;
|
|
384
384
|
<Cases extends {
|
|
385
|
-
readonly InputStreaming: (args: {
|
|
386
|
-
readonly _tag: "InputStreaming";
|
|
387
|
-
readonly id: string;
|
|
388
|
-
readonly name?: string;
|
|
389
|
-
readonly input: string;
|
|
390
|
-
}) => any;
|
|
391
|
-
readonly InputReady: (args: {
|
|
392
|
-
readonly _tag: "InputReady";
|
|
393
|
-
readonly call: ToolCall;
|
|
394
|
-
}) => any;
|
|
395
|
-
readonly ApprovalRequested: (args: {
|
|
396
|
-
readonly _tag: "ApprovalRequested";
|
|
397
|
-
readonly call: ToolCall;
|
|
398
|
-
readonly request?: ToolApprovalRequest;
|
|
399
|
-
}) => any;
|
|
400
|
-
readonly Denied: (args: {
|
|
401
|
-
readonly _tag: "Denied";
|
|
402
|
-
readonly toolCallId: string;
|
|
403
|
-
readonly reason: string;
|
|
404
|
-
}) => any;
|
|
405
385
|
readonly QuestionRequested: (args: {
|
|
406
386
|
readonly _tag: "QuestionRequested";
|
|
407
387
|
readonly request: QuestionRequest;
|
|
@@ -444,6 +424,26 @@ declare const AgentToolRun: {
|
|
|
444
424
|
readonly response: InteractionResponse;
|
|
445
425
|
readonly request?: InteractionRequest;
|
|
446
426
|
}) => any;
|
|
427
|
+
readonly InputStreaming: (args: {
|
|
428
|
+
readonly _tag: "InputStreaming";
|
|
429
|
+
readonly id: string;
|
|
430
|
+
readonly name?: string;
|
|
431
|
+
readonly input: string;
|
|
432
|
+
}) => any;
|
|
433
|
+
readonly InputReady: (args: {
|
|
434
|
+
readonly _tag: "InputReady";
|
|
435
|
+
readonly call: ToolCall;
|
|
436
|
+
}) => any;
|
|
437
|
+
readonly ApprovalRequested: (args: {
|
|
438
|
+
readonly _tag: "ApprovalRequested";
|
|
439
|
+
readonly call: ToolCall;
|
|
440
|
+
readonly request?: ToolApprovalRequest;
|
|
441
|
+
}) => any;
|
|
442
|
+
readonly Denied: (args: {
|
|
443
|
+
readonly _tag: "Denied";
|
|
444
|
+
readonly toolCallId: string;
|
|
445
|
+
readonly reason: string;
|
|
446
|
+
}) => any;
|
|
447
447
|
readonly Executing: (args: {
|
|
448
448
|
readonly _tag: "Executing";
|
|
449
449
|
readonly call: ToolCall;
|
|
@@ -475,7 +475,7 @@ declare const AgentToolRun: {
|
|
|
475
475
|
readonly call: ToolCall;
|
|
476
476
|
readonly result: ToolResult;
|
|
477
477
|
}) => any;
|
|
478
|
-
}>(value: AgentToolRun, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["
|
|
478
|
+
}>(value: AgentToolRun, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["QuestionRequested" | "QuestionAnswered" | "QuestionCancelled" | "InputRequested" | "InputSubmitted" | "InputCancelled" | "InteractionRequested" | "InteractionSubmitted" | "InteractionCancelled" | "InputStreaming" | "InputReady" | "ApprovalRequested" | "Denied" | "Executing" | "Completed" | "Accepted" | "Errored" | "ProviderCompleted"]>>;
|
|
479
479
|
};
|
|
480
480
|
};
|
|
481
481
|
type AgentClientState = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.mts","names":[],"sources":["../../src/client/state.ts"],"mappings":";;;;KAoBY,cAAA;AAAA,KAEA,YAAA;EAAA,SAEG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QAAA;AAAA;EAAA;iBAG7B,QAAA;EAAA,mBACI,mBAAA;AAAA;EAAA;oBAGmC,eAAA;AAAA;EAAA;oBAWH,YAAA;AAAA;EAAA;oBAWM,kBAAA;AAAA;EAAA;qBAGtC,mBAAA;EAAA,mBACA,kBAAA;AAAA;EAAA;iBASJ,QAAA;EAAA;;;cA+HR,iBAAA,GAAqB,IAAA,EAAM,aAAA,CAAc,YAAA;EAAA;iBAxHjC,QAAA;EAAA,iBACE,UAAA;EAAA;;;cAoIV,wBAAA,GACX,QAAA,EAAU,aAAA,CAAc,WAAA,MACvB,aAAA,CAAc,YAAA;AAAA,cAwNJ,kBAAA,GACX,QAAA,EAAU,aAAA,CAAc,YAAA,GACxB,OAAA,EAAS,YAAA,KACR,eAAA;AAAA,cAUU,eAAA,GAAmB,KAAA,EAAO,gBAAA,EAAkB,KAAA,EAAO,UAAA,KAAa,gBAAA;AAAA,cAMhE,0BAAA,GACX,KAAA,EAAO,gBAAA,EACP,KAAA,EAAO,UAAA,EACP,OAAA,GAAS,sBAAA,KACR,gBAAA;AAAA,cA2SU,sBAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,EAAS,WAAA,KACR,gBAAA;AAAA,cAcU,cAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,WACA,SAAA,GAAW,UAAA,YACV,gBAAA;AAAA,cASU,gBAAA,GAAoB,KAAA,EAAO,gBAAA,KAAmB,gBAOzD;AAAA,cAEW,iBAAA,GACX,MAAA,EAAQ,aAAA,CAAc,UAAA,GACtB,YAAA,GAAc,gBAAA,EACd,OAAA,GAAS,sBAAA,KAA2B,gBAAA"}
|
|
@@ -120,8 +120,25 @@ type OpenAiRequestBodyConfig = {
|
|
|
120
120
|
readonly providerName?: string;
|
|
121
121
|
};
|
|
122
122
|
declare const toOpenAiRequestBody: (request: LLMRequest, config: OpenAiRequestBodyConfig) => Effect.Effect<OpenAiRequestBody, LLMError>;
|
|
123
|
+
/**
|
|
124
|
+
* `ProviderErrorInfo.providerCode` values (kind `invalid_response`) naming the check a Chat
|
|
125
|
+
* Completions response failed. Fixed literals that never carry upstream values, so hosts can log
|
|
126
|
+
* and persist them:
|
|
127
|
+
*
|
|
128
|
+
* - `invalid_stream_json`: an SSE `data:` payload is not JSON.
|
|
129
|
+
* - `invalid_stream_chunk`: a stream chunk does not match the `chat.completion.chunk` shape.
|
|
130
|
+
* - `invalid_reasoning`: reasoning content is neither a string nor null.
|
|
131
|
+
* - `invalid_tool_call`: a streamed tool call has no id or no name.
|
|
132
|
+
* - `invalid_tool_arguments`: tool call arguments are not JSON.
|
|
133
|
+
* - `invalid_usage`: the usage block lacks its token counts.
|
|
134
|
+
* - `invalid_response_json`: a JSON (non-streaming) response body is not JSON.
|
|
135
|
+
* - `invalid_response_body`: a JSON response does not match the `chat.completion` shape.
|
|
136
|
+
* - `missing_choices`: a JSON response has no choices.
|
|
137
|
+
*/
|
|
138
|
+
declare const openAiChatResponseIssues: readonly ["invalid_stream_json", "invalid_stream_chunk", "invalid_reasoning", "invalid_tool_call", "invalid_tool_arguments", "invalid_usage", "invalid_response_json", "invalid_response_body", "missing_choices"];
|
|
139
|
+
type OpenAiChatResponseIssue = (typeof openAiChatResponseIssues)[number];
|
|
123
140
|
declare const makeOpenAiProviderLayer: (config: OpenAiProviderConfig) => Layer.Layer<LLMProvider, never, HttpClient.HttpClient>;
|
|
124
141
|
declare const OpenAiProviderLayer: Layer.Layer<LLMProvider, LLMError, never>;
|
|
125
142
|
//#endregion
|
|
126
|
-
export { OpenAiProviderConfig, OpenAiProviderLayer, OpenAiRequestExtras, makeOpenAiProviderLayer, toOpenAiRequestBody };
|
|
143
|
+
export { OpenAiChatResponseIssue, OpenAiProviderConfig, OpenAiProviderLayer, OpenAiRequestExtras, makeOpenAiProviderLayer, openAiChatResponseIssues, toOpenAiRequestBody };
|
|
127
144
|
//# sourceMappingURL=provider.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.mts","names":[],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AA;EAAA,SACA,MAAA;EAAA,SACA,cAAA;IAAA,SACE,aAAA;EAAA;EAAA,SAEF,SAAA;IAAA,SACE,MAAA,EAAQ,oBAAA;EAAA;EAAA,SAEV,gBAAA,GAAmB,oBAAA;EAAA,SACnB,KAAA,GAAQ,aAAA,CAAc,UAAA;EAAA,SACtB,mBAAA;EAAA,SACA,WAAA;AAAA;AAAA,KAGN,aAAA,IAAiB,GAAA,aAAgB,MAAA,CAAO,MAAM,SAAS,QAAA;AAAA,KAEvD,uBAAA;EAAA,SACM,mBAAA;EAAA,SACA,oBAAA;EAAA,SACA,SAAA;EAAA,SACA,qBAAA;EAAA,SACA,gBAAA;EAAA,SACA,SAAA;EAAA,SACA,sBAAA;EAAA,SACA,aAAA,GAAgB,aAAa;EAAA,SAC7B,YAAA;AAAA;AAAA,cA4nBE,mBAAA,GACX,OAAA,EAAS,UAAA,EACT,MAAA,EAAQ,uBAAA,KACP,MAAA,CAAO,MAAA,CAAO,iBAAA,EAAmB,QAAA;;;;;AAvqBwC;AAAA;;;;;;;;;;cAm8B/D,wBAAA;AAAA,KAYD,uBAAA,WAAkC,wBAAwB;AAAA,cA4tBzD,uBAAA,GAA2B,MAAA,EAAQ,oBAAA,KAAoB,KAAA,CAAA,KAAA,CAAA,WAAA,SAAA,UAAA,CAAA,UAAA;AAAA,cAYvD,mBAAA,EAAmB,KAAA,CAAA,KAAA,CAAA,WAAA,EAAA,QAAA"}
|
|
@@ -203,7 +203,6 @@ const snapshotOpenAiRequestExtras = (extraBody, config, providerName) => {
|
|
|
203
203
|
}
|
|
204
204
|
return Effect.succeed(surviving);
|
|
205
205
|
};
|
|
206
|
-
const decodeJsonString = (raw, message) => Schema$1.decodeUnknownEffect(JsonFromJsonString)(raw).pipe(Effect.mapError(schemaErrorToLlmError("invalid_response", message)));
|
|
207
206
|
const unsupportedContentError = (contentType, providerName) => new LLMError({
|
|
208
207
|
cause: "provider_error",
|
|
209
208
|
message: `${contentType} content is not supported by the ${providerName} provider yet`,
|
|
@@ -413,7 +412,12 @@ const toOpenAiRequestBody = (request, config) => Effect.gen(function* () {
|
|
|
413
412
|
...toolChoice
|
|
414
413
|
};
|
|
415
414
|
});
|
|
416
|
-
const parseToolArguments = (raw,
|
|
415
|
+
const parseToolArguments = (raw, providerIdentity, stream) => Schema$1.decodeUnknownEffect(JsonFromJsonString)(raw).pipe(Effect.mapError(chatSchemaIssueError({
|
|
416
|
+
providerIdentity,
|
|
417
|
+
issue: "invalid_tool_arguments",
|
|
418
|
+
message: `Invalid ${providerIdentity.name} tool arguments JSON`,
|
|
419
|
+
stream
|
|
420
|
+
})));
|
|
417
421
|
const toLlmEvents = (choice, providerIdentity, reasoningContent) => Effect.gen(function* () {
|
|
418
422
|
if (choice.finish_reason === "length" || choice.finish_reason === "content_filter") return yield* Effect.fail(new LLMError({
|
|
419
423
|
cause: "invalid_response",
|
|
@@ -426,11 +430,16 @@ const toLlmEvents = (choice, providerIdentity, reasoningContent) => Effect.gen(f
|
|
|
426
430
|
})
|
|
427
431
|
}));
|
|
428
432
|
const content = choice.message.content ?? "";
|
|
429
|
-
const reasoning = reasoningContent ? (yield* Schema$1.decodeUnknownEffect(Schema$1.NullOr(Schema$1.String))(choice.message.reasoning_content ?? choice.message.reasoning ?? null).pipe(Effect.mapError(
|
|
433
|
+
const reasoning = reasoningContent ? (yield* Schema$1.decodeUnknownEffect(Schema$1.NullOr(Schema$1.String))(choice.message.reasoning_content ?? choice.message.reasoning ?? null).pipe(Effect.mapError(chatSchemaIssueError({
|
|
434
|
+
providerIdentity,
|
|
435
|
+
issue: "invalid_reasoning",
|
|
436
|
+
message: `Invalid ${providerIdentity.name} reasoning content`,
|
|
437
|
+
stream: void 0
|
|
438
|
+
})))) ?? "" : "";
|
|
430
439
|
const textEvents = [];
|
|
431
440
|
if (reasoning.length > 0) textEvents.push(LLMReasoningDelta$1.make({ text: reasoning }));
|
|
432
441
|
if (content.length > 0) textEvents.push(LLMTextDelta$1.make({ text: content }));
|
|
433
|
-
const toolCallEvents = yield* Effect.forEach(choice.message.tool_calls ?? [], (call) => parseToolArguments(call.function.arguments, providerIdentity
|
|
442
|
+
const toolCallEvents = yield* Effect.forEach(choice.message.tool_calls ?? [], (call) => parseToolArguments(call.function.arguments, providerIdentity, void 0).pipe(Effect.map((params) => LLMToolCall.make({ call: ToolCall.make({
|
|
434
443
|
id: call.id,
|
|
435
444
|
name: call.function.name,
|
|
436
445
|
params
|
|
@@ -481,10 +490,56 @@ const chatSseBlockData = (block) => {
|
|
|
481
490
|
payload: data.length > 0 ? data : void 0
|
|
482
491
|
};
|
|
483
492
|
};
|
|
484
|
-
|
|
493
|
+
/**
|
|
494
|
+
* `ProviderErrorInfo.providerCode` values (kind `invalid_response`) naming the check a Chat
|
|
495
|
+
* Completions response failed. Fixed literals that never carry upstream values, so hosts can log
|
|
496
|
+
* and persist them:
|
|
497
|
+
*
|
|
498
|
+
* - `invalid_stream_json`: an SSE `data:` payload is not JSON.
|
|
499
|
+
* - `invalid_stream_chunk`: a stream chunk does not match the `chat.completion.chunk` shape.
|
|
500
|
+
* - `invalid_reasoning`: reasoning content is neither a string nor null.
|
|
501
|
+
* - `invalid_tool_call`: a streamed tool call has no id or no name.
|
|
502
|
+
* - `invalid_tool_arguments`: tool call arguments are not JSON.
|
|
503
|
+
* - `invalid_usage`: the usage block lacks its token counts.
|
|
504
|
+
* - `invalid_response_json`: a JSON (non-streaming) response body is not JSON.
|
|
505
|
+
* - `invalid_response_body`: a JSON response does not match the `chat.completion` shape.
|
|
506
|
+
* - `missing_choices`: a JSON response has no choices.
|
|
507
|
+
*/
|
|
508
|
+
const openAiChatResponseIssues = [
|
|
509
|
+
"invalid_stream_json",
|
|
510
|
+
"invalid_stream_chunk",
|
|
511
|
+
"invalid_reasoning",
|
|
512
|
+
"invalid_tool_call",
|
|
513
|
+
"invalid_tool_arguments",
|
|
514
|
+
"invalid_usage",
|
|
515
|
+
"invalid_response_json",
|
|
516
|
+
"invalid_response_body",
|
|
517
|
+
"missing_choices"
|
|
518
|
+
];
|
|
519
|
+
const chatResponseIssueError = (input) => new LLMError({
|
|
485
520
|
cause: "invalid_response",
|
|
486
|
-
message:
|
|
487
|
-
retryable: false
|
|
521
|
+
message: input.message,
|
|
522
|
+
retryable: false,
|
|
523
|
+
provider: input.stream === void 0 ? providerErrorInfo({
|
|
524
|
+
provider: input.providerIdentity.id,
|
|
525
|
+
kind: "invalid_response",
|
|
526
|
+
providerCode: input.issue
|
|
527
|
+
}) : providerErrorInfo({
|
|
528
|
+
provider: input.providerIdentity.id,
|
|
529
|
+
kind: "invalid_response",
|
|
530
|
+
providerCode: input.issue,
|
|
531
|
+
stream: input.stream
|
|
532
|
+
})
|
|
533
|
+
});
|
|
534
|
+
const chatSchemaIssueError = (input) => (error) => chatResponseIssueError({
|
|
535
|
+
...input,
|
|
536
|
+
message: `${input.message}: ${schemaErrorMessage(error)}`
|
|
537
|
+
});
|
|
538
|
+
const invalidChatStreamEvent = (context, issue, state) => chatResponseIssueError({
|
|
539
|
+
providerIdentity: context.providerIdentity,
|
|
540
|
+
issue,
|
|
541
|
+
message: `Invalid ${context.providerIdentity.name} stream event`,
|
|
542
|
+
stream: chatStreamDiagnostics(context.responseFormat, state)
|
|
488
543
|
});
|
|
489
544
|
const chatStreamError = (providerIdentity, raw) => Effect.gen(function* () {
|
|
490
545
|
const errorCode = yield* decodeOpenAiHttpErrorCode(raw);
|
|
@@ -511,20 +566,20 @@ const mergeChatToolCallDelta = (toolCalls, delta) => {
|
|
|
511
566
|
};
|
|
512
567
|
return [...toolCalls.filter((call) => call.index !== index), merged];
|
|
513
568
|
};
|
|
514
|
-
const decodeChatDeltaReasoning = (
|
|
515
|
-
const processChatStreamPayload = (
|
|
516
|
-
const parsed = yield* Schema$1.decodeUnknownEffect(JsonFromJsonString)(payload).pipe(Effect.mapError(() => invalidChatStreamEvent(
|
|
569
|
+
const decodeChatDeltaReasoning = (context, state, reasoning) => Schema$1.decodeUnknownEffect(Schema$1.NullOr(Schema$1.String))(reasoning).pipe(Effect.map((value) => value ?? ""), Effect.mapError(() => invalidChatStreamEvent(context, "invalid_reasoning", state)));
|
|
570
|
+
const processChatStreamPayload = (context, state, payload) => Effect.gen(function* () {
|
|
571
|
+
const parsed = yield* Schema$1.decodeUnknownEffect(JsonFromJsonString)(payload).pipe(Effect.mapError(() => invalidChatStreamEvent(context, "invalid_stream_json", state)));
|
|
517
572
|
const envelope = isJsonRecord(parsed) ? jsonRecordField(parsed, "error") : void 0;
|
|
518
|
-
if (envelope !== void 0 && isJsonRecord(envelope)) return yield* chatStreamError(providerIdentity, payload);
|
|
519
|
-
const chunk = yield* Schema$1.decodeUnknownEffect(OpenAiChatStreamChunk)(parsed).pipe(Effect.mapError(() => invalidChatStreamEvent(
|
|
573
|
+
if (envelope !== void 0 && isJsonRecord(envelope)) return yield* chatStreamError(context.providerIdentity, payload);
|
|
574
|
+
const chunk = yield* Schema$1.decodeUnknownEffect(OpenAiChatStreamChunk)(parsed).pipe(Effect.mapError(() => invalidChatStreamEvent(context, "invalid_stream_chunk", state)));
|
|
520
575
|
const events = [];
|
|
521
576
|
let toolCalls = state.toolCalls;
|
|
522
577
|
let finishReason = state.finishReason;
|
|
523
578
|
let usage = state.usage;
|
|
524
579
|
for (const choice of chunk.choices ?? []) {
|
|
525
580
|
if (choice.delta?.content) events.push(LLMTextDelta$1.make({ text: choice.delta.content }));
|
|
526
|
-
if (reasoningContent && (choice.delta?.reasoning_content != null || choice.delta?.reasoning != null)) {
|
|
527
|
-
const reasoning = yield* decodeChatDeltaReasoning(
|
|
581
|
+
if (context.reasoningContent && (choice.delta?.reasoning_content != null || choice.delta?.reasoning != null)) {
|
|
582
|
+
const reasoning = yield* decodeChatDeltaReasoning(context, state, choice.delta.reasoning_content ?? choice.delta.reasoning ?? null);
|
|
528
583
|
if (reasoning.length > 0) events.push(LLMReasoningDelta$1.make({ text: reasoning }));
|
|
529
584
|
}
|
|
530
585
|
for (const call of choice.delta?.tool_calls ?? []) toolCalls = mergeChatToolCallDelta(toolCalls, call);
|
|
@@ -544,7 +599,7 @@ const processChatStreamPayload = (providerIdentity, reasoningContent, state, pay
|
|
|
544
599
|
events
|
|
545
600
|
};
|
|
546
601
|
});
|
|
547
|
-
const processChatStreamBlock = (
|
|
602
|
+
const processChatStreamBlock = (context, state, block) => Effect.gen(function* () {
|
|
548
603
|
if (state.streamClosed) return {
|
|
549
604
|
state,
|
|
550
605
|
events: []
|
|
@@ -559,7 +614,7 @@ const processChatStreamBlock = (providerIdentity, reasoningContent, state, block
|
|
|
559
614
|
state: current,
|
|
560
615
|
events: []
|
|
561
616
|
};
|
|
562
|
-
return yield* processChatStreamPayload(
|
|
617
|
+
return yield* processChatStreamPayload(context, current, payload);
|
|
563
618
|
});
|
|
564
619
|
const chatStreamDiagnostics = (responseFormat, state) => ProviderStreamDiagnostics.make({
|
|
565
620
|
protocol: "chat-completions",
|
|
@@ -569,7 +624,7 @@ const chatStreamDiagnostics = (responseFormat, state) => ProviderStreamDiagnosti
|
|
|
569
624
|
outputStarted: state.outputStarted,
|
|
570
625
|
terminalSeen: state.hasTerminal
|
|
571
626
|
});
|
|
572
|
-
const processChatStreamText = (
|
|
627
|
+
const processChatStreamText = (context, state, text) => Effect.gen(function* () {
|
|
573
628
|
const split = splitCompleteChatSseBlocks(`${state.buffer}${text}`);
|
|
574
629
|
let current = {
|
|
575
630
|
...state,
|
|
@@ -577,7 +632,7 @@ const processChatStreamText = (providerIdentity, reasoningContent, state, text)
|
|
|
577
632
|
};
|
|
578
633
|
const events = [];
|
|
579
634
|
for (const block of split.completeBlocks) {
|
|
580
|
-
const step = yield* processChatStreamBlock(
|
|
635
|
+
const step = yield* processChatStreamBlock(context, current, block);
|
|
581
636
|
current = step.state;
|
|
582
637
|
events.push(...step.events);
|
|
583
638
|
}
|
|
@@ -586,7 +641,8 @@ const processChatStreamText = (providerIdentity, reasoningContent, state, text)
|
|
|
586
641
|
events
|
|
587
642
|
};
|
|
588
643
|
});
|
|
589
|
-
const finalizeChatStreamState = (
|
|
644
|
+
const finalizeChatStreamState = (context, state) => Effect.gen(function* () {
|
|
645
|
+
const { providerIdentity, responseFormat } = context;
|
|
590
646
|
if (!state.hasTerminal) return yield* Effect.fail(new LLMError({
|
|
591
647
|
cause: "invalid_response",
|
|
592
648
|
message: `${providerIdentity.name} stream ended before a terminal chunk`,
|
|
@@ -625,12 +681,13 @@ const finalizeChatStreamState = (providerIdentity, responseFormat, state) => Eff
|
|
|
625
681
|
const toolCallEvents = yield* Effect.forEach(orderedCalls, (call) => {
|
|
626
682
|
const id = call.id;
|
|
627
683
|
const name = call.name;
|
|
628
|
-
if (id === void 0 || name === void 0) return Effect.fail(
|
|
629
|
-
|
|
684
|
+
if (id === void 0 || name === void 0) return Effect.fail(chatResponseIssueError({
|
|
685
|
+
providerIdentity,
|
|
686
|
+
issue: "invalid_tool_call",
|
|
630
687
|
message: `Invalid ${providerIdentity.name} streamed tool call`,
|
|
631
|
-
|
|
688
|
+
stream: chatStreamDiagnostics(responseFormat, state)
|
|
632
689
|
}));
|
|
633
|
-
return parseToolArguments(call.arguments, providerIdentity
|
|
690
|
+
return parseToolArguments(call.arguments, providerIdentity, chatStreamDiagnostics(responseFormat, state)).pipe(Effect.map((params) => LLMToolCall.make({ call: ToolCall.make({
|
|
634
691
|
id,
|
|
635
692
|
name,
|
|
636
693
|
params
|
|
@@ -639,7 +696,7 @@ const finalizeChatStreamState = (providerIdentity, responseFormat, state) => Eff
|
|
|
639
696
|
const events = [...toolCallEvents];
|
|
640
697
|
events.push(LLMDone.make({ stopReason: toolCallEvents.length > 0 ? "tool_use" : "stop" }));
|
|
641
698
|
if (state.usage !== void 0) {
|
|
642
|
-
const usage = yield* Schema$1.decodeUnknownEffect(OpenAiUsageResponse)(state.usage).pipe(Effect.mapError(() => invalidChatStreamEvent(
|
|
699
|
+
const usage = yield* Schema$1.decodeUnknownEffect(OpenAiUsageResponse)(state.usage).pipe(Effect.mapError(() => invalidChatStreamEvent(context, "invalid_usage", state)));
|
|
643
700
|
events.push(LLMUsage.make({ usage: toAgentUsage(usage) }));
|
|
644
701
|
}
|
|
645
702
|
return events;
|
|
@@ -675,15 +732,20 @@ const expectChatSseResponse = (providerIdentity, response) => {
|
|
|
675
732
|
}));
|
|
676
733
|
};
|
|
677
734
|
const streamOpenAiChatResponse = (providerIdentity, reasoningContent, responseFormat, response) => Stream.unwrap(Ref.make(initialOpenAiChatStreamState).pipe(Effect.map((stateRef) => {
|
|
735
|
+
const context = {
|
|
736
|
+
providerIdentity,
|
|
737
|
+
reasoningContent,
|
|
738
|
+
responseFormat
|
|
739
|
+
};
|
|
678
740
|
const chunks = response.stream.pipe(Stream.mapError(toHttpClientLlmError(providerIdentity, true)), Stream.tap((chunk) => Ref.update(stateRef, (state) => ({
|
|
679
741
|
...state,
|
|
680
742
|
receivedBytes: state.receivedBytes + chunk.byteLength
|
|
681
743
|
}))), Stream.decodeText, Stream.mapEffect((chunk) => Effect.gen(function* () {
|
|
682
|
-
const step = yield* processChatStreamText(
|
|
744
|
+
const step = yield* processChatStreamText(context, yield* Ref.get(stateRef), chunk);
|
|
683
745
|
yield* Ref.set(stateRef, step.state);
|
|
684
746
|
return step.events;
|
|
685
747
|
})), Stream.flatMap((events) => Stream.fromIterable(events)));
|
|
686
|
-
const finalEvents = Stream.fromEffect(Ref.get(stateRef).pipe(Effect.flatMap((state) => finalizeChatStreamState(
|
|
748
|
+
const finalEvents = Stream.fromEffect(Ref.get(stateRef).pipe(Effect.flatMap((state) => finalizeChatStreamState(context, state)))).pipe(Stream.flatMap((events) => Stream.fromIterable(events)));
|
|
687
749
|
return chunks.pipe(Stream.concat(finalEvents));
|
|
688
750
|
})));
|
|
689
751
|
const toHttpClientLlmError = (providerIdentity, retryable) => (error) => new LLMError({
|
|
@@ -695,13 +757,19 @@ const toHttpClientLlmError = (providerIdentity, retryable) => (error) => new LLM
|
|
|
695
757
|
kind: retryable ? "network" : "unknown"
|
|
696
758
|
})
|
|
697
759
|
});
|
|
698
|
-
const parseOpenAiResponseJson = (response,
|
|
699
|
-
const raw = yield* response.json.pipe(Effect.mapError((error) =>
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
760
|
+
const parseOpenAiResponseJson = (response, providerIdentity) => Effect.gen(function* () {
|
|
761
|
+
const raw = yield* response.json.pipe(Effect.mapError((error) => chatResponseIssueError({
|
|
762
|
+
providerIdentity,
|
|
763
|
+
issue: "invalid_response_json",
|
|
764
|
+
message: `Could not parse ${providerIdentity.name} response JSON: ${error.message}`,
|
|
765
|
+
stream: void 0
|
|
766
|
+
})));
|
|
767
|
+
return yield* Schema$1.decodeUnknownEffect(Schema$1.Json)(raw).pipe(Effect.mapError(chatSchemaIssueError({
|
|
768
|
+
providerIdentity,
|
|
769
|
+
issue: "invalid_response_json",
|
|
770
|
+
message: `Could not parse ${providerIdentity.name} response JSON`,
|
|
771
|
+
stream: void 0
|
|
703
772
|
})));
|
|
704
|
-
return yield* Schema$1.decodeUnknownEffect(Schema$1.Json)(raw).pipe(Effect.mapError(schemaErrorToLlmError("invalid_response", `Could not parse ${providerName} response JSON`)));
|
|
705
773
|
});
|
|
706
774
|
const openAiRequestBodyFields = (config, providerIdentity, resolvePdfUrl) => {
|
|
707
775
|
const fields = {
|
|
@@ -772,13 +840,19 @@ const sendOpenAiRequestBody = (config, request, providerIdentity, client) => Eff
|
|
|
772
840
|
});
|
|
773
841
|
const sendOpenAiRequest = (config, request, client) => Effect.gen(function* () {
|
|
774
842
|
const providerIdentity = config.providerIdentity ?? defaultOpenAiProviderIdentity;
|
|
775
|
-
const json = yield* parseOpenAiResponseJson(yield* postOpenAiRequest(config, providerIdentity, yield* sendOpenAiRequestBody(config, request, providerIdentity, client), client, request.cacheKey), providerIdentity
|
|
776
|
-
const parsed = yield* Schema$1.decodeUnknownEffect(OpenAiChatCompletionResponse)(json).pipe(Effect.mapError(
|
|
843
|
+
const json = yield* parseOpenAiResponseJson(yield* postOpenAiRequest(config, providerIdentity, yield* sendOpenAiRequestBody(config, request, providerIdentity, client), client, request.cacheKey), providerIdentity);
|
|
844
|
+
const parsed = yield* Schema$1.decodeUnknownEffect(OpenAiChatCompletionResponse)(json).pipe(Effect.mapError(chatSchemaIssueError({
|
|
845
|
+
providerIdentity,
|
|
846
|
+
issue: "invalid_response_body",
|
|
847
|
+
message: `Invalid ${providerIdentity.name} response`,
|
|
848
|
+
stream: void 0
|
|
849
|
+
})));
|
|
777
850
|
const choice = parsed.choices[0];
|
|
778
|
-
if (choice === void 0) return yield* Effect.fail(
|
|
779
|
-
|
|
851
|
+
if (choice === void 0) return yield* Effect.fail(chatResponseIssueError({
|
|
852
|
+
providerIdentity,
|
|
853
|
+
issue: "missing_choices",
|
|
780
854
|
message: `${providerIdentity.name} response contained no choices`,
|
|
781
|
-
|
|
855
|
+
stream: void 0
|
|
782
856
|
}));
|
|
783
857
|
const events = yield* toLlmEvents(choice, providerIdentity, config.reasoningContent ?? false);
|
|
784
858
|
if (parsed.usage === void 0) return events;
|
|
@@ -801,6 +875,6 @@ const OpenAiProviderLayer = Layer.effect(LLMProvider, Effect.gen(function* () {
|
|
|
801
875
|
return LLMProvider.of({ stream: (request) => openAiProviderStream(config, request, client) });
|
|
802
876
|
})).pipe(Layer.provide(Layer.mergeAll(OpenAiConfigLayer, FetchHttpClient.layer)));
|
|
803
877
|
//#endregion
|
|
804
|
-
export { OpenAiProviderLayer, makeOpenAiProviderLayer, toOpenAiRequestBody };
|
|
878
|
+
export { OpenAiProviderLayer, makeOpenAiProviderLayer, openAiChatResponseIssues, toOpenAiRequestBody };
|
|
805
879
|
|
|
806
880
|
//# sourceMappingURL=provider.mjs.map
|