@av-pi-studio/server 0.0.114 → 0.0.116
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 +8 -8
- package/dist/agent/agent-service.d.ts +5 -0
- package/dist/agent/agent-service.js +12 -0
- package/dist/agent/index.d.ts +0 -1
- package/dist/agent/index.js +0 -1
- package/dist/agent/mcp-server.d.ts +3 -13
- package/dist/agent/mcp-server.js +2 -10
- package/dist/agent/provider-contract.d.ts +0 -7
- package/dist/agent/providers/mock/mock-provider.d.ts +16 -3
- package/dist/agent/providers/mock/mock-provider.js +80 -8
- package/dist/agent/providers/mock/stream-script.d.ts +28 -0
- package/dist/agent/providers/mock/stream-script.js +57 -0
- package/dist/agent/providers/mock/tool-script.d.ts +28 -0
- package/dist/agent/providers/mock/tool-script.js +72 -0
- package/dist/agent/providers/pi/agent.js +15 -7
- package/dist/agent/providers/pi/event-mapper.d.ts +15 -12
- package/dist/agent/providers/pi/event-mapper.js +33 -15
- package/dist/agent/providers/pi/tool-output-coalescer.d.ts +58 -0
- package/dist/agent/providers/pi/tool-output-coalescer.js +121 -0
- package/dist/daemon/bootstrap.d.ts +18 -2
- package/dist/daemon/bootstrap.js +63 -13
- package/dist/daemon/dev-bootstrap.d.ts +7 -0
- package/dist/daemon/dev-bootstrap.js +34 -5
- package/dist/daemon/dev-main.js +5 -2
- package/dist/daemon/loopback.d.ts +4 -0
- package/dist/daemon/loopback.js +12 -0
- package/dist/daemon/main.js +4 -10
- package/dist/extensions/curated-packs.d.ts +0 -1
- package/dist/extensions/curated-packs.js +1 -6
- package/dist/extensions/sync-executor.js +1 -1
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +1 -0
- package/dist/logging/log-tap.d.ts +33 -0
- package/dist/logging/log-tap.js +233 -0
- package/dist/logging/logger.d.ts +6 -0
- package/dist/logging/logger.js +4 -0
- package/dist/observability/daemon-logs-rpc.d.ts +12 -0
- package/dist/observability/daemon-logs-rpc.js +17 -0
- package/dist/observability/daemon-logs-service.d.ts +67 -0
- package/dist/observability/daemon-logs-service.js +165 -0
- package/dist/observability/daemon-status-rpc.d.ts +12 -0
- package/dist/observability/daemon-status-rpc.js +21 -0
- package/dist/observability/daemon-status-service.d.ts +85 -0
- package/dist/observability/daemon-status-service.js +154 -0
- package/dist/test-support/auth-gated-rpc.d.ts +18 -0
- package/dist/test-support/auth-gated-rpc.js +80 -0
- package/dist/test-support/daemon-test-client.d.ts +43 -0
- package/dist/test-support/daemon-test-client.js +91 -0
- package/dist/test-support/external-fixtures-scenario.d.ts +30 -0
- package/dist/test-support/external-fixtures-scenario.js +223 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +7 -0
- package/dist/ws/session.d.ts +11 -0
- package/dist/ws/session.js +11 -0
- package/dist/ws/ws-server.js +2 -0
- package/package.json +3 -3
- package/dist/agent/permissions.d.ts +0 -71
- package/dist/agent/permissions.js +0 -132
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { DevBootstrapHandle } from "../daemon/dev-bootstrap.js";
|
|
2
|
+
import { LogTap } from "../logging/log-tap.js";
|
|
3
|
+
import { type Logger } from "../logging/logger.js";
|
|
4
|
+
import { type TestClient, type WireFrame } from "./daemon-test-client.js";
|
|
5
|
+
/**
|
|
6
|
+
* The scripted dev-daemon scenario behind the external-client wire fixtures
|
|
7
|
+
* (swe/architecture/external-client-fixtures.md). Shared by the Layer B contract test
|
|
8
|
+
* (`daemon/external-fixtures-e2e.test.ts`) and the recorder script
|
|
9
|
+
* (`scripts/record-external-fixtures.ts`), so what is recorded is exactly what is verified.
|
|
10
|
+
*
|
|
11
|
+
* Drives every daemon-output type through its real path and returns the FIRST captured frame per
|
|
12
|
+
* fixture variant key (the manifest `file` stem, e.g. `agent_stream.tool_call.partial`). Matching
|
|
13
|
+
* is by predicate over the frame log, never by index.
|
|
14
|
+
*/
|
|
15
|
+
/** The dev daemon must be started with at least this `mockTurnDelayMs` so a mock turn is still
|
|
16
|
+
* running when `interrupt_agent` arrives (`turn_canceled`). */
|
|
17
|
+
export declare const SCENARIO_MOCK_TURN_DELAY_MS = 150;
|
|
18
|
+
/**
|
|
19
|
+
* Dev-daemon options the scenario needs: the turn delay plus a tapped silent-output logger, so the
|
|
20
|
+
* `daemon_logs_*` stage 2 steps have a stream (`logTap` is shared with the bootstrap's service).
|
|
21
|
+
*/
|
|
22
|
+
export declare function scenarioDaemonOptions(): {
|
|
23
|
+
logger: Logger;
|
|
24
|
+
logTap: LogTap;
|
|
25
|
+
mockTurnDelayMs: number;
|
|
26
|
+
};
|
|
27
|
+
/** Fixture-variant key for `frame`, or `undefined` when the frame is not a fixtured variant. */
|
|
28
|
+
export declare function variantKey(frame: WireFrame): string | undefined;
|
|
29
|
+
export declare function runExternalFixtureScenario(dev: DevBootstrapHandle, client: TestClient): Promise<Map<string, WireFrame>>;
|
|
30
|
+
//# sourceMappingURL=external-fixtures-scenario.d.ts.map
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
import { MOCK_REBIND_ENTRY_ID } from "../agent/providers/mock/mock-provider.js";
|
|
3
|
+
import { LogTap } from "../logging/log-tap.js";
|
|
4
|
+
import { createLogger } from "../logging/logger.js";
|
|
5
|
+
import { listeningPort, messageOf } from "./daemon-test-client.js";
|
|
6
|
+
/**
|
|
7
|
+
* The scripted dev-daemon scenario behind the external-client wire fixtures
|
|
8
|
+
* (swe/architecture/external-client-fixtures.md). Shared by the Layer B contract test
|
|
9
|
+
* (`daemon/external-fixtures-e2e.test.ts`) and the recorder script
|
|
10
|
+
* (`scripts/record-external-fixtures.ts`), so what is recorded is exactly what is verified.
|
|
11
|
+
*
|
|
12
|
+
* Drives every daemon-output type through its real path and returns the FIRST captured frame per
|
|
13
|
+
* fixture variant key (the manifest `file` stem, e.g. `agent_stream.tool_call.partial`). Matching
|
|
14
|
+
* is by predicate over the frame log, never by index.
|
|
15
|
+
*/
|
|
16
|
+
/** The dev daemon must be started with at least this `mockTurnDelayMs` so a mock turn is still
|
|
17
|
+
* running when `interrupt_agent` arrives (`turn_canceled`). */
|
|
18
|
+
export const SCENARIO_MOCK_TURN_DELAY_MS = 150;
|
|
19
|
+
/**
|
|
20
|
+
* Dev-daemon options the scenario needs: the turn delay plus a tapped silent-output logger, so the
|
|
21
|
+
* `daemon_logs_*` stage 2 steps have a stream (`logTap` is shared with the bootstrap's service).
|
|
22
|
+
*/
|
|
23
|
+
export function scenarioDaemonOptions() {
|
|
24
|
+
const logTap = new LogTap();
|
|
25
|
+
const logger = createLogger({
|
|
26
|
+
level: "info",
|
|
27
|
+
tap: logTap,
|
|
28
|
+
stdoutStream: new PassThrough(),
|
|
29
|
+
pretty: false,
|
|
30
|
+
});
|
|
31
|
+
return { logger, logTap, mockTurnDelayMs: SCENARIO_MOCK_TURN_DELAY_MS };
|
|
32
|
+
}
|
|
33
|
+
/** Fixture-variant key for `frame`, or `undefined` when the frame is not a fixtured variant. */
|
|
34
|
+
export function variantKey(frame) {
|
|
35
|
+
const m = messageOf(frame);
|
|
36
|
+
const type = String(m.type);
|
|
37
|
+
switch (type) {
|
|
38
|
+
case "status":
|
|
39
|
+
return "status.server_info";
|
|
40
|
+
case "agent_stream": {
|
|
41
|
+
const event = m.event;
|
|
42
|
+
return `agent_stream.${event.kind}${event.kind === "tool_call" && event.partial ? ".partial" : ""}`;
|
|
43
|
+
}
|
|
44
|
+
case "agent_update":
|
|
45
|
+
if ("model" in m)
|
|
46
|
+
return "agent_update.model";
|
|
47
|
+
return "status" in m ? "agent_update" : undefined;
|
|
48
|
+
case "agent_ui_request":
|
|
49
|
+
return `agent_ui_request.${String(m.method)}${m.removed === true ? ".removed" : ""}`;
|
|
50
|
+
case "agent_ui_resolved":
|
|
51
|
+
return `agent_ui_resolved.${String(m.reason)}`;
|
|
52
|
+
case "agent_ui_respond_response": {
|
|
53
|
+
const payload = m.payload;
|
|
54
|
+
return payload.ok ? "agent_ui_respond_response.ok" : "agent_ui_respond_response.not_found";
|
|
55
|
+
}
|
|
56
|
+
case "pong":
|
|
57
|
+
case "daemon_status_response":
|
|
58
|
+
case "daemon_status_subscribe_response":
|
|
59
|
+
case "daemon_status_unsubscribe_response":
|
|
60
|
+
case "daemon_status_update":
|
|
61
|
+
case "daemon_logs_subscribe_response":
|
|
62
|
+
case "daemon_logs_unsubscribe_response":
|
|
63
|
+
case "daemon_log_lines":
|
|
64
|
+
case "list_agents_response":
|
|
65
|
+
case "agent_archived":
|
|
66
|
+
case "agent_deleted":
|
|
67
|
+
case "agent_timeline_reset":
|
|
68
|
+
case "fetch_agent_timeline_response":
|
|
69
|
+
case "agent_session_stats_response":
|
|
70
|
+
case "interrupt_response":
|
|
71
|
+
case "agent_ui_list_response":
|
|
72
|
+
case "rpc_error":
|
|
73
|
+
return type;
|
|
74
|
+
default:
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const isStream = (kind, extra = () => true) => (frame) => {
|
|
79
|
+
const m = messageOf(frame);
|
|
80
|
+
if (m.type !== "agent_stream")
|
|
81
|
+
return false;
|
|
82
|
+
const event = m.event;
|
|
83
|
+
return event.kind === kind && extra(event);
|
|
84
|
+
};
|
|
85
|
+
const isType = (type, extra = () => true) => (frame) => {
|
|
86
|
+
const m = messageOf(frame);
|
|
87
|
+
return m.type === type && extra(m);
|
|
88
|
+
};
|
|
89
|
+
export async function runExternalFixtureScenario(dev, client) {
|
|
90
|
+
const { rpc, waitFor } = client;
|
|
91
|
+
const createAgent = async (initialPrompt) => {
|
|
92
|
+
const created = await rpc("create_agent_request", {
|
|
93
|
+
config: { provider: "mock", cwd: "/tmp" },
|
|
94
|
+
...(initialPrompt !== undefined ? { initialPrompt } : {}),
|
|
95
|
+
});
|
|
96
|
+
return created.payload.agentId;
|
|
97
|
+
};
|
|
98
|
+
// `MockAgentSession.emitUiRequest` is deliberately not part of the provider-neutral
|
|
99
|
+
// `AgentSession` contract; the dev handle's `manager` is the sanctioned test seam to reach it.
|
|
100
|
+
const mockSession = (agentId) => {
|
|
101
|
+
const session = dev.manager.get(agentId)?.session;
|
|
102
|
+
if (!session)
|
|
103
|
+
throw new Error(`no live session for ${agentId}`);
|
|
104
|
+
return session;
|
|
105
|
+
};
|
|
106
|
+
// Liveness.
|
|
107
|
+
client.send({ type: "ping", requestId: "scenario-ping", clientSentAt: Date.now() });
|
|
108
|
+
await waitFor(isType("pong"));
|
|
109
|
+
// Normal turn: user_message, turn_started, assistant_message, turn_completed, agent_update.
|
|
110
|
+
const agentId = await createAgent("hello");
|
|
111
|
+
await waitFor(isStream("turn_completed"));
|
|
112
|
+
await waitFor(isType("agent_update", (m) => m.status === "idle"));
|
|
113
|
+
// Tool call with partials, then the `#stream` kinds the normal turn never produces.
|
|
114
|
+
await rpc("send_agent_prompt", { agentId, prompt: "#tool shell" });
|
|
115
|
+
for (const recipe of ["reasoning", "fail", "error"]) {
|
|
116
|
+
await rpc("send_agent_prompt", { agentId, prompt: `#stream ${recipe}` });
|
|
117
|
+
}
|
|
118
|
+
// Cancellation: `send_agent_prompt` blocks until the turn ends, so send raw and interrupt once
|
|
119
|
+
// the daemon has recorded the prompt (the mock turn is still pending its delay).
|
|
120
|
+
client.send({
|
|
121
|
+
type: "session",
|
|
122
|
+
message: {
|
|
123
|
+
type: "send_agent_prompt",
|
|
124
|
+
requestId: "scenario-slow",
|
|
125
|
+
agentId,
|
|
126
|
+
prompt: "slow turn to cancel",
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
await waitFor(isStream("user_message", (e) => e.text === "slow turn to cancel"));
|
|
130
|
+
await rpc("interrupt_agent", { agentId });
|
|
131
|
+
await waitFor(isStream("turn_canceled"));
|
|
132
|
+
await waitFor(isType("agent_prompt_response", (m) => m.requestId === "scenario-slow"));
|
|
133
|
+
// Compaction (mock holds `started` for ~1.5 s).
|
|
134
|
+
await rpc("agent_compact_request", { agentId });
|
|
135
|
+
// Reads.
|
|
136
|
+
await rpc("list_agents_request");
|
|
137
|
+
await rpc("fetch_agent_timeline_request", { agentId, direction: "after" });
|
|
138
|
+
await rpc("agent_session_stats_request", { agentId });
|
|
139
|
+
// Extension UI: dialogs, a hand-off pair, a non-dialog, a retained surface, list, removal.
|
|
140
|
+
const session = mockSession(agentId);
|
|
141
|
+
session.emitUiRequest({ method: "select", payload: { title: "Pick one", options: ["a", "b"] } });
|
|
142
|
+
session.emitUiRequest({
|
|
143
|
+
method: "confirm",
|
|
144
|
+
payload: { title: "Proceed?", message: "Apply the change?" },
|
|
145
|
+
});
|
|
146
|
+
session.emitUiRequest({ method: "input", payload: { title: "Name", placeholder: "name" } });
|
|
147
|
+
session.emitUiRequest({ method: "editor", payload: { title: "Edit", prefill: "text" } });
|
|
148
|
+
session.emitUiRequest({ method: "notify", expectsResponse: false, payload: { message: "Done" } });
|
|
149
|
+
session.emitUiRequest({
|
|
150
|
+
method: "setStatus",
|
|
151
|
+
expectsResponse: false,
|
|
152
|
+
surfaceKey: "status:build",
|
|
153
|
+
payload: { statusText: "building" },
|
|
154
|
+
});
|
|
155
|
+
await waitFor(isType("agent_ui_request", (m) => m.method === "setStatus"));
|
|
156
|
+
await rpc("agent_ui_list_request", { agentId });
|
|
157
|
+
session.emitUiRequest({
|
|
158
|
+
method: "setStatus",
|
|
159
|
+
expectsResponse: false,
|
|
160
|
+
surfaceKey: "status:build",
|
|
161
|
+
removed: true,
|
|
162
|
+
payload: {},
|
|
163
|
+
});
|
|
164
|
+
// Answered (confirm → {confirmed}, select → {value}); unknown id → not_found; timeout.
|
|
165
|
+
const uiRequestId = async (method) => String(messageOf(await waitFor(isType("agent_ui_request", (m) => m.method === method))).requestId);
|
|
166
|
+
await rpc("agent_ui_respond_request", {
|
|
167
|
+
uiRequestId: await uiRequestId("confirm"),
|
|
168
|
+
response: { confirmed: true },
|
|
169
|
+
});
|
|
170
|
+
await rpc("agent_ui_respond_request", {
|
|
171
|
+
uiRequestId: await uiRequestId("select"),
|
|
172
|
+
response: { value: "a" },
|
|
173
|
+
});
|
|
174
|
+
await rpc("agent_ui_respond_request", {
|
|
175
|
+
uiRequestId: "unknown-request-id",
|
|
176
|
+
response: { confirmed: true },
|
|
177
|
+
});
|
|
178
|
+
session.emitUiRequest({ method: "confirm", timeoutMs: 50, payload: { title: "Hurry" } });
|
|
179
|
+
await waitFor(isType("agent_ui_resolved", (m) => m.reason === "timeout"));
|
|
180
|
+
// Aborted + archived + deleted: a second agent with a dialog pending, then archive / delete.
|
|
181
|
+
const doomedId = await createAgent("bye");
|
|
182
|
+
await waitFor(isType("agent_update", (m) => m.agentId === doomedId && m.status === "idle"));
|
|
183
|
+
mockSession(doomedId).emitUiRequest({ method: "input", payload: { title: "Never answered" } });
|
|
184
|
+
await waitFor(isType("agent_ui_request", (m) => m.agentId === doomedId));
|
|
185
|
+
await rpc("archive_agent", { agentId: doomedId });
|
|
186
|
+
await waitFor(isType("agent_ui_resolved", (m) => m.reason === "aborted"));
|
|
187
|
+
await rpc("delete_agent", { agentId: doomedId });
|
|
188
|
+
// A session-less draft: the model switch is broadcast as `agent_update {model, modelProvider}`.
|
|
189
|
+
const draftId = await createAgent();
|
|
190
|
+
await rpc("agent_set_model_request", { agentId: draftId, provider: "mock", modelId: "mock-2" });
|
|
191
|
+
// Timeline reset: the mock rebinds its persistence handle, so `handleFork` runs for real.
|
|
192
|
+
await rpc("agent_fork_request", { agentId, entryId: MOCK_REBIND_ENTRY_ID });
|
|
193
|
+
await waitFor(isType("agent_timeline_reset"));
|
|
194
|
+
// Unknown message type with a requestId → rpc_error.
|
|
195
|
+
await rpc("scenario_no_such_type");
|
|
196
|
+
// Stage 2 (daemonObservability): status one-shot, subscribe → push (real 5 s interval) →
|
|
197
|
+
// unsubscribe; then a log subscription with a one-line backlog, a live push and unsubscribe.
|
|
198
|
+
await rpc("daemon_status_request");
|
|
199
|
+
await rpc("daemon_status_subscribe_request");
|
|
200
|
+
await waitFor(isType("daemon_status_update"), 10_000);
|
|
201
|
+
await rpc("daemon_status_unsubscribe_request");
|
|
202
|
+
dev.logger.info("external fixture log line");
|
|
203
|
+
await rpc("daemon_logs_subscribe_request", { minLevel: "info", tail: 1 });
|
|
204
|
+
dev.logger.info("external fixture live line");
|
|
205
|
+
await waitFor(isType("daemon_log_lines"), 2000);
|
|
206
|
+
await rpc("daemon_logs_unsubscribe_request");
|
|
207
|
+
const captured = new Map();
|
|
208
|
+
for (const frame of client.frames) {
|
|
209
|
+
const key = variantKey(frame);
|
|
210
|
+
if (key !== undefined && !captured.has(key))
|
|
211
|
+
captured.set(key, frame);
|
|
212
|
+
}
|
|
213
|
+
// HTTP health (unauthenticated).
|
|
214
|
+
const port = await listeningPort(dev.httpServer);
|
|
215
|
+
const response = await fetch(`http://127.0.0.1:${port}/api/health`);
|
|
216
|
+
captured.set("health", {
|
|
217
|
+
status: response.status,
|
|
218
|
+
contentType: response.headers.get("content-type"),
|
|
219
|
+
body: await response.json(),
|
|
220
|
+
});
|
|
221
|
+
return captured;
|
|
222
|
+
}
|
|
223
|
+
//# sourceMappingURL=external-fixtures-scenario.js.map
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
// Aligned workspace version, read from packages/server/package.json (never the root one — the
|
|
3
|
+
// root package.json deliberately carries no "version" field). This module sits one level below
|
|
4
|
+
// the package root in both `src/` and compiled `dist/`, so the specifier is "../package.json".
|
|
5
|
+
export const SERVER_VERSION = createRequire(import.meta.url)("../package.json")
|
|
6
|
+
.version;
|
|
7
|
+
//# sourceMappingURL=version.js.map
|
package/dist/ws/session.d.ts
CHANGED
|
@@ -9,6 +9,13 @@ export declare class Session {
|
|
|
9
9
|
readonly clientId: string;
|
|
10
10
|
readonly clientType: string;
|
|
11
11
|
capabilities: Record<string, boolean>;
|
|
12
|
+
/** Epoch ms of the handshake. A wall-clock fact for the connected-clients list. */
|
|
13
|
+
readonly connectedAt: number;
|
|
14
|
+
/** The hello's `appVersion`, verbatim; a connection fact (never persisted as a capability). */
|
|
15
|
+
readonly appVersion: string | undefined;
|
|
16
|
+
/** Socket peer address; direct sessions only (the relay has no peer address). */
|
|
17
|
+
readonly remoteAddress: string | undefined;
|
|
18
|
+
readonly transport: "direct" | "relay";
|
|
12
19
|
private readonly socket;
|
|
13
20
|
constructor(opts: {
|
|
14
21
|
id: string;
|
|
@@ -16,6 +23,10 @@ export declare class Session {
|
|
|
16
23
|
clientType: string;
|
|
17
24
|
capabilities: Record<string, boolean>;
|
|
18
25
|
socket: WebSocket;
|
|
26
|
+
connectedAt?: number;
|
|
27
|
+
appVersion?: string;
|
|
28
|
+
remoteAddress?: string;
|
|
29
|
+
transport?: "direct" | "relay";
|
|
19
30
|
});
|
|
20
31
|
/** True if the client advertised support for `flag` (or it was rehydrated from a prior hello). */
|
|
21
32
|
supports(flag: string): boolean;
|
package/dist/ws/session.js
CHANGED
|
@@ -9,12 +9,23 @@ export class Session {
|
|
|
9
9
|
clientId;
|
|
10
10
|
clientType;
|
|
11
11
|
capabilities;
|
|
12
|
+
/** Epoch ms of the handshake. A wall-clock fact for the connected-clients list. */
|
|
13
|
+
connectedAt;
|
|
14
|
+
/** The hello's `appVersion`, verbatim; a connection fact (never persisted as a capability). */
|
|
15
|
+
appVersion;
|
|
16
|
+
/** Socket peer address; direct sessions only (the relay has no peer address). */
|
|
17
|
+
remoteAddress;
|
|
18
|
+
transport;
|
|
12
19
|
socket;
|
|
13
20
|
constructor(opts) {
|
|
14
21
|
this.id = opts.id;
|
|
15
22
|
this.clientId = opts.clientId;
|
|
16
23
|
this.clientType = opts.clientType;
|
|
17
24
|
this.capabilities = opts.capabilities;
|
|
25
|
+
this.connectedAt = opts.connectedAt ?? Date.now();
|
|
26
|
+
this.appVersion = opts.appVersion;
|
|
27
|
+
this.remoteAddress = opts.remoteAddress;
|
|
28
|
+
this.transport = opts.transport ?? "direct";
|
|
18
29
|
this.socket = opts.socket;
|
|
19
30
|
}
|
|
20
31
|
/** True if the client advertised support for `flag` (or it was rehydrated from a prior hello). */
|
package/dist/ws/ws-server.js
CHANGED
|
@@ -73,6 +73,8 @@ export function createWebSocketServer(httpServer, deps) {
|
|
|
73
73
|
clientType: hello.data.clientType,
|
|
74
74
|
capabilities,
|
|
75
75
|
socket: ws,
|
|
76
|
+
appVersion: hello.data.appVersion,
|
|
77
|
+
remoteAddress: _req.socket.remoteAddress,
|
|
76
78
|
});
|
|
77
79
|
sessions.add(session);
|
|
78
80
|
const payload = serverInfoPayloadSchema.parse({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@av-pi-studio/server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.116",
|
|
4
4
|
"bin": {
|
|
5
5
|
"pi-studio-daemon": "dist/daemon/main.js"
|
|
6
6
|
},
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"clean": "rm -rf dist *.tsbuildinfo"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@av-pi-studio/protocol": "^0.0.
|
|
28
|
-
"@av-pi-studio/relay": "^0.0.
|
|
27
|
+
"@av-pi-studio/protocol": "^0.0.116",
|
|
28
|
+
"@av-pi-studio/relay": "^0.0.116",
|
|
29
29
|
"@earendil-works/pi-coding-agent": "^1.4.0",
|
|
30
30
|
"@xterm/addon-serialize": "^0.14.0",
|
|
31
31
|
"@xterm/headless": "^6.0.0",
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import type { Session } from "../ws/session.js";
|
|
2
|
-
import type { HandlerRegistry } from "../ws/router.js";
|
|
3
|
-
import type { AgentManager } from "./agent-manager.js";
|
|
4
|
-
/**
|
|
5
|
-
* Tool-call permission flow + question-permission bridge
|
|
6
|
-
* (features/tool-permissions.md § Flow messages / § Behavior / § Question-permission bridge).
|
|
7
|
-
*
|
|
8
|
-
* When an agent's mode requires approval:
|
|
9
|
-
* 1. A tool call creates an `AgentPermissionRequest`, flags the agent as awaiting-input, and
|
|
10
|
-
* broadcasts `agent_permission_request` to all clients.
|
|
11
|
-
* 2. The turn WAITS until `resolvePermission(requestId, response)` is called.
|
|
12
|
-
* 3. The first resolution wins; `agent_permission_resolved` is broadcast to all clients.
|
|
13
|
-
* 4. Full-access modes (`colorTier:"dangerous"`) emit no requests.
|
|
14
|
-
*
|
|
15
|
-
* Question bridge: Pi `select`/`input`/`editor`/`confirm` surface as question permissions. A
|
|
16
|
-
* `select` with `allowComment:true` is ONE combined question — answer the `select`, then
|
|
17
|
-
* auto-answer the follow-up optional `input` (supplied comment or empty string).
|
|
18
|
-
*/
|
|
19
|
-
export interface AgentPermissionRequestRecord {
|
|
20
|
-
requestId: string;
|
|
21
|
-
agentId: string;
|
|
22
|
-
toolName?: string;
|
|
23
|
-
action?: unknown;
|
|
24
|
-
responses?: string[];
|
|
25
|
-
/** Question-bridge kind. */
|
|
26
|
-
questionKind?: "select" | "input" | "editor" | "confirm";
|
|
27
|
-
allowComment?: boolean;
|
|
28
|
-
}
|
|
29
|
-
export type ResolutionResponse = string | Record<string, unknown>;
|
|
30
|
-
export interface LivePermission extends AgentPermissionRequestRecord {
|
|
31
|
-
resolve: (response: ResolutionResponse) => void;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* In-memory permission state (not separately persisted — only broadcast-live per scope).
|
|
35
|
-
* Keyed by `requestId`.
|
|
36
|
-
*/
|
|
37
|
-
export declare class PermissionStore {
|
|
38
|
-
private readonly pending;
|
|
39
|
-
add(req: LivePermission): void;
|
|
40
|
-
get(requestId: string): LivePermission | undefined;
|
|
41
|
-
remove(requestId: string): void;
|
|
42
|
-
listForAgent(agentId: string): LivePermission[];
|
|
43
|
-
}
|
|
44
|
-
export declare const globalPermissionStore: PermissionStore;
|
|
45
|
-
export interface PermissionServiceDeps {
|
|
46
|
-
manager: AgentManager;
|
|
47
|
-
broadcast: (sessions: Iterable<Session>, message: unknown) => void;
|
|
48
|
-
store?: PermissionStore;
|
|
49
|
-
}
|
|
50
|
-
export declare class PermissionService {
|
|
51
|
-
private readonly deps;
|
|
52
|
-
private readonly store;
|
|
53
|
-
constructor(deps: PermissionServiceDeps);
|
|
54
|
-
registerHandlers(registry: HandlerRegistry, getActiveSessions: () => Iterable<Session>): void;
|
|
55
|
-
private broadcastAll;
|
|
56
|
-
/**
|
|
57
|
-
* Create a permission request, broadcast it, and wait for resolution. Returns the decision.
|
|
58
|
-
* Throws if interrupted (the promise is rejected externally).
|
|
59
|
-
*/
|
|
60
|
-
requestPermission(req: Omit<AgentPermissionRequestRecord, "requestId">, getSessions: () => Iterable<Session>): {
|
|
61
|
-
requestId: string;
|
|
62
|
-
decision: Promise<ResolutionResponse>;
|
|
63
|
-
};
|
|
64
|
-
/**
|
|
65
|
-
* Handle a respond-to-permission RPC. First resolution wins; subsequent calls are no-ops.
|
|
66
|
-
*/
|
|
67
|
-
handleRespond(msg: Record<string, unknown>, getSessions: () => Iterable<Session>): Record<string, unknown>;
|
|
68
|
-
/** Cancel all pending permissions for an agent (called on interrupt). */
|
|
69
|
-
cancelPending(agentId: string, getSessions: () => Iterable<Session>): void;
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=permissions.d.ts.map
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
-
/**
|
|
3
|
-
* In-memory permission state (not separately persisted — only broadcast-live per scope).
|
|
4
|
-
* Keyed by `requestId`.
|
|
5
|
-
*/
|
|
6
|
-
export class PermissionStore {
|
|
7
|
-
pending = new Map();
|
|
8
|
-
add(req) {
|
|
9
|
-
this.pending.set(req.requestId, req);
|
|
10
|
-
}
|
|
11
|
-
get(requestId) {
|
|
12
|
-
return this.pending.get(requestId);
|
|
13
|
-
}
|
|
14
|
-
remove(requestId) {
|
|
15
|
-
this.pending.delete(requestId);
|
|
16
|
-
}
|
|
17
|
-
listForAgent(agentId) {
|
|
18
|
-
return [...this.pending.values()].filter((p) => p.agentId === agentId);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export const globalPermissionStore = new PermissionStore();
|
|
22
|
-
export class PermissionService {
|
|
23
|
-
deps;
|
|
24
|
-
store;
|
|
25
|
-
constructor(deps) {
|
|
26
|
-
this.deps = deps;
|
|
27
|
-
this.store = deps.store ?? globalPermissionStore;
|
|
28
|
-
}
|
|
29
|
-
registerHandlers(registry, getActiveSessions) {
|
|
30
|
-
registry.register("agent.permission.respond.request", (ctx) => this.handleRespond(ctx.message, getActiveSessions));
|
|
31
|
-
registry.registerAlias("respond_to_permission", "agent.permission.respond.request");
|
|
32
|
-
}
|
|
33
|
-
broadcastAll(sessions, msg) {
|
|
34
|
-
this.deps.broadcast(sessions, msg);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Create a permission request, broadcast it, and wait for resolution. Returns the decision.
|
|
38
|
-
* Throws if interrupted (the promise is rejected externally).
|
|
39
|
-
*/
|
|
40
|
-
requestPermission(req, getSessions) {
|
|
41
|
-
const requestId = randomUUID();
|
|
42
|
-
let resolve;
|
|
43
|
-
const decision = new Promise((res) => {
|
|
44
|
-
resolve = res;
|
|
45
|
-
});
|
|
46
|
-
this.store.add({ ...req, requestId, resolve });
|
|
47
|
-
this.broadcastAll(getSessions(), {
|
|
48
|
-
type: "session",
|
|
49
|
-
message: {
|
|
50
|
-
type: "agent_permission_request",
|
|
51
|
-
requestId,
|
|
52
|
-
agentId: req.agentId,
|
|
53
|
-
toolName: req.toolName,
|
|
54
|
-
action: req.action,
|
|
55
|
-
responses: req.responses ?? ["allow", "deny"],
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
return { requestId, decision };
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Handle a respond-to-permission RPC. First resolution wins; subsequent calls are no-ops.
|
|
62
|
-
*/
|
|
63
|
-
handleRespond(msg, getSessions) {
|
|
64
|
-
const permId = msg.permissionRequestId;
|
|
65
|
-
const response = msg.response;
|
|
66
|
-
const pending = this.store.get(permId);
|
|
67
|
-
if (!pending) {
|
|
68
|
-
// Already resolved or unknown.
|
|
69
|
-
return {
|
|
70
|
-
type: "agent.permission.respond.response",
|
|
71
|
-
requestId: msg.requestId,
|
|
72
|
-
payload: { resolved: false },
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
this.store.remove(permId);
|
|
76
|
-
pending.resolve(response);
|
|
77
|
-
this.broadcastAll(getSessions(), {
|
|
78
|
-
type: "session",
|
|
79
|
-
message: {
|
|
80
|
-
type: "agent_permission_resolved",
|
|
81
|
-
requestId: permId,
|
|
82
|
-
agentId: pending.agentId,
|
|
83
|
-
decision: typeof response === "string" ? response : "allow",
|
|
84
|
-
},
|
|
85
|
-
});
|
|
86
|
-
// Question bridge: auto-answer a follow-up optional comment input.
|
|
87
|
-
if (pending.allowComment) {
|
|
88
|
-
// The Pi adapter will surface the follow-up `input` as another question permission;
|
|
89
|
-
// the comment (if any) is embedded in the response, or we auto-answer with empty string.
|
|
90
|
-
const comment = typeof response === "object" && "comment" in response ? response.comment : "";
|
|
91
|
-
// Find and resolve any pending follow-up input for the same agent.
|
|
92
|
-
const followUp = this.store
|
|
93
|
-
.listForAgent(pending.agentId)
|
|
94
|
-
.find((p) => p.questionKind === "input");
|
|
95
|
-
if (followUp) {
|
|
96
|
-
this.store.remove(followUp.requestId);
|
|
97
|
-
followUp.resolve(comment);
|
|
98
|
-
this.broadcastAll(getSessions(), {
|
|
99
|
-
type: "session",
|
|
100
|
-
message: {
|
|
101
|
-
type: "agent_permission_resolved",
|
|
102
|
-
requestId: followUp.requestId,
|
|
103
|
-
agentId: pending.agentId,
|
|
104
|
-
decision: "auto",
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
type: "agent.permission.respond.response",
|
|
111
|
-
requestId: msg.requestId,
|
|
112
|
-
payload: { resolved: true },
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
/** Cancel all pending permissions for an agent (called on interrupt). */
|
|
116
|
-
cancelPending(agentId, getSessions) {
|
|
117
|
-
for (const pending of this.store.listForAgent(agentId)) {
|
|
118
|
-
this.store.remove(pending.requestId);
|
|
119
|
-
pending.resolve("canceled");
|
|
120
|
-
this.broadcastAll(getSessions(), {
|
|
121
|
-
type: "session",
|
|
122
|
-
message: {
|
|
123
|
-
type: "agent_permission_resolved",
|
|
124
|
-
requestId: pending.requestId,
|
|
125
|
-
agentId,
|
|
126
|
-
decision: "canceled",
|
|
127
|
-
},
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
//# sourceMappingURL=permissions.js.map
|