@yolk-sdk/agent 0.0.1-canary.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/LICENSE +21 -0
- package/README.md +93 -0
- package/dist/client/index.d.mts +3 -0
- package/dist/client/index.mjs +3 -0
- package/dist/client/state.d.mts +99 -0
- package/dist/client/state.d.mts.map +1 -0
- package/dist/client/state.mjs +245 -0
- package/dist/client/state.mjs.map +1 -0
- package/dist/client/transport.d.mts +67 -0
- package/dist/client/transport.d.mts.map +1 -0
- package/dist/client/transport.mjs +219 -0
- package/dist/client/transport.mjs.map +1 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/loop/accumulator.d.mts +11 -0
- package/dist/loop/accumulator.d.mts.map +1 -0
- package/dist/loop/accumulator.mjs +40 -0
- package/dist/loop/accumulator.mjs.map +1 -0
- package/dist/loop/error.d.mts +36 -0
- package/dist/loop/error.d.mts.map +1 -0
- package/dist/loop/error.mjs +84 -0
- package/dist/loop/error.mjs.map +1 -0
- package/dist/loop/index.d.mts +9 -0
- package/dist/loop/index.mjs +9 -0
- package/dist/loop/llm-event.d.mts +44 -0
- package/dist/loop/llm-event.d.mts.map +1 -0
- package/dist/loop/llm-event.mjs +34 -0
- package/dist/loop/llm-event.mjs.map +1 -0
- package/dist/loop/run.d.mts +37 -0
- package/dist/loop/run.d.mts.map +1 -0
- package/dist/loop/run.mjs +624 -0
- package/dist/loop/run.mjs.map +1 -0
- package/dist/loop/services/context-transformer.d.mts +18 -0
- package/dist/loop/services/context-transformer.d.mts.map +1 -0
- package/dist/loop/services/context-transformer.mjs +12 -0
- package/dist/loop/services/context-transformer.mjs.map +1 -0
- package/dist/loop/services/llm-provider.d.mts +20 -0
- package/dist/loop/services/llm-provider.d.mts.map +1 -0
- package/dist/loop/services/llm-provider.mjs +7 -0
- package/dist/loop/services/llm-provider.mjs.map +1 -0
- package/dist/loop/services/loop-config.d.mts +17 -0
- package/dist/loop/services/loop-config.d.mts.map +1 -0
- package/dist/loop/services/loop-config.mjs +15 -0
- package/dist/loop/services/loop-config.mjs.map +1 -0
- package/dist/loop/services/tool-executor.d.mts +12 -0
- package/dist/loop/services/tool-executor.d.mts.map +1 -0
- package/dist/loop/services/tool-executor.mjs +7 -0
- package/dist/loop/services/tool-executor.mjs.map +1 -0
- package/dist/loop/testing/faux-provider.d.mts +31 -0
- package/dist/loop/testing/faux-provider.d.mts.map +1 -0
- package/dist/loop/testing/faux-provider.mjs +47 -0
- package/dist/loop/testing/faux-provider.mjs.map +1 -0
- package/dist/loop/testing/index.d.mts +3 -0
- package/dist/loop/testing/index.mjs +3 -0
- package/dist/loop/testing/test-tool-executor.d.mts +10 -0
- package/dist/loop/testing/test-tool-executor.d.mts.map +1 -0
- package/dist/loop/testing/test-tool-executor.mjs +21 -0
- package/dist/loop/testing/test-tool-executor.mjs.map +1 -0
- package/dist/protocol/capability.d.mts +20 -0
- package/dist/protocol/capability.d.mts.map +1 -0
- package/dist/protocol/capability.mjs +34 -0
- package/dist/protocol/capability.mjs.map +1 -0
- package/dist/protocol/content.d.mts +31 -0
- package/dist/protocol/content.d.mts.map +1 -0
- package/dist/protocol/content.mjs +52 -0
- package/dist/protocol/content.mjs.map +1 -0
- package/dist/protocol/event.d.mts +228 -0
- package/dist/protocol/event.d.mts.map +1 -0
- package/dist/protocol/event.mjs +217 -0
- package/dist/protocol/event.mjs.map +1 -0
- package/dist/protocol/index.d.mts +14 -0
- package/dist/protocol/index.d.mts.map +1 -0
- package/dist/protocol/index.mjs +9 -0
- package/dist/protocol/message.d.mts +53 -0
- package/dist/protocol/message.d.mts.map +1 -0
- package/dist/protocol/message.mjs +49 -0
- package/dist/protocol/message.mjs.map +1 -0
- package/dist/protocol/reasoning.d.mts +8 -0
- package/dist/protocol/reasoning.d.mts.map +1 -0
- package/dist/protocol/reasoning.mjs +13 -0
- package/dist/protocol/reasoning.mjs.map +1 -0
- package/dist/protocol/session.d.mts +39 -0
- package/dist/protocol/session.d.mts.map +1 -0
- package/dist/protocol/session.mjs +38 -0
- package/dist/protocol/session.mjs.map +1 -0
- package/dist/protocol/tool.d.mts +101 -0
- package/dist/protocol/tool.d.mts.map +1 -0
- package/dist/protocol/tool.mjs +102 -0
- package/dist/protocol/tool.mjs.map +1 -0
- package/dist/protocol/usage.d.mts +26 -0
- package/dist/protocol/usage.d.mts.map +1 -0
- package/dist/protocol/usage.mjs +40 -0
- package/dist/protocol/usage.mjs.map +1 -0
- package/dist/runtime/error.d.mts +29 -0
- package/dist/runtime/error.d.mts.map +1 -0
- package/dist/runtime/error.mjs +46 -0
- package/dist/runtime/error.mjs.map +1 -0
- package/dist/runtime/index.d.mts +9 -0
- package/dist/runtime/index.d.mts.map +1 -0
- package/dist/runtime/index.mjs +4 -0
- package/dist/runtime/run-runtime.d.mts +47 -0
- package/dist/runtime/run-runtime.d.mts.map +1 -0
- package/dist/runtime/run-runtime.mjs +112 -0
- package/dist/runtime/run-runtime.mjs.map +1 -0
- package/dist/runtime/session-event-store.d.mts +75 -0
- package/dist/runtime/session-event-store.d.mts.map +1 -0
- package/dist/runtime/session-event-store.mjs +124 -0
- package/dist/runtime/session-event-store.mjs.map +1 -0
- package/dist/tools/index.d.mts +4 -0
- package/dist/tools/index.mjs +4 -0
- package/dist/tools/question.d.mts +21 -0
- package/dist/tools/question.d.mts.map +1 -0
- package/dist/tools/question.mjs +41 -0
- package/dist/tools/question.mjs.map +1 -0
- package/dist/tools/registry.d.mts +61 -0
- package/dist/tools/registry.d.mts.map +1 -0
- package/dist/tools/registry.mjs +113 -0
- package/dist/tools/registry.mjs.map +1 -0
- package/dist/tools/task.d.mts +34 -0
- package/dist/tools/task.d.mts.map +1 -0
- package/dist/tools/task.mjs +81 -0
- package/dist/tools/task.mjs.map +1 -0
- package/package.json +86 -0
- package/src/client/README.md +23 -0
- package/src/client/index.ts +43 -0
- package/src/client/state.ts +380 -0
- package/src/client/transport.ts +517 -0
- package/src/index.ts +2 -0
- package/src/loop/README.md +23 -0
- package/src/loop/accumulator.ts +71 -0
- package/src/loop/error.ts +105 -0
- package/src/loop/index.ts +35 -0
- package/src/loop/llm-event.ts +52 -0
- package/src/loop/run.ts +1237 -0
- package/src/loop/services/context-transformer.ts +24 -0
- package/src/loop/services/llm-provider.ts +20 -0
- package/src/loop/services/loop-config.ts +20 -0
- package/src/loop/services/tool-executor.ts +11 -0
- package/src/loop/testing/faux-provider.ts +94 -0
- package/src/loop/testing/index.ts +3 -0
- package/src/loop/testing/test-tool-executor.ts +28 -0
- package/src/protocol/README.md +24 -0
- package/src/protocol/capability.ts +29 -0
- package/src/protocol/content.ts +76 -0
- package/src/protocol/event.ts +286 -0
- package/src/protocol/index.ts +109 -0
- package/src/protocol/message.ts +86 -0
- package/src/protocol/reasoning.ts +4 -0
- package/src/protocol/session.ts +47 -0
- package/src/protocol/tool.ts +154 -0
- package/src/protocol/usage.ts +48 -0
- package/src/runtime/README.md +44 -0
- package/src/runtime/error.ts +70 -0
- package/src/runtime/index.ts +43 -0
- package/src/runtime/run-runtime.ts +307 -0
- package/src/runtime/session-event-store.ts +254 -0
- package/src/tools/README.md +22 -0
- package/src/tools/index.ts +29 -0
- package/src/tools/question.ts +58 -0
- package/src/tools/registry.ts +228 -0
- package/src/tools/task.ts +132 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yolk SDK contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# @yolk-sdk/agent
|
|
2
|
+
|
|
3
|
+
Domain-free agent protocol, loop, runtime, client, and tool primitives.
|
|
4
|
+
|
|
5
|
+
Root export is intentionally tiny. Import feature APIs from explicit subpaths.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @yolk-sdk/agent@canary effect
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Canary APIs are unstable. Keep all `@yolk-sdk/*` packages on the same version.
|
|
14
|
+
|
|
15
|
+
## Subpaths
|
|
16
|
+
|
|
17
|
+
| Subpath | Purpose |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `@yolk-sdk/agent/protocol` | Wire messages, events, content, usage, tool schemas |
|
|
20
|
+
| `@yolk-sdk/agent/loop` | Stateless LLM/tool loop |
|
|
21
|
+
| `@yolk-sdk/agent/loop/testing` | Faux provider and tool executor test helpers |
|
|
22
|
+
| `@yolk-sdk/agent/runtime` | Transcript or append-backed runtime orchestration |
|
|
23
|
+
| `@yolk-sdk/agent/client` | HTTP/NDJSON transport and client state helpers |
|
|
24
|
+
| `@yolk-sdk/agent/tools` | Tool module registry, `makeTool`, task/question tool contracts |
|
|
25
|
+
|
|
26
|
+
## Imports
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import { UserMessage } from '@yolk-sdk/agent/protocol'
|
|
30
|
+
import { run } from '@yolk-sdk/agent/loop'
|
|
31
|
+
import { runRuntime } from '@yolk-sdk/agent/runtime'
|
|
32
|
+
import { initialAgentClientState } from '@yolk-sdk/agent/client'
|
|
33
|
+
import { makeQuestionToolModule, makeTaskToolModule, resolveTools } from '@yolk-sdk/agent/tools'
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Test helpers live behind their own subpath:
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { FauxProvider, Reply, TestToolExecutor } from '@yolk-sdk/agent/loop/testing'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick start
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { Stream } from 'effect'
|
|
46
|
+
import { UserMessage } from '@yolk-sdk/agent/protocol'
|
|
47
|
+
import { run } from '@yolk-sdk/agent/loop'
|
|
48
|
+
|
|
49
|
+
const program = run({
|
|
50
|
+
messages: [UserMessage.make({ content: 'Hello' })],
|
|
51
|
+
systemPrompt: 'Be helpful.',
|
|
52
|
+
tools: [],
|
|
53
|
+
model: 'gpt-5.5'
|
|
54
|
+
}).pipe(Stream.runCollect)
|
|
55
|
+
|
|
56
|
+
// Provide LLM provider, loop config, context transformer, and tool executor layers in the host app.
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Human-in-the-loop
|
|
60
|
+
|
|
61
|
+
HITL is protocol-level, not UI-level:
|
|
62
|
+
|
|
63
|
+
- Add `approval: { mode: 'manual' }` to a `ToolDef` to pause before execution.
|
|
64
|
+
- `run` / `runRuntime` emit `ToolApprovalRequested` then `AgentAwaitingInput`.
|
|
65
|
+
- Resume by passing `hitlResponses` or using client helpers like `submitToolApprovalResponse`.
|
|
66
|
+
- Denials become model-visible `ToolResult` messages with `isError = true`.
|
|
67
|
+
- Use `makeQuestionToolModule` to expose the package-owned `question` tool; answers resume as structured tool results and model-visible text with selected labels.
|
|
68
|
+
- Approval is a host-enforced per-call gate for normal tools, not a model-callable permission tool or persisted allow-always system.
|
|
69
|
+
|
|
70
|
+
## Host responsibilities
|
|
71
|
+
|
|
72
|
+
- Choose models/providers and map provider streams into protocol events.
|
|
73
|
+
- Persist sessions, transcripts, and append logs.
|
|
74
|
+
- Provide tools, approval policy, auth, storage, and observability.
|
|
75
|
+
- Compact context and decide memory/search policy.
|
|
76
|
+
|
|
77
|
+
## Boundaries
|
|
78
|
+
|
|
79
|
+
- No React, Next.js, provider SDKs, auth, storage drivers, or app concepts.
|
|
80
|
+
- Loop stays stateless: transcript in, events out.
|
|
81
|
+
- Runtime owns generic session orchestration only; host apps own persistence adapters and policy.
|
|
82
|
+
- Tools model generic metadata/execution; host apps own concrete tool catalogs.
|
|
83
|
+
- `task` is the standard subagent delegation tool. Packages define the schema; host apps execute subagents and omit `task` from subagent toolsets in v1.
|
|
84
|
+
|
|
85
|
+
## Testing
|
|
86
|
+
|
|
87
|
+
Use `@yolk-sdk/agent/loop/testing` for deterministic provider/tool tests.
|
|
88
|
+
|
|
89
|
+
## Tree-shaking
|
|
90
|
+
|
|
91
|
+
- ESM package with `sideEffects: false`.
|
|
92
|
+
- Explicit subpath exports only.
|
|
93
|
+
- No top-level env reads, network calls, SDK clients, or service construction.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { AgentClientState, AgentRunStatus, AgentToolRun, AgentTranscript, ApplyAgentEventOptions, appendAgentMessage, applyAgentEvent, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, submitAgentUserMessage } from "./state.mjs";
|
|
2
|
+
import { AgentHttpResponseInfo, AgentTransportError, CancelAgentRunRequest, StreamAgentEventsRequest, StreamAgentRunEventsRequest, StreamCloudflareAgentEventsRequest, SubmitQuestionResponseRequest, SubmitToolApprovalResponseRequest, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitQuestionResponse, submitToolApprovalResponse } from "./transport.mjs";
|
|
3
|
+
export { type AgentClientState, type AgentHttpResponseInfo, type AgentRunStatus, type AgentToolRun, type AgentTranscript, AgentTransportError, type ApplyAgentEventOptions, type CancelAgentRunRequest, type StreamAgentEventsRequest, type StreamAgentRunEventsRequest, type StreamCloudflareAgentEventsRequest, type SubmitQuestionResponseRequest, type SubmitToolApprovalResponseRequest, appendAgentMessage, applyAgentEvent, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitAgentUserMessage, submitQuestionResponse, submitToolApprovalResponse };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { appendAgentMessage, applyAgentEvent, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, submitAgentUserMessage } from "./state.mjs";
|
|
2
|
+
import { AgentTransportError, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitQuestionResponse, submitToolApprovalResponse } from "./transport.mjs";
|
|
3
|
+
export { AgentTransportError, appendAgentMessage, applyAgentEvent, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitAgentUserMessage, submitQuestionResponse, submitToolApprovalResponse };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { AgentEvent, AgentMessage, QuestionRequest, QuestionResponse, ToolCall, ToolResult, UserMessage } from "@yolk-sdk/agent/protocol";
|
|
2
|
+
|
|
3
|
+
//#region src/client/state.d.ts
|
|
4
|
+
type AgentRunStatus = 'idle' | 'running' | 'waiting' | 'done' | 'error' | 'aborted';
|
|
5
|
+
type AgentToolRun = {
|
|
6
|
+
readonly _tag: 'InputStreaming';
|
|
7
|
+
readonly id: string;
|
|
8
|
+
readonly name?: string;
|
|
9
|
+
readonly input: string;
|
|
10
|
+
} | {
|
|
11
|
+
readonly _tag: 'InputReady';
|
|
12
|
+
readonly call: ToolCall;
|
|
13
|
+
} | {
|
|
14
|
+
readonly _tag: 'ApprovalRequested';
|
|
15
|
+
readonly call: ToolCall;
|
|
16
|
+
} | {
|
|
17
|
+
readonly _tag: 'Denied';
|
|
18
|
+
readonly toolCallId: string;
|
|
19
|
+
readonly reason: string;
|
|
20
|
+
} | {
|
|
21
|
+
readonly _tag: 'QuestionRequested';
|
|
22
|
+
readonly request: QuestionRequest;
|
|
23
|
+
} | {
|
|
24
|
+
readonly _tag: 'QuestionAnswered';
|
|
25
|
+
readonly response: QuestionResponse;
|
|
26
|
+
} | {
|
|
27
|
+
readonly _tag: 'QuestionCancelled';
|
|
28
|
+
readonly response: QuestionResponse;
|
|
29
|
+
} | {
|
|
30
|
+
readonly _tag: 'Executing';
|
|
31
|
+
readonly call: ToolCall;
|
|
32
|
+
readonly startedAtMs: number;
|
|
33
|
+
} | {
|
|
34
|
+
readonly _tag: 'Completed';
|
|
35
|
+
readonly call: ToolCall;
|
|
36
|
+
readonly result: ToolResult;
|
|
37
|
+
readonly startedAtMs: number;
|
|
38
|
+
readonly endedAtMs: number;
|
|
39
|
+
} | {
|
|
40
|
+
readonly _tag: 'Errored';
|
|
41
|
+
readonly call: ToolCall;
|
|
42
|
+
readonly message: string;
|
|
43
|
+
readonly endedAtMs: number;
|
|
44
|
+
} | {
|
|
45
|
+
readonly _tag: 'ProviderCompleted';
|
|
46
|
+
readonly call: ToolCall;
|
|
47
|
+
readonly result: ToolResult;
|
|
48
|
+
};
|
|
49
|
+
type AgentClientState = {
|
|
50
|
+
readonly status: AgentRunStatus;
|
|
51
|
+
readonly messages: ReadonlyArray<AgentMessage>;
|
|
52
|
+
readonly liveMessages: ReadonlyArray<AgentMessage>;
|
|
53
|
+
readonly text: string;
|
|
54
|
+
readonly reasoning: string;
|
|
55
|
+
readonly toolRuns: ReadonlyArray<AgentToolRun>;
|
|
56
|
+
readonly error: string | null;
|
|
57
|
+
readonly seenEventIds: ReadonlyArray<string>;
|
|
58
|
+
};
|
|
59
|
+
type ApplyAgentEventOptions = {
|
|
60
|
+
readonly nowMs?: number;
|
|
61
|
+
};
|
|
62
|
+
type AgentTranscript = readonly [AgentMessage, ...Array<AgentMessage>];
|
|
63
|
+
declare const initialAgentClientState: AgentClientState;
|
|
64
|
+
declare const isActiveToolRun: (run: AgentToolRun) => run is {
|
|
65
|
+
readonly _tag: "InputStreaming";
|
|
66
|
+
readonly id: string;
|
|
67
|
+
readonly name?: string;
|
|
68
|
+
readonly input: string;
|
|
69
|
+
} | {
|
|
70
|
+
readonly _tag: "InputReady";
|
|
71
|
+
readonly call: ToolCall;
|
|
72
|
+
} | {
|
|
73
|
+
readonly _tag: "ApprovalRequested";
|
|
74
|
+
readonly call: ToolCall;
|
|
75
|
+
} | {
|
|
76
|
+
readonly _tag: "QuestionRequested";
|
|
77
|
+
readonly request: QuestionRequest;
|
|
78
|
+
} | {
|
|
79
|
+
readonly _tag: "Executing";
|
|
80
|
+
readonly call: ToolCall;
|
|
81
|
+
readonly startedAtMs: number;
|
|
82
|
+
};
|
|
83
|
+
declare const completedToolRuns: (runs: ReadonlyArray<AgentToolRun>) => {
|
|
84
|
+
readonly _tag: "Completed";
|
|
85
|
+
readonly call: ToolCall;
|
|
86
|
+
readonly result: ToolResult;
|
|
87
|
+
readonly startedAtMs: number;
|
|
88
|
+
readonly endedAtMs: number;
|
|
89
|
+
}[];
|
|
90
|
+
declare const appendAgentMessage: (messages: ReadonlyArray<AgentMessage>, message: AgentMessage) => AgentTranscript;
|
|
91
|
+
declare const applyAgentEvent: (state: AgentClientState, event: AgentEvent) => AgentClientState;
|
|
92
|
+
declare const applyAgentEventWithOptions: (state: AgentClientState, event: AgentEvent, options?: ApplyAgentEventOptions) => AgentClientState;
|
|
93
|
+
declare const submitAgentUserMessage: (state: AgentClientState, message: UserMessage) => AgentClientState;
|
|
94
|
+
declare const markAgentError: (state: AgentClientState, message?: string) => AgentClientState;
|
|
95
|
+
declare const markAgentAborted: (state: AgentClientState) => AgentClientState;
|
|
96
|
+
declare const reduceAgentEvents: (events: ReadonlyArray<AgentEvent>, initialState?: AgentClientState, options?: ApplyAgentEventOptions) => AgentClientState;
|
|
97
|
+
//#endregion
|
|
98
|
+
export { AgentClientState, AgentRunStatus, AgentToolRun, AgentTranscript, ApplyAgentEventOptions, appendAgentMessage, applyAgentEvent, applyAgentEventWithOptions, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, submitAgentUserMessage };
|
|
99
|
+
//# sourceMappingURL=state.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.mts","names":[],"sources":["../../src/client/state.ts"],"mappings":";;;KAUY,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,SACnC,IAAA;EAAA,SAAoC,IAAA,EAAM,QAAA;AAAA;EAAA,SAC1C,IAAA;EAAA,SAAyB,UAAA;EA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BAAA,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,cA6KU,sBAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,EAAS,WAAA,KACR,gBAAA;AAAA,cAYU,cAAA,GACX,KAAA,EAAO,gBAAA,EACP,OAAA,cACC,gBAKD;AAAA,cAEW,gBAAA,GAAoB,KAAA,EAAO,gBAAA,KAAmB,gBAKzD;AAAA,cAEW,iBAAA,GACX,MAAA,EAAQ,aAAA,CAAc,UAAA,GACtB,YAAA,GAAc,gBAAA,EACd,OAAA,GAAS,sBAAA,KAA2B,gBAAA"}
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
//#region src/client/state.ts
|
|
2
|
+
const initialAgentClientState = {
|
|
3
|
+
status: "idle",
|
|
4
|
+
messages: [],
|
|
5
|
+
liveMessages: [],
|
|
6
|
+
text: "",
|
|
7
|
+
reasoning: "",
|
|
8
|
+
toolRuns: [],
|
|
9
|
+
error: null,
|
|
10
|
+
seenEventIds: []
|
|
11
|
+
};
|
|
12
|
+
const hasSeenEvent = (state, event) => event.eventId !== void 0 && state.seenEventIds.includes(event.eventId);
|
|
13
|
+
const rememberEvent = (state, event) => event.eventId === void 0 ? state : {
|
|
14
|
+
...state,
|
|
15
|
+
seenEventIds: [...state.seenEventIds, event.eventId]
|
|
16
|
+
};
|
|
17
|
+
const toolRunId = (run) => {
|
|
18
|
+
switch (run._tag) {
|
|
19
|
+
case "InputStreaming": return run.id;
|
|
20
|
+
case "Denied": return run.toolCallId;
|
|
21
|
+
case "QuestionRequested": return run.request.toolCallId;
|
|
22
|
+
case "QuestionAnswered":
|
|
23
|
+
case "QuestionCancelled": return run.response.toolCallId;
|
|
24
|
+
case "InputReady":
|
|
25
|
+
case "ApprovalRequested":
|
|
26
|
+
case "Executing":
|
|
27
|
+
case "Completed":
|
|
28
|
+
case "Errored":
|
|
29
|
+
case "ProviderCompleted": return run.call.id;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
const isActiveToolRun = (run) => run._tag !== "Completed" && run._tag !== "Errored" && run._tag !== "Denied" && run._tag !== "QuestionAnswered" && run._tag !== "QuestionCancelled" && run._tag !== "ProviderCompleted";
|
|
33
|
+
const completedToolRuns = (runs) => runs.filter((run) => run._tag === "Completed");
|
|
34
|
+
const replaceToolRun = (runs, run) => {
|
|
35
|
+
const id = toolRunId(run);
|
|
36
|
+
const replaceIndex = runs.findIndex((current) => toolRunId(current) === id);
|
|
37
|
+
if (replaceIndex === -1) return [...runs, run];
|
|
38
|
+
return runs.flatMap((current, index) => {
|
|
39
|
+
if (toolRunId(current) !== id) return [current];
|
|
40
|
+
return index === replaceIndex ? [run] : [];
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const isStartedToolRun = (run) => run._tag === "Executing" || run._tag === "Completed";
|
|
44
|
+
const startedAtMsFor = (runs, toolCallId) => runs.filter(isStartedToolRun).find((run) => run.call.id === toolCallId)?.startedAtMs;
|
|
45
|
+
const appendToolInputDelta = (runs, id, delta) => runs.map((run) => run._tag === "InputStreaming" && run.id === id ? {
|
|
46
|
+
...run,
|
|
47
|
+
input: `${run.input}${delta}`
|
|
48
|
+
} : run);
|
|
49
|
+
const appendAgentMessage = (messages, message) => {
|
|
50
|
+
const first = messages[0];
|
|
51
|
+
if (first === void 0) return [message];
|
|
52
|
+
return [
|
|
53
|
+
first,
|
|
54
|
+
...messages.slice(1),
|
|
55
|
+
message
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
const applyAgentEvent = (state, event) => {
|
|
59
|
+
return applyAgentEventWithOptions(state, event, { nowMs: 0 });
|
|
60
|
+
};
|
|
61
|
+
const applyAgentEventWithOptions = (state, event, options = {}) => {
|
|
62
|
+
const nowMs = options.nowMs ?? 0;
|
|
63
|
+
if (hasSeenEvent(state, event)) return state;
|
|
64
|
+
return rememberEvent(applyAgentEventUnchecked(state, event, nowMs), event);
|
|
65
|
+
};
|
|
66
|
+
const applyAgentEventUnchecked = (state, event, nowMs) => {
|
|
67
|
+
switch (event._tag) {
|
|
68
|
+
case "AgentStart": return {
|
|
69
|
+
...state,
|
|
70
|
+
status: "running",
|
|
71
|
+
text: "",
|
|
72
|
+
reasoning: "",
|
|
73
|
+
liveMessages: [],
|
|
74
|
+
toolRuns: completedToolRuns(state.toolRuns),
|
|
75
|
+
error: null
|
|
76
|
+
};
|
|
77
|
+
case "AgentError": return markAgentError(state, event.message);
|
|
78
|
+
case "LLMTextDelta": return {
|
|
79
|
+
...state,
|
|
80
|
+
text: `${state.text}${event.text}`
|
|
81
|
+
};
|
|
82
|
+
case "LLMReasoningDelta": return {
|
|
83
|
+
...state,
|
|
84
|
+
reasoning: `${state.reasoning}${event.text}`
|
|
85
|
+
};
|
|
86
|
+
case "ToolInputStart": return {
|
|
87
|
+
...state,
|
|
88
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
89
|
+
_tag: "InputStreaming",
|
|
90
|
+
id: event.id,
|
|
91
|
+
name: event.name,
|
|
92
|
+
input: ""
|
|
93
|
+
})
|
|
94
|
+
};
|
|
95
|
+
case "ToolInputDelta": return {
|
|
96
|
+
...state,
|
|
97
|
+
toolRuns: appendToolInputDelta(state.toolRuns, event.id, event.delta)
|
|
98
|
+
};
|
|
99
|
+
case "ToolInputEnd": return {
|
|
100
|
+
...state,
|
|
101
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
102
|
+
_tag: "InputReady",
|
|
103
|
+
call: event.call
|
|
104
|
+
})
|
|
105
|
+
};
|
|
106
|
+
case "ToolApprovalRequested": return {
|
|
107
|
+
...state,
|
|
108
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
109
|
+
_tag: "ApprovalRequested",
|
|
110
|
+
call: event.call
|
|
111
|
+
})
|
|
112
|
+
};
|
|
113
|
+
case "ToolApprovalGranted": return state;
|
|
114
|
+
case "ToolApprovalDenied": return {
|
|
115
|
+
...state,
|
|
116
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
117
|
+
_tag: "Denied",
|
|
118
|
+
toolCallId: event.toolCallId,
|
|
119
|
+
reason: event.reason
|
|
120
|
+
})
|
|
121
|
+
};
|
|
122
|
+
case "QuestionRequested": return {
|
|
123
|
+
...state,
|
|
124
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
125
|
+
_tag: "QuestionRequested",
|
|
126
|
+
request: event.request
|
|
127
|
+
})
|
|
128
|
+
};
|
|
129
|
+
case "QuestionAnswered": return {
|
|
130
|
+
...state,
|
|
131
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
132
|
+
_tag: "QuestionAnswered",
|
|
133
|
+
response: event.response
|
|
134
|
+
})
|
|
135
|
+
};
|
|
136
|
+
case "QuestionCancelled": return {
|
|
137
|
+
...state,
|
|
138
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
139
|
+
_tag: "QuestionCancelled",
|
|
140
|
+
response: event.response
|
|
141
|
+
})
|
|
142
|
+
};
|
|
143
|
+
case "ToolExecutionStarted": return {
|
|
144
|
+
...state,
|
|
145
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
146
|
+
_tag: "Executing",
|
|
147
|
+
call: event.call,
|
|
148
|
+
startedAtMs: nowMs
|
|
149
|
+
})
|
|
150
|
+
};
|
|
151
|
+
case "ToolExecutionCompleted": {
|
|
152
|
+
const endedAtMs = nowMs;
|
|
153
|
+
const startedAtMs = startedAtMsFor(state.toolRuns, event.call.id) ?? endedAtMs;
|
|
154
|
+
return {
|
|
155
|
+
...state,
|
|
156
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
157
|
+
_tag: "Completed",
|
|
158
|
+
call: event.call,
|
|
159
|
+
result: event.result,
|
|
160
|
+
startedAtMs,
|
|
161
|
+
endedAtMs
|
|
162
|
+
})
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
case "ToolExecutionError": return {
|
|
166
|
+
...state,
|
|
167
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
168
|
+
_tag: "Errored",
|
|
169
|
+
call: event.call,
|
|
170
|
+
message: event.message,
|
|
171
|
+
endedAtMs: nowMs
|
|
172
|
+
})
|
|
173
|
+
};
|
|
174
|
+
case "ProviderToolResult": return {
|
|
175
|
+
...state,
|
|
176
|
+
toolRuns: replaceToolRun(state.toolRuns, {
|
|
177
|
+
_tag: "ProviderCompleted",
|
|
178
|
+
call: event.call,
|
|
179
|
+
result: event.result
|
|
180
|
+
})
|
|
181
|
+
};
|
|
182
|
+
case "AssistantMessage": return {
|
|
183
|
+
...state,
|
|
184
|
+
liveMessages: [...state.liveMessages, event.message],
|
|
185
|
+
text: "",
|
|
186
|
+
reasoning: ""
|
|
187
|
+
};
|
|
188
|
+
case "AgentEnd": return {
|
|
189
|
+
...state,
|
|
190
|
+
status: "done",
|
|
191
|
+
messages: [...state.messages, ...event.messages],
|
|
192
|
+
liveMessages: [],
|
|
193
|
+
text: "",
|
|
194
|
+
reasoning: "",
|
|
195
|
+
toolRuns: completedToolRuns(state.toolRuns)
|
|
196
|
+
};
|
|
197
|
+
case "AgentAwaitingInput": return {
|
|
198
|
+
...state,
|
|
199
|
+
status: "waiting",
|
|
200
|
+
messages: [...state.messages, ...event.messages],
|
|
201
|
+
liveMessages: [],
|
|
202
|
+
text: "",
|
|
203
|
+
reasoning: "",
|
|
204
|
+
error: null
|
|
205
|
+
};
|
|
206
|
+
case "AgentRetry":
|
|
207
|
+
case "CompactionEnd":
|
|
208
|
+
case "CompactionStart":
|
|
209
|
+
case "LLMStreamEnd":
|
|
210
|
+
case "LLMStreamStart":
|
|
211
|
+
case "SubagentCompleted":
|
|
212
|
+
case "SubagentStarted":
|
|
213
|
+
case "TurnEnd":
|
|
214
|
+
case "TurnStart":
|
|
215
|
+
case "UsageUpdate": return state;
|
|
216
|
+
}
|
|
217
|
+
};
|
|
218
|
+
const submitAgentUserMessage = (state, message) => ({
|
|
219
|
+
...state,
|
|
220
|
+
status: "running",
|
|
221
|
+
messages: appendAgentMessage(state.messages, message),
|
|
222
|
+
liveMessages: [],
|
|
223
|
+
text: "",
|
|
224
|
+
reasoning: "",
|
|
225
|
+
toolRuns: completedToolRuns(state.toolRuns),
|
|
226
|
+
error: null,
|
|
227
|
+
seenEventIds: []
|
|
228
|
+
});
|
|
229
|
+
const markAgentError = (state, message = "Agent request failed") => ({
|
|
230
|
+
...state,
|
|
231
|
+
status: "error",
|
|
232
|
+
toolRuns: completedToolRuns(state.toolRuns),
|
|
233
|
+
error: message
|
|
234
|
+
});
|
|
235
|
+
const markAgentAborted = (state) => ({
|
|
236
|
+
...state,
|
|
237
|
+
status: "aborted",
|
|
238
|
+
toolRuns: completedToolRuns(state.toolRuns),
|
|
239
|
+
error: null
|
|
240
|
+
});
|
|
241
|
+
const reduceAgentEvents = (events, initialState = initialAgentClientState, options = {}) => events.reduce((state, event) => applyAgentEventWithOptions(state, event, options), initialState);
|
|
242
|
+
//#endregion
|
|
243
|
+
export { appendAgentMessage, applyAgentEvent, applyAgentEventWithOptions, completedToolRuns, initialAgentClientState, isActiveToolRun, markAgentAborted, markAgentError, reduceAgentEvents, submitAgentUserMessage };
|
|
244
|
+
|
|
245
|
+
//# sourceMappingURL=state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.mjs","names":[],"sources":["../../src/client/state.ts"],"sourcesContent":["import {\n type AgentEvent,\n type AgentMessage,\n type QuestionRequest,\n type QuestionResponse,\n type ToolCall,\n type ToolResult,\n type UserMessage\n} from '@yolk-sdk/agent/protocol'\n\nexport type AgentRunStatus = 'idle' | 'running' | 'waiting' | 'done' | 'error' | 'aborted'\n\nexport type AgentToolRun =\n | {\n readonly _tag: 'InputStreaming'\n readonly id: string\n readonly name?: string\n readonly input: string\n }\n | { readonly _tag: 'InputReady'; readonly call: ToolCall }\n | { readonly _tag: 'ApprovalRequested'; readonly call: ToolCall }\n | { readonly _tag: 'Denied'; readonly toolCallId: string; readonly reason: string }\n | { readonly _tag: 'QuestionRequested'; readonly request: QuestionRequest }\n | { readonly _tag: 'QuestionAnswered'; readonly response: QuestionResponse }\n | { readonly _tag: 'QuestionCancelled'; readonly response: QuestionResponse }\n | { readonly _tag: 'Executing'; readonly call: ToolCall; readonly startedAtMs: number }\n | {\n readonly _tag: 'Completed'\n readonly call: ToolCall\n readonly result: ToolResult\n readonly startedAtMs: number\n readonly endedAtMs: number\n }\n | {\n readonly _tag: 'Errored'\n readonly call: ToolCall\n readonly message: string\n readonly endedAtMs: number\n }\n | { readonly _tag: 'ProviderCompleted'; readonly call: ToolCall; readonly result: ToolResult }\n\ntype StartedAgentToolRun = Extract<AgentToolRun, { readonly _tag: 'Executing' | 'Completed' }>\n\nexport type AgentClientState = {\n readonly status: AgentRunStatus\n readonly messages: ReadonlyArray<AgentMessage>\n readonly liveMessages: ReadonlyArray<AgentMessage>\n readonly text: string\n readonly reasoning: string\n readonly toolRuns: ReadonlyArray<AgentToolRun>\n readonly error: string | null\n readonly seenEventIds: ReadonlyArray<string>\n}\n\nexport type ApplyAgentEventOptions = {\n readonly nowMs?: number\n}\n\nexport type AgentTranscript = readonly [AgentMessage, ...Array<AgentMessage>]\n\nexport const initialAgentClientState: AgentClientState = {\n status: 'idle',\n messages: [],\n liveMessages: [],\n text: '',\n reasoning: '',\n toolRuns: [],\n error: null,\n seenEventIds: []\n}\n\nconst hasSeenEvent = (state: AgentClientState, event: AgentEvent) =>\n event.eventId !== undefined && state.seenEventIds.includes(event.eventId)\n\nconst rememberEvent = (state: AgentClientState, event: AgentEvent): AgentClientState =>\n event.eventId === undefined\n ? state\n : { ...state, seenEventIds: [...state.seenEventIds, event.eventId] }\n\nconst toolRunId = (run: AgentToolRun) => {\n switch (run._tag) {\n case 'InputStreaming':\n return run.id\n case 'Denied':\n return run.toolCallId\n case 'QuestionRequested':\n return run.request.toolCallId\n case 'QuestionAnswered':\n case 'QuestionCancelled':\n return run.response.toolCallId\n case 'InputReady':\n case 'ApprovalRequested':\n case 'Executing':\n case 'Completed':\n case 'Errored':\n case 'ProviderCompleted':\n return run.call.id\n }\n}\n\nexport const isActiveToolRun = (run: AgentToolRun) =>\n run._tag !== 'Completed' &&\n run._tag !== 'Errored' &&\n run._tag !== 'Denied' &&\n run._tag !== 'QuestionAnswered' &&\n run._tag !== 'QuestionCancelled' &&\n run._tag !== 'ProviderCompleted'\n\nexport const completedToolRuns = (runs: ReadonlyArray<AgentToolRun>) =>\n runs.filter(run => run._tag === 'Completed')\n\nconst replaceToolRun = (\n runs: ReadonlyArray<AgentToolRun>,\n run: AgentToolRun\n): ReadonlyArray<AgentToolRun> => {\n const id = toolRunId(run)\n const replaceIndex = runs.findIndex(current => toolRunId(current) === id)\n\n if (replaceIndex === -1) {\n return [...runs, run]\n }\n\n return runs.flatMap((current, index) => {\n if (toolRunId(current) !== id) {\n return [current]\n }\n\n return index === replaceIndex ? [run] : []\n })\n}\n\nconst isStartedToolRun = (run: AgentToolRun): run is StartedAgentToolRun =>\n run._tag === 'Executing' || run._tag === 'Completed'\n\nconst startedAtMsFor = (runs: ReadonlyArray<AgentToolRun>, toolCallId: string) =>\n runs.filter(isStartedToolRun).find(run => run.call.id === toolCallId)?.startedAtMs\n\nconst appendToolInputDelta = (\n runs: ReadonlyArray<AgentToolRun>,\n id: string,\n delta: string\n): ReadonlyArray<AgentToolRun> =>\n runs.map(run =>\n run._tag === 'InputStreaming' && run.id === id ? { ...run, input: `${run.input}${delta}` } : run\n )\n\nexport const appendAgentMessage = (\n messages: ReadonlyArray<AgentMessage>,\n message: AgentMessage\n): AgentTranscript => {\n const first = messages[0]\n\n if (first === undefined) {\n return [message]\n }\n\n return [first, ...messages.slice(1), message]\n}\n\nexport const applyAgentEvent = (state: AgentClientState, event: AgentEvent): AgentClientState => {\n const nowMs = 0\n\n return applyAgentEventWithOptions(state, event, { nowMs })\n}\n\nexport const applyAgentEventWithOptions = (\n state: AgentClientState,\n event: AgentEvent,\n options: ApplyAgentEventOptions = {}\n): AgentClientState => {\n const nowMs = options.nowMs ?? 0\n\n if (hasSeenEvent(state, event)) {\n return state\n }\n\n return rememberEvent(applyAgentEventUnchecked(state, event, nowMs), event)\n}\n\nconst applyAgentEventUnchecked = (\n state: AgentClientState,\n event: AgentEvent,\n nowMs: number\n): AgentClientState => {\n switch (event._tag) {\n case 'AgentStart':\n return {\n ...state,\n status: 'running',\n text: '',\n reasoning: '',\n liveMessages: [],\n toolRuns: completedToolRuns(state.toolRuns),\n error: null\n }\n case 'AgentError':\n return markAgentError(state, event.message)\n case 'LLMTextDelta':\n return { ...state, text: `${state.text}${event.text}` }\n case 'LLMReasoningDelta':\n return { ...state, reasoning: `${state.reasoning}${event.text}` }\n case 'ToolInputStart':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'InputStreaming',\n id: event.id,\n name: event.name,\n input: ''\n })\n }\n case 'ToolInputDelta':\n return { ...state, toolRuns: appendToolInputDelta(state.toolRuns, event.id, event.delta) }\n case 'ToolInputEnd':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, { _tag: 'InputReady', call: event.call })\n }\n case 'ToolApprovalRequested':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, { _tag: 'ApprovalRequested', call: event.call })\n }\n case 'ToolApprovalGranted':\n return state\n case 'ToolApprovalDenied':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'Denied',\n toolCallId: event.toolCallId,\n reason: event.reason\n })\n }\n case 'QuestionRequested':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'QuestionRequested',\n request: event.request\n })\n }\n case 'QuestionAnswered':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'QuestionAnswered',\n response: event.response\n })\n }\n case 'QuestionCancelled':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'QuestionCancelled',\n response: event.response\n })\n }\n case 'ToolExecutionStarted':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'Executing',\n call: event.call,\n startedAtMs: nowMs\n })\n }\n case 'ToolExecutionCompleted': {\n const endedAtMs = nowMs\n const startedAtMs = startedAtMsFor(state.toolRuns, event.call.id) ?? endedAtMs\n\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'Completed',\n call: event.call,\n result: event.result,\n startedAtMs,\n endedAtMs\n })\n }\n }\n case 'ToolExecutionError':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'Errored',\n call: event.call,\n message: event.message,\n endedAtMs: nowMs\n })\n }\n case 'ProviderToolResult':\n return {\n ...state,\n toolRuns: replaceToolRun(state.toolRuns, {\n _tag: 'ProviderCompleted',\n call: event.call,\n result: event.result\n })\n }\n case 'AssistantMessage':\n return {\n ...state,\n liveMessages: [...state.liveMessages, event.message],\n text: '',\n reasoning: ''\n }\n case 'AgentEnd':\n return {\n ...state,\n status: 'done',\n messages: [...state.messages, ...event.messages],\n liveMessages: [],\n text: '',\n reasoning: '',\n toolRuns: completedToolRuns(state.toolRuns)\n }\n case 'AgentAwaitingInput':\n return {\n ...state,\n status: 'waiting',\n messages: [...state.messages, ...event.messages],\n liveMessages: [],\n text: '',\n reasoning: '',\n error: null\n }\n case 'AgentRetry':\n case 'CompactionEnd':\n case 'CompactionStart':\n case 'LLMStreamEnd':\n case 'LLMStreamStart':\n case 'SubagentCompleted':\n case 'SubagentStarted':\n case 'TurnEnd':\n case 'TurnStart':\n case 'UsageUpdate':\n return state\n }\n}\n\nexport const submitAgentUserMessage = (\n state: AgentClientState,\n message: UserMessage\n): AgentClientState => ({\n ...state,\n status: 'running',\n messages: appendAgentMessage(state.messages, message),\n liveMessages: [],\n text: '',\n reasoning: '',\n toolRuns: completedToolRuns(state.toolRuns),\n error: null,\n seenEventIds: []\n})\n\nexport const markAgentError = (\n state: AgentClientState,\n message = 'Agent request failed'\n): AgentClientState => ({\n ...state,\n status: 'error',\n toolRuns: completedToolRuns(state.toolRuns),\n error: message\n})\n\nexport const markAgentAborted = (state: AgentClientState): AgentClientState => ({\n ...state,\n status: 'aborted',\n toolRuns: completedToolRuns(state.toolRuns),\n error: null\n})\n\nexport const reduceAgentEvents = (\n events: ReadonlyArray<AgentEvent>,\n initialState: AgentClientState = initialAgentClientState,\n options: ApplyAgentEventOptions = {}\n) =>\n events.reduce((state, event) => applyAgentEventWithOptions(state, event, options), initialState)\n"],"mappings":";AA4DA,MAAa,0BAA4C;CACvD,QAAQ;CACR,UAAU,CAAC;CACX,cAAc,CAAC;CACf,MAAM;CACN,WAAW;CACX,UAAU,CAAC;CACX,OAAO;CACP,cAAc,CAAC;AACjB;AAEA,MAAM,gBAAgB,OAAyB,UAC7C,MAAM,YAAY,KAAA,KAAa,MAAM,aAAa,SAAS,MAAM,OAAO;AAE1E,MAAM,iBAAiB,OAAyB,UAC9C,MAAM,YAAY,KAAA,IACd,QACA;CAAE,GAAG;CAAO,cAAc,CAAC,GAAG,MAAM,cAAc,MAAM,OAAO;AAAE;AAEvE,MAAM,aAAa,QAAsB;CACvC,QAAQ,IAAI,MAAZ;EACE,KAAK,kBACH,OAAO,IAAI;EACb,KAAK,UACH,OAAO,IAAI;EACb,KAAK,qBACH,OAAO,IAAI,QAAQ;EACrB,KAAK;EACL,KAAK,qBACH,OAAO,IAAI,SAAS;EACtB,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,qBACH,OAAO,IAAI,KAAK;CACpB;AACF;AAEA,MAAa,mBAAmB,QAC9B,IAAI,SAAS,eACX,IAAI,SAAS,aACb,IAAI,SAAS,YACb,IAAI,SAAS,sBACb,IAAI,SAAS,uBACb,IAAI,SAAS;AAEjB,MAAa,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OACA,aACsB;CACtB,GAAG;CACH,QAAQ;CACR,UAAU,mBAAmB,MAAM,UAAU,OAAO;CACpD,cAAc,CAAC;CACf,MAAM;CACN,WAAW;CACX,UAAU,kBAAkB,MAAM,QAAQ;CAC1C,OAAO;CACP,cAAc,CAAC;AACjB;AAEA,MAAa,kBACX,OACA,UAAU,4BACY;CACtB,GAAG;CACH,QAAQ;CACR,UAAU,kBAAkB,MAAM,QAAQ;CAC1C,OAAO;AACT;AAEA,MAAa,oBAAoB,WAA+C;CAC9E,GAAG;CACH,QAAQ;CACR,UAAU,kBAAkB,MAAM,QAAQ;CAC1C,OAAO;AACT;AAEA,MAAa,qBACX,QACA,eAAiC,yBACjC,UAAkC,CAAC,MAEnC,OAAO,QAAQ,OAAO,UAAU,2BAA2B,OAAO,OAAO,OAAO,GAAG,YAAY"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { AgentTranscript } from "./state.mjs";
|
|
2
|
+
import { Cause, Effect, Layer, Stream } from "effect";
|
|
3
|
+
import { HttpClient } from "effect/unstable/http";
|
|
4
|
+
import * as Schema from "effect/Schema";
|
|
5
|
+
import { AgentEvent, AgentReasoningEffort, HitlResponse, QuestionResponse, ToolApprovalResponse } from "@yolk-sdk/agent/protocol";
|
|
6
|
+
|
|
7
|
+
//#region src/client/transport.d.ts
|
|
8
|
+
declare const AgentTransportError_base: Schema.Class<AgentTransportError, Schema.TaggedStruct<"AgentTransportError", {
|
|
9
|
+
readonly message: Schema.String;
|
|
10
|
+
readonly cause: Schema.Unknown;
|
|
11
|
+
}>, Cause.YieldableError>;
|
|
12
|
+
declare class AgentTransportError extends AgentTransportError_base {}
|
|
13
|
+
type StreamAgentEventsRequest = {
|
|
14
|
+
readonly endpoint?: string;
|
|
15
|
+
readonly sessionId: string;
|
|
16
|
+
readonly messages: AgentTranscript;
|
|
17
|
+
readonly hitlResponses?: ReadonlyArray<HitlResponse>;
|
|
18
|
+
readonly model?: string;
|
|
19
|
+
readonly reasoningEffort?: AgentReasoningEffort;
|
|
20
|
+
readonly signal?: AbortSignal;
|
|
21
|
+
readonly httpClientLayer?: Layer.Layer<HttpClient.HttpClient>;
|
|
22
|
+
readonly onResponse?: (response: AgentHttpResponseInfo) => void;
|
|
23
|
+
};
|
|
24
|
+
type StreamAgentRunEventsRequest = {
|
|
25
|
+
readonly endpoint: string;
|
|
26
|
+
readonly signal?: AbortSignal;
|
|
27
|
+
readonly httpClientLayer?: Layer.Layer<HttpClient.HttpClient>;
|
|
28
|
+
readonly onResponse?: (response: AgentHttpResponseInfo) => void;
|
|
29
|
+
};
|
|
30
|
+
type CancelAgentRunRequest = {
|
|
31
|
+
readonly endpoint: string;
|
|
32
|
+
readonly httpClientLayer?: Layer.Layer<HttpClient.HttpClient>;
|
|
33
|
+
};
|
|
34
|
+
type SubmitToolApprovalResponseRequest = StreamAgentEventsRequest & {
|
|
35
|
+
readonly response: ToolApprovalResponse;
|
|
36
|
+
};
|
|
37
|
+
type SubmitQuestionResponseRequest = StreamAgentEventsRequest & {
|
|
38
|
+
readonly response: QuestionResponse;
|
|
39
|
+
};
|
|
40
|
+
type AgentHttpResponseInfo = {
|
|
41
|
+
readonly status: number;
|
|
42
|
+
readonly headers: Readonly<Record<string, string | undefined>>;
|
|
43
|
+
};
|
|
44
|
+
type StreamCloudflareAgentEventsRequest = {
|
|
45
|
+
readonly webSocketUrl: string;
|
|
46
|
+
readonly messages: AgentTranscript;
|
|
47
|
+
readonly hitlResponses?: ReadonlyArray<HitlResponse>;
|
|
48
|
+
readonly model?: string;
|
|
49
|
+
readonly reasoningEffort?: AgentReasoningEffort;
|
|
50
|
+
readonly signal?: AbortSignal;
|
|
51
|
+
};
|
|
52
|
+
declare const streamAgentEventStream: (request: StreamAgentEventsRequest) => Stream.Stream<import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted, AgentTransportError, never>;
|
|
53
|
+
declare const streamAgentRunEventStream: (request: StreamAgentRunEventsRequest) => Stream.Stream<import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted, AgentTransportError, never>;
|
|
54
|
+
declare const streamToolApprovalResponseEventStream: (request: SubmitToolApprovalResponseRequest) => Stream.Stream<import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted, AgentTransportError, never>;
|
|
55
|
+
declare const streamQuestionResponseEventStream: (request: SubmitQuestionResponseRequest) => Stream.Stream<import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted, AgentTransportError, never>;
|
|
56
|
+
declare const streamCloudflareAgentEventStream: (request: StreamCloudflareAgentEventsRequest) => Stream.Stream<import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted, AgentTransportError, never>;
|
|
57
|
+
declare function streamCloudflareAgentEvents(request: StreamCloudflareAgentEventsRequest): AsyncGenerator<AgentEvent, void, void>;
|
|
58
|
+
declare function streamAgentEvents(request: StreamAgentEventsRequest): AsyncGenerator<AgentEvent, void, void>;
|
|
59
|
+
declare function streamAgentRunEvents(request: StreamAgentRunEventsRequest): AsyncGenerator<AgentEvent, void, void>;
|
|
60
|
+
declare function submitToolApprovalResponse(request: SubmitToolApprovalResponseRequest): AsyncGenerator<AgentEvent, void, void>;
|
|
61
|
+
declare function submitQuestionResponse(request: SubmitQuestionResponseRequest): AsyncGenerator<AgentEvent, void, void>;
|
|
62
|
+
declare const cancelAgentRun: (request: CancelAgentRunRequest) => Promise<undefined>;
|
|
63
|
+
declare const collectAgentEventsEffect: (request: StreamAgentEventsRequest) => Effect.Effect<(import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted)[], AgentTransportError, never>;
|
|
64
|
+
declare const collectAgentEvents: (request: StreamAgentEventsRequest) => Promise<(import("@yolk-sdk/agent/protocol").AgentStart | import("@yolk-sdk/agent/protocol").AgentError | import("@yolk-sdk/agent/protocol").AgentEnd | import("@yolk-sdk/agent/protocol").AgentAwaitingInput | import("@yolk-sdk/agent/protocol").UsageUpdate | import("@yolk-sdk/agent/protocol").AgentRetry | import("@yolk-sdk/agent/protocol").CompactionStart | import("@yolk-sdk/agent/protocol").CompactionEnd | import("@yolk-sdk/agent/protocol").TurnStart | import("@yolk-sdk/agent/protocol").TurnEnd | import("@yolk-sdk/agent/protocol").LLMStreamStart | import("@yolk-sdk/agent/protocol").LLMTextDelta | import("@yolk-sdk/agent/protocol").LLMReasoningDelta | import("@yolk-sdk/agent/protocol").ToolInputStart | import("@yolk-sdk/agent/protocol").ToolInputDelta | import("@yolk-sdk/agent/protocol").ToolInputEnd | import("@yolk-sdk/agent/protocol").LLMStreamEnd | import("@yolk-sdk/agent/protocol").AssistantMessageEvent | import("@yolk-sdk/agent/protocol").ToolApprovalRequested | import("@yolk-sdk/agent/protocol").ToolApprovalGranted | import("@yolk-sdk/agent/protocol").ToolApprovalDenied | import("@yolk-sdk/agent/protocol").QuestionRequested | import("@yolk-sdk/agent/protocol").QuestionAnswered | import("@yolk-sdk/agent/protocol").QuestionCancelled | import("@yolk-sdk/agent/protocol").ToolExecutionStarted | import("@yolk-sdk/agent/protocol").ToolExecutionCompleted | import("@yolk-sdk/agent/protocol").ToolExecutionError | import("@yolk-sdk/agent/protocol").ProviderToolResult | import("@yolk-sdk/agent/protocol").SubagentStarted | import("@yolk-sdk/agent/protocol").SubagentCompleted)[]>;
|
|
65
|
+
//#endregion
|
|
66
|
+
export { AgentHttpResponseInfo, AgentTransportError, CancelAgentRunRequest, StreamAgentEventsRequest, StreamAgentRunEventsRequest, StreamCloudflareAgentEventsRequest, SubmitQuestionResponseRequest, SubmitToolApprovalResponseRequest, cancelAgentRun, collectAgentEvents, collectAgentEventsEffect, streamAgentEventStream, streamAgentEvents, streamAgentRunEventStream, streamAgentRunEvents, streamCloudflareAgentEventStream, streamCloudflareAgentEvents, streamQuestionResponseEventStream, streamToolApprovalResponseEventStream, submitQuestionResponse, submitToolApprovalResponse };
|
|
67
|
+
//# sourceMappingURL=transport.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.mts","names":[],"sources":["../../src/client/transport.ts"],"mappings":";;;;;;;cA0BiD,wBAAA;;;;cAEpC,mBAAA,SAA4B,wBAMxC;AAAA,KAEW,wBAAA;EAAA,SACD,QAAA;EAAA,SACA,SAAA;EAAA,SACA,QAAA,EAAU,eAAA;EAAA,SACV,aAAA,GAAgB,aAAA,CAAc,YAAA;EAAA,SAC9B,KAAA;EAAA,SACA,eAAA,GAAkB,oBAAA;EAAA,SAClB,MAAA,GAAS,WAAA;EAAA,SACT,eAAA,GAAkB,KAAA,CAAM,KAAA,CAAM,UAAA,CAAW,UAAA;EAAA,SACzC,UAAA,IAAc,QAAA,EAAU,qBAAA;AAAA;AAAA,KAGvB,2BAAA;EAAA,SACD,QAAA;EAAA,SACA,MAAA,GAAS,WAAA;EAAA,SACT,eAAA,GAAkB,KAAA,CAAM,KAAA,CAAM,UAAA,CAAW,UAAA;EAAA,SACzC,UAAA,IAAc,QAAA,EAAU,qBAAA;AAAA;AAAA,KAGvB,qBAAA;EAA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