@wrongstack/acp 0.293.0 → 0.295.1
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 +22 -2
- package/dist/agent/protocol-contract.d.ts +210 -0
- package/dist/agent/protocol-contract.d.ts.map +1 -0
- package/dist/agent/protocol-handler.d.ts +15 -189
- package/dist/agent/protocol-handler.d.ts.map +1 -1
- package/dist/agent/server-agent-turn.d.ts +89 -1
- package/dist/agent/server-agent-turn.d.ts.map +1 -1
- package/dist/agent/session-store.d.ts.map +1 -1
- package/dist/agent/stdio-transport.d.ts +30 -1
- package/dist/agent/stdio-transport.d.ts.map +1 -1
- package/dist/agent/tools-registry.d.ts +1 -1
- package/dist/agent/tools-registry.d.ts.map +1 -1
- package/dist/agent/wrongstack-acp-agent.d.ts +37 -0
- package/dist/agent/wrongstack-acp-agent.d.ts.map +1 -1
- package/dist/agent.js +189 -32
- package/dist/agent.js.map +4 -4
- package/dist/client/acp-session.d.ts +13 -1
- package/dist/client/acp-session.d.ts.map +1 -1
- package/dist/client/file-server.d.ts +19 -0
- package/dist/client/file-server.d.ts.map +1 -1
- package/dist/client/index.d.ts +11 -9
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/terminal-server.d.ts +5 -0
- package/dist/client/terminal-server.d.ts.map +1 -1
- package/dist/client/tool-translator.d.ts +1 -1
- package/dist/client/tool-translator.d.ts.map +1 -1
- package/dist/client/trust-boundary-permission.d.ts +31 -0
- package/dist/client/trust-boundary-permission.d.ts.map +1 -0
- package/dist/client/websocket-transport.d.ts +6 -0
- package/dist/client/websocket-transport.d.ts.map +1 -1
- package/dist/client.js +459 -243
- package/dist/client.js.map +4 -4
- package/dist/index.d.ts +29 -29
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2116 -1802
- package/dist/index.js.map +4 -4
- package/dist/integration/acp-bench.d.ts +32 -0
- package/dist/integration/acp-bench.d.ts.map +1 -1
- package/dist/integration/acp-subagent-runner.d.ts +3 -3
- package/dist/integration/acp-subagent-runner.d.ts.map +1 -1
- package/dist/integration/ensemble-runner.d.ts +22 -1
- package/dist/integration/ensemble-runner.d.ts.map +1 -1
- package/dist/legacy.d.ts +8 -0
- package/dist/legacy.d.ts.map +1 -0
- package/dist/legacy.js +6 -0
- package/dist/legacy.js.map +7 -0
- package/dist/registry/acp-registry-fetch.d.ts +1 -1
- package/dist/registry/acp-registry-fetch.d.ts.map +1 -1
- package/dist/registry/ensemble-registry.d.ts +22 -0
- package/dist/registry/ensemble-registry.d.ts.map +1 -1
- package/dist/sdk.d.ts +10 -8
- package/dist/sdk.d.ts.map +1 -1
- package/dist/sdk.js +22 -0
- package/dist/sdk.js.map +3 -3
- package/dist/v1.d.ts +3 -0
- package/dist/v1.d.ts.map +1 -0
- package/dist/v1.js +12 -0
- package/dist/v1.js.map +7 -0
- package/dist/version.d.ts +10 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/wrongstack-acp-agent.js +121 -24
- package/dist/wrongstack-acp-agent.js.map +4 -4
- package/package.json +10 -2
package/README.md
CHANGED
|
@@ -9,6 +9,20 @@ WebSocket support plus an HTTP server transport. Some optional protocol surfaces
|
|
|
9
9
|
are intentionally unavailable; see [COMPLIANCE.md](COMPLIANCE.md) for the tested
|
|
10
10
|
surface and current limitations.
|
|
11
11
|
|
|
12
|
+
## Public entry points
|
|
13
|
+
|
|
14
|
+
| Import | Authority |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `@wrongstack/acp` | WrongStack's v1 client/server implementation, integrations, and stable v1 contracts |
|
|
17
|
+
| `@wrongstack/acp/client` | Client-only implementation surface |
|
|
18
|
+
| `@wrongstack/acp/agent` | Server/agent-only implementation surface |
|
|
19
|
+
| `@wrongstack/acp/v1` | WrongStack-owned stable v1 protocol contracts only |
|
|
20
|
+
| `@wrongstack/acp/sdk` | Official `@agentclientprotocol/sdk` APIs and experimental transport helpers |
|
|
21
|
+
| `@wrongstack/acp/legacy` | Deprecated pre-v1 draft envelope types; compatibility only |
|
|
22
|
+
|
|
23
|
+
New code must not import legacy draft contracts from the package root. Use `/v1`
|
|
24
|
+
for protocol types and `/sdk` only when intentionally adopting the upstream SDK.
|
|
25
|
+
|
|
12
26
|
## Compliance
|
|
13
27
|
|
|
14
28
|
The package test suite includes client/server protocol tests and an in-process
|
|
@@ -65,11 +79,17 @@ await server.start();
|
|
|
65
79
|
### Using the Official SDK (for advanced use cases)
|
|
66
80
|
|
|
67
81
|
```typescript
|
|
68
|
-
import {
|
|
82
|
+
import {
|
|
83
|
+
AcpServer,
|
|
84
|
+
AgentApp,
|
|
85
|
+
createHttpStream,
|
|
86
|
+
createWebSocketStream,
|
|
87
|
+
} from '@wrongstack/acp/sdk';
|
|
69
88
|
```
|
|
70
89
|
|
|
71
90
|
The `/sdk` entry point re-exports the official SDK's public high-level APIs, method
|
|
72
|
-
constants, and experimental Node/WebSocket helpers
|
|
91
|
+
constants, and experimental HTTP/Node/WebSocket helpers. WrongStack's `ACPSession`
|
|
92
|
+
is intentionally available from the package root or `/client`, not from `/sdk`.
|
|
73
93
|
|
|
74
94
|
## Architecture
|
|
75
95
|
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public contracts and wire-boundary helpers for the ACP v1 protocol handler.
|
|
3
|
+
* Keeping these declarations separate leaves the handler focused on request dispatch.
|
|
4
|
+
*/
|
|
5
|
+
import type { ACPMessage } from '../types/acp-messages.js';
|
|
6
|
+
import { ACP_PROTOCOL_VERSION, type ContentBlock, type PermissionOption, type PlanEntry, type RequestPermissionOutcome, type StopReason, type ToolKind, type UsageCost } from '../types/acp-v1.js';
|
|
7
|
+
import type { AgentServerTransport } from './stdio-transport.js';
|
|
8
|
+
export { ACP_PROTOCOL_VERSION };
|
|
9
|
+
export type { ACPMessage, ContentBlock, RequestPermissionOutcome };
|
|
10
|
+
type WireMessage = {
|
|
11
|
+
jsonrpc?: '2.0';
|
|
12
|
+
id?: string | number;
|
|
13
|
+
method?: string;
|
|
14
|
+
params?: unknown;
|
|
15
|
+
result?: unknown;
|
|
16
|
+
error?: unknown;
|
|
17
|
+
};
|
|
18
|
+
export declare function toWire(msg: WireMessage): ACPMessage;
|
|
19
|
+
export declare const WRONGSTACK_VERSION: string;
|
|
20
|
+
/** What kinds of content the agent accepts in a prompt. */
|
|
21
|
+
export interface PromptCapabilities {
|
|
22
|
+
image: boolean;
|
|
23
|
+
audio: boolean;
|
|
24
|
+
embeddedContext: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface AgentCapabilities {
|
|
27
|
+
loadSession: boolean;
|
|
28
|
+
promptCapabilities: PromptCapabilities;
|
|
29
|
+
}
|
|
30
|
+
export interface RunTurnInput {
|
|
31
|
+
sessionId: string;
|
|
32
|
+
/** Content blocks the client sent. */
|
|
33
|
+
prompt: readonly ContentBlock[];
|
|
34
|
+
/** Cancelled when the client sends `session/cancel` for this session. */
|
|
35
|
+
signal: AbortSignal;
|
|
36
|
+
}
|
|
37
|
+
export interface RunTurnResult {
|
|
38
|
+
stopReason: StopReason;
|
|
39
|
+
/** Optional summary text the agent produced. */
|
|
40
|
+
text?: string;
|
|
41
|
+
plan?: PlanEntry[];
|
|
42
|
+
usage?: {
|
|
43
|
+
used: number;
|
|
44
|
+
size: number;
|
|
45
|
+
cost?: UsageCost | undefined;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* A tool-call permission request the agent surfaces to the client.
|
|
50
|
+
*/
|
|
51
|
+
export interface RunTurnPermissionRequest {
|
|
52
|
+
toolCall: {
|
|
53
|
+
toolCallId: string;
|
|
54
|
+
title: string;
|
|
55
|
+
kind?: ToolKind | undefined;
|
|
56
|
+
};
|
|
57
|
+
options: PermissionOption[];
|
|
58
|
+
}
|
|
59
|
+
/** Client filesystem/terminal capabilities advertised at initialize. */
|
|
60
|
+
export interface ClientCapabilities {
|
|
61
|
+
fs?: {
|
|
62
|
+
readTextFile?: boolean | undefined;
|
|
63
|
+
writeTextFile?: boolean | undefined;
|
|
64
|
+
} | undefined;
|
|
65
|
+
terminal?: boolean | undefined;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Client-callback API handed to `runTurn`. Lets the agent's tools call back
|
|
69
|
+
* into the connected ACP client — ask for permission, and (when the client
|
|
70
|
+
* advertises the capability) use the client's filesystem and terminal so the
|
|
71
|
+
* editor's view (including unsaved buffers) is the source of truth.
|
|
72
|
+
*/
|
|
73
|
+
export interface RunTurnApi {
|
|
74
|
+
/**
|
|
75
|
+
* Ask the connected ACP client to approve/reject a tool call via the
|
|
76
|
+
* `session/request_permission` method. Resolves with the client's
|
|
77
|
+
* outcome. Rejects if no client channel is available or the request
|
|
78
|
+
* times out — the caller decides the fallback.
|
|
79
|
+
*/
|
|
80
|
+
requestPermission(req: RunTurnPermissionRequest): Promise<RequestPermissionOutcome>;
|
|
81
|
+
/** Capabilities the client advertised at initialize — gate tool wiring on these. */
|
|
82
|
+
clientCapabilities: ClientCapabilities;
|
|
83
|
+
/** Read a text file from the client's filesystem (`fs/read_text_file`). */
|
|
84
|
+
readTextFile(params: {
|
|
85
|
+
path: string;
|
|
86
|
+
line?: number;
|
|
87
|
+
limit?: number;
|
|
88
|
+
}): Promise<string>;
|
|
89
|
+
/** Write a text file in the client's filesystem (`fs/write_text_file`). */
|
|
90
|
+
writeTextFile(params: {
|
|
91
|
+
path: string;
|
|
92
|
+
content: string;
|
|
93
|
+
}): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Run a command in the client's terminal (`terminal/create` →
|
|
96
|
+
* `wait_for_exit` → `output` → `release`) and resolve with the combined
|
|
97
|
+
* output and exit code.
|
|
98
|
+
*/
|
|
99
|
+
runTerminal(params: {
|
|
100
|
+
command: string;
|
|
101
|
+
args?: string[] | undefined;
|
|
102
|
+
cwd?: string | undefined;
|
|
103
|
+
}): Promise<{
|
|
104
|
+
output: string;
|
|
105
|
+
exitCode: number | null;
|
|
106
|
+
}>;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* The agent's per-turn work. Streams `SessionUpdate` notifications to
|
|
110
|
+
* `emit` and resolves with the final stopReason. Errors thrown from
|
|
111
|
+
* this iterable are converted to a `prompt_failed` JSON-RPC error.
|
|
112
|
+
*
|
|
113
|
+
* `api` is an optional client-callback surface (permission requests).
|
|
114
|
+
* Older runTurn implementations that ignore it keep working unchanged.
|
|
115
|
+
*/
|
|
116
|
+
export type RunTurn = (input: RunTurnInput, emit: (update: unknown) => void, api?: RunTurnApi) => Promise<RunTurnResult>;
|
|
117
|
+
export interface SessionState {
|
|
118
|
+
id: string;
|
|
119
|
+
cwd: string;
|
|
120
|
+
/** Per-turn abort signal — aborted when the session is cancelled or closed. */
|
|
121
|
+
abort: AbortController;
|
|
122
|
+
/** Active mode, advertised to the client in current_mode_update. */
|
|
123
|
+
modeId: string;
|
|
124
|
+
/** Created at, for session/list ordering. */
|
|
125
|
+
createdAt: string;
|
|
126
|
+
/** Last activity timestamp, for session/info_update. */
|
|
127
|
+
updatedAt: string;
|
|
128
|
+
/** Optional human title. */
|
|
129
|
+
title?: string;
|
|
130
|
+
}
|
|
131
|
+
/** MCP-style session mode advertised in current_mode_update. */
|
|
132
|
+
export interface SessionMode {
|
|
133
|
+
id: string;
|
|
134
|
+
name: string;
|
|
135
|
+
description?: string | undefined;
|
|
136
|
+
}
|
|
137
|
+
export interface SessionConfigOption {
|
|
138
|
+
id: string;
|
|
139
|
+
name: string;
|
|
140
|
+
type: 'select' | string;
|
|
141
|
+
currentValue: string;
|
|
142
|
+
options: {
|
|
143
|
+
value: string;
|
|
144
|
+
name: string;
|
|
145
|
+
description?: string | undefined;
|
|
146
|
+
}[];
|
|
147
|
+
}
|
|
148
|
+
export interface ProtocolHandlerOptions {
|
|
149
|
+
transport: AgentServerTransport;
|
|
150
|
+
/** Where the server is running; used for new sessions' default cwd. */
|
|
151
|
+
defaultCwd: string;
|
|
152
|
+
/** Agent's per-turn implementation. */
|
|
153
|
+
runTurn: RunTurn;
|
|
154
|
+
/**
|
|
155
|
+
* Optional callbacks for the lifecycle events the server should
|
|
156
|
+
* surface to the client. All default to no-ops.
|
|
157
|
+
*/
|
|
158
|
+
onSessionNew?: ((state: SessionState) => void) | undefined;
|
|
159
|
+
/** Static list of available modes (advertised to clients). */
|
|
160
|
+
modes?: readonly SessionMode[] | undefined;
|
|
161
|
+
/** Static list of config options. */
|
|
162
|
+
configOptions?: readonly SessionConfigOption[] | undefined;
|
|
163
|
+
/** Agent name advertised in initialize. */
|
|
164
|
+
agentName?: string | undefined;
|
|
165
|
+
/**
|
|
166
|
+
* Optional source of replayable conversation history for `session/load`.
|
|
167
|
+
* Returns the `session/update` payloads (user/agent message chunks) to
|
|
168
|
+
* stream back to the client before the load response. Wired from
|
|
169
|
+
* `makeACPServerAgentTurn(...).replay`.
|
|
170
|
+
*/
|
|
171
|
+
replayFor?: ((sessionId: string) => Array<{
|
|
172
|
+
sessionUpdate: string;
|
|
173
|
+
content: unknown;
|
|
174
|
+
}>) | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* Optional hook to prime the turn engine's session history on cold
|
|
177
|
+
* `session/load` (server restart). Wired from `makeACPServerAgentTurn(...).seed`
|
|
178
|
+
* — it re-feeds the persisted conversation into the next-created Agent so
|
|
179
|
+
* the model resumes, not just the client UI.
|
|
180
|
+
*/
|
|
181
|
+
seedFor?: ((sessionId: string, history: Array<{
|
|
182
|
+
sessionUpdate: string;
|
|
183
|
+
content: unknown;
|
|
184
|
+
}>) => void) | undefined;
|
|
185
|
+
/** Release per-session agent/history resources after close, delete, or handler teardown. */
|
|
186
|
+
disposeFor?: ((sessionId: string) => void) | undefined;
|
|
187
|
+
/** Maximum sessions retained concurrently by one protocol handler. Default 64. */
|
|
188
|
+
maxSessions?: number | undefined;
|
|
189
|
+
/**
|
|
190
|
+
* Optional durable session store. When set, sessions + their recorded
|
|
191
|
+
* history are persisted on create/prompt and restored on `session/load`,
|
|
192
|
+
* so a reconnecting client can resume after a server restart.
|
|
193
|
+
* (Structural type — `ACPSessionStore` satisfies it without a value import.)
|
|
194
|
+
*/
|
|
195
|
+
store?: SessionPersistence | undefined;
|
|
196
|
+
}
|
|
197
|
+
/** Minimal durable-store contract the handler uses (ACPSessionStore satisfies it). */
|
|
198
|
+
export interface SessionPersistence {
|
|
199
|
+
save(state: SessionState, history?: Array<{
|
|
200
|
+
sessionUpdate: string;
|
|
201
|
+
content: unknown;
|
|
202
|
+
}>): Promise<unknown>;
|
|
203
|
+
load(sessionId: string): Promise<(Partial<SessionState> & {
|
|
204
|
+
history?: Array<{
|
|
205
|
+
sessionUpdate: string;
|
|
206
|
+
content: unknown;
|
|
207
|
+
}> | undefined;
|
|
208
|
+
}) | null>;
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=protocol-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-contract.d.ts","sourceRoot":"","sources":["../../src/agent/protocol-contract.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,oBAAoB,CAAC;AAE5B,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAChC,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,wBAAwB,EAAE,CAAC;AAMnE,KAAK,WAAW,GAAG;IAAE,OAAO,CAAC,EAAE,KAAK,CAAC;IAAC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,OAAO,CAAC;I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OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC,GAAG,SAAS,CAAC;IACpG;;;;;OAKG;IACH,OAAO,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACjH,4FAA4F;IAC5F,UAAU,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IACvD,kFAAkF;IAClF,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACjC;;;;;OAKG;IACH,KAAK,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CACxC;AAED,sFAAsF;AACtF,MAAM,WAAW,kBAAkB;IACjC,IAAI,CACF,KAAK,EAAE,YAAY,EACnB,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC,GAC3D,OAAO,CAAC,OAAO,CAAC,CAAC;IACpB,IAAI,CACF,SAAS,EAAE,MAAM,GAChB,OAAO,CACN,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG;QAAE,OAAO,CAAC,EAAE,KAAK,CAAC;YAAE,aAAa,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAA;SAAE,CAAC,GAAG,SAAS,CAAA;KAAE,CAAC,GACtG,IAAI,CACP,CAAC;CACH"}
|
|
@@ -42,195 +42,9 @@
|
|
|
42
42
|
* notification can stop the running turn mid-stream without tearing
|
|
43
43
|
* down the session. Multiple sessions can be active concurrently.
|
|
44
44
|
*/
|
|
45
|
-
import {
|
|
46
|
-
|
|
47
|
-
export
|
|
48
|
-
/** What kinds of content the agent accepts in a prompt. */
|
|
49
|
-
export interface PromptCapabilities {
|
|
50
|
-
image: boolean;
|
|
51
|
-
audio: boolean;
|
|
52
|
-
embeddedContext: boolean;
|
|
53
|
-
}
|
|
54
|
-
export interface AgentCapabilities {
|
|
55
|
-
loadSession: boolean;
|
|
56
|
-
promptCapabilities: PromptCapabilities;
|
|
57
|
-
}
|
|
58
|
-
export interface RunTurnInput {
|
|
59
|
-
sessionId: string;
|
|
60
|
-
/** Content blocks the client sent. */
|
|
61
|
-
prompt: readonly ContentBlock[];
|
|
62
|
-
/** Cancelled when the client sends `session/cancel` for this session. */
|
|
63
|
-
signal: AbortSignal;
|
|
64
|
-
}
|
|
65
|
-
export interface RunTurnResult {
|
|
66
|
-
stopReason: StopReason;
|
|
67
|
-
/** Optional summary text the agent produced. */
|
|
68
|
-
text?: string;
|
|
69
|
-
plan?: PlanEntry[];
|
|
70
|
-
usage?: {
|
|
71
|
-
used: number;
|
|
72
|
-
size: number;
|
|
73
|
-
cost?: UsageCost | undefined;
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* A tool-call permission request the agent surfaces to the client.
|
|
78
|
-
*/
|
|
79
|
-
export interface RunTurnPermissionRequest {
|
|
80
|
-
toolCall: {
|
|
81
|
-
toolCallId: string;
|
|
82
|
-
title: string;
|
|
83
|
-
kind?: ToolKind | undefined;
|
|
84
|
-
};
|
|
85
|
-
options: PermissionOption[];
|
|
86
|
-
}
|
|
87
|
-
/** Client filesystem/terminal capabilities advertised at initialize. */
|
|
88
|
-
export interface ClientCapabilities {
|
|
89
|
-
fs?: {
|
|
90
|
-
readTextFile?: boolean | undefined;
|
|
91
|
-
writeTextFile?: boolean | undefined;
|
|
92
|
-
} | undefined;
|
|
93
|
-
terminal?: boolean | undefined;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Client-callback API handed to `runTurn`. Lets the agent's tools call back
|
|
97
|
-
* into the connected ACP client — ask for permission, and (when the client
|
|
98
|
-
* advertises the capability) use the client's filesystem and terminal so the
|
|
99
|
-
* editor's view (including unsaved buffers) is the source of truth.
|
|
100
|
-
*/
|
|
101
|
-
export interface RunTurnApi {
|
|
102
|
-
/**
|
|
103
|
-
* Ask the connected ACP client to approve/reject a tool call via the
|
|
104
|
-
* `session/request_permission` method. Resolves with the client's
|
|
105
|
-
* outcome. Rejects if no client channel is available or the request
|
|
106
|
-
* times out — the caller decides the fallback.
|
|
107
|
-
*/
|
|
108
|
-
requestPermission(req: RunTurnPermissionRequest): Promise<RequestPermissionOutcome>;
|
|
109
|
-
/** Capabilities the client advertised at initialize — gate tool wiring on these. */
|
|
110
|
-
clientCapabilities: ClientCapabilities;
|
|
111
|
-
/** Read a text file from the client's filesystem (`fs/read_text_file`). */
|
|
112
|
-
readTextFile(params: {
|
|
113
|
-
path: string;
|
|
114
|
-
line?: number;
|
|
115
|
-
limit?: number;
|
|
116
|
-
}): Promise<string>;
|
|
117
|
-
/** Write a text file in the client's filesystem (`fs/write_text_file`). */
|
|
118
|
-
writeTextFile(params: {
|
|
119
|
-
path: string;
|
|
120
|
-
content: string;
|
|
121
|
-
}): Promise<void>;
|
|
122
|
-
/**
|
|
123
|
-
* Run a command in the client's terminal (`terminal/create` →
|
|
124
|
-
* `wait_for_exit` → `output` → `release`) and resolve with the combined
|
|
125
|
-
* output and exit code.
|
|
126
|
-
*/
|
|
127
|
-
runTerminal(params: {
|
|
128
|
-
command: string;
|
|
129
|
-
args?: string[] | undefined;
|
|
130
|
-
cwd?: string | undefined;
|
|
131
|
-
}): Promise<{
|
|
132
|
-
output: string;
|
|
133
|
-
exitCode: number | null;
|
|
134
|
-
}>;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* The agent's per-turn work. Streams `SessionUpdate` notifications to
|
|
138
|
-
* `emit` and resolves with the final stopReason. Errors thrown from
|
|
139
|
-
* this iterable are converted to a `prompt_failed` JSON-RPC error.
|
|
140
|
-
*
|
|
141
|
-
* `api` is an optional client-callback surface (permission requests).
|
|
142
|
-
* Older runTurn implementations that ignore it keep working unchanged.
|
|
143
|
-
*/
|
|
144
|
-
export type RunTurn = (input: RunTurnInput, emit: (update: unknown) => void, api?: RunTurnApi) => Promise<RunTurnResult>;
|
|
145
|
-
export interface SessionState {
|
|
146
|
-
id: string;
|
|
147
|
-
cwd: string;
|
|
148
|
-
/** Per-turn abort signal — aborted when the session is cancelled or closed. */
|
|
149
|
-
abort: AbortController;
|
|
150
|
-
/** Active mode, advertised to the client in current_mode_update. */
|
|
151
|
-
modeId: string;
|
|
152
|
-
/** Created at, for session/list ordering. */
|
|
153
|
-
createdAt: string;
|
|
154
|
-
/** Last activity timestamp, for session/info_update. */
|
|
155
|
-
updatedAt: string;
|
|
156
|
-
/** Optional human title. */
|
|
157
|
-
title?: string;
|
|
158
|
-
}
|
|
159
|
-
/** MCP-style session mode advertised in current_mode_update. */
|
|
160
|
-
export interface SessionMode {
|
|
161
|
-
id: string;
|
|
162
|
-
name: string;
|
|
163
|
-
description?: string | undefined;
|
|
164
|
-
}
|
|
165
|
-
export interface SessionConfigOption {
|
|
166
|
-
id: string;
|
|
167
|
-
name: string;
|
|
168
|
-
type: 'select' | string;
|
|
169
|
-
currentValue: string;
|
|
170
|
-
options: {
|
|
171
|
-
value: string;
|
|
172
|
-
name: string;
|
|
173
|
-
description?: string | undefined;
|
|
174
|
-
}[];
|
|
175
|
-
}
|
|
176
|
-
export interface ProtocolHandlerOptions {
|
|
177
|
-
transport: AgentServerTransport;
|
|
178
|
-
/** Where the server is running; used for new sessions' default cwd. */
|
|
179
|
-
defaultCwd: string;
|
|
180
|
-
/** Agent's per-turn implementation. */
|
|
181
|
-
runTurn: RunTurn;
|
|
182
|
-
/**
|
|
183
|
-
* Optional callbacks for the lifecycle events the server should
|
|
184
|
-
* surface to the client. All default to no-ops.
|
|
185
|
-
*/
|
|
186
|
-
onSessionNew?: ((state: SessionState) => void) | undefined;
|
|
187
|
-
/** Static list of available modes (advertised to clients). */
|
|
188
|
-
modes?: readonly SessionMode[] | undefined;
|
|
189
|
-
/** Static list of config options. */
|
|
190
|
-
configOptions?: readonly SessionConfigOption[] | undefined;
|
|
191
|
-
/** Agent name advertised in initialize. */
|
|
192
|
-
agentName?: string | undefined;
|
|
193
|
-
/**
|
|
194
|
-
* Optional source of replayable conversation history for `session/load`.
|
|
195
|
-
* Returns the `session/update` payloads (user/agent message chunks) to
|
|
196
|
-
* stream back to the client before the load response. Wired from
|
|
197
|
-
* `makeACPServerAgentTurn(...).replay`.
|
|
198
|
-
*/
|
|
199
|
-
replayFor?: ((sessionId: string) => Array<{
|
|
200
|
-
sessionUpdate: string;
|
|
201
|
-
content: unknown;
|
|
202
|
-
}>) | undefined;
|
|
203
|
-
/**
|
|
204
|
-
* Optional hook to prime the turn engine's session history on cold
|
|
205
|
-
* `session/load` (server restart). Wired from `makeACPServerAgentTurn(...).seed`
|
|
206
|
-
* — it re-feeds the persisted conversation into the next-created Agent so
|
|
207
|
-
* the model resumes, not just the client UI.
|
|
208
|
-
*/
|
|
209
|
-
seedFor?: ((sessionId: string, history: Array<{
|
|
210
|
-
sessionUpdate: string;
|
|
211
|
-
content: unknown;
|
|
212
|
-
}>) => void) | undefined;
|
|
213
|
-
/**
|
|
214
|
-
* Optional durable session store. When set, sessions + their recorded
|
|
215
|
-
* history are persisted on create/prompt and restored on `session/load`,
|
|
216
|
-
* so a reconnecting client can resume after a server restart.
|
|
217
|
-
* (Structural type — `ACPSessionStore` satisfies it without a value import.)
|
|
218
|
-
*/
|
|
219
|
-
store?: SessionPersistence | undefined;
|
|
220
|
-
}
|
|
221
|
-
/** Minimal durable-store contract the handler uses (ACPSessionStore satisfies it). */
|
|
222
|
-
export interface SessionPersistence {
|
|
223
|
-
save(state: SessionState, history?: Array<{
|
|
224
|
-
sessionUpdate: string;
|
|
225
|
-
content: unknown;
|
|
226
|
-
}>): Promise<unknown>;
|
|
227
|
-
load(sessionId: string): Promise<(Partial<SessionState> & {
|
|
228
|
-
history?: Array<{
|
|
229
|
-
sessionUpdate: string;
|
|
230
|
-
content: unknown;
|
|
231
|
-
}> | undefined;
|
|
232
|
-
}) | null>;
|
|
233
|
-
}
|
|
45
|
+
import { WRONGSTACK_VERSION, type ProtocolHandlerOptions } from './protocol-contract.js';
|
|
46
|
+
export { WRONGSTACK_VERSION };
|
|
47
|
+
export type { AgentCapabilities, ClientCapabilities, PromptCapabilities, ProtocolHandlerOptions, RunTurn, RunTurnApi, RunTurnInput, RunTurnPermissionRequest, RunTurnResult, SessionConfigOption, SessionMode, SessionPersistence, SessionState, } from './protocol-contract.js';
|
|
234
48
|
export declare class ACPProtocolHandler {
|
|
235
49
|
private readonly transport;
|
|
236
50
|
private readonly defaultCwd;
|
|
@@ -241,6 +55,8 @@ export declare class ACPProtocolHandler {
|
|
|
241
55
|
private readonly agentName;
|
|
242
56
|
private readonly replayFor;
|
|
243
57
|
private readonly seedFor;
|
|
58
|
+
private readonly disposeFor;
|
|
59
|
+
private readonly maxSessions;
|
|
244
60
|
private readonly store;
|
|
245
61
|
private initialized;
|
|
246
62
|
private clientCapabilities;
|
|
@@ -264,6 +80,7 @@ export declare class ACPProtocolHandler {
|
|
|
264
80
|
handleMessage(msg: unknown): Promise<boolean>;
|
|
265
81
|
/** Abort all active turns and drop session state. */
|
|
266
82
|
close(): void;
|
|
83
|
+
private disposeSession;
|
|
267
84
|
private handleRequest;
|
|
268
85
|
private handleInitialize;
|
|
269
86
|
private handleAuthenticate;
|
|
@@ -289,4 +106,13 @@ export declare class ACPProtocolHandler {
|
|
|
289
106
|
private sendError;
|
|
290
107
|
private allocId;
|
|
291
108
|
}
|
|
109
|
+
declare function errorToJsonRpc(err: unknown): {
|
|
110
|
+
code: number;
|
|
111
|
+
message: string;
|
|
112
|
+
data?: unknown;
|
|
113
|
+
};
|
|
114
|
+
/** Internal deterministic seam used by the per-file coverage suite. */
|
|
115
|
+
export declare const protocolHandlerCoverage: {
|
|
116
|
+
errorToJsonRpc: typeof errorToJsonRpc;
|
|
117
|
+
};
|
|
292
118
|
//# sourceMappingURL=protocol-handler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol-handler.d.ts","sourceRoot":"","sources":["../../src/agent/protocol-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,OAAO,EAEL,
|
|
1
|
+
{"version":3,"file":"protocol-handler.d.ts","sourceRoot":"","sources":["../../src/agent/protocol-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,OAAO,EAEL,kBAAkB,EAKlB,KAAK,sBAAsB,EAS5B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAC9B,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,kBAAkB,EAClB,sBAAsB,EACtB,OAAO,EACP,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,aAAa,EACb,mBAAmB,EACnB,WAAW,EACX,kBAAkB,EAClB,YAAY,GACb,MAAM,wBAAwB,CAAC;AAwBhC,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsC;IAChE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgC;IAC7D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAyB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAiC;IAC/D,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAEZ;IACd,OAAO,CAAC,QAAQ,CAAC,OAAO,CAEV;IACd,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA4C;IACvE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAiC;IAEvD,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,kBAAkB,CAA0B;IACpD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmC;IAC5D,OAAO,CAAC,MAAM,CAAK;IAInB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAGvB;IACJ,OAAO,CAAC,SAAS,CAAK;IAEtB,YAAY,IAAI,EAAE,sBAAsB,EAyBvC;IAED;;;;OAIG;IACH,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,mBAAmB;IAY3B;;;;OAIG;IACG,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAoBlD;IAED,qDAAqD;IACrD,KAAK,IAAI,IAAI,CAWZ;IAED,OAAO,CAAC,cAAc;YAYR,aAAa;YA+Db,gBAAgB;YAwDhB,kBAAkB;YAUlB,YAAY;YAUZ,gBAAgB;YAqDhB,iBAAiB;YA0FjB,mBAAmB;YAwBnB,kBAAkB;YAuBlB,mBAAmB;YA0BnB,iBAAiB;YAiDjB,mBAAmB;YAanB,kBAAkB;YAKlB,sBAAsB;YAStB,gBAAgB;YAKhB,mBAAmB;YAoGnB,aAAa;YAmBb,qBAAqB;YAwBrB,iBAAiB;YAsBjB,kBAAkB;YA6BlB,gBAAgB;IAI9B,2EAA2E;YAC7D,OAAO;YAYP,SAAS;IAWvB,OAAO,CAAC,OAAO;CAGhB;AAMD,iBAAS,cAAc,CAAC,GAAG,EAAE,OAAO,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,OAAO,CAAA;CAAE,CAcvF;AAED,uEAAuE;AACvE,eAAO,MAAM,uBAAuB;;CAAqB,CAAC"}
|
|
@@ -38,7 +38,8 @@
|
|
|
38
38
|
* it. On abort, the adapter maps the resulting `AbortError` to
|
|
39
39
|
* `{stopReason: 'cancelled'}`.
|
|
40
40
|
*/
|
|
41
|
-
import type { Agent } from '@wrongstack/core';
|
|
41
|
+
import type { Agent, AgentInput } from '@wrongstack/core/agent';
|
|
42
|
+
import type { ContentBlock, PlanEntry, StopReason, ToolKind, UsageCost } from '../types/acp-v1.js';
|
|
42
43
|
import type { RunTurn, RunTurnApi, RunTurnResult } from './protocol-handler.js';
|
|
43
44
|
export interface ACPServerAgentTurnOptions {
|
|
44
45
|
/**
|
|
@@ -60,6 +61,10 @@ export interface ACPServerAgentTurnOptions {
|
|
|
60
61
|
* Default 5 minutes.
|
|
61
62
|
*/
|
|
62
63
|
timeoutMs?: number | undefined;
|
|
64
|
+
/** Maximum replay entries retained per session. Default 1000. */
|
|
65
|
+
maxHistoryEntries?: number | undefined;
|
|
66
|
+
/** Maximum serialized replay bytes retained per session. Default 8 MiB. */
|
|
67
|
+
maxHistoryBytes?: number | undefined;
|
|
63
68
|
}
|
|
64
69
|
/** A recorded conversation turn, replayable on `session/load`. */
|
|
65
70
|
interface SessionReplayUpdate {
|
|
@@ -87,6 +92,8 @@ export interface ACPServerAgentTurn {
|
|
|
87
92
|
sessionUpdate: string;
|
|
88
93
|
content: unknown;
|
|
89
94
|
}>): void;
|
|
95
|
+
/** Drop the session's Agent, timers, seed marker, and in-memory replay history. */
|
|
96
|
+
dispose(sessionId: string): void;
|
|
90
97
|
}
|
|
91
98
|
/**
|
|
92
99
|
* Build a `RunTurn` that owns per-session `Agent` instances and
|
|
@@ -97,6 +104,33 @@ export interface ACPServerAgentTurn {
|
|
|
97
104
|
* `.replay(sessionId)`).
|
|
98
105
|
*/
|
|
99
106
|
export declare function makeACPServerAgentTurn(opts: ACPServerAgentTurnOptions): ACPServerAgentTurn;
|
|
107
|
+
declare function finitePositiveLimit(value: number | undefined, fallback: number): number;
|
|
108
|
+
declare function trimHistory(entries: SessionReplayUpdate[], retainedBytes: number, maxEntries: number, maxBytes: number): number;
|
|
109
|
+
declare function replayEntryBytes(entry: SessionReplayUpdate): number;
|
|
110
|
+
/**
|
|
111
|
+
* Prime a freshly-created agent's conversation state with restored history.
|
|
112
|
+
* Each recorded user/agent chunk becomes a `user`/`assistant` message so the
|
|
113
|
+
* model continues the prior conversation instead of starting blank.
|
|
114
|
+
*/
|
|
115
|
+
declare function seedAgentContext(agent: Agent, history: ReadonlyArray<{
|
|
116
|
+
sessionUpdate: string;
|
|
117
|
+
content: unknown;
|
|
118
|
+
}>): void;
|
|
119
|
+
/** Map a WrongStack tool name to the closest ACP ToolKind for UI grouping. */
|
|
120
|
+
declare function toolNameToKind(name: string): ToolKind;
|
|
121
|
+
/** A short, human-readable title for a tool call card. */
|
|
122
|
+
declare function toolTitle(name: string, input: unknown): string;
|
|
123
|
+
declare function isRecord(v: unknown): v is Record<string, unknown>;
|
|
124
|
+
/**
|
|
125
|
+
* Convert an ACP `ContentBlock[]` prompt into a core `AgentInput`.
|
|
126
|
+
*
|
|
127
|
+
* When the prompt is all text we return a plain string (the common,
|
|
128
|
+
* cheapest path). When it carries images we build a multimodal
|
|
129
|
+
* `ContentBlock[]` the provider can pass to a vision-capable model.
|
|
130
|
+
* Audio and resource blocks have no core representation yet, so they're
|
|
131
|
+
* recorded as bracketed text placeholders alongside the other content.
|
|
132
|
+
*/
|
|
133
|
+
declare function promptToAgentInput(blocks: readonly ContentBlock[]): AgentInput;
|
|
100
134
|
/**
|
|
101
135
|
* Tear down the agents and timers held by a turn factory. The
|
|
102
136
|
* server's `close()` should call this so child connections don't
|
|
@@ -105,5 +139,59 @@ export declare function makeACPServerAgentTurn(opts: ACPServerAgentTurnOptions):
|
|
|
105
139
|
export declare function disposeACPServerAgentTurn(opts: {
|
|
106
140
|
agents: Map<string, Agent>;
|
|
107
141
|
}): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* Convert an ACP `ContentBlock[]` prompt to a single user-message
|
|
144
|
+
* string. Text blocks are concatenated; image / audio / resource
|
|
145
|
+
* blocks are recorded as a bracketed placeholder (full multimodal
|
|
146
|
+
* support is a future PR — the adapter is v1-text only for now).
|
|
147
|
+
*/
|
|
148
|
+
declare function promptToText(blocks: readonly ContentBlock[]): string;
|
|
149
|
+
/**
|
|
150
|
+
* Extract the agent's final text from a `RunResult`. The shape
|
|
151
|
+
* varies across core versions, so we read the most common fields
|
|
152
|
+
* defensively and concatenate whatever text we find.
|
|
153
|
+
*/
|
|
154
|
+
declare function extractText(result: unknown): string;
|
|
155
|
+
/**
|
|
156
|
+
* Map a `RunResult` (and the parent signal) to a v1 `StopReason`.
|
|
157
|
+
*
|
|
158
|
+
* If the parent signal was aborted, return `'cancelled'`. Otherwise
|
|
159
|
+
* the agent completed normally — we treat any non-error result
|
|
160
|
+
* as `'end_turn'`. The core `RunResult` doesn't currently surface
|
|
161
|
+
* a per-turn stop reason, so v1's `'max_tokens'`, `'max_turn_requests'`,
|
|
162
|
+
* and `'refusal'` discriminators can't be emitted precisely; we
|
|
163
|
+
* log a warning if the result carries an error and return the
|
|
164
|
+
* generic end_turn.
|
|
165
|
+
*/
|
|
166
|
+
declare function pickStopReason(result: unknown, signal: AbortSignal): StopReason;
|
|
167
|
+
/**
|
|
168
|
+
* Extract a plan from the agent's RunResult, if available.
|
|
169
|
+
* The plan is an array of PlanEntry objects.
|
|
170
|
+
*/
|
|
171
|
+
declare function extractPlan(result: unknown): PlanEntry[];
|
|
172
|
+
/**
|
|
173
|
+
* Extract usage/token info from the agent's RunResult, if available.
|
|
174
|
+
*/
|
|
175
|
+
declare function extractUsage(result: unknown): {
|
|
176
|
+
used: number;
|
|
177
|
+
size: number;
|
|
178
|
+
cost?: UsageCost | undefined;
|
|
179
|
+
} | null;
|
|
180
|
+
/** Internal deterministic seams used by the per-file coverage suite. */
|
|
181
|
+
export declare const serverAgentTurnCoverage: {
|
|
182
|
+
finitePositiveLimit: typeof finitePositiveLimit;
|
|
183
|
+
trimHistory: typeof trimHistory;
|
|
184
|
+
replayEntryBytes: typeof replayEntryBytes;
|
|
185
|
+
seedAgentContext: typeof seedAgentContext;
|
|
186
|
+
toolNameToKind: typeof toolNameToKind;
|
|
187
|
+
toolTitle: typeof toolTitle;
|
|
188
|
+
isRecord: typeof isRecord;
|
|
189
|
+
promptToAgentInput: typeof promptToAgentInput;
|
|
190
|
+
promptToText: typeof promptToText;
|
|
191
|
+
extractText: typeof extractText;
|
|
192
|
+
pickStopReason: typeof pickStopReason;
|
|
193
|
+
extractPlan: typeof extractPlan;
|
|
194
|
+
extractUsage: typeof extractUsage;
|
|
195
|
+
};
|
|
108
196
|
export {};
|
|
109
197
|
//# sourceMappingURL=server-agent-turn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-agent-turn.d.ts","sourceRoot":"","sources":["../../src/agent/server-agent-turn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"server-agent-turn.d.ts","sourceRoot":"","sources":["../../src/agent/server-agent-turn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAChE,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,EACV,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EACV,OAAO,EACP,UAAU,EACV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,MAAM,WAAW,yBAAyB;IACxC;;;;;;;;;;;OAWG;IACH,QAAQ,EAAE,CACR,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,UAAU,KACb,OAAO,CAAC,KAAK,CAAC,GAAG,KAAK,CAAC;IAC5B;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,iEAAiE;IACjE,iBAAiB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,2EAA2E;IAC3E,eAAe,CAAC,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CAcrE;AAED,wEAAwE;AACxE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;CAcnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/agent/session-store.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,2EAA2E;AAC3E,UAAU,sBAAsB;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,uEAAuE;AACvE,MAAM,WAAW,gBAAiB,SAAQ,OAAO,CAAC,YAAY,CAAC;IAC7D,OAAO,CAAC,EAAE,sBAAsB,EAAE,GAAG,SAAS,CAAC;CAChD;AAED,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B;;;;;OAKG;IACH,OAAO,CAAC,WAAW,CAAS;IAE5B,YAAY,IAAI,GAAE,mBAAwB,EAEzC;IAED,sEAAsE;IAChE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAI1B;IAED;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,sBAAsB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"session-store.d.ts","sourceRoot":"","sources":["../../src/agent/session-store.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE1D,2EAA2E;AAC3E,UAAU,sBAAsB;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,uEAAuE;AACvE,MAAM,WAAW,gBAAiB,SAAQ,OAAO,CAAC,YAAY,CAAC;IAC7D,OAAO,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