dsh-browser-firefox 0.4.6 → 0.4.8
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/lib/index.js +450 -51
- package/lib/protocol.js +19 -2
- package/lib/types/approvals.d.ts +73 -0
- package/lib/types/extension-sessions.d.ts +72 -12
- package/lib/types/protocol.d.ts +25 -0
- package/lib/types/questions.d.ts +1 -1
- package/lib/types/server.d.ts +23 -0
- package/lib/types/session-follow.d.ts +46 -0
- package/lib/types/waterfall.d.ts +49 -0
- package/package.json +29 -33
- package/src/approvals.ts +143 -0
- package/src/extension-sessions.ts +123 -16
- package/src/index.ts +121 -20
- package/src/protocol.ts +35 -0
- package/src/questions.ts +20 -38
- package/src/server.ts +59 -4
- package/src/session-follow.ts +76 -0
- package/src/waterfall.ts +91 -0
package/lib/protocol.js
CHANGED
|
@@ -36,7 +36,7 @@ const DEFAULT_TOKEN_BYTES = 32;
|
|
|
36
36
|
* @returns true for server-sendable frames.
|
|
37
37
|
*/
|
|
38
38
|
function isServerFrame(frame) {
|
|
39
|
-
return frame.t === "hello.ok" || frame.t === "rpc.result" || frame.t === "stream.frame" || frame.t === "stream.error" || frame.t === "tool.call" || frame.t === "tool.cancel" || frame.t === "question.requested" || frame.t === "question.resolved" || frame.t === "ping" || frame.t === "error";
|
|
39
|
+
return frame.t === "hello.ok" || frame.t === "rpc.result" || frame.t === "stream.frame" || frame.t === "stream.error" || frame.t === "tool.call" || frame.t === "tool.cancel" || frame.t === "question.requested" || frame.t === "question.resolved" || frame.t === "approval.requested" || frame.t === "approval.resolved" || frame.t === "ping" || frame.t === "error";
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Type guard: is this frame one the CLIENT may send? Server-only shapes
|
|
@@ -167,6 +167,23 @@ function parseBridgeFrame(text) {
|
|
|
167
167
|
id: frame.id,
|
|
168
168
|
sessionId: frame.sessionId
|
|
169
169
|
} : void 0;
|
|
170
|
+
case "approval.requested":
|
|
171
|
+
if (typeof frame.id !== "string" || typeof frame.sessionId !== "string" || typeof frame.toolName !== "string") return;
|
|
172
|
+
if (frame.callId !== void 0 && typeof frame.callId !== "string") return void 0;
|
|
173
|
+
if (frame.reason !== void 0 && typeof frame.reason !== "string") return void 0;
|
|
174
|
+
return {
|
|
175
|
+
t: "approval.requested",
|
|
176
|
+
id: frame.id,
|
|
177
|
+
sessionId: frame.sessionId,
|
|
178
|
+
toolName: frame.toolName,
|
|
179
|
+
...typeof frame.callId === "string" ? { callId: frame.callId } : {},
|
|
180
|
+
...typeof frame.reason === "string" ? { reason: frame.reason } : {}
|
|
181
|
+
};
|
|
182
|
+
case "approval.resolved": return typeof frame.id === "string" && typeof frame.sessionId === "string" ? {
|
|
183
|
+
t: "approval.resolved",
|
|
184
|
+
id: frame.id,
|
|
185
|
+
sessionId: frame.sessionId
|
|
186
|
+
} : void 0;
|
|
170
187
|
case "ping": return { t: "ping" };
|
|
171
188
|
case "error": return typeof frame.code === "string" && typeof frame.message === "string" ? {
|
|
172
189
|
t: "error",
|
|
@@ -179,7 +196,7 @@ function parseBridgeFrame(text) {
|
|
|
179
196
|
function isCaps(value) {
|
|
180
197
|
if (typeof value !== "object" || value === null) return false;
|
|
181
198
|
const caps = value;
|
|
182
|
-
return typeof caps.snapshotMaxChars === "number" && caps.snapshotMaxChars > 0 && typeof caps.maxInteractiveItems === "number" && caps.maxInteractiveItems > 0 && (caps.questions === void 0 || typeof caps.questions === "boolean");
|
|
199
|
+
return typeof caps.snapshotMaxChars === "number" && caps.snapshotMaxChars > 0 && typeof caps.maxInteractiveItems === "number" && caps.maxInteractiveItems > 0 && (caps.questions === void 0 || typeof caps.questions === "boolean") && (caps.approvals === void 0 || typeof caps.approvals === "boolean");
|
|
183
200
|
}
|
|
184
201
|
/** Narrow one question item; unknown extra keys (e.g. host `intent`) pass through. */
|
|
185
202
|
function isQuestionItem(value) {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host approval ownership: claim the host `approval/request` waterfall for
|
|
3
|
+
* extension-owned sessions, push the decision request to the connected
|
|
4
|
+
* extension, and settle the waterfall with the sidebar's choice.
|
|
5
|
+
*
|
|
6
|
+
* Settlement paths (first wins, later ones no-op):
|
|
7
|
+
* - the sidebar decides → the waterfall resolves with that outcome;
|
|
8
|
+
* - the host aborts `request.signal` (turn cancelled, session disposed) →
|
|
9
|
+
* the extension is sent `approval.resolved` and the waterfall resolves
|
|
10
|
+
* with `'cancelled'` (the host vocabulary has no rejection channel here);
|
|
11
|
+
* - the bridge connection drops ({@link delegateAll}) → the waterfall is
|
|
12
|
+
* delegated to `next()` so another answerer (dsh web) can still decide;
|
|
13
|
+
* - plugin unload ({@link dispose}) → `'unavailable'`, the fail-closed
|
|
14
|
+
* outcome of the host's closed outcome set.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
import type { ServerFrame } from './protocol.ts';
|
|
19
|
+
/** The host's closed approval outcome vocabulary. */
|
|
20
|
+
export type ApprovalOutcome = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable';
|
|
21
|
+
/** One approval prompt as it crosses the bridge. */
|
|
22
|
+
export interface ApprovalPrompt {
|
|
23
|
+
toolName: string;
|
|
24
|
+
callId?: string;
|
|
25
|
+
reason?: string;
|
|
26
|
+
}
|
|
27
|
+
/** Decision the sidebar sends back over `bridge/approvalDecision`. */
|
|
28
|
+
export type ApprovalDecision = 'allowed-once' | 'rejected';
|
|
29
|
+
/** Receipt answered to the extension's `bridge/approvalDecision` rpc. */
|
|
30
|
+
export type ApprovalReceipt = {
|
|
31
|
+
accepted: true;
|
|
32
|
+
} | {
|
|
33
|
+
accepted: false;
|
|
34
|
+
reason: 'not-pending' | 'bad-decision';
|
|
35
|
+
};
|
|
36
|
+
/** Args of the plugin-local `bridge/approvalDecision` rpc method (decision already narrowed by the parser). */
|
|
37
|
+
export interface ApprovalDecisionArgs {
|
|
38
|
+
approvalId: string;
|
|
39
|
+
sessionId: string;
|
|
40
|
+
decision: ApprovalDecision;
|
|
41
|
+
}
|
|
42
|
+
/** Parse the extension's `bridge/approvalDecision` rpc args (ids + closed decision). */
|
|
43
|
+
export declare function asApprovalDecisionArgs(value: unknown): ApprovalDecisionArgs | undefined;
|
|
44
|
+
/** Owns the host approval waterfall for extension-driven sessions. */
|
|
45
|
+
export declare class ApprovalBridge {
|
|
46
|
+
private readonly deps;
|
|
47
|
+
private readonly waterfalls;
|
|
48
|
+
constructor(deps: {
|
|
49
|
+
/** Push one server frame to the connected extension (must tolerate a dead socket). */
|
|
50
|
+
push: (frame: ServerFrame) => void;
|
|
51
|
+
});
|
|
52
|
+
/**
|
|
53
|
+
* Own one host waterfall request: push `approval.requested` to the
|
|
54
|
+
* extension and suspend until one of the settlement paths wins.
|
|
55
|
+
*
|
|
56
|
+
* @param routingSessionId - extension-visible session id (the owned session the card is filed under).
|
|
57
|
+
* @param prompt - tool name, optional call id and human-readable reason.
|
|
58
|
+
* @param next - waterfall delegation, used when the bridge connection drops.
|
|
59
|
+
* @param signal - host cancellation lifetime for this request.
|
|
60
|
+
* @returns the host approval outcome.
|
|
61
|
+
*/
|
|
62
|
+
ask(routingSessionId: string, prompt: ApprovalPrompt, next: () => Promise<ApprovalOutcome>, signal?: AbortSignal): Promise<ApprovalOutcome>;
|
|
63
|
+
/**
|
|
64
|
+
* Settle one pending approval from the extension's `bridge/approvalDecision`
|
|
65
|
+
* rpc. The server replies with this receipt.
|
|
66
|
+
*/
|
|
67
|
+
decide(args: ApprovalDecisionArgs): ApprovalReceipt;
|
|
68
|
+
/** Bridge connection replaced/closed: delegate every unsettled approval. */
|
|
69
|
+
delegateAll(): void;
|
|
70
|
+
/** Plugin unload: answer everything fail-closed so no tool call outlives the plugin. */
|
|
71
|
+
dispose(): void;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=approvals.d.ts.map
|
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Track session ids that the browser extension has driven through the bridge.
|
|
3
|
-
* Sessions the extension never touched must keep the host
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Sessions the extension never touched must keep the host waterfalls
|
|
4
|
+
* (user-questions, approvals) so the dsh web UI (or any other answerer)
|
|
5
|
+
* renders the cards.
|
|
6
|
+
*
|
|
7
|
+
* Ownership has three sources, all revocable:
|
|
8
|
+
* - **driven**: the extension created or prompted the session (kept until the
|
|
9
|
+
* plugin unloads);
|
|
10
|
+
* - **followed**: an open `session/follow` stream means the sidebar is
|
|
11
|
+
* displaying that session right now (released when the stream closes);
|
|
12
|
+
* - **inherited**: an ask from a subagent child session belongs to the
|
|
13
|
+
* nearest extension-owned ancestor, so child questions/approvals surface in
|
|
14
|
+
* the parent conversation the user is actually watching.
|
|
15
|
+
*
|
|
6
16
|
* @module
|
|
7
17
|
*/
|
|
8
18
|
/** Mutable registry of extension-owned session ids. */
|
|
@@ -10,22 +20,72 @@ export declare class ExtensionSessionRegistry {
|
|
|
10
20
|
private readonly ids;
|
|
11
21
|
/** Remember a session the extension successfully created or prompted. */
|
|
12
22
|
note(sessionId: string | undefined): void;
|
|
23
|
+
/** Forget a session (a failed dispatch revoked an optimistic note). */
|
|
24
|
+
forget(sessionId: string | undefined): void;
|
|
13
25
|
/** Whether the extension has touched this session over the bridge. */
|
|
14
26
|
has(sessionId: string | undefined): boolean;
|
|
15
27
|
/** Test helper: drop all tracked ids. */
|
|
16
28
|
clear(): void;
|
|
17
29
|
}
|
|
18
30
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* the native answerer waterfall (dsh web) keeps working.
|
|
31
|
+
* Live `session/follow` subscriptions: the sidebar is displaying these
|
|
32
|
+
* sessions, so they count as extension-owned while the stream is open.
|
|
33
|
+
* Reference-counted per session because one session can be followed by more
|
|
34
|
+
* than one panel connection.
|
|
24
35
|
*/
|
|
25
|
-
export declare
|
|
36
|
+
export declare class FollowedSessions {
|
|
37
|
+
private readonly counts;
|
|
38
|
+
/** Register one open follow stream for a session. */
|
|
39
|
+
open(sessionId: string | undefined): void;
|
|
40
|
+
/** Release one follow stream; the last release drops the session. */
|
|
41
|
+
close(sessionId: string | undefined): void;
|
|
42
|
+
/** Whether any open follow stream is displaying this session. */
|
|
43
|
+
has(sessionId: string | undefined): boolean;
|
|
44
|
+
/** Drop every subscription (bridge generation replacement, plugin unload). */
|
|
45
|
+
clear(): void;
|
|
46
|
+
}
|
|
47
|
+
/** Ownership sources consulted by {@link owningSessionId}. */
|
|
48
|
+
export interface OwnershipSources {
|
|
49
|
+
/** Sessions the extension created or prompted. */
|
|
50
|
+
driven: Pick<ExtensionSessionRegistry, 'has'>;
|
|
51
|
+
/** Sessions an open follow stream is displaying. */
|
|
52
|
+
followed?: Pick<FollowedSessions, 'has'>;
|
|
53
|
+
}
|
|
54
|
+
/** Whether one exact session id is extension-owned by either source. */
|
|
55
|
+
export declare function isOwnedSession(sessionId: string | undefined, sources: OwnershipSources): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Resolve which session id the sidebar card should be filed under: the asking
|
|
58
|
+
* session itself when it is owned, otherwise the nearest owned ancestor (a
|
|
59
|
+
* subagent child session inherits its parent's ownership).
|
|
60
|
+
*
|
|
61
|
+
* @param sessionId - the asking session (the host event's agent id).
|
|
62
|
+
* @param sources - ownership sources.
|
|
63
|
+
* @param parentOf - session-id → parent-session-id lookup; absent disables inheritance.
|
|
64
|
+
* @returns the owned session id to route to, or undefined when nothing owns it.
|
|
65
|
+
*/
|
|
66
|
+
export declare function owningSessionId(sessionId: string | undefined, sources: OwnershipSources, parentOf?: (sessionId: string) => string | undefined): string | undefined;
|
|
67
|
+
/** Why a host interaction was delegated to the next answerer. */
|
|
68
|
+
export type DelegateReason = 'no-connection' | 'unsupported-client' | 'not-owned';
|
|
69
|
+
/** One interaction-ownership decision, kept inspectable for logging and tests. */
|
|
70
|
+
export type InteractionOwnership = {
|
|
71
|
+
owned: true;
|
|
72
|
+
sessionId: string;
|
|
73
|
+
} | {
|
|
74
|
+
owned: false;
|
|
75
|
+
reason: DelegateReason;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Decide whether the bridge should own one host interaction (question or
|
|
79
|
+
* approval). All gates must pass: an extension is connected, it advertised
|
|
80
|
+
* the matching card capability in its hello caps, and the asking session is
|
|
81
|
+
* extension-owned (directly or through an owned ancestor). Everything else
|
|
82
|
+
* falls through to `next()` so the native answerer waterfall keeps working.
|
|
83
|
+
*/
|
|
84
|
+
export declare function resolveInteractionOwnership(input: {
|
|
26
85
|
hasExtensionConnection: boolean;
|
|
27
|
-
|
|
86
|
+
clientSupports: boolean;
|
|
28
87
|
sessionId: string | undefined;
|
|
29
|
-
|
|
30
|
-
|
|
88
|
+
sources: OwnershipSources;
|
|
89
|
+
parentOf?: (sessionId: string) => string | undefined;
|
|
90
|
+
}): InteractionOwnership;
|
|
31
91
|
//# sourceMappingURL=extension-sessions.d.ts.map
|
package/lib/types/protocol.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export interface BridgeCaps {
|
|
|
51
51
|
maxInteractiveItems: number;
|
|
52
52
|
/** Client advertises it can render ask_user_question cards; the plugin only claims the user-questions waterfall for extension-owned sessions when set. */
|
|
53
53
|
questions?: boolean;
|
|
54
|
+
/** Client advertises it can render host approval (permission) cards; the plugin only claims the approval waterfall for extension-owned sessions when set. */
|
|
55
|
+
approvals?: boolean;
|
|
54
56
|
}
|
|
55
57
|
/** One Remote failure as plain wire data (RemoteError's message is non-enumerable, so it is restated explicitly). */
|
|
56
58
|
export interface RemoteWireFailure {
|
|
@@ -194,6 +196,29 @@ export type ServerFrame =
|
|
|
194
196
|
id: string;
|
|
195
197
|
sessionId: string;
|
|
196
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* The host needs one approval decision (a hooked tool call, a permission
|
|
201
|
+
* ask) in an extension-owned session and the bridge claimed the waterfall:
|
|
202
|
+
* the extension should render an approval card. The decision rides a normal
|
|
203
|
+
* `rpc` frame with the plugin-local method `bridge/approvalDecision` (args
|
|
204
|
+
* `{approvalId, sessionId, decision: 'allowed-once' | 'rejected'}`),
|
|
205
|
+
* answered `{accepted: true} | {accepted: false, reason: 'not-pending' |
|
|
206
|
+
* 'bad-decision'}`.
|
|
207
|
+
*/
|
|
208
|
+
| {
|
|
209
|
+
t: 'approval.requested';
|
|
210
|
+
id: string;
|
|
211
|
+
sessionId: string;
|
|
212
|
+
toolName: string;
|
|
213
|
+
callId?: string;
|
|
214
|
+
reason?: string;
|
|
215
|
+
}
|
|
216
|
+
/** A previously pushed approval is gone (host cancelled it or the bridge delegated the waterfall elsewhere); dismiss the card without deciding. */
|
|
217
|
+
| {
|
|
218
|
+
t: 'approval.resolved';
|
|
219
|
+
id: string;
|
|
220
|
+
sessionId: string;
|
|
221
|
+
}
|
|
197
222
|
/** Liveness probe. */
|
|
198
223
|
| {
|
|
199
224
|
t: 'ping';
|
package/lib/types/questions.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ export declare function asQuestionAnswerArgs(value: unknown): QuestionAnswerArgs
|
|
|
47
47
|
/** Owns the user-questions waterfall for extension-driven sessions. */
|
|
48
48
|
export declare class QuestionBridge {
|
|
49
49
|
private readonly deps;
|
|
50
|
-
private readonly
|
|
50
|
+
private readonly waterfalls;
|
|
51
51
|
constructor(deps: {
|
|
52
52
|
/** Push one server frame to the connected extension (must tolerate a dead socket). */
|
|
53
53
|
push: (frame: ServerFrame) => void;
|
package/lib/types/server.d.ts
CHANGED
|
@@ -31,6 +31,15 @@ import { type BridgeCaps, type RemoteWireResult, type ServerFrame, type ToolErro
|
|
|
31
31
|
* same commit.
|
|
32
32
|
*/
|
|
33
33
|
export declare const PRIVILEGED_METHODS: Set<string>;
|
|
34
|
+
/**
|
|
35
|
+
* Race one promise against an abort signal. Resolves `undefined` when the
|
|
36
|
+
* signal wins; the loser's handlers are always attached, so a late rejection
|
|
37
|
+
* cannot surface as an unhandled rejection — the host loader escalates those
|
|
38
|
+
* to a fatal load failure.
|
|
39
|
+
*
|
|
40
|
+
* Exported for tests.
|
|
41
|
+
*/
|
|
42
|
+
export declare function raceAbort<T>(promise: Promise<T>, signal: AbortSignal): Promise<T | undefined>;
|
|
34
43
|
/** Loopback IPv4/IPv6 literals (IPv4-mapped included). Exported for tests and reuse. */
|
|
35
44
|
export declare function isLoopbackAddress(address: string | undefined): boolean;
|
|
36
45
|
/** Error thrown by requestTool; the tool registry turns it into an isError result. */
|
|
@@ -64,6 +73,18 @@ export interface BridgeServerDeps {
|
|
|
64
73
|
* rpc result value `{accepted: true} | {accepted: false, reason}`.
|
|
65
74
|
*/
|
|
66
75
|
answerQuestion: (args: Record<string, unknown>) => unknown;
|
|
76
|
+
/**
|
|
77
|
+
* Plugin-local endpoint `bridge/approvalDecision`: settle one pending host
|
|
78
|
+
* approval the bridge pushed to this extension. Answered as the rpc result
|
|
79
|
+
* value `{accepted: true} | {accepted: false, reason}`.
|
|
80
|
+
*/
|
|
81
|
+
answerApproval: (args: Record<string, unknown>) => unknown;
|
|
82
|
+
/**
|
|
83
|
+
* A `session/follow` stream opened (`open: true`) or ended (`open: false`)
|
|
84
|
+
* for a session: the sidebar is displaying that session while the stream
|
|
85
|
+
* lives, so interaction ownership can follow the visible conversation.
|
|
86
|
+
*/
|
|
87
|
+
onFollowChanged?: (sessionId: string, open: boolean) => void;
|
|
67
88
|
/** The active connection was replaced or closed (settle pushed questions). */
|
|
68
89
|
onConnectionLost?: () => void;
|
|
69
90
|
/**
|
|
@@ -133,6 +154,8 @@ export declare class BridgeServer {
|
|
|
133
154
|
hasConnection(): boolean;
|
|
134
155
|
/** @returns whether the connected extension advertised question-card support. */
|
|
135
156
|
clientSupportsQuestions(): boolean;
|
|
157
|
+
/** @returns whether the connected extension advertised approval-card support. */
|
|
158
|
+
clientSupportsApprovals(): boolean;
|
|
136
159
|
/**
|
|
137
160
|
* Push one unsolicited server frame (question.requested/question.resolved)
|
|
138
161
|
* to the connected extension. No-op when no extension is connected or the
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `session/follow` 的参数形状:宿主描述符要求
|
|
3
|
+
* `{request: {address: SessionAddress}}`,其中 address 是
|
|
4
|
+
* `{kind:'session', sessionId}` 或
|
|
5
|
+
* `{kind:'subagent', parentSessionId, childSessionId, mode}`。
|
|
6
|
+
*
|
|
7
|
+
* 扩展用 {@link sessionFollowArgs} 构造订阅参数,插件用
|
|
8
|
+
* {@link followedSessionOf} 从原生 args 里取回「正在展示哪个会话」。两者
|
|
9
|
+
* 同处一个模块,是为了让形状只有**一个**真实来源:0.4.7 曾因插件侧测试用
|
|
10
|
+
* 臆造形状(`request.sessionId`)而没发现 follow 归属在生产环境从未生效。
|
|
11
|
+
*
|
|
12
|
+
* @module @deepseek-ai/dsh-bridge-browser/src/session-follow
|
|
13
|
+
*/
|
|
14
|
+
/** 普通会话的 follow 地址。 */
|
|
15
|
+
export interface SessionFollowAddress {
|
|
16
|
+
kind: 'session';
|
|
17
|
+
sessionId: string;
|
|
18
|
+
}
|
|
19
|
+
/** 直接 subagent 子会话的 follow 地址(宿主 SessionAddress 的另一形态)。 */
|
|
20
|
+
export interface SubagentFollowAddress {
|
|
21
|
+
kind: 'subagent';
|
|
22
|
+
parentSessionId: string;
|
|
23
|
+
childSessionId: string;
|
|
24
|
+
mode: 'one-shot' | 'continuable' | 'unknown';
|
|
25
|
+
}
|
|
26
|
+
/** 一次性订阅参数(`stream.open` 的 args)。 */
|
|
27
|
+
export interface SessionFollowArgs {
|
|
28
|
+
request: {
|
|
29
|
+
address: SessionFollowAddress | SubagentFollowAddress;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/** 订阅一个普通会话(面板当前会话始终用这一形态)。 */
|
|
33
|
+
export declare function sessionFollowArgs(sessionId: string): SessionFollowArgs;
|
|
34
|
+
/** 订阅一个 direct subagent 子会话(预留:目前面板不展示子会话)。 */
|
|
35
|
+
export declare function subagentFollowArgs(parentSessionId: string, childSessionId: string, mode?: SubagentFollowAddress['mode']): SessionFollowArgs;
|
|
36
|
+
/**
|
|
37
|
+
* Session id displayed by a `session/follow` stream, read from the host's
|
|
38
|
+
* `SessionFollowRequest.address`. A subagent address carries the child session
|
|
39
|
+
* on `childSessionId`; ownership then walks up to the parent conversation, so
|
|
40
|
+
* either form routes the card correctly.
|
|
41
|
+
*
|
|
42
|
+
* @param args - native args of the `stream.open` frame.
|
|
43
|
+
* @returns the followed session id, or undefined when absent/malformed.
|
|
44
|
+
*/
|
|
45
|
+
export declare function followedSessionOf(args: Record<string, unknown>): string | undefined;
|
|
46
|
+
//# sourceMappingURL=session-follow.d.ts.map
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bookkeeping shared by the host waterfalls the bridge claims
|
|
3
|
+
* (`user-questions/request`, `approval/request`).
|
|
4
|
+
*
|
|
5
|
+
* Both bridges need exactly the same lifecycle: one pending entry per
|
|
6
|
+
* generated id, a **single settlement** guarantee against concurrent paths
|
|
7
|
+
* (extension answer vs host abort vs connection loss vs plugin unload), an
|
|
8
|
+
* abort listener that is detached once settled, and the id+session match the
|
|
9
|
+
* uplink must pass before it may touch an entry. Only the outcome vocabulary
|
|
10
|
+
* and the push/settle policy differ, and those stay in the domain modules.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
/** Registry of pending waterfall requests, keyed by the id sent to the extension. */
|
|
15
|
+
export declare class PendingWaterfalls<TOutcome, TPayload = undefined> {
|
|
16
|
+
private readonly entries;
|
|
17
|
+
/**
|
|
18
|
+
* Track one request pushed to the extension.
|
|
19
|
+
*
|
|
20
|
+
* @param input - id, asking session, host cancellation signal, the domain's
|
|
21
|
+
* settlement policy, and the abort handler (typically: tell the extension
|
|
22
|
+
* the card is gone, then settle).
|
|
23
|
+
*/
|
|
24
|
+
register(input: {
|
|
25
|
+
id: string;
|
|
26
|
+
sessionId: string;
|
|
27
|
+
signal: AbortSignal | undefined;
|
|
28
|
+
payload: TPayload;
|
|
29
|
+
complete: (outcome: TOutcome) => void;
|
|
30
|
+
onAbort: () => void;
|
|
31
|
+
}): void;
|
|
32
|
+
/**
|
|
33
|
+
* Whether an unsettled entry exists for exactly this id and session. The
|
|
34
|
+
* uplink must not be able to settle another session's card.
|
|
35
|
+
*/
|
|
36
|
+
matches(id: string, sessionId: string): boolean;
|
|
37
|
+
/** Domain payload registered with one unsettled entry (undefined once settled). */
|
|
38
|
+
payloadOf(id: string): TPayload | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Settle one request. Later settlements for the same id are no-ops, and the
|
|
41
|
+
* entry is dropped together with its abort listener.
|
|
42
|
+
*
|
|
43
|
+
* @returns true when this call performed the settlement.
|
|
44
|
+
*/
|
|
45
|
+
settle(id: string, outcome: TOutcome): boolean;
|
|
46
|
+
/** Every unsettled id, for the connection-loss and unload sweeps. */
|
|
47
|
+
ids(): string[];
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=waterfall.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-browser-firefox",
|
|
3
3
|
"description": "Firefox browser control for DeepSeek Harness: token-authenticated WebSocket bridge + browser_* tools (native-image screenshots) driving the user's own Firefox via the companion AMO extension, with sidebar ask_user_question answering",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.8",
|
|
5
5
|
"author": "tuojc",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -53,18 +53,20 @@
|
|
|
53
53
|
],
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"@deepseek-ai/cordis": "^4.0.2",
|
|
56
|
-
"@deepseek-ai/dsh-api-gateway": "^0.
|
|
57
|
-
"@deepseek-ai/dsh-api-session-controller": "^0.
|
|
58
|
-
"@deepseek-ai/dsh-api-workspace-controller": "^0.
|
|
59
|
-
"@deepseek-ai/dsh-attachment": "^0.
|
|
60
|
-
"@deepseek-ai/dsh-
|
|
61
|
-
"@deepseek-ai/dsh-
|
|
62
|
-
"@deepseek-ai/dsh-
|
|
63
|
-
"@deepseek-ai/dsh-
|
|
64
|
-
"@deepseek-ai/dsh-
|
|
56
|
+
"@deepseek-ai/dsh-api-gateway": "^0.2.0-rc.1",
|
|
57
|
+
"@deepseek-ai/dsh-api-session-controller": "^0.2.0-rc.1",
|
|
58
|
+
"@deepseek-ai/dsh-api-workspace-controller": "^0.2.0-rc.1",
|
|
59
|
+
"@deepseek-ai/dsh-attachment": "^0.2.0-rc.1",
|
|
60
|
+
"@deepseek-ai/dsh-home-paths": "^0.2.0-rc.1",
|
|
61
|
+
"@deepseek-ai/dsh-host-webserver": "^0.2.0-rc.1",
|
|
62
|
+
"@deepseek-ai/dsh-invariants": "^0.2.0-rc.1",
|
|
63
|
+
"@deepseek-ai/dsh-session": "^0.2.0-rc.1",
|
|
64
|
+
"@deepseek-ai/dsh-tools": "^0.2.0-rc.1",
|
|
65
|
+
"@deepseek-ai/dsh-user-approval": "^0.2.0-rc.1",
|
|
66
|
+
"@deepseek-ai/dsh-user-questions": "^0.2.0-rc.1"
|
|
65
67
|
},
|
|
66
68
|
"dependencies": {
|
|
67
|
-
"@deepseek-ai/schemastery": "^3.18.
|
|
69
|
+
"@deepseek-ai/schemastery": "^3.18.4",
|
|
68
70
|
"ws": "^8.21.0"
|
|
69
71
|
},
|
|
70
72
|
"scripts": {
|
|
@@ -74,32 +76,26 @@
|
|
|
74
76
|
"prepublishOnly": "pnpm run build"
|
|
75
77
|
},
|
|
76
78
|
"devDependencies": {
|
|
77
|
-
"@deepseek-ai/cordis": "4.0.
|
|
78
|
-
"@deepseek-ai/cordis-plugin-include": "1.0.
|
|
79
|
-
"@deepseek-ai/cordis-plugin-loader": "1.0.
|
|
80
|
-
"@deepseek-ai/dsh-
|
|
81
|
-
"@deepseek-ai/dsh-
|
|
82
|
-
"@deepseek-ai/dsh-api-
|
|
83
|
-
"@deepseek-ai/dsh-
|
|
84
|
-
"@deepseek-ai/dsh-
|
|
85
|
-
"@deepseek-ai/dsh-
|
|
86
|
-
"@deepseek-ai/dsh-
|
|
87
|
-
"@deepseek-ai/dsh-
|
|
88
|
-
"@deepseek-ai/dsh-
|
|
89
|
-
"@deepseek-ai/dsh-
|
|
90
|
-
"@deepseek-ai/dsh-
|
|
91
|
-
"@deepseek-ai/dsh-storage": "0.1.2-alpha.5",
|
|
92
|
-
"@deepseek-ai/dsh-storage-domain": "0.1.2-alpha.5",
|
|
93
|
-
"@deepseek-ai/dsh-storage-json": "0.1.2-alpha.5",
|
|
94
|
-
"@deepseek-ai/dsh-system-prompt": "0.1.2-alpha.5",
|
|
95
|
-
"@deepseek-ai/dsh-tools": "0.1.2-alpha.5",
|
|
96
|
-
"@deepseek-ai/dsh-user-questions": "0.1.2-alpha.5",
|
|
97
|
-
"@deepseek-ai/dsh-workspace": "0.1.2-alpha.5",
|
|
79
|
+
"@deepseek-ai/cordis": "4.0.4",
|
|
80
|
+
"@deepseek-ai/cordis-plugin-include": "1.0.9",
|
|
81
|
+
"@deepseek-ai/cordis-plugin-loader": "1.0.5",
|
|
82
|
+
"@deepseek-ai/dsh-api-gateway": "0.2.0-rc.1",
|
|
83
|
+
"@deepseek-ai/dsh-api-session-controller": "0.2.0-rc.1",
|
|
84
|
+
"@deepseek-ai/dsh-api-workspace-controller": "0.2.0-rc.1",
|
|
85
|
+
"@deepseek-ai/dsh-attachment": "0.2.0-rc.1",
|
|
86
|
+
"@deepseek-ai/dsh-host-webserver": "0.2.0-rc.1",
|
|
87
|
+
"@deepseek-ai/dsh-invariants": "0.2.0-rc.1",
|
|
88
|
+
"@deepseek-ai/dsh-home-paths": "0.2.0-rc.1",
|
|
89
|
+
"@deepseek-ai/dsh-session": "0.2.0-rc.1",
|
|
90
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.0-rc.1",
|
|
91
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.1",
|
|
92
|
+
"@deepseek-ai/dsh-user-questions": "0.2.0-rc.1",
|
|
98
93
|
"@types/node": "^22.20.0",
|
|
99
94
|
"@types/ws": "^8.18.1",
|
|
100
95
|
"playwright-core": "^1.61.1",
|
|
101
96
|
"tsdown": "0.22.2",
|
|
102
97
|
"typescript": "^6.0.3",
|
|
103
|
-
"vitest": "^4.1.8"
|
|
98
|
+
"vitest": "^4.1.8",
|
|
99
|
+
"@deepseek-ai/dsh-user-approval": "0.2.0-rc.1"
|
|
104
100
|
}
|
|
105
101
|
}
|
package/src/approvals.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host approval ownership: claim the host `approval/request` waterfall for
|
|
3
|
+
* extension-owned sessions, push the decision request to the connected
|
|
4
|
+
* extension, and settle the waterfall with the sidebar's choice.
|
|
5
|
+
*
|
|
6
|
+
* Settlement paths (first wins, later ones no-op):
|
|
7
|
+
* - the sidebar decides → the waterfall resolves with that outcome;
|
|
8
|
+
* - the host aborts `request.signal` (turn cancelled, session disposed) →
|
|
9
|
+
* the extension is sent `approval.resolved` and the waterfall resolves
|
|
10
|
+
* with `'cancelled'` (the host vocabulary has no rejection channel here);
|
|
11
|
+
* - the bridge connection drops ({@link delegateAll}) → the waterfall is
|
|
12
|
+
* delegated to `next()` so another answerer (dsh web) can still decide;
|
|
13
|
+
* - plugin unload ({@link dispose}) → `'unavailable'`, the fail-closed
|
|
14
|
+
* outcome of the host's closed outcome set.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { randomUUID } from 'node:crypto'
|
|
20
|
+
import type { ServerFrame } from './protocol.ts'
|
|
21
|
+
import { PendingWaterfalls } from './waterfall.ts'
|
|
22
|
+
|
|
23
|
+
/** The host's closed approval outcome vocabulary. */
|
|
24
|
+
export type ApprovalOutcome = 'allowed-once' | 'rejected' | 'cancelled' | 'unavailable'
|
|
25
|
+
|
|
26
|
+
/** One approval prompt as it crosses the bridge. */
|
|
27
|
+
export interface ApprovalPrompt {
|
|
28
|
+
toolName: string
|
|
29
|
+
callId?: string
|
|
30
|
+
reason?: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Decision the sidebar sends back over `bridge/approvalDecision`. */
|
|
34
|
+
export type ApprovalDecision = 'allowed-once' | 'rejected'
|
|
35
|
+
|
|
36
|
+
/** Receipt answered to the extension's `bridge/approvalDecision` rpc. */
|
|
37
|
+
export type ApprovalReceipt =
|
|
38
|
+
| { accepted: true }
|
|
39
|
+
| { accepted: false; reason: 'not-pending' | 'bad-decision' }
|
|
40
|
+
|
|
41
|
+
/** Args of the plugin-local `bridge/approvalDecision` rpc method (decision already narrowed by the parser). */
|
|
42
|
+
export interface ApprovalDecisionArgs {
|
|
43
|
+
approvalId: string
|
|
44
|
+
sessionId: string
|
|
45
|
+
decision: ApprovalDecision
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type PendingOutcome =
|
|
49
|
+
| { kind: 'decide'; outcome: ApprovalOutcome }
|
|
50
|
+
| { kind: 'delegate' }
|
|
51
|
+
|
|
52
|
+
/** Parse the extension's `bridge/approvalDecision` rpc args (ids + closed decision). */
|
|
53
|
+
export function asApprovalDecisionArgs(value: unknown): ApprovalDecisionArgs | undefined {
|
|
54
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return undefined
|
|
55
|
+
const args = value as Record<string, unknown>
|
|
56
|
+
if (typeof args.approvalId !== 'string' || typeof args.sessionId !== 'string') return undefined
|
|
57
|
+
const decision = args.decision
|
|
58
|
+
if (decision !== 'allowed-once' && decision !== 'rejected') return undefined
|
|
59
|
+
return { approvalId: args.approvalId, sessionId: args.sessionId, decision }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Owns the host approval waterfall for extension-driven sessions. */
|
|
63
|
+
export class ApprovalBridge {
|
|
64
|
+
private readonly waterfalls = new PendingWaterfalls<PendingOutcome>()
|
|
65
|
+
|
|
66
|
+
constructor(private readonly deps: {
|
|
67
|
+
/** Push one server frame to the connected extension (must tolerate a dead socket). */
|
|
68
|
+
push: (frame: ServerFrame) => void
|
|
69
|
+
}) {}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Own one host waterfall request: push `approval.requested` to the
|
|
73
|
+
* extension and suspend until one of the settlement paths wins.
|
|
74
|
+
*
|
|
75
|
+
* @param routingSessionId - extension-visible session id (the owned session the card is filed under).
|
|
76
|
+
* @param prompt - tool name, optional call id and human-readable reason.
|
|
77
|
+
* @param next - waterfall delegation, used when the bridge connection drops.
|
|
78
|
+
* @param signal - host cancellation lifetime for this request.
|
|
79
|
+
* @returns the host approval outcome.
|
|
80
|
+
*/
|
|
81
|
+
ask(
|
|
82
|
+
routingSessionId: string,
|
|
83
|
+
prompt: ApprovalPrompt,
|
|
84
|
+
next: () => Promise<ApprovalOutcome>,
|
|
85
|
+
signal?: AbortSignal,
|
|
86
|
+
): Promise<ApprovalOutcome> {
|
|
87
|
+
if (signal?.aborted) return Promise.resolve<ApprovalOutcome>('cancelled')
|
|
88
|
+
const approvalId = randomUUID()
|
|
89
|
+
return new Promise<ApprovalOutcome>((resolve, reject) => {
|
|
90
|
+
this.waterfalls.register({
|
|
91
|
+
id: approvalId,
|
|
92
|
+
sessionId: routingSessionId,
|
|
93
|
+
signal,
|
|
94
|
+
payload: undefined,
|
|
95
|
+
complete: (outcome) => {
|
|
96
|
+
if (outcome.kind === 'decide') resolve(outcome.outcome)
|
|
97
|
+
else next().then(resolve, reject)
|
|
98
|
+
},
|
|
99
|
+
onAbort: () => {
|
|
100
|
+
// Withdraw the card before settling so a late click can never be
|
|
101
|
+
// reported as accepted for a dead request.
|
|
102
|
+
this.deps.push({ t: 'approval.resolved', id: approvalId, sessionId: routingSessionId })
|
|
103
|
+
this.waterfalls.settle(approvalId, { kind: 'decide', outcome: 'cancelled' })
|
|
104
|
+
},
|
|
105
|
+
})
|
|
106
|
+
this.deps.push({
|
|
107
|
+
t: 'approval.requested',
|
|
108
|
+
id: approvalId,
|
|
109
|
+
sessionId: routingSessionId,
|
|
110
|
+
toolName: prompt.toolName,
|
|
111
|
+
...(prompt.callId === undefined ? {} : { callId: prompt.callId }),
|
|
112
|
+
...(prompt.reason === undefined ? {} : { reason: prompt.reason }),
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Settle one pending approval from the extension's `bridge/approvalDecision`
|
|
119
|
+
* rpc. The server replies with this receipt.
|
|
120
|
+
*/
|
|
121
|
+
decide(args: ApprovalDecisionArgs): ApprovalReceipt {
|
|
122
|
+
if (!this.waterfalls.matches(args.approvalId, args.sessionId)) {
|
|
123
|
+
return { accepted: false, reason: 'not-pending' }
|
|
124
|
+
}
|
|
125
|
+
if (args.decision !== 'allowed-once' && args.decision !== 'rejected') {
|
|
126
|
+
return { accepted: false, reason: 'bad-decision' }
|
|
127
|
+
}
|
|
128
|
+
this.waterfalls.settle(args.approvalId, { kind: 'decide', outcome: args.decision })
|
|
129
|
+
return { accepted: true }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Bridge connection replaced/closed: delegate every unsettled approval. */
|
|
133
|
+
delegateAll(): void {
|
|
134
|
+
for (const id of this.waterfalls.ids()) this.waterfalls.settle(id, { kind: 'delegate' })
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Plugin unload: answer everything fail-closed so no tool call outlives the plugin. */
|
|
138
|
+
dispose(): void {
|
|
139
|
+
for (const id of this.waterfalls.ids()) {
|
|
140
|
+
this.waterfalls.settle(id, { kind: 'decide', outcome: 'unavailable' })
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|