@av-pi-studio/server 0.0.115 → 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/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 +12 -3
- package/dist/agent/providers/mock/mock-provider.js +46 -7
- 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/pi/agent.js +0 -7
- 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
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
|