@yolk-sdk/agent 0.1.0-canary.105 → 0.1.0-canary.107
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 +15 -0
- package/dist/client/state.d.mts +75 -75
- package/dist/client/state.d.mts.map +1 -1
- package/dist/loop/run.d.mts +35 -1
- package/dist/loop/run.d.mts.map +1 -1
- package/dist/loop/run.mjs +109 -34
- package/dist/loop/run.mjs.map +1 -1
- package/dist/loop/services/llm-provider.d.mts +20 -0
- package/dist/loop/services/llm-provider.d.mts.map +1 -1
- package/dist/loop/services/llm-provider.mjs.map +1 -1
- package/dist/providers/anthropic/claude-provider.d.mts +22 -2
- package/dist/providers/anthropic/claude-provider.d.mts.map +1 -1
- package/dist/providers/anthropic/claude-provider.mjs.map +1 -1
- package/dist/providers/anthropic/conformance/cases.d.mts.map +1 -1
- package/dist/providers/anthropic/conformance/cases.mjs +3 -2
- package/dist/providers/anthropic/conformance/cases.mjs.map +1 -1
- package/dist/providers/anthropic/conformance/error-envelope.d.mts.map +1 -1
- package/dist/providers/anthropic/conformance/error-envelope.mjs +7 -2
- package/dist/providers/anthropic/conformance/error-envelope.mjs.map +1 -1
- package/dist/providers/anthropic/conformance/max-tokens.d.mts.map +1 -1
- package/dist/providers/anthropic/conformance/max-tokens.mjs +7 -2
- package/dist/providers/anthropic/conformance/max-tokens.mjs.map +1 -1
- package/dist/providers/anthropic/conformance/plain-text.d.mts.map +1 -1
- package/dist/providers/anthropic/conformance/plain-text.mjs +7 -2
- package/dist/providers/anthropic/conformance/plain-text.mjs.map +1 -1
- package/dist/providers/anthropic/conformance/thinking-before-text.d.mts.map +1 -1
- package/dist/providers/anthropic/conformance/thinking-before-text.mjs +7 -2
- package/dist/providers/anthropic/conformance/thinking-before-text.mjs.map +1 -1
- package/dist/providers/anthropic/conformance/tool-use-input-deltas.d.mts.map +1 -1
- package/dist/providers/anthropic/conformance/tool-use-input-deltas.mjs +9 -3
- package/dist/providers/anthropic/conformance/tool-use-input-deltas.mjs.map +1 -1
- package/dist/providers/anthropic-messages-provider-internal.d.mts +6 -3
- package/dist/providers/anthropic-messages-provider-internal.d.mts.map +1 -1
- package/dist/providers/anthropic-messages-provider-internal.mjs +6 -1
- package/dist/providers/anthropic-messages-provider-internal.mjs.map +1 -1
- package/dist/providers/anthropic-provider-internal.d.mts +28 -2
- package/dist/providers/anthropic-provider-internal.d.mts.map +1 -1
- package/dist/providers/anthropic-provider-internal.mjs +96 -5
- package/dist/providers/anthropic-provider-internal.mjs.map +1 -1
- package/dist/providers/cache-key-headers.d.mts +7 -0
- package/dist/providers/cache-key-headers.d.mts.map +1 -0
- package/dist/providers/cache-key-headers.mjs +10 -0
- package/dist/providers/cache-key-headers.mjs.map +1 -0
- package/dist/providers/openai/codex-provider.d.mts +2 -0
- package/dist/providers/openai/codex-provider.d.mts.map +1 -1
- package/dist/providers/openai/codex-provider.mjs +6 -0
- package/dist/providers/openai/codex-provider.mjs.map +1 -1
- package/dist/providers/openai/provider.d.mts +6 -0
- package/dist/providers/openai/provider.d.mts.map +1 -1
- package/dist/providers/openai/provider.mjs +18 -5
- package/dist/providers/openai/provider.mjs.map +1 -1
- package/dist/providers/openai-responses-provider-internal.d.mts +8 -1
- package/dist/providers/openai-responses-provider-internal.d.mts.map +1 -1
- package/dist/providers/openai-responses-provider-internal.mjs +19 -3
- package/dist/providers/openai-responses-provider-internal.mjs.map +1 -1
- package/dist/providers/opencode/conformance/messages-plain-text.d.mts.map +1 -1
- package/dist/providers/opencode/conformance/messages-plain-text.mjs +7 -2
- package/dist/providers/opencode/conformance/messages-plain-text.mjs.map +1 -1
- package/dist/providers/opencode/go-provider.d.mts.map +1 -1
- package/dist/providers/opencode/go-provider.mjs +6 -2
- package/dist/providers/opencode/go-provider.mjs.map +1 -1
- package/dist/providers/vercel/ai-gateway-provider.d.mts.map +1 -1
- package/dist/providers/vercel/ai-gateway-provider.mjs +8 -8
- package/dist/providers/vercel/ai-gateway-provider.mjs.map +1 -1
- package/dist/providers/vercel/conformance/cases.d.mts.map +1 -1
- package/dist/providers/vercel/conformance/cases.mjs.map +1 -1
- package/dist/providers/xai/grok-provider.d.mts +2 -0
- package/dist/providers/xai/grok-provider.d.mts.map +1 -1
- package/dist/providers/xai/grok-provider.mjs +6 -0
- package/dist/providers/xai/grok-provider.mjs.map +1 -1
- package/dist/react/chat-items.d.mts +45 -45
- package/dist/react/chat-items.d.mts.map +1 -1
- package/dist/react/chat-messages.d.mts +60 -60
- package/dist/react/chat-messages.d.mts.map +1 -1
- package/dist/runtime/run-runtime.d.mts +2 -1
- package/dist/runtime/run-runtime.d.mts.map +1 -1
- package/dist/runtime/run-runtime.mjs +46 -19
- package/dist/runtime/run-runtime.mjs.map +1 -1
- package/dist/skillset/merge.d.mts +1 -1
- package/dist/skillset/name.d.mts +2 -2
- package/dist/skillset/name.d.mts.map +1 -1
- package/package.json +2 -2
- package/src/loop/run.ts +225 -51
- package/src/loop/services/llm-provider.ts +20 -0
- package/src/providers/anthropic/claude-provider.ts +25 -1
- package/src/providers/anthropic/conformance/cases.ts +3 -2
- package/src/providers/anthropic/conformance/error-envelope.ts +13 -2
- package/src/providers/anthropic/conformance/max-tokens.ts +13 -2
- package/src/providers/anthropic/conformance/plain-text.ts +13 -2
- package/src/providers/anthropic/conformance/thinking-before-text.ts +13 -2
- package/src/providers/anthropic/conformance/tool-use-input-deltas.ts +16 -2
- package/src/providers/anthropic-messages-provider-internal.ts +11 -1
- package/src/providers/anthropic-provider-internal.ts +165 -11
- package/src/providers/cache-key-headers.ts +13 -0
- package/src/providers/openai/codex-provider.ts +11 -0
- package/src/providers/openai/provider.ts +40 -5
- package/src/providers/openai-responses-provider-internal.ts +31 -3
- package/src/providers/opencode/conformance/messages-plain-text.ts +13 -2
- package/src/providers/opencode/go-provider.ts +8 -2
- package/src/providers/vercel/ai-gateway-provider.ts +18 -14
- package/src/providers/vercel/conformance/cases.ts +2 -1
- package/src/providers/xai/grok-provider.ts +10 -0
- package/src/runtime/run-runtime.ts +71 -16
package/README.md
CHANGED
|
@@ -297,6 +297,21 @@ configuration. Anthropic Claude forwards `low`, `medium`, `high`, and `xhigh` th
|
|
|
297
297
|
`output_config.effort`. It omits `minimal`, which Anthropic does not support. Hosts remain
|
|
298
298
|
responsible for choosing an effort accepted by the selected provider and model.
|
|
299
299
|
|
|
300
|
+
### Prompt caching
|
|
301
|
+
|
|
302
|
+
Provider prompt caching is always on (ADR 0008). Set `cacheKey` (for example the session id) on
|
|
303
|
+
`run` or `runRuntime` so providers route a conversation to its cached prefix: Anthropic gets
|
|
304
|
+
`cache_control` breakpoints and a Claude session header derived from the key, Codex and Grok `prompt_cache_key` plus their session headers, Vercel AI
|
|
305
|
+
Gateway `caching: 'auto'` and `x-session-affinity`, and OpenCode Go `x-opencode-session`. The
|
|
306
|
+
generic OpenAI-compatible chat provider sends nothing unless its config sets `cacheKeyHeaders`.
|
|
307
|
+
Claude entries last five minutes unless the provider sets `promptCacheTtl: '1h'`.
|
|
308
|
+
|
|
309
|
+
Keep the prefix byte-identical: per-request facts (fresh signed URLs, the current time) belong in
|
|
310
|
+
`LLMRequest.turnContext`, which adapters append after the conversation (Anthropic after every
|
|
311
|
+
breakpoint; Gateway's automatic markers still read the prefix before it). Loop hosts set it by
|
|
312
|
+
decorating `LLMProvider`. `LLMRequest.toolChoice: 'none'` forbids tool calls but keeps the tool
|
|
313
|
+
definitions; on Anthropic a changed `tool_choice` invalidates the cached messages.
|
|
314
|
+
|
|
300
315
|
### Anthropic tool schemas
|
|
301
316
|
|
|
302
317
|
Claude subscription OAuth rejects some valid JSON Schema constructs that Effect Schema can emit
|
package/dist/client/state.d.mts
CHANGED
|
@@ -122,16 +122,26 @@ declare const AgentToolRun: {
|
|
|
122
122
|
readonly response: InteractionResponse;
|
|
123
123
|
readonly request?: InteractionRequest;
|
|
124
124
|
}, "_tag">;
|
|
125
|
+
readonly Completed: Data.TaggedEnum.ConstructorFrom<{
|
|
126
|
+
readonly _tag: "Completed";
|
|
127
|
+
readonly call: ToolCall;
|
|
128
|
+
readonly result: ToolResult;
|
|
129
|
+
readonly startedAtMs: number;
|
|
130
|
+
readonly endedAtMs: number;
|
|
131
|
+
}, "_tag">;
|
|
132
|
+
readonly Accepted: Data.TaggedEnum.ConstructorFrom<{
|
|
133
|
+
readonly _tag: "Accepted";
|
|
134
|
+
readonly call: ToolCall;
|
|
135
|
+
readonly result: ToolResult;
|
|
136
|
+
readonly startedAtMs: number;
|
|
137
|
+
readonly endedAtMs: number;
|
|
138
|
+
}, "_tag">;
|
|
125
139
|
readonly InputStreaming: Data.TaggedEnum.ConstructorFrom<{
|
|
126
140
|
readonly _tag: "InputStreaming";
|
|
127
141
|
readonly id: string;
|
|
128
142
|
readonly name?: string;
|
|
129
143
|
readonly input: string;
|
|
130
144
|
}, "_tag">;
|
|
131
|
-
readonly InputReady: Data.TaggedEnum.ConstructorFrom<{
|
|
132
|
-
readonly _tag: "InputReady";
|
|
133
|
-
readonly call: ToolCall;
|
|
134
|
-
}, "_tag">;
|
|
135
145
|
readonly ApprovalRequested: Data.TaggedEnum.ConstructorFrom<{
|
|
136
146
|
readonly _tag: "ApprovalRequested";
|
|
137
147
|
readonly call: ToolCall;
|
|
@@ -142,26 +152,6 @@ declare const AgentToolRun: {
|
|
|
142
152
|
readonly toolCallId: string;
|
|
143
153
|
readonly reason: string;
|
|
144
154
|
}, "_tag">;
|
|
145
|
-
readonly Executing: Data.TaggedEnum.ConstructorFrom<{
|
|
146
|
-
readonly _tag: "Executing";
|
|
147
|
-
readonly call: ToolCall;
|
|
148
|
-
readonly startedAtMs: number; /** Preserve witnessed interaction acceptance across transport interruptions. */
|
|
149
|
-
readonly interaction?: true;
|
|
150
|
-
}, "_tag">;
|
|
151
|
-
readonly Completed: Data.TaggedEnum.ConstructorFrom<{
|
|
152
|
-
readonly _tag: "Completed";
|
|
153
|
-
readonly call: ToolCall;
|
|
154
|
-
readonly result: ToolResult;
|
|
155
|
-
readonly startedAtMs: number;
|
|
156
|
-
readonly endedAtMs: number;
|
|
157
|
-
}, "_tag">;
|
|
158
|
-
readonly Accepted: Data.TaggedEnum.ConstructorFrom<{
|
|
159
|
-
readonly _tag: "Accepted";
|
|
160
|
-
readonly call: ToolCall;
|
|
161
|
-
readonly result: ToolResult;
|
|
162
|
-
readonly startedAtMs: number;
|
|
163
|
-
readonly endedAtMs: number;
|
|
164
|
-
}, "_tag">;
|
|
165
155
|
readonly Errored: Data.TaggedEnum.ConstructorFrom<{
|
|
166
156
|
readonly _tag: "Errored";
|
|
167
157
|
readonly call: ToolCall;
|
|
@@ -173,7 +163,17 @@ declare const AgentToolRun: {
|
|
|
173
163
|
readonly call: ToolCall;
|
|
174
164
|
readonly result: ToolResult;
|
|
175
165
|
}, "_tag">;
|
|
176
|
-
readonly
|
|
166
|
+
readonly InputReady: Data.TaggedEnum.ConstructorFrom<{
|
|
167
|
+
readonly _tag: "InputReady";
|
|
168
|
+
readonly call: ToolCall;
|
|
169
|
+
}, "_tag">;
|
|
170
|
+
readonly Executing: Data.TaggedEnum.ConstructorFrom<{
|
|
171
|
+
readonly _tag: "Executing";
|
|
172
|
+
readonly call: ToolCall;
|
|
173
|
+
readonly startedAtMs: number; /** Preserve witnessed interaction acceptance across transport interruptions. */
|
|
174
|
+
readonly interaction?: true;
|
|
175
|
+
}, "_tag">;
|
|
176
|
+
readonly $is: <Tag extends "QuestionRequested" | "QuestionAnswered" | "QuestionCancelled" | "InputRequested" | "InputSubmitted" | "InputCancelled" | "InteractionRequested" | "InteractionSubmitted" | "InteractionCancelled" | "Completed" | "Accepted" | "InputStreaming" | "ApprovalRequested" | "Denied" | "Errored" | "ProviderCompleted" | "InputReady" | "Executing">(tag: Tag) => (u: unknown) => u is Extract<{
|
|
177
177
|
readonly _tag: "InputStreaming";
|
|
178
178
|
readonly id: string;
|
|
179
179
|
readonly name?: string;
|
|
@@ -329,16 +329,26 @@ declare const AgentToolRun: {
|
|
|
329
329
|
readonly response: InteractionResponse;
|
|
330
330
|
readonly request?: InteractionRequest;
|
|
331
331
|
}) => any;
|
|
332
|
+
readonly Completed: (args: {
|
|
333
|
+
readonly _tag: "Completed";
|
|
334
|
+
readonly call: ToolCall;
|
|
335
|
+
readonly result: ToolResult;
|
|
336
|
+
readonly startedAtMs: number;
|
|
337
|
+
readonly endedAtMs: number;
|
|
338
|
+
}) => any;
|
|
339
|
+
readonly Accepted: (args: {
|
|
340
|
+
readonly _tag: "Accepted";
|
|
341
|
+
readonly call: ToolCall;
|
|
342
|
+
readonly result: ToolResult;
|
|
343
|
+
readonly startedAtMs: number;
|
|
344
|
+
readonly endedAtMs: number;
|
|
345
|
+
}) => any;
|
|
332
346
|
readonly InputStreaming: (args: {
|
|
333
347
|
readonly _tag: "InputStreaming";
|
|
334
348
|
readonly id: string;
|
|
335
349
|
readonly name?: string;
|
|
336
350
|
readonly input: string;
|
|
337
351
|
}) => any;
|
|
338
|
-
readonly InputReady: (args: {
|
|
339
|
-
readonly _tag: "InputReady";
|
|
340
|
-
readonly call: ToolCall;
|
|
341
|
-
}) => any;
|
|
342
352
|
readonly ApprovalRequested: (args: {
|
|
343
353
|
readonly _tag: "ApprovalRequested";
|
|
344
354
|
readonly call: ToolCall;
|
|
@@ -349,26 +359,6 @@ declare const AgentToolRun: {
|
|
|
349
359
|
readonly toolCallId: string;
|
|
350
360
|
readonly reason: string;
|
|
351
361
|
}) => any;
|
|
352
|
-
readonly Executing: (args: {
|
|
353
|
-
readonly _tag: "Executing";
|
|
354
|
-
readonly call: ToolCall;
|
|
355
|
-
readonly startedAtMs: number; /** Preserve witnessed interaction acceptance across transport interruptions. */
|
|
356
|
-
readonly interaction?: true;
|
|
357
|
-
}) => any;
|
|
358
|
-
readonly Completed: (args: {
|
|
359
|
-
readonly _tag: "Completed";
|
|
360
|
-
readonly call: ToolCall;
|
|
361
|
-
readonly result: ToolResult;
|
|
362
|
-
readonly startedAtMs: number;
|
|
363
|
-
readonly endedAtMs: number;
|
|
364
|
-
}) => any;
|
|
365
|
-
readonly Accepted: (args: {
|
|
366
|
-
readonly _tag: "Accepted";
|
|
367
|
-
readonly call: ToolCall;
|
|
368
|
-
readonly result: ToolResult;
|
|
369
|
-
readonly startedAtMs: number;
|
|
370
|
-
readonly endedAtMs: number;
|
|
371
|
-
}) => any;
|
|
372
362
|
readonly Errored: (args: {
|
|
373
363
|
readonly _tag: "Errored";
|
|
374
364
|
readonly call: ToolCall;
|
|
@@ -380,7 +370,17 @@ declare const AgentToolRun: {
|
|
|
380
370
|
readonly call: ToolCall;
|
|
381
371
|
readonly result: ToolResult;
|
|
382
372
|
}) => any;
|
|
383
|
-
|
|
373
|
+
readonly InputReady: (args: {
|
|
374
|
+
readonly _tag: "InputReady";
|
|
375
|
+
readonly call: ToolCall;
|
|
376
|
+
}) => any;
|
|
377
|
+
readonly Executing: (args: {
|
|
378
|
+
readonly _tag: "Executing";
|
|
379
|
+
readonly call: ToolCall;
|
|
380
|
+
readonly startedAtMs: number; /** Preserve witnessed interaction acceptance across transport interruptions. */
|
|
381
|
+
readonly interaction?: true;
|
|
382
|
+
}) => any;
|
|
383
|
+
}>(cases: Cases): (value: AgentToolRun) => import("effect/Unify").Unify<ReturnType<Cases["QuestionRequested" | "QuestionAnswered" | "QuestionCancelled" | "InputRequested" | "InputSubmitted" | "InputCancelled" | "InteractionRequested" | "InteractionSubmitted" | "InteractionCancelled" | "Completed" | "Accepted" | "InputStreaming" | "ApprovalRequested" | "Denied" | "Errored" | "ProviderCompleted" | "InputReady" | "Executing"]>>;
|
|
384
384
|
<Cases extends {
|
|
385
385
|
readonly QuestionRequested: (args: {
|
|
386
386
|
readonly _tag: "QuestionRequested";
|
|
@@ -424,16 +424,26 @@ declare const AgentToolRun: {
|
|
|
424
424
|
readonly response: InteractionResponse;
|
|
425
425
|
readonly request?: InteractionRequest;
|
|
426
426
|
}) => any;
|
|
427
|
+
readonly Completed: (args: {
|
|
428
|
+
readonly _tag: "Completed";
|
|
429
|
+
readonly call: ToolCall;
|
|
430
|
+
readonly result: ToolResult;
|
|
431
|
+
readonly startedAtMs: number;
|
|
432
|
+
readonly endedAtMs: number;
|
|
433
|
+
}) => any;
|
|
434
|
+
readonly Accepted: (args: {
|
|
435
|
+
readonly _tag: "Accepted";
|
|
436
|
+
readonly call: ToolCall;
|
|
437
|
+
readonly result: ToolResult;
|
|
438
|
+
readonly startedAtMs: number;
|
|
439
|
+
readonly endedAtMs: number;
|
|
440
|
+
}) => any;
|
|
427
441
|
readonly InputStreaming: (args: {
|
|
428
442
|
readonly _tag: "InputStreaming";
|
|
429
443
|
readonly id: string;
|
|
430
444
|
readonly name?: string;
|
|
431
445
|
readonly input: string;
|
|
432
446
|
}) => any;
|
|
433
|
-
readonly InputReady: (args: {
|
|
434
|
-
readonly _tag: "InputReady";
|
|
435
|
-
readonly call: ToolCall;
|
|
436
|
-
}) => any;
|
|
437
447
|
readonly ApprovalRequested: (args: {
|
|
438
448
|
readonly _tag: "ApprovalRequested";
|
|
439
449
|
readonly call: ToolCall;
|
|
@@ -444,26 +454,6 @@ declare const AgentToolRun: {
|
|
|
444
454
|
readonly toolCallId: string;
|
|
445
455
|
readonly reason: string;
|
|
446
456
|
}) => any;
|
|
447
|
-
readonly Executing: (args: {
|
|
448
|
-
readonly _tag: "Executing";
|
|
449
|
-
readonly call: ToolCall;
|
|
450
|
-
readonly startedAtMs: number; /** Preserve witnessed interaction acceptance across transport interruptions. */
|
|
451
|
-
readonly interaction?: true;
|
|
452
|
-
}) => any;
|
|
453
|
-
readonly Completed: (args: {
|
|
454
|
-
readonly _tag: "Completed";
|
|
455
|
-
readonly call: ToolCall;
|
|
456
|
-
readonly result: ToolResult;
|
|
457
|
-
readonly startedAtMs: number;
|
|
458
|
-
readonly endedAtMs: number;
|
|
459
|
-
}) => any;
|
|
460
|
-
readonly Accepted: (args: {
|
|
461
|
-
readonly _tag: "Accepted";
|
|
462
|
-
readonly call: ToolCall;
|
|
463
|
-
readonly result: ToolResult;
|
|
464
|
-
readonly startedAtMs: number;
|
|
465
|
-
readonly endedAtMs: number;
|
|
466
|
-
}) => any;
|
|
467
457
|
readonly Errored: (args: {
|
|
468
458
|
readonly _tag: "Errored";
|
|
469
459
|
readonly call: ToolCall;
|
|
@@ -475,7 +465,17 @@ declare const AgentToolRun: {
|
|
|
475
465
|
readonly call: ToolCall;
|
|
476
466
|
readonly result: ToolResult;
|
|
477
467
|
}) => any;
|
|
478
|
-
|
|
468
|
+
readonly InputReady: (args: {
|
|
469
|
+
readonly _tag: "InputReady";
|
|
470
|
+
readonly call: ToolCall;
|
|
471
|
+
}) => any;
|
|
472
|
+
readonly Executing: (args: {
|
|
473
|
+
readonly _tag: "Executing";
|
|
474
|
+
readonly call: ToolCall;
|
|
475
|
+
readonly startedAtMs: number; /** Preserve witnessed interaction acceptance across transport interruptions. */
|
|
476
|
+
readonly interaction?: true;
|
|
477
|
+
}) => any;
|
|
478
|
+
}>(value: AgentToolRun, cases: Cases): import("effect/Unify").Unify<ReturnType<Cases["QuestionRequested" | "QuestionAnswered" | "QuestionCancelled" | "InputRequested" | "InputSubmitted" | "InputCancelled" | "InteractionRequested" | "InteractionSubmitted" | "InteractionCancelled" | "Completed" | "Accepted" | "InputStreaming" | "ApprovalRequested" | "Denied" | "Errored" | "ProviderCompleted" | "InputReady" | "Executing"]>>;
|
|
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,IAAA;EAAA,SACA,EAAA;EAAA,SACA,IAAA;EAAA,SACA,KAAA;AAAA;EAAA,SAEA,IAAA;EAAA,SAA6B,IAAA,EAAM,QAAA;AAAA;EAAA,SAEnC,IAAA;EAAA,SACA,IAAA,EAAM,QAAA;EAAA,SACN,OAAA,GAAU,mBAAA;AAAA;EAAA,SAEV,IAAA;EAAA,SAAyB,UAAA;EAAA,S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their preview.
|
|
24
24
|
*/
|
|
25
25
|
readonly approvalPreviews?: Readonly<Record<string, ToolApprovalPreviewer>>;
|
|
26
|
+
/** The requests of the pause being resumed (`AgentAwaitingInput.requests`). An unanswered
|
|
27
|
+
* approval request listed here stays pending even when its tool no longer requires approval.
|
|
28
|
+
*/
|
|
29
|
+
readonly awaitingRequests?: ReadonlyArray<HitlRequest>;
|
|
30
|
+
/** Whether the transcript's pending tool calls resume a pause. Default: they do when
|
|
31
|
+
* `hitlResponses`, `awaitingRequests` or an `interactionHost` is given (otherwise a new model
|
|
32
|
+
* turn runs). `true` resumes them even without responses; `false` prepares them as a fresh
|
|
33
|
+
* batch (current policy, no recorded approval responses consulted).
|
|
34
|
+
*/
|
|
35
|
+
readonly resume?: boolean;
|
|
26
36
|
readonly model: string;
|
|
27
37
|
readonly reasoningEffort?: AgentReasoningEffort;
|
|
28
|
-
readonly capabilities?: AgentModelCapabilities;
|
|
38
|
+
readonly capabilities?: AgentModelCapabilities; /** Forwarded as `LLMRequest.cacheKey` on every model request of this run. */
|
|
39
|
+
readonly cacheKey?: string;
|
|
29
40
|
};
|
|
30
41
|
type ModelTurnConfig = RunConfig & {
|
|
31
42
|
readonly turn: number;
|
|
@@ -41,6 +52,18 @@ type ToolBatchConfig = {
|
|
|
41
52
|
* ResolvedToolSet.approvalPreviews).
|
|
42
53
|
*/
|
|
43
54
|
readonly approvalPreviews?: Readonly<Record<string, ToolApprovalPreviewer>>;
|
|
55
|
+
/** The requests of the pause being resumed (`AgentAwaitingInput.requests`). An unanswered
|
|
56
|
+
* approval request listed here stays pending even when its tool no longer requires approval.
|
|
57
|
+
* A batch with `awaitingRequests` or any `hitlResponses` is a resume (recorded answers win
|
|
58
|
+
* over the current policy); pass only the responses of the batch being resumed, or set
|
|
59
|
+
* `resume`.
|
|
60
|
+
*/
|
|
61
|
+
readonly awaitingRequests?: ReadonlyArray<HitlRequest>;
|
|
62
|
+
/** Whether this batch resumes a pause (default: `awaitingRequests` given, or any
|
|
63
|
+
* `hitlResponses`). Set `false` for a new model turn's batch even when passing responses: a
|
|
64
|
+
* provider may reuse call ids, and only a resume lets recorded answers override the policy.
|
|
65
|
+
*/
|
|
66
|
+
readonly resume?: boolean;
|
|
44
67
|
readonly model?: string;
|
|
45
68
|
readonly createdMessages?: ReadonlyArray<AgentMessage>;
|
|
46
69
|
readonly turn?: number;
|
|
@@ -87,6 +110,17 @@ declare const prepareToolBatch: (input: {
|
|
|
87
110
|
* is pending, at most 8 at a time.
|
|
88
111
|
*/
|
|
89
112
|
readonly approvalPreviews?: Readonly<Record<string, ToolApprovalPreviewer>>;
|
|
113
|
+
/** The requests of the pause being resumed (`AgentAwaitingInput.requests`). An unanswered
|
|
114
|
+
* approval request listed here stays pending even when its tool no longer requires approval;
|
|
115
|
+
* a recorded answer always wins over the current policy.
|
|
116
|
+
*/
|
|
117
|
+
readonly awaitingRequests?: ReadonlyArray<HitlRequest>;
|
|
118
|
+
/** Whether this batch resumes a pause (default: `awaitingRequests` given, or any `responses`).
|
|
119
|
+
* Only a resume consults recorded approvals and the pause; a fresh batch (a new model turn,
|
|
120
|
+
* whose provider may reuse call ids) never settles an approval from `responses`: the current
|
|
121
|
+
* policy decides, and a gated call asks again.
|
|
122
|
+
*/
|
|
123
|
+
readonly resume?: boolean | undefined;
|
|
90
124
|
}) => Effect.Effect<PreparedToolBatch, ToolError>;
|
|
91
125
|
declare const runModelTurn: (config: ModelTurnConfig) => Stream.Stream<AgentEvent, AgentLoopError, ContextTransformer | LLMProvider | LoopConfig>;
|
|
92
126
|
declare const runToolBatch: (config: ToolBatchConfig) => Stream.Stream<AgentEvent, AgentLoopError, LoopConfig | ToolExecutor>;
|
package/dist/loop/run.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run.d.mts","names":[],"sources":["../../src/loop/run.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"run.d.mts","names":[],"sources":["../../src/loop/run.ts"],"mappings":";;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MAAA,CAAO,UAAA,EAAY,cAAA,EAAgB,kBAAA,GAAqB,WAAA,GAAc,UAAA;AAAA,cAuBnE,YAAA,GACX,MAAA,EAAQ,eAAA,KACP,MAAA,CAAO,MAAA,CAAO,UAAA,EAAY,cAAA,EAAgB,UAAA,GAAa,YAAA;AAAA,cAuD7C,GAAA,GACX,MAAA,EAAQ,SAAA,KACP,MAAA,CAAO,MAAA,CACR,UAAA,EACA,cAAA,EACA,kBAAA,GAAqB,WAAA,GAAc,UAAA,GAAa,YAAA"}
|
package/dist/loop/run.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import "../protocol/change-preview.mjs";
|
|
|
8
8
|
import { truncateCodePoints } from "../protocol/bounded-text.mjs";
|
|
9
9
|
import { validInteractionReceipt as validInteractionReceipt$1 } from "../protocol/tool.mjs";
|
|
10
10
|
import { withToolArgumentsErrorHint } from "../protocol/tool-argument-hints.mjs";
|
|
11
|
-
import { Clock, Data, Effect, Match, Option, Predicate, Ref, Stream } from "effect";
|
|
11
|
+
import { Array as Array$1, Clock, Data, Effect, Match, Option, Predicate, Ref, Stream, Struct } from "effect";
|
|
12
12
|
import * as Schema$1 from "effect/Schema";
|
|
13
13
|
import { AgentAwaitingInput, AgentEnd, AgentRetry, AgentStart, AssistantMessageEvent, InputRequest, InputRequested, InteractionRequest, InteractionRequested, InteractionResponse, LLMReasoningDelta, LLMStreamEnd, LLMStreamStart, LLMTextDelta, ProviderToolResult, QuestionRequest, QuestionRequested, QuestionToolParams, SubagentCompleted, SubagentStarted, ToolApprovalRequest, ToolApprovalRequested, ToolExecutionAccepted, ToolExecutionCompleted, ToolExecutionError, ToolExecutionStarted, ToolInputDelta, ToolInputEnd, ToolInputStart, ToolResult, TurnEnd, TurnStart, UsageUpdate, addAgentUsage, assistantHostToolCalls, contentParts, contentPreview, decodeBackgroundToolInput, formatInputResponseContent, formatQuestionResponseContent, hitlResponseEvent, inputRequestId, inputResponseStructuredContent, interactionRequestId, makeSubagentRunId, providerToolDefs, questionResponseStructuredContent, toolResultMessageFromResult, zeroAgentUsage } from "@yolk-sdk/agent/protocol";
|
|
14
14
|
//#region src/loop/run.ts
|
|
@@ -198,6 +198,26 @@ const questionRequestId = (call) => `question:${call.id}`;
|
|
|
198
198
|
const matchesApproval = (response, call, tools) => response.toolCallId === call.id && response.requestId === approvalRequestId(call, tools);
|
|
199
199
|
const matchesQuestion = (response, call) => response.toolCallId === call.id && response.requestId === questionRequestId(call);
|
|
200
200
|
const approvalResponseFor = (responses, call, tools) => responses.flatMap((response) => Predicate.isTagged(response, "ToolApprovalResponse") && matchesApproval(response, call, tools) ? [response] : [])[0];
|
|
201
|
+
/** Resume only: a denial for this call under another approval id of the same call (its tool's
|
|
202
|
+
* execution mode changed since the request) still denies. Approvals need the exact id.
|
|
203
|
+
*/
|
|
204
|
+
const callDenialFor = (responses, call) => responses.flatMap((response) => Predicate.isTagged(response, "ToolApprovalResponse") && response.decision === "denied" && response.toolCallId === call.id && (response.requestId === `approval:${call.id}` || response.requestId.startsWith(`approval:${call.id}:`)) ? [response] : [])[0];
|
|
205
|
+
const outstandingApprovalFor = (awaiting, call) => awaiting.flatMap((request) => Predicate.isTagged(request, "ToolApprovalRequest") && request.toolCallId === call.id ? [request] : [])[0];
|
|
206
|
+
const canonicalParams = (params) => Schema$1.decodeUnknownOption(Schema$1.Json)(params).pipe(Option.map(canonicalJson));
|
|
207
|
+
const sameParams = (left, right) => {
|
|
208
|
+
const leftJson = canonicalParams(left);
|
|
209
|
+
const rightJson = canonicalParams(right);
|
|
210
|
+
return Option.isSome(leftJson) && Option.isSome(rightJson) && leftJson.value === rightJson.value;
|
|
211
|
+
};
|
|
212
|
+
/** The outstanding request, when it still describes this call exactly, without its preview
|
|
213
|
+
* (recomputed only while the tool has a previewer).
|
|
214
|
+
*/
|
|
215
|
+
const reusableApprovalRequest = (outstanding, call, tools) => outstanding !== void 0 && outstanding.call.name === call.name && sameParams(outstanding.call.params, call.params) && outstanding.requestId === approvalRequestId(call, tools) ? ToolApprovalRequest.make({
|
|
216
|
+
requestId: outstanding.requestId,
|
|
217
|
+
toolCallId: outstanding.toolCallId,
|
|
218
|
+
call,
|
|
219
|
+
policy: outstanding.policy
|
|
220
|
+
}) : void 0;
|
|
201
221
|
const questionResponseFor = (responses, call) => responses.flatMap((response) => Predicate.isTagged(response, "QuestionResponse") && matchesQuestion(response, call) ? [response] : [])[0];
|
|
202
222
|
const toolApprovalRequest = (tools, call) => ToolApprovalRequest.make({
|
|
203
223
|
requestId: approvalRequestId(call, tools),
|
|
@@ -262,7 +282,23 @@ const prepareQuestionCall = (call, index, responses) => Effect.gen(function* ()
|
|
|
262
282
|
events: [QuestionRequested.make({ request })]
|
|
263
283
|
});
|
|
264
284
|
});
|
|
265
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Approval of one call. A fresh batch (a new model turn) follows the current policy and never
|
|
287
|
+
* consults recorded answers: a provider may reuse call ids, so an earlier answer must never
|
|
288
|
+
* settle a new call (a gated call asks again). A resume batch binds the call to its pause
|
|
289
|
+
* instead, because hosts re-read tool policy at execution and the policy can change between the
|
|
290
|
+
* request and the answer:
|
|
291
|
+
*
|
|
292
|
+
* 1. A recorded answer wins: the first exact-match response settles the call (`denied`: the
|
|
293
|
+
* denied result, never executed; `approved`: executed). A denial for the same call under
|
|
294
|
+
* another approval id of that call (`approval:<id>` or `approval:<id>:…`) also denies.
|
|
295
|
+
* 2. Else an outstanding request from the resumed pause (`awaitingRequests`) stays pending: the
|
|
296
|
+
* same request while it still describes the call (name, canonical params, request id), else a
|
|
297
|
+
* fresh one.
|
|
298
|
+
* 3. Else the current policy decides: `manual` asks, anything else executes.
|
|
299
|
+
*/
|
|
300
|
+
const prepareApprovalCall = (input) => {
|
|
301
|
+
const { tools, call, index, responses } = input;
|
|
266
302
|
const envelope = backgroundEnvelope(tools, call);
|
|
267
303
|
if (envelope !== void 0 && Option.isNone(envelope)) return PreparedToolCall.Result({
|
|
268
304
|
index,
|
|
@@ -274,31 +310,37 @@ const prepareApprovalCall = (tools, call, index, responses) => {
|
|
|
274
310
|
content: "Expected exactly execution (foreground or background) and arguments."
|
|
275
311
|
})
|
|
276
312
|
});
|
|
277
|
-
if (!approvalRequired(tools, call)) return PreparedToolCall.Execute({
|
|
313
|
+
if (!input.resume && !approvalRequired(tools, call)) return PreparedToolCall.Execute({
|
|
278
314
|
index,
|
|
279
315
|
call,
|
|
280
316
|
events: []
|
|
281
317
|
});
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
if (response === void 0) return PreparedToolCall.Pending({
|
|
285
|
-
request,
|
|
286
|
-
events: [ToolApprovalRequested.make({
|
|
287
|
-
call,
|
|
288
|
-
request
|
|
289
|
-
})]
|
|
290
|
-
});
|
|
291
|
-
if (response.decision === "denied") return PreparedToolCall.Result({
|
|
318
|
+
const response = input.resume ? approvalResponseFor(responses, call, tools) ?? callDenialFor(responses, call) : void 0;
|
|
319
|
+
if (response?.decision === "denied") return PreparedToolCall.Result({
|
|
292
320
|
index,
|
|
293
321
|
call,
|
|
294
322
|
result: deniedToolResult(call, response),
|
|
295
323
|
events: [hitlResponseEvent(response)]
|
|
296
324
|
});
|
|
297
|
-
return PreparedToolCall.Execute({
|
|
325
|
+
if (response !== void 0) return PreparedToolCall.Execute({
|
|
298
326
|
index,
|
|
299
327
|
call,
|
|
300
328
|
events: [hitlResponseEvent(response)]
|
|
301
329
|
});
|
|
330
|
+
const outstanding = input.resume ? outstandingApprovalFor(input.awaiting, call) : void 0;
|
|
331
|
+
if (outstanding === void 0 && !approvalRequired(tools, call)) return PreparedToolCall.Execute({
|
|
332
|
+
index,
|
|
333
|
+
call,
|
|
334
|
+
events: []
|
|
335
|
+
});
|
|
336
|
+
const request = reusableApprovalRequest(outstanding, call, tools) ?? toolApprovalRequest(tools, call);
|
|
337
|
+
return PreparedToolCall.Pending({
|
|
338
|
+
request,
|
|
339
|
+
events: [ToolApprovalRequested.make({
|
|
340
|
+
call,
|
|
341
|
+
request
|
|
342
|
+
})]
|
|
343
|
+
});
|
|
302
344
|
};
|
|
303
345
|
/** Most approval change previews one batch computes at once. */
|
|
304
346
|
const approvalPreviewConcurrency = 8;
|
|
@@ -533,7 +575,14 @@ const prepareModelToolCall = (input) => !input.receipts.has(input.call.id) && to
|
|
|
533
575
|
content: "Question tool is unavailable",
|
|
534
576
|
isError: true
|
|
535
577
|
})
|
|
536
|
-
})) : Effect.succeed(prepareApprovalCall(
|
|
578
|
+
})) : Effect.succeed(prepareApprovalCall({
|
|
579
|
+
tools: input.tools,
|
|
580
|
+
call: input.call,
|
|
581
|
+
index: input.index,
|
|
582
|
+
responses: input.responses,
|
|
583
|
+
awaiting: input.awaiting,
|
|
584
|
+
resume: input.resume
|
|
585
|
+
}));
|
|
537
586
|
/** Preflight the entire batch before dispatching ANY call. Pending requests fence all execution.
|
|
538
587
|
* Fails (`ToolError` `unavailable`) only when host storage an interaction call validator reads is
|
|
539
588
|
* unavailable: the batch fails closed, like `loadInteractionReceipts`, and nothing runs.
|
|
@@ -542,12 +591,15 @@ const prepareToolBatch = (input) => Effect.gen(function* () {
|
|
|
542
591
|
const handlers = input.inputs ?? {};
|
|
543
592
|
const preflights = input.interactions ?? {};
|
|
544
593
|
const previewers = input.approvalPreviews ?? {};
|
|
594
|
+
const resume = input.resume ?? (input.awaitingRequests !== void 0 || input.responses.length > 0);
|
|
545
595
|
const planned = yield* Effect.forEach(input.calls, (call, index) => prepareToolCall({
|
|
546
596
|
tools: input.tools,
|
|
547
597
|
responses: input.responses,
|
|
548
598
|
handlers,
|
|
549
599
|
preflights,
|
|
550
600
|
receipts: input.interactionReceipts ?? /* @__PURE__ */ new Map(),
|
|
601
|
+
awaiting: resume ? input.awaitingRequests ?? [] : [],
|
|
602
|
+
resume,
|
|
551
603
|
call,
|
|
552
604
|
index
|
|
553
605
|
}));
|
|
@@ -574,10 +626,16 @@ const syntheticToolCompletionEvents = (prepared) => prepared.flatMap((item) => P
|
|
|
574
626
|
result: item.result
|
|
575
627
|
})] : []);
|
|
576
628
|
const toolResultIds = (messages) => new Set(messages.flatMap((message) => Predicate.isTagged(message, "ToolResult") ? [message.toolCallId] : []));
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
629
|
+
/**
|
|
630
|
+
* Host tool calls without a result. A call is settled only by a result in its result window: the
|
|
631
|
+
* consecutive `ToolResult` messages right after its assistant message (the transcript rule of
|
|
632
|
+
* `danglingHostToolCalls`). A provider-reused call id is never settled by an earlier call's result.
|
|
633
|
+
*/
|
|
634
|
+
const pendingHostToolCalls = (messages) => messages.flatMap((message, index) => {
|
|
635
|
+
if (!Predicate.isTagged(message, "Assistant")) return [];
|
|
636
|
+
const completed = toolResultIds(Array$1.takeWhile(messages.slice(index + 1), (later) => Predicate.isTagged(later, "ToolResult")));
|
|
637
|
+
return assistantHostToolCalls(message).filter((call) => !completed.has(call.id));
|
|
638
|
+
});
|
|
581
639
|
const nonEmptyHitlRequests = (requests) => {
|
|
582
640
|
const first = requests[0];
|
|
583
641
|
return first === void 0 ? void 0 : [first, ...requests.slice(1)];
|
|
@@ -652,6 +710,7 @@ const makeAfterLlmStream = (input, llmEventsRef) => Stream.unwrap(Effect.gen(fun
|
|
|
652
710
|
const toolResultMessages = yield* Ref.make([]);
|
|
653
711
|
const prepared = yield* prepareToolBatch({
|
|
654
712
|
tools: input.config.tools,
|
|
713
|
+
resume: false,
|
|
655
714
|
responses: input.config.hitlResponses ?? [],
|
|
656
715
|
calls: completion.toolCalls,
|
|
657
716
|
inputs: input.config.inputs,
|
|
@@ -699,6 +758,7 @@ const makeAfterLlmStream = (input, llmEventsRef) => Stream.unwrap(Effect.gen(fun
|
|
|
699
758
|
reason: completion.stopReason
|
|
700
759
|
})).pipe(Stream.concat(makeTurnStream({
|
|
701
760
|
...input,
|
|
761
|
+
config: withoutConsumedAnswers(input.config),
|
|
702
762
|
currentMessages: [
|
|
703
763
|
...input.currentMessages,
|
|
704
764
|
assistantMessage,
|
|
@@ -723,14 +783,19 @@ const makeModelOnlyAfterLlmStream = (input, llmEventsRef) => Stream.unwrap(Effec
|
|
|
723
783
|
})
|
|
724
784
|
]);
|
|
725
785
|
}));
|
|
786
|
+
const providerRequest = (config, messages) => {
|
|
787
|
+
const request = {
|
|
788
|
+
messages,
|
|
789
|
+
tools: providerToolDefs(config.tools),
|
|
790
|
+
model: config.model,
|
|
791
|
+
reasoningEffort: config.reasoningEffort,
|
|
792
|
+
systemPrompt: config.systemPrompt
|
|
793
|
+
};
|
|
794
|
+
if (config.cacheKey !== void 0) request.cacheKey = config.cacheKey;
|
|
795
|
+
return request;
|
|
796
|
+
};
|
|
726
797
|
const makeLlmStream = (input, llmEvents, result) => {
|
|
727
|
-
const makeStream = () => input.provider.stream(
|
|
728
|
-
messages: result.messages,
|
|
729
|
-
tools: providerToolDefs(input.config.tools),
|
|
730
|
-
model: input.config.model,
|
|
731
|
-
reasoningEffort: input.config.reasoningEffort,
|
|
732
|
-
systemPrompt: input.config.systemPrompt
|
|
733
|
-
});
|
|
798
|
+
const makeStream = () => input.provider.stream(providerRequest(input.config, result.messages));
|
|
734
799
|
return Stream.fromIterable(result.events).pipe(Stream.concat(withProviderRetries(makeStream(), input.loopConfig, makeStream, 1))).pipe(Stream.tap((event) => {
|
|
735
800
|
if (!isLlmEvent(event)) return Effect.void;
|
|
736
801
|
const appendEvent = Ref.update(llmEvents, (events) => [...events, event]);
|
|
@@ -739,13 +804,7 @@ const makeLlmStream = (input, llmEvents, result) => {
|
|
|
739
804
|
}), Stream.flatMap((event) => Predicate.isTagged(event, "AgentRetry") ? Stream.make(event) : isLlmEvent(event) ? Stream.fromIterable(toLlmEvent(event)) : Stream.make(event)), Stream.concat(makeAfterLlmStream(input, llmEvents)));
|
|
740
805
|
};
|
|
741
806
|
const makeModelOnlyLlmStream = (input, llmEvents, result) => {
|
|
742
|
-
const makeStream = () => input.provider.stream(
|
|
743
|
-
messages: result.messages,
|
|
744
|
-
tools: providerToolDefs(input.config.tools),
|
|
745
|
-
model: input.config.model,
|
|
746
|
-
reasoningEffort: input.config.reasoningEffort,
|
|
747
|
-
systemPrompt: input.config.systemPrompt
|
|
748
|
-
});
|
|
807
|
+
const makeStream = () => input.provider.stream(providerRequest(input.config, result.messages));
|
|
749
808
|
return Stream.fromIterable(result.events).pipe(Stream.concat(withProviderRetries(makeStream(), input.loopConfig, makeStream, 1))).pipe(Stream.tap((event) => {
|
|
750
809
|
if (!isLlmEvent(event)) return Effect.void;
|
|
751
810
|
const appendEvent = Ref.update(llmEvents, (events) => [...events, event]);
|
|
@@ -753,6 +812,15 @@ const makeModelOnlyLlmStream = (input, llmEvents, result) => {
|
|
|
753
812
|
return Ref.update(input.usage, (usage) => addAgentUsage(usage, event.usage)).pipe(Effect.flatMap(() => appendEvent));
|
|
754
813
|
}), Stream.flatMap((event) => Predicate.isTagged(event, "AgentRetry") ? Stream.make(event) : isLlmEvent(event) ? Stream.fromIterable(toLlmEvent(event)) : Stream.make(event)), Stream.concat(makeModelOnlyAfterLlmStream(input, llmEvents)));
|
|
755
814
|
};
|
|
815
|
+
/**
|
|
816
|
+
* The config of the model turns after a batch settled: answers and the pause are consumed by the
|
|
817
|
+
* batch they settled and never reach a later turn, where a provider may reuse a call id.
|
|
818
|
+
*/
|
|
819
|
+
const withoutConsumedAnswers = (config) => Struct.omit(config, [
|
|
820
|
+
"hitlResponses",
|
|
821
|
+
"awaitingRequests",
|
|
822
|
+
"resume"
|
|
823
|
+
]);
|
|
756
824
|
const makeTurnStream = (input) => Stream.suspend(() => {
|
|
757
825
|
if (input.turn > input.loopConfig.maxTurns) return Stream.fail(new AbortError({ reason: "max_turns" }));
|
|
758
826
|
const llmStream = Stream.unwrap(Effect.gen(function* () {
|
|
@@ -765,15 +833,19 @@ const makeTurnStream = (input) => Stream.suspend(() => {
|
|
|
765
833
|
});
|
|
766
834
|
const makePendingToolResumeStream = (input) => Stream.unwrap(Effect.gen(function* () {
|
|
767
835
|
const pendingCalls = pendingHostToolCalls(input.currentMessages);
|
|
768
|
-
|
|
836
|
+
const detected = (input.config.hitlResponses ?? []).length > 0 || (input.config.awaitingRequests ?? []).length > 0 || input.config.interactionHost !== void 0;
|
|
837
|
+
if (pendingCalls.length === 0 || input.config.resume === void 0 && !detected) return makeTurnStream(input);
|
|
838
|
+
const resume = input.config.resume ?? true;
|
|
769
839
|
const toolResultMessages = yield* Ref.make([]);
|
|
770
840
|
const prepared = yield* prepareToolBatch({
|
|
771
841
|
tools: input.config.tools,
|
|
842
|
+
resume,
|
|
772
843
|
responses: input.config.hitlResponses ?? [],
|
|
773
844
|
calls: pendingCalls,
|
|
774
845
|
inputs: input.config.inputs,
|
|
775
846
|
interactions: input.config.interactions,
|
|
776
847
|
approvalPreviews: input.config.approvalPreviews,
|
|
848
|
+
awaitingRequests: input.config.awaitingRequests,
|
|
777
849
|
interactionReceipts: yield* loadInteractionReceipts(pendingCalls, input.config.interactionHost)
|
|
778
850
|
});
|
|
779
851
|
if (prepared.resultMessages.length > 0) yield* Ref.update(toolResultMessages, (results) => [...results, ...prepared.resultMessages]);
|
|
@@ -808,6 +880,7 @@ const makePendingToolResumeStream = (input) => Stream.unwrap(Effect.gen(function
|
|
|
808
880
|
const orderedResults = orderedToolResultMessages(results);
|
|
809
881
|
return Ref.update(input.createdMessages, (messages) => [...messages, ...orderedResults]).pipe(Effect.as(makeTurnStream({
|
|
810
882
|
...input,
|
|
883
|
+
config: withoutConsumedAnswers(input.config),
|
|
811
884
|
currentMessages: [...input.currentMessages, ...orderedResults]
|
|
812
885
|
})));
|
|
813
886
|
})));
|
|
@@ -852,6 +925,8 @@ const runToolBatch = (config) => Stream.unwrap(Effect.gen(function* () {
|
|
|
852
925
|
inputs: config.inputs,
|
|
853
926
|
interactions: config.interactions,
|
|
854
927
|
approvalPreviews: config.approvalPreviews,
|
|
928
|
+
awaitingRequests: config.awaitingRequests,
|
|
929
|
+
resume: config.resume,
|
|
855
930
|
interactionReceipts: yield* loadInteractionReceipts(config.calls, config.interactionHost)
|
|
856
931
|
});
|
|
857
932
|
const hasPendingRequests = prepared.pendingRequests.length > 0;
|