@addozhang/dsh-discord 0.4.0 → 0.5.0-alpha.2
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 +13 -14
- package/README.zh.md +12 -13
- package/cordis.patch.yml +1 -1
- package/lib/client/card-controller.d.ts +1 -1
- package/lib/client/card-form.d.ts +2 -1
- package/lib/client/index.d.ts +2 -2
- package/lib/client/slot-contract.d.ts +7 -0
- package/lib/client/snapshot-store.d.ts +1 -1
- package/lib/compose.d.ts +2 -2
- package/lib/compose.js +1 -1
- package/lib/dsh/host-asks.d.ts +96 -0
- package/lib/dsh/host-asks.js +151 -0
- package/lib/dsh/host-events.d.ts +42 -0
- package/lib/dsh/host-events.js +279 -0
- package/lib/dsh/host-face.d.ts +418 -0
- package/lib/dsh/host-face.js +598 -0
- package/lib/features/adapter-status.d.ts +15 -2
- package/lib/features/adapter-status.js +100 -4
- package/lib/features/approval-store.d.ts +1 -1
- package/lib/features/interaction-router.d.ts +2 -2
- package/lib/features/model-control.d.ts +1 -1
- package/lib/features/project-list.d.ts +1 -1
- package/lib/features/project-list.js +1 -1
- package/lib/features/session-resume.d.ts +1 -1
- package/lib/i18n.d.ts +5 -0
- package/lib/i18n.js +14 -0
- package/lib/index.js +121 -67
- package/lib/settings.js +5 -2
- package/lib/startup.d.ts +1 -1
- package/lib/startup.js +14 -7
- package/lib/stream/live.d.ts +13 -36
- package/lib/stream/live.js +157 -86
- package/lib/stream/tool-view.d.ts +12 -2
- package/lib/stream/tool-view.js +32 -2
- package/package.json +10 -12
- package/lib/dsh/api-proxy-face.d.ts +0 -400
- package/lib/dsh/api-proxy-face.js +0 -515
|
@@ -1,400 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The typed face over the Host's in-process `ctx.apiProxy` service
|
|
3
|
-
* (ApiProxyService, the transport-agnostic gateway's direct implementation).
|
|
4
|
-
* Its domain methods speak the narrow RPC signature: `RpcRequest<P>` in,
|
|
5
|
-
* `RpcResponse<T>` out, business errors on `result.ok === false` — they never
|
|
6
|
-
* throw for business outcomes. Two guarantees are added here:
|
|
7
|
-
*
|
|
8
|
-
* 1. Boundedness — a Host that never answers must not wedge an interaction
|
|
9
|
-
* handler (or a Discord ephemeral) forever; every call races a timeout and
|
|
10
|
-
* resolves to an unobservable outcome instead.
|
|
11
|
-
* 2. Observability — every terminal outcome is reported through the injected
|
|
12
|
-
* log sink, so a silent-void call can never again be misread as a hang.
|
|
13
|
-
*/
|
|
14
|
-
import type { ProjectListPort } from '../features/project-list.js';
|
|
15
|
-
import type { WorkspaceResolver } from '../features/project-bind.js';
|
|
16
|
-
/** The workspace rows the catalog port needs (subset of WorkspaceView). */
|
|
17
|
-
export interface WorkspaceCatalogEntry {
|
|
18
|
-
workspaceId: string;
|
|
19
|
-
title: string;
|
|
20
|
-
/** Canonical directory; present in Host responses, rendered only to proven administrators. */
|
|
21
|
-
path?: string | undefined;
|
|
22
|
-
}
|
|
23
|
-
/** The narrow slice of ApiProxy this module speaks. */
|
|
24
|
-
export interface DshApiProxyFace {
|
|
25
|
-
workspace: {
|
|
26
|
-
list(request: RpcRequestShape<Record<string, never>>): Promise<RpcResponseShape<{
|
|
27
|
-
items: WorkspaceCatalogEntry[];
|
|
28
|
-
}>>;
|
|
29
|
-
};
|
|
30
|
-
sessions: {
|
|
31
|
-
prompt(request: RpcRequestShape<{
|
|
32
|
-
sessionId: string;
|
|
33
|
-
mode: 'queue' | 'steer';
|
|
34
|
-
content: Array<{
|
|
35
|
-
type: 'text';
|
|
36
|
-
text: string;
|
|
37
|
-
} | {
|
|
38
|
-
type: 'image';
|
|
39
|
-
mediaType: string;
|
|
40
|
-
data: string;
|
|
41
|
-
}>;
|
|
42
|
-
}>): Promise<RpcResponseShape<{
|
|
43
|
-
accepted: true;
|
|
44
|
-
}>>;
|
|
45
|
-
create(request: RpcRequestShape<{
|
|
46
|
-
workspaceId?: string;
|
|
47
|
-
sessionId?: string;
|
|
48
|
-
agentPreset?: string;
|
|
49
|
-
}>): Promise<RpcResponseShape<{
|
|
50
|
-
sessionId: string;
|
|
51
|
-
}>>;
|
|
52
|
-
cancel(request: RpcRequestShape<{
|
|
53
|
-
sessionId: string;
|
|
54
|
-
}>): Promise<RpcResponseShape<{
|
|
55
|
-
accepted: true;
|
|
56
|
-
}>>;
|
|
57
|
-
updateQueue(request: RpcRequestShape<{
|
|
58
|
-
sessionId: string;
|
|
59
|
-
itemId: string;
|
|
60
|
-
action: {
|
|
61
|
-
kind: 'remove';
|
|
62
|
-
};
|
|
63
|
-
}>): Promise<RpcResponseShape<{
|
|
64
|
-
accepted: true;
|
|
65
|
-
}>>;
|
|
66
|
-
list(request: RpcRequestShape<{
|
|
67
|
-
cursor?: string;
|
|
68
|
-
}>): Promise<RpcResponseShape<{
|
|
69
|
-
items: SessionSummaryShape[];
|
|
70
|
-
}>>;
|
|
71
|
-
models(request: RpcRequestShape<{
|
|
72
|
-
sessionId: string;
|
|
73
|
-
}>): Promise<RpcResponseShape<SessionModelsShape>>;
|
|
74
|
-
selectModel(request: RpcRequestShape<{
|
|
75
|
-
sessionId: string;
|
|
76
|
-
provider: string;
|
|
77
|
-
model: string;
|
|
78
|
-
reasoningEffort?: string;
|
|
79
|
-
}>): Promise<RpcResponseShape<{
|
|
80
|
-
selected: ModelSelectionShape;
|
|
81
|
-
}>>;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
/** Defensive read of the title projection in a list row's values. */
|
|
85
|
-
export interface SessionProjectionsShape {
|
|
86
|
-
values?: {
|
|
87
|
-
title?: unknown;
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/** The per-session summary `sessions.list` returns (rc.2 rich rows). */
|
|
91
|
-
export interface SessionSummaryShape {
|
|
92
|
-
sessionId: string;
|
|
93
|
-
updatedAt: number;
|
|
94
|
-
running: boolean;
|
|
95
|
-
blank: boolean;
|
|
96
|
-
cwd?: string;
|
|
97
|
-
agentPreset?: string;
|
|
98
|
-
origin?: 'subagent';
|
|
99
|
-
projections?: SessionProjectionsShape;
|
|
100
|
-
}
|
|
101
|
-
/** The complete provider/model/reasoning selection (dsh-agent ModelSelection). */
|
|
102
|
-
export interface ModelSelectionShape {
|
|
103
|
-
provider: string;
|
|
104
|
-
model: string;
|
|
105
|
-
reasoningEffort?: string;
|
|
106
|
-
}
|
|
107
|
-
/** One reasoning effort a model's adapter advertises (sessions.d.ts). */
|
|
108
|
-
import type { DshModelPort } from '../features/model-control.js';
|
|
109
|
-
export interface ModelReasoningEffortShape {
|
|
110
|
-
id: string;
|
|
111
|
-
name: string;
|
|
112
|
-
description?: string;
|
|
113
|
-
}
|
|
114
|
-
/** Exact-route reasoning metadata for one catalog model. */
|
|
115
|
-
export interface ModelReasoningShape {
|
|
116
|
-
efforts: ModelReasoningEffortShape[];
|
|
117
|
-
defaultEffort?: string;
|
|
118
|
-
}
|
|
119
|
-
/** One model inside a provider group (sessions.d.ts ModelCatalogModel). */
|
|
120
|
-
export interface ModelCatalogModelShape {
|
|
121
|
-
id: string;
|
|
122
|
-
name: string;
|
|
123
|
-
description?: string;
|
|
124
|
-
reasoning?: ModelReasoningShape;
|
|
125
|
-
}
|
|
126
|
-
/** One provider group and its models (sessions.d.ts ModelProviderGroup). */
|
|
127
|
-
export interface ModelProviderGroupShape {
|
|
128
|
-
id: string;
|
|
129
|
-
name: string;
|
|
130
|
-
models: ModelCatalogModelShape[];
|
|
131
|
-
}
|
|
132
|
-
/** The detached model directory `session.models` returns for one session. */
|
|
133
|
-
export interface SessionModelsShape {
|
|
134
|
-
current: ModelSelectionShape;
|
|
135
|
-
routable: boolean;
|
|
136
|
-
groups: ModelProviderGroupShape[];
|
|
137
|
-
failures: Array<{
|
|
138
|
-
id: string;
|
|
139
|
-
name: string;
|
|
140
|
-
message: string;
|
|
141
|
-
}>;
|
|
142
|
-
}
|
|
143
|
-
/** Signature-layer narrow request form (RpcId brand erased at this seam). */
|
|
144
|
-
export interface RpcRequestShape<P> {
|
|
145
|
-
rpcId: string;
|
|
146
|
-
payload: P;
|
|
147
|
-
}
|
|
148
|
-
/** Signature-layer narrow response form with the business ok/error result. */
|
|
149
|
-
export interface RpcResponseShape<T> {
|
|
150
|
-
rpcId: string;
|
|
151
|
-
result: {
|
|
152
|
-
ok: true;
|
|
153
|
-
value: T;
|
|
154
|
-
} | {
|
|
155
|
-
ok: false;
|
|
156
|
-
error: {
|
|
157
|
-
code: string;
|
|
158
|
-
message: string;
|
|
159
|
-
};
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
/** Raised when the Host did not answer within the bounded window. */
|
|
163
|
-
export declare class RpcTimeoutError extends Error {
|
|
164
|
-
constructor(timeoutMs: number);
|
|
165
|
-
}
|
|
166
|
-
/** Race one apiProxy promise against a bounded window. */
|
|
167
|
-
export declare function withRpcTimeout<T>(promise: Promise<T>, timeoutMs: number): Promise<T>;
|
|
168
|
-
/** Diagnostic sink shared by both faces. */
|
|
169
|
-
export type ApiProxyLog = (event: string, detail?: unknown) => void;
|
|
170
|
-
export interface ApiProxyFaceOptions {
|
|
171
|
-
timeoutMs?: number;
|
|
172
|
-
log?: ApiProxyLog;
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* The bind flow's catalog verifier: resolves an opaque `ws:` reference
|
|
176
|
-
* against the live workspace list. A well-formed reference the catalog no
|
|
177
|
-
* longer knows — and any malformed one — resolve `stale` (fail-closed, no
|
|
178
|
-
* write can follow); a Host error is `failed`; a timeout is `unknown`.
|
|
179
|
-
*/
|
|
180
|
-
export declare function createWorkspaceResolver(dsh: DshApiProxyFace, options?: ApiProxyFaceOptions): WorkspaceResolver;
|
|
181
|
-
/**
|
|
182
|
-
* The `/project list` catalog port satisfied by the in-process apiProxy.
|
|
183
|
-
* Outcomes follow the port contract: a definitive Host error is `failed`
|
|
184
|
-
* (sanitized before Discord), while a timeout or unreadable body is
|
|
185
|
-
* `unknown` — delivery was not observed, so no retry is implied.
|
|
186
|
-
*/
|
|
187
|
-
export declare function createWorkspaceCatalogPort(dsh: DshApiProxyFace, options?: ApiProxyFaceOptions): ProjectListPort;
|
|
188
|
-
export type WorkspaceDetailOutcome = {
|
|
189
|
-
outcome: 'found';
|
|
190
|
-
workspace: {
|
|
191
|
-
id: string;
|
|
192
|
-
title: string;
|
|
193
|
-
path: string | undefined;
|
|
194
|
-
};
|
|
195
|
-
} | {
|
|
196
|
-
outcome: 'stale';
|
|
197
|
-
} | {
|
|
198
|
-
outcome: 'failed';
|
|
199
|
-
} | {
|
|
200
|
-
outcome: 'unknown';
|
|
201
|
-
};
|
|
202
|
-
/**
|
|
203
|
-
* Read one Workspace's full view (title plus canonical path). The path is
|
|
204
|
-
* for the administrator-only ephemeral info response — the disclosure
|
|
205
|
-
* policy owns whether it ever renders; this face only carries it in memory.
|
|
206
|
-
*/
|
|
207
|
-
export declare function readWorkspaceDetail(dsh: DshApiProxyFace, reference: string, options?: ApiProxyFaceOptions): Promise<WorkspaceDetailOutcome>;
|
|
208
|
-
export type PromptOutcome = {
|
|
209
|
-
outcome: 'accepted';
|
|
210
|
-
} | {
|
|
211
|
-
outcome: 'rejected';
|
|
212
|
-
reason: string;
|
|
213
|
-
} | {
|
|
214
|
-
outcome: 'unknown';
|
|
215
|
-
};
|
|
216
|
-
/**
|
|
217
|
-
* Submit one prompt turn through the in-process apiProxy. A definitive Host
|
|
218
|
-
* error is a rejection carrying the sanitized code; a timeout is `unknown` —
|
|
219
|
-
* the turn may or may not have been admitted, so callers must not resubmit.
|
|
220
|
-
* `options.rpcId` pins the adapter-owned stable request id, which the Host
|
|
221
|
-
* records on the durable `user/message` (`source.rpcId`) for reconciliation.
|
|
222
|
-
* Images (16.50) encode as ordered `image` parts after the text part — the
|
|
223
|
-
* rc.2 `session.prompt` content is parts-shaped at this seam.
|
|
224
|
-
*/
|
|
225
|
-
export declare function promptSession(dsh: DshApiProxyFace, request: {
|
|
226
|
-
sessionId: string;
|
|
227
|
-
prompt: string;
|
|
228
|
-
images?: ReadonlyArray<{
|
|
229
|
-
mediaType: string;
|
|
230
|
-
base64: string;
|
|
231
|
-
}>;
|
|
232
|
-
}, options?: ApiProxyFaceOptions & {
|
|
233
|
-
rpcId?: string;
|
|
234
|
-
}): Promise<PromptOutcome>;
|
|
235
|
-
/**
|
|
236
|
-
* Steer the session's active turn: `session.prompt` with `mode: 'steer'`,
|
|
237
|
-
* carrying the same stable request-id discipline as the queue path.
|
|
238
|
-
*/
|
|
239
|
-
export declare function steerSession(dsh: DshApiProxyFace, request: {
|
|
240
|
-
sessionId: string;
|
|
241
|
-
prompt: string;
|
|
242
|
-
}, options?: ApiProxyFaceOptions & {
|
|
243
|
-
rpcId?: string;
|
|
244
|
-
}): Promise<PromptOutcome>;
|
|
245
|
-
export type CreateSessionOutcome = {
|
|
246
|
-
outcome: 'completed';
|
|
247
|
-
sessionId: string;
|
|
248
|
-
} | {
|
|
249
|
-
outcome: 'rejected';
|
|
250
|
-
reason: string;
|
|
251
|
-
} | {
|
|
252
|
-
outcome: 'unknown';
|
|
253
|
-
};
|
|
254
|
-
/**
|
|
255
|
-
* Create one DSH Session against a preallocated id (design.md §10): DSH
|
|
256
|
-
* adopts the same session id idempotently, so an uncertain response never
|
|
257
|
-
* forks a second Session. Same outcome discipline as the prompt path.
|
|
258
|
-
*/
|
|
259
|
-
export declare function createSessionViaProxy(dsh: DshApiProxyFace, request: {
|
|
260
|
-
sessionId: string;
|
|
261
|
-
workspaceId: string;
|
|
262
|
-
}, options?: ApiProxyFaceOptions): Promise<CreateSessionOutcome>;
|
|
263
|
-
/** The durable Session-id baseline reconciliation reconciles against. */
|
|
264
|
-
export type SessionIdListOutcome = {
|
|
265
|
-
outcome: 'completed';
|
|
266
|
-
ids: string[];
|
|
267
|
-
} | {
|
|
268
|
-
outcome: 'failed';
|
|
269
|
-
} | {
|
|
270
|
-
outcome: 'unknown';
|
|
271
|
-
};
|
|
272
|
-
/** List durable Session ids (`session.list`, v1 returns everything). */
|
|
273
|
-
export declare function listSessionIds(dsh: DshApiProxyFace, options?: ApiProxyFaceOptions): Promise<SessionIdListOutcome>;
|
|
274
|
-
/** A list row narrowed to what the /session resume surface renders. */
|
|
275
|
-
export interface SessionResumeRow {
|
|
276
|
-
sessionId: string;
|
|
277
|
-
title: string | undefined;
|
|
278
|
-
updatedAt: number;
|
|
279
|
-
running: boolean;
|
|
280
|
-
blank: boolean;
|
|
281
|
-
cwd: string | undefined;
|
|
282
|
-
origin: 'subagent' | undefined;
|
|
283
|
-
}
|
|
284
|
-
export type SessionSummariesOutcome = {
|
|
285
|
-
outcome: 'completed';
|
|
286
|
-
sessions: SessionResumeRow[];
|
|
287
|
-
} | {
|
|
288
|
-
outcome: 'failed';
|
|
289
|
-
} | {
|
|
290
|
-
outcome: 'unknown';
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* The rich `sessions.list` for the /session resume surface: titles ride each
|
|
294
|
-
* row's projection values (absence = the session has no title yet), blank
|
|
295
|
-
* sessions are flagged, and rows arrive updatedAt-descending. Defensive
|
|
296
|
-
* narrowing: the wire is untrusted, extra/missing fields never throw.
|
|
297
|
-
*/
|
|
298
|
-
export declare function listSessionSummaries(dsh: DshApiProxyFace, options?: ApiProxyFaceOptions): Promise<SessionSummariesOutcome>;
|
|
299
|
-
export type CancelOutcome = {
|
|
300
|
-
outcome: 'accepted';
|
|
301
|
-
} | {
|
|
302
|
-
outcome: 'rejected';
|
|
303
|
-
reason: string;
|
|
304
|
-
} | {
|
|
305
|
-
outcome: 'unknown';
|
|
306
|
-
};
|
|
307
|
-
/** Cancel the session's active turn (`session.cancel`); DSH preserves the pending inbox. */
|
|
308
|
-
export declare function cancelSessionViaProxy(dsh: DshApiProxyFace, request: {
|
|
309
|
-
sessionId: string;
|
|
310
|
-
}, options?: ApiProxyFaceOptions): Promise<CancelOutcome>;
|
|
311
|
-
export type QueueRemoveOutcome = {
|
|
312
|
-
outcome: 'accepted';
|
|
313
|
-
} | {
|
|
314
|
-
outcome: 'rejected';
|
|
315
|
-
reason: string;
|
|
316
|
-
} | {
|
|
317
|
-
outcome: 'unknown';
|
|
318
|
-
};
|
|
319
|
-
/** Remove one pending inbox item (`session.updateQueue`, action remove). */
|
|
320
|
-
export declare function removeQueueItemViaProxy(dsh: DshApiProxyFace, request: {
|
|
321
|
-
sessionId: string;
|
|
322
|
-
itemId: string;
|
|
323
|
-
}, options?: ApiProxyFaceOptions): Promise<QueueRemoveOutcome>;
|
|
324
|
-
/** The carrier verdict apiProxy.respond resolves with (RpcReceipt). */
|
|
325
|
-
export type RespondReceipt = {
|
|
326
|
-
accepted: true;
|
|
327
|
-
} | {
|
|
328
|
-
accepted: false;
|
|
329
|
-
reason: 'not-pending' | 'bad-response';
|
|
330
|
-
} | {
|
|
331
|
-
accepted: unknown;
|
|
332
|
-
};
|
|
333
|
-
export type RespondOutcome = {
|
|
334
|
-
outcome: 'confirmed';
|
|
335
|
-
} | {
|
|
336
|
-
outcome: 'rejected';
|
|
337
|
-
reason: string;
|
|
338
|
-
} | {
|
|
339
|
-
outcome: 'unknown';
|
|
340
|
-
};
|
|
341
|
-
/**
|
|
342
|
-
* The respond face for answerable server-requests (approvals, questions).
|
|
343
|
-
* Builds the full ClientResponse envelope — {type: 'client-response',
|
|
344
|
-
* rpcId, result: {ok: true, value}} is the wire contract; posting the bare
|
|
345
|
-
* payload is silently ignored by the Host (rpcId never resolves) — and
|
|
346
|
-
* maps the RpcReceipt onto the port outcome. Like every call in this module
|
|
347
|
-
* it is bounded (a Host that never resolves the receipt must not wedge an
|
|
348
|
-
* interaction handler or an expiry sweep forever) and never throws: a Host
|
|
349
|
-
* rejection or timeout resolves to `unknown` — the response may or may not
|
|
350
|
-
* have landed, and the callers park the ask `unresolved` on exactly that.
|
|
351
|
-
*/
|
|
352
|
-
export declare function createClientRespondPort(dsh: {
|
|
353
|
-
respond(message: unknown): Promise<unknown>;
|
|
354
|
-
}, options?: ApiProxyFaceOptions): {
|
|
355
|
-
respond(rpcId: string, value: unknown): Promise<RespondOutcome>;
|
|
356
|
-
};
|
|
357
|
-
export type SessionModelsOutcome = {
|
|
358
|
-
outcome: 'completed';
|
|
359
|
-
models: SessionModelsShape;
|
|
360
|
-
} | {
|
|
361
|
-
outcome: 'failed';
|
|
362
|
-
} | {
|
|
363
|
-
outcome: 'unknown';
|
|
364
|
-
};
|
|
365
|
-
/**
|
|
366
|
-
* The session's detached model directory: the live selection, whether the
|
|
367
|
-
* current route still serves, and the per-provider catalog groups the
|
|
368
|
-
* /model cascade browses.
|
|
369
|
-
*/
|
|
370
|
-
export declare function sessionModels(dsh: DshApiProxyFace, request: {
|
|
371
|
-
sessionId: string;
|
|
372
|
-
}, options?: ApiProxyFaceOptions): Promise<SessionModelsOutcome>;
|
|
373
|
-
export type SelectModelOutcome = {
|
|
374
|
-
outcome: 'completed';
|
|
375
|
-
selected: ModelSelectionShape;
|
|
376
|
-
} | {
|
|
377
|
-
outcome: 'rejected';
|
|
378
|
-
reason: string;
|
|
379
|
-
} | {
|
|
380
|
-
outcome: 'unknown';
|
|
381
|
-
};
|
|
382
|
-
/**
|
|
383
|
-
* Select the complete model selection for one session (session.selectModel):
|
|
384
|
-
* the session switches immediately and the Host records the choice as the
|
|
385
|
-
* default for sessions that have not logged their own — the response only
|
|
386
|
-
* proves the session switch, so callers must not claim the persistence
|
|
387
|
-
* outcome (design.md §7).
|
|
388
|
-
*/
|
|
389
|
-
export declare function selectSessionModel(dsh: DshApiProxyFace, request: {
|
|
390
|
-
sessionId: string;
|
|
391
|
-
provider: string;
|
|
392
|
-
model: string;
|
|
393
|
-
reasoningEffort?: string;
|
|
394
|
-
}, options?: ApiProxyFaceOptions): Promise<SelectModelOutcome>;
|
|
395
|
-
/**
|
|
396
|
-
* The /model surface over the real session RPCs: the per-session live
|
|
397
|
-
* directory (`session.models`) and the guarded selection mutation
|
|
398
|
-
* (`session.selectModel`) — the shapes model-control reasons about.
|
|
399
|
-
*/
|
|
400
|
-
export declare function createModelPort(dsh: DshApiProxyFace, options?: ApiProxyFaceOptions): DshModelPort;
|