@eum-agent/plugin 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1114 +0,0 @@
1
- import { $i as AgentRevisionPage, Ar as SubprocessBytes$1, Bi as MessageFileInput, Bn as PromptSlot, Br as TriggerRun, Dn as PluginSummary, Gr as TriggerSummary, Hn as ReadingSessionOperationResult, Ht as MessageAttachmentInput, Ir as TriggerInput, Ji as AgentRestorePreview, Jn as ResultMap, Kt as ParamsOf, Mr as SubprocessSummary, Nr as Toolset, On as PluginSurface, Qi as AgentRevisionComparison, Qt as PluginActivationPlan, To as FileRef, Ua as SessionLimits, Ui as AuthorizationRecord, Ut as ModelRef, Vi as AuthorizationInput, Xn as RewindSendResult, Yi as AgentRestoreResult, Yn as ResultOf, Zt as PluginActivationBatchPlan, _ as AvatarImage, a as AgentPromptSlots, ar as SessionFrame, br as SessionSnapshot, bt as HumanReply, cn as PluginRemovalBatchPlan, ct as ForkResult, ei as WatchSessionSummary, jo as MessageVia, jt as InboxItem, ko as Message, ln as PluginRemovalPlan, mr as SessionOperationResult, ni as WorkspaceSummary, nt as CredentialStatus, ot as DirectoryListing, qi as AgentRestoreInput, r as AccessRevokeInput, s as AgentSummary, xn as PluginSignalFrame, xr as SessionSummary } from "./index-Br0Y0fFq.js";
2
- import "./storage-CpsDibqp.js";
3
- import { ZodType } from "zod";
4
- import { ComponentProps, ComponentType, ReactElement, ReactNode } from "react";
5
- import { DatabaseSync } from "node:sqlite";
6
- //#region src/widgets.d.ts
7
- /** Pure readable rendering over an already authenticated effective history. */
8
- type MessageTextRenderer = (message: Message, transcript: readonly Message[]) => string;
9
- //#endregion
10
- //#region src/client-io.d.ts
11
- /** A single inclusive byte range, or the requested number of trailing bytes. */
12
- type ResourceRangeRequest = {
13
- readonly kind: 'absolute';
14
- readonly start: number;
15
- readonly end?: number;
16
- } | {
17
- readonly kind: 'suffix';
18
- readonly length: number;
19
- };
20
- /** The authenticated resource operation; the host supplies cancellation and PUT bytes. */
21
- type ResourceCall = {
22
- readonly method: 'HEAD';
23
- readonly signal: AbortSignal;
24
- } | {
25
- readonly method: 'GET';
26
- readonly signal: AbortSignal;
27
- readonly range?: ResourceRangeRequest;
28
- } | {
29
- readonly method: 'PUT';
30
- readonly signal: AbortSignal;
31
- readonly body: AsyncIterable<Uint8Array>;
32
- };
33
- /** Validated response headers for an opened byte resource. Lengths and offsets are bytes. */
34
- interface ResourceByteMetadata {
35
- /** A media type without line breaks or control characters. */
36
- readonly contentType: string;
37
- /** The exact number of bytes returned, including a selected range. */
38
- readonly contentLength: number;
39
- /** A download filename and the requested browser disposition. */
40
- readonly contentDisposition: {
41
- readonly filename: string;
42
- readonly disposition: 'inline' | 'attachment';
43
- };
44
- /** Inclusive offsets and total object length for a partial GET. */
45
- readonly range?: {
46
- readonly start: number;
47
- readonly end: number;
48
- readonly total: number;
49
- };
50
- }
51
- /** HEAD returns headers, GET returns bytes, and PUT returns its declared JSON result. */
52
- type ResourceResult<R = unknown, M = unknown> = {
53
- readonly kind: 'head';
54
- readonly bytes: ResourceByteMetadata;
55
- readonly metadata?: M;
56
- } | {
57
- readonly kind: 'bytes';
58
- readonly bytes: ResourceByteMetadata;
59
- readonly metadata?: M;
60
- readonly body: AsyncIterable<Uint8Array>;
61
- /** Releases an opened source even when no body iteration began; invoked at most once. */
62
- close(): Promise<void> | void;
63
- } | {
64
- readonly kind: 'json';
65
- readonly result: R;
66
- readonly metadata?: M;
67
- };
68
- /** A plugin's accepted stream; ready precedes every business output on the wire. */
69
- interface ClientStreamHandle<R = unknown, I = unknown> {
70
- /** The unique initial metadata carried by the opened reply. */
71
- readonly ready: R;
72
- /** Consumes one validated client payload; calls are serialized by the host. */
73
- input(payload: I): Promise<void> | void;
74
- /** Releases this attachment; the host invokes it at most once, including late opens. */
75
- close(): Promise<void> | void;
76
- }
77
- /** Host resource lease; callers close it after completion or cancellation. */
78
- interface ClientResourceResponse {
79
- /** The validated response, with byte iteration bound to this lease. */
80
- readonly result: ResourceResult;
81
- /** Cancellation shared by owner, registration and request. */
82
- readonly signal: AbortSignal;
83
- /** Cancels and releases active source and request-body iterators; idempotent. */
84
- close(): Promise<void>;
85
- }
86
- /** Host stream lease; ready and all payloads have passed the owner's declared schemas. */
87
- interface ClientStreamConnection extends ClientStreamHandle {
88
- /** Cancellation shared by owner, registration and connection. */
89
- readonly signal: AbortSignal;
90
- /** Queues one validated input within the bounded connection budget and preserves call order. */
91
- input(payload: unknown): Promise<void>;
92
- /** Releases the plugin handle; idempotent. */
93
- close(): Promise<void>;
94
- }
95
- //#endregion
96
- //#region ../gateway/src/runtime-port.d.ts
97
- /** What `session.send` carries besides the session id: the text, the
98
- * command a person wrote when `text` is its expansion, and what they
99
- * attached. */
100
- interface SessionSendInput {
101
- readonly text: string;
102
- readonly invocation?: {
103
- readonly text: string;
104
- readonly namespace: string;
105
- };
106
- readonly attachments?: readonly MessageAttachmentInput[];
107
- readonly files?: readonly MessageFileInput[];
108
- readonly operationId?: string;
109
- readonly rewind?: {
110
- readonly beforeMessageId: string;
111
- readonly expectedRevision: number;
112
- };
113
- }
114
- /** Ordinary input returns synchronously; historical replacement has a separate admission port. */
115
- type SessionRegularSendInput = Omit<SessionSendInput, 'rewind'>;
116
- /** Optimistic history identity required by asynchronous rewind admission. */
117
- type SessionRewindSendInput = SessionRegularSendInput & {
118
- readonly operationId: string;
119
- readonly rewind: NonNullable<SessionSendInput['rewind']>;
120
- };
121
- /** Validated Agent patch fields from the framework's own wire contract. */
122
- type AgentSaveInput = Omit<ParamsOf<'config.agent.save'>, 'agentId' | 'expectedRevision' | 'expectedContentHash'>;
123
- /**
124
- * The `std.*` family, as the gateway sees it: one member per wire module.
125
- *
126
- * The gateway declares the shape and implements none of it — the same
127
- * relationship it has to every other port. Mirroring the wire is right for
128
- * this family alone: `session.*` and `config.*` speak the product's own
129
- * vocabulary and their methods sit flat on `RuntimePort`, while `std.*` is a
130
- * library whose modules *are* its units.
131
- */
132
- interface StdPort {
133
- readonly fs: {
134
- /** Immediate file and directory metadata, never contents. A file path lists its parent
135
- * and identifies the file; omitting the path starts at home. */
136
- list(path?: string): DirectoryListing | Promise<DirectoryListing>;
137
- };
138
- }
139
- interface RuntimePort {
140
- /** Reads confirmed global limits through controlled configuration recovery. */
141
- getLimits(): SessionLimits;
142
- /** Saves a complete limits replacement for future turns. */
143
- setLimits(limits: SessionLimits): SessionLimits;
144
- /** Sole producer of confirmed limits notifications, including successful recovery. */
145
- onLimitsChanged(listener: (limits: SessionLimits) => void): () => void;
146
- /** Reads managed instruction sources for a session's Agent address. */
147
- sessionInstructions(sessionId: string): ResultMap['session.instructions'];
148
- /** Every session, most recently active first. Answers without loading any
149
- * of them. */
150
- listSessions(): readonly SessionSummary[];
151
- createSession(input: {
152
- readonly origin?: {
153
- readonly kind: 'trigger' | 'channel';
154
- readonly ref: string | null;
155
- };
156
- readonly agentId: string;
157
- readonly workspaceId: string;
158
- readonly title?: string;
159
- }): SessionSummary;
160
- /** Commits an independent history prefix and returns its composer refill. */
161
- forkSession(input: ParamsOf<'session.fork'>): ForkResult;
162
- /** Reads a committed fork or rewind result by its durable operation ID. */
163
- getSessionOperation(operationId: string): SessionOperationResult;
164
- /** Bounded session browser metadata with lazy immutable full values. */
165
- listReadingSessions(): Promise<readonly WatchSessionSummary[]>;
166
- /** Bounded durable receipt lookup independent of current source history. */
167
- getReadingSessionOperation(operationId: string, ownerId?: string): ReadingSessionOperationResult;
168
- /** Bounded summary for subscription updates. */
169
- readingSessionSummary(sessionId: string): WatchSessionSummary;
170
- /** Read-only projection preparation and bounded source methods. */
171
- ensureReadingReady(sessionId: string, options?: {
172
- readingLeaseId?: string;
173
- ownerId?: string;
174
- signal?: AbortSignal;
175
- wait?: boolean;
176
- }): Promise<void>;
177
- releaseReadingLease(id: string, ownerId?: string): void;
178
- historyPage(params: ParamsOf<'session.historyPage'>): ResultMap['session.historyPage'];
179
- messageParts(params: ParamsOf<'session.messageParts'>): ResultMap['session.messageParts'];
180
- messageContent(params: ParamsOf<'session.messageContent'>, ownerId?: string): ResultMap['session.messageContent'];
181
- livePage(params: ParamsOf<'session.livePage'>): ResultMap['session.livePage'];
182
- /** Hydrates an original message without using an execution driver. */
183
- readMessage(sessionId: string, messageId: string, generation: number): Promise<Message>;
184
- /** Resolves retained saved facts for non-browser channels. */
185
- readMessageText(sessionId: string, messageId: string, generation: number): Promise<string>;
186
- /** Reads a session off disk and folds it, if it is not already in memory.
187
- * Asynchronous, and that is exactly why it is a separate operation from
188
- * `watch` — see below. */
189
- load(sessionId: string): Promise<void>;
190
- /**
191
- * Registers the subscription and captures a ready bounded reading snapshot in one
192
- * synchronous section. This read does not load an execution driver; cold reading
193
- * preparation remains an explicit asynchronous readiness operation.
194
- */
195
- watch(sessionId: string, listener: (frame: SessionFrame) => void, readingLeaseId?: string, ownerId?: string): {
196
- readonly snapshot: SessionSnapshot;
197
- readonly unwatch: () => void;
198
- };
199
- /** Takes the message and returns — never awaits the turn. An idle session
200
- * opens a turn with it; a running one holds it as a steer for its next
201
- * step, named by the returned `steerId`. Throws when the session is
202
- * waiting for a person: a message would sit behind a turn only that
203
- * person can end. Also throws, with nothing written, for a message over
204
- * the total limit, one with neither text nor an attachment, and
205
- * attachments bound for a delegated session. */
206
- send(sessionId: string, input: SessionRegularSendInput & {
207
- readonly via?: MessageVia;
208
- }): {
209
- readonly steerId?: string;
210
- };
211
- /**
212
- * Prepares a rewind, commits its durable receipt, then admits one replacement turn.
213
- * Identical retries resolve before execution loading. Connection cancellation withdraws
214
- * only precommit admission; committed turns keep their independent execution lifetime.
215
- */
216
- rewindSend(sessionId: string, input: SessionRewindSendInput & {
217
- readonly via?: MessageVia;
218
- }, options?: {
219
- readonly signal?: AbortSignal;
220
- }): Promise<RewindSendResult>;
221
- /** Takes a steer back before its step claims it and returns its message.
222
- * Throws once it has reached the conversation, opened a turn or been
223
- * handed back by a cancellation. */
224
- withdraw(sessionId: string, steerId: string): Message;
225
- /** Takes one reply to a request the session is waiting on and returns —
226
- * the turn's continuation arrives as frames. Throws, with nothing taken,
227
- * when the session is not waiting, the request is unknown or already
228
- * answered, or the reply does not fit the request. */
229
- answer(sessionId: string, reply: HumanReply): void;
230
- /** Notified when a session's summary changes — its title was named by its
231
- * first message, its last-active time moved, its phase changed, a turn
232
- * ended with an outcome, somebody pinned a model or filed it away.
233
- * Without it a list on another connection keeps showing the raw session id
234
- * until that page reconnects, which is exactly what the first look at the
235
- * real UI showed.
236
- *
237
- * **This is the one writer of `session.updated`.** Every cause goes
238
- * through it, request-driven or not, which is what keeps the frame from
239
- * arriving twice for the causes that do have a request behind them — a
240
- * request handler that broadcast its own copy as well is exactly the
241
- * defect this sentence exists to prevent. A fake in a test must announce
242
- * too, or it is testing a path production does not use.
243
- *
244
- * It reaches the built-in channel as a broadcast, and every other channel
245
- * through its `ChannelContext.onSessionUpdated`. */
246
- onSessionUpdated(listener: (session: WatchSessionSummary) => void): () => void;
247
- /** A no-op when the session is idle, and a no-op when it is not loaded: a
248
- * session with no driver in this process cannot be running, and cancelling
249
- * must not cost a read of its whole log. */
250
- cancel(sessionId: string): Promise<void>;
251
- /** Prepares the target context, then atomically commits a session model.
252
- * Preparation failure or cancellation leaves the selected model unchanged.
253
- *
254
- * **It announces through `onSessionUpdated`, and the gateway therefore
255
- * broadcasts nothing of its own** — see that method for why one writer
256
- * matters here. */
257
- setSessionModel(sessionId: string, model: ModelRef): Promise<SessionSummary>;
258
- /** The settings this session will use for one model, whole rather than a
259
- * difference. Announces the same way `setSessionModel` does. */
260
- setSessionModelParams(sessionId: string, model: ModelRef, params: Readonly<Record<string, unknown>>): SessionSummary;
261
- /** Files a session away, or takes it back out. Idempotent, and it leaves
262
- * `updatedAt` alone — filing is not activity, and a list should not
263
- * reorder because somebody tidied up. Throws when nothing is known under
264
- * that id, which is the caller's mistake rather than a state the session
265
- * has. Announces the same way `setSessionModel` does. */
266
- setSessionArchived(sessionId: string, archived: boolean): SessionSummary;
267
- /** Sets or clears the name a person gives a session. Throws for an unknown
268
- * id or a name over the limit; announces like `setSessionArchived`. */
269
- setSessionName(sessionId: string, name: string): SessionSummary;
270
- /** The person joins an agent-created session; unchanged answers the same. */
271
- joinSession(sessionId: string): Promise<SessionSummary>;
272
- /** The person leaves; refused for a session they created. */
273
- leaveSession(sessionId: string): Promise<SessionSummary>;
274
- /** Before a person's message: joins a session they are not in yet. */
275
- joinBeforeSend(sessionId: string): Promise<void>;
276
- /** Watches edits originating inside a model tool. */
277
- onAgentChanged(listener: (agent: AgentSummary) => void): () => void;
278
- /** Refuses business operations while generic configuration recovery remains incomplete. */
279
- assertConfigurationReady(): void;
280
- listAgents(): readonly AgentSummary[];
281
- /** Read-only journal of persistent edits to this definition. */
282
- /** Lists successful configuration snapshots. */
283
- checkAgentRevision(id: string, revision: number, hash: string): void;
284
- agentRevisions(agentId: string, limit?: number, cursor?: string): AgentRevisionPage;
285
- /** Compares two retained versions. */
286
- compareAgentRevisions(agentId: string, from: number, to: number): AgentRevisionComparison;
287
- /** Validates a historical configuration without writing it. */
288
- previewAgentRestore(agentId: string, target: number): AgentRestorePreview;
289
- /** Saves a historical configuration once per confirmation id. */
290
- restoreAgentRevision(agentId: string, input: AgentRestoreInput): AgentRestoreResult;
291
- createAgent(input: {
292
- readonly name: string;
293
- }): AgentSummary;
294
- /** The slots the system prompt template declares. */
295
- listPromptSlots(): readonly PromptSlot[];
296
- updateAgent(agentId: string, changes: {
297
- readonly name?: string;
298
- readonly description?: string;
299
- readonly tools?: readonly string[] | null;
300
- readonly skills?: readonly string[];
301
- readonly startsSessions?: boolean;
302
- }): AgentSummary;
303
- setAgentPromptSlot(agentId: string, slot: 'identity' | 'instructions' | 'style' | 'reminder', text: string): AgentSummary;
304
- agentPromptSlots(agentId: string): AgentPromptSlots;
305
- /** Sets an agent's picture from base64, or returns it to the derived one
306
- * with `null`. Refuses anything that is not a whole 256×256 PNG of at
307
- * most 512 KiB. */
308
- setAgentAvatar(agentId: string, image: string | null): AgentSummary;
309
- /** The uploaded picture, or `null` when the agent has none. */
310
- agentAvatar(agentId: string): AvatarImage | null;
311
- /** Saves any part of an agent's definition, prompt slots and picture at
312
- * once, or nothing: a refusal of any field writes none of them. */
313
- saveAgent(agentId: string, save: AgentSaveInput): AgentSummary;
314
- /** Removes a user-created agent whole or not at all, or throws saying why:
315
- * the general-purpose agent, an unknown id, something of it still
316
- * running, or a step that failed. The gateway broadcasts
317
- * `config.agentRemoved` after this returns. */
318
- removeAgent(agentId: string): void;
319
- listWorkspaces(): readonly WorkspaceSummary[];
320
- /** Every inbox item, newest first. */
321
- listInbox(): readonly InboxItem[];
322
- readInbox(ids: readonly string[]): void;
323
- /** Marks every unread notice about one session read. */
324
- readInboxSession(sessionId: string): void;
325
- /** Removes items; a request still waiting is kept. */
326
- clearInbox(ids: readonly string[]): void;
327
- clearReadInbox(): void;
328
- /** **The one writer of `inbox.changed`**, request-driven or not. */
329
- onInboxChanged(listener: (change: {
330
- readonly upserted: readonly InboxItem[];
331
- readonly removed: readonly string[];
332
- }) => void): () => void;
333
- listTriggers(workspaceId?: string): readonly TriggerSummary[];
334
- /** Refuses with the rule's or the scope's reason and writes nothing. */
335
- createTrigger(input: TriggerInput & {
336
- readonly source: string;
337
- }): TriggerSummary;
338
- updateTrigger(id: string, input: TriggerInput): TriggerSummary;
339
- setTriggerEnabled(id: string, enabled: boolean): TriggerSummary;
340
- removeTrigger(id: string): boolean;
341
- triggerRuns(id: string): readonly TriggerRun[];
342
- /** **The one writer of `trigger.changed`**: the whole table. */
343
- onTriggersChanged(listener: (triggers: readonly TriggerSummary[]) => void): () => void;
344
- /** **The one writer of `trigger.runChanged`**. */
345
- onTriggerRunChanged(listener: (run: TriggerRun) => void): () => void;
346
- /** Every registered subprocess, most recent first: running and recently
347
- * ended alike. */
348
- listSubprocesses(): readonly SubprocessSummary[];
349
- /** The signal ladder — SIGTERM, three seconds, SIGKILL — settling once the
350
- * group is empty. A process already gone answers with what it ended as. */
351
- stopSubprocess(processId: string): Promise<SubprocessSummary>;
352
- /** One stream's bytes by range, read from the log file. */
353
- readSubprocessOutput(read: {
354
- readonly processId: string;
355
- readonly stream: 'stdout' | 'stderr';
356
- readonly offset?: number;
357
- readonly limit?: number;
358
- }): Promise<SubprocessBytes$1>;
359
- /** The standard library a client gets from the process hosting it —
360
- * `std.fs.list` and whatever joins it. Nested rather than flattened into
361
- * methods here, because for a library the wire's own shape is the
362
- * vocabulary, and that makes where a new `std.*` method goes obvious. */
363
- readonly std: StdPort;
364
- createWorkspace(input: {
365
- readonly name: string;
366
- }): WorkspaceSummary;
367
- /** Rename a workspace. An omitted field is left alone. */
368
- updateWorkspace(workspaceId: string, input: {
369
- readonly name?: string;
370
- }): WorkspaceSummary;
371
- /** Sets a workspace's picture from base64, or returns it to the letters
372
- * face with `null`. Throws the avatar refusal for anything that is not a
373
- * whole 256×256 PNG of at most `AVATAR_MAX_BYTES`, and `no such
374
- * workspace: <id>` for an unknown one. */
375
- setWorkspaceAvatar(workspaceId: string, image: string | null): WorkspaceSummary;
376
- /** The workspace's uploaded picture, or `null` when it has none. */
377
- workspaceAvatar(workspaceId: string): AvatarImage | null;
378
- /** Every tool the agent can see, with the description the model is given
379
- * for it, the plugin that registered it and whether the agent's whitelist
380
- * permits it. Answers without a session, because tool visibility is
381
- * decided on the agent alone — and because the failure this exists to
382
- * catch, a registration that never happened, has to be visible before
383
- * anybody opens anything. Throws `no such agent: <id>`. */
384
- listTools(agentId: string): Toolset;
385
- /** `path` is resolved to a real absolute path here, at add time, so the
386
- * fence check later is a plain prefix comparison. A work directory carries
387
- * no mode: it is always readable, and what may be *changed* under it is a
388
- * permission, answered by a person when a tool asks. Authorizing a path
389
- * that is already authorized is a no-op. */
390
- addDirectory(workspaceId: string, path: string): WorkspaceSummary;
391
- removeDirectory(workspaceId: string, path: string): WorkspaceSummary;
392
- /** Lists access records with ownership; omitted scope filters include all records. */
393
- listAccessGrants(): {
394
- readonly grants: readonly AuthorizationRecord[];
395
- };
396
- /** Adds a validated global resource batch atomically. */
397
- addAccessGrant(input: AuthorizationInput): {
398
- readonly grants: readonly AuthorizationRecord[];
399
- };
400
- /** Removes one permission and says whether there was one to remove.
401
- * `revoked: false` for a permission that was never there, rather than a
402
- * throw — a retried revoke answers the same way the first one did. */
403
- revokeAccessGrant(input: AccessRevokeInput): {
404
- readonly revoked: boolean;
405
- };
406
- /** Notified whenever the permissions of one (agent, workspace) pair
407
- * change — a person answering one into existence inside a tool call, or
408
- * revoking one from a settings page. Both go through this, no request
409
- * behind either necessarily.
410
- *
411
- * **This is the one writer of `config.accessChanged`**, and a fake in a test
412
- * must announce too, or it is testing a path production does not use. */
413
- onAccessChanged(listener: (change: {
414
- readonly grants: readonly AuthorizationRecord[];
415
- }) => void): () => void;
416
- /** Host-only registration after listening; a different second port is refused. */
417
- bindSandboxGatewayPort(port: number): void;
418
- /** Notified whenever the subprocess registry changes.
419
- *
420
- * **The one writer of `process.changed`.** Most of its causes have no
421
- * request behind them — a process exits on its own, a timeout fires, the
422
- * machine is shutting down — so a request handler announcing its own
423
- * change would cover a fraction of them and hide the rest. */
424
- onSubprocessesChanged(listener: (processes: readonly SubprocessSummary[]) => void): () => void;
425
- /** A plugin's credentials, addressed by the plugin's full name and a scope
426
- * of its own. Each answers the scope's status — name, `set` and four
427
- * characters — and never a value. A name that is not declared is refused;
428
- * a write also needs the plugin active and holding the `credentials`
429
- * service, because nothing else could ever read what is written. */
430
- credentialStatus(plugin: string, scope: string): readonly CredentialStatus[];
431
- setCredential(plugin: string, scope: string, name: string, value: string): readonly CredentialStatus[];
432
- clearCredential(plugin: string, scope: string, name?: string): readonly CredentialStatus[];
433
- /** Every write or clear of a plugin's credentials that changed a row.
434
- * **The one place a `config.credentialChanged` frame comes from.** */
435
- onCredentialChanged(listener: (plugin: string, scope: string) => void): () => void;
436
- /** Every plugin the configuration declares, plus any the host loaded
437
- * without declaring. Synchronous: it reads what is already in memory. */
438
- listPlugins(): readonly PluginSummary[];
439
- /**
440
- * Installs a package, loads what it exports, and records it — or answers
441
- * why it could not.
442
- *
443
- * **Never rejects for a plugin's own failure.** An npm that cannot find the
444
- * package, a configuration section its schema refuses, an `apply` that
445
- * threw: each comes back as `status: 'failed'` with a reason, because each
446
- * is a fact about that plugin rather than about the request, and the
447
- * gateway goes on running either way.
448
- */
449
- installPlugin(spec: string, config?: Record<string, unknown>): Promise<PluginSummary>;
450
- /** Installs a shared root batch and reports each actual result. */
451
- installPluginBatch(items: readonly {
452
- spec: string;
453
- config?: Record<string, unknown>;
454
- }[]): Promise<ResultOf<'plugin.installBatch'>>;
455
- /** Previews a complete activation union. */
456
- previewSetPluginEnabledBatch(names: readonly string[], enabled: boolean): Promise<PluginActivationBatchPlan>;
457
- /** Commits the current activation union once. */
458
- setPluginEnabledBatch(names: readonly string[], enabled: boolean, token: string): Promise<readonly PluginSummary[]>;
459
- /** Previews a complete uninstall union, refusing protected owners. */
460
- previewRemovePluginBatch(names: readonly string[]): Promise<PluginRemovalBatchPlan>;
461
- /** Uninstalls the current union in one physical mutation. */
462
- removePluginBatch(names: readonly string[], token: string): Promise<ResultOf<'plugin.removeBatch'>>;
463
- /** Previews changed owners without importing modules or modifying state. */
464
- previewSetPluginEnabled(name: string, enabled: boolean): Promise<PluginActivationPlan>;
465
- /** Changes activation; a supplied stale preview token rejects before mutation. */
466
- setPluginEnabled(name: string, enabled: boolean, token?: string): Promise<readonly PluginSummary[]>;
467
- /** Reads the plugin's declared JSON configuration. */
468
- getPluginConfig(name: string): Record<string, unknown>;
469
- /** Saves configuration and reloads the affected active plugins. */
470
- setPluginConfig(name: string, config: Record<string, unknown>): Promise<readonly PluginSummary[]>;
471
- /**
472
- * Unloads one plugin and everything that required what it provided, and
473
- * hands back every name that went — the requested one first.
474
- *
475
- * Rejects when nothing is installed under that name: the one failure in
476
- * this family that is the caller's mistake, and the one that becomes a
477
- * failed result rather than a `failed` status.
478
- */
479
- /** Previews the complete installed dependant cascade without mutation. */
480
- previewRemovePlugin(name: string): Promise<PluginRemovalPlan>;
481
- removePlugin(name: string, token: string): Promise<{
482
- readonly removed: readonly string[];
483
- /** Names that were turned off rather than uninstalled — a built-in
484
- * cannot be taken away, because its package ships with the product. */
485
- readonly disabled?: readonly string[];
486
- }>;
487
- /**
488
- * Everything plugins have declared on the client surface, as it is now —
489
- * what `plugin.surface` answers.
490
- *
491
- * Read per call rather than held: a declaration arrives and goes with the
492
- * plugin that made it, so a surface kept anywhere would be a second answer
493
- * to "what can this client call".
494
- */
495
- pluginSurface(): PluginSurface;
496
- /**
497
- * Runs one method a plugin declared, named by its minted wire name.
498
- *
499
- * The gateway reads the segments of that name and carries the parameters
500
- * without looking at them: their shape is the plugin's own zod, checked on
501
- * the other side of this port along with the result.
502
- *
503
- * **Rejects with the text the client is shown**, so nothing here composes a
504
- * message: a missing registration, arguments the plugin refused, a handler
505
- * that threw and a plugin unloaded mid-call each arrive already worded, and
506
- * the ones that are a plugin's fault already name it.
507
- *
508
- * `signal` is this connection's end of the call. There is no host timeout
509
- * beside it: an unreturning handler is an unanswered call, ended by the
510
- * connection going away or by the plugin being unloaded.
511
- */
512
- invokePlugin(method: string, params: unknown, options?: {
513
- readonly signal?: AbortSignal;
514
- }): Promise<unknown>;
515
- /** Dispatches a declared authenticated byte resource with owner and caller cancellation. */
516
- invokePluginResource(owner: string, local: string, ownerEpoch: string, params: unknown, call: ResourceCall): Promise<ClientResourceResponse>;
517
- /** Opens a declared connection-bound stream; ready is validated separately from output. */
518
- openPluginStream(owner: string, local: string, ownerEpoch: string, params: unknown, options: {
519
- readonly signal: AbortSignal;
520
- readonly send: (payload: unknown) => Promise<void>;
521
- }): Promise<ClientStreamConnection>;
522
- /**
523
- * The bytes of one plugin's browser module, by the owner segment and the
524
- * revision a client read off `plugin.surface`.
525
- *
526
- * Synchronous, and it opens nothing: the bytes were read once when the
527
- * plugin registered them and they go when it does, so this is a lookup in a
528
- * table rather than a file being served. `undefined` is the single answer
529
- * to every way there is nothing to serve — an owner nobody holds, a plugin
530
- * that declared no module, one since unloaded, and a revision that is no
531
- * longer current — because a caller able to tell those apart would be able
532
- * to ask which plugins exist.
533
- */
534
- pluginModule(owner: string, rev: string): Uint8Array | undefined;
535
- /** `POST /files`: stores one upload in the session's workspace. */
536
- putFile(sessionId: string, name: string, source: AsyncIterable<Uint8Array>): Promise<{
537
- readonly file: FileRef;
538
- }>;
539
- /** `GET /files/<id>`: one stored file's bytes. */
540
- readFile(sessionId: string, fileId: string, variant: 'model' | 'original'): Promise<{
541
- readonly mediaType: string;
542
- readonly bytes: Uint8Array;
543
- }>;
544
- /**
545
- * Receives the latest snapshot after plugin changes in an event-loop turn;
546
- * registration bursts coalesce without coalescing broadcast/session events.
547
- * Changes include installation, removal and client surface declarations
548
- * made outside a request.
549
- *
550
- * **This is the one writer of `plugin.changed`**, and the third cause is why it
551
- * has to be: a plugin can register a method from a timer, and there is no
552
- * request for that announcement to ride. The two `plugin.*` handlers
553
- * therefore broadcast nothing of their own, and a fake in a test must
554
- * announce or it is testing a path production does not use.
555
- */
556
- onPluginsChanged(listener: (plugins: readonly PluginSummary[]) => void): () => void;
557
- /**
558
- * Notified for every frame a plugin emitted under `delivery: 'broadcast'`.
559
- *
560
- * It reaches every authenticated connection, which is why it arrives here
561
- * rather than on a session's stream: there is no session in the frame and
562
- * nothing to address it by. The session-scoped frames a plugin declares
563
- * travel `watch` like every other session frame, so nothing about them is
564
- * on this port.
565
- */
566
- onPluginBroadcast(listener: (frame: PluginSignalFrame) => void): () => void;
567
- }
568
- //#endregion
569
- //#region ../gateway/src/channel.d.ts
570
- /** Undoes one registration. Handed back by whatever made it, and safe to
571
- * call twice — the second call does nothing. */
572
- type Dispose = () => void;
573
- interface Channel {
574
- /**
575
- * For logs and diagnostics only. Typed as a plain `string` rather than a
576
- * literal union of known channel names, so there is no finite set of
577
- * values declared anywhere in this port for an access layer to
578
- * exhaustively `switch` over — nothing here even states what the known
579
- * channels are. TypeScript cannot forbid a stray `id === 'feishu'`
580
- * comparison from compiling, but nothing in this port gives one anything
581
- * to act on: every behavioural decision reads `capabilities` instead, and
582
- * a new channel's `id` is never registered anywhere for a branch to
583
- * notice it.
584
- */
585
- readonly id: string;
586
- /**
587
- * What a person calls this channel ("飞书"), when it has a name worth
588
- * showing. A channel that declares one has every person's message it sends
589
- * stamped `via: { channel: id, label, sender }` by the access layer, which is
590
- * how a client shows where a message came from and how the channel knows
591
- * its own messages when they come back. The built-in channel declares none.
592
- */
593
- readonly label?: string;
594
- readonly capabilities: ChannelCapabilities;
595
- /**
596
- * The access layer starts it. Whether that means "begin listening" or
597
- * "connect out and hold the connection, reconnecting as needed" is left to
598
- * the channel — the five platforms this port is calibrated against share no
599
- * connection shape.
600
- */
601
- start(ctx: ChannelContext): Promise<void>;
602
- stop(): Promise<void>;
603
- /**
604
- * One delivery, handed down by the access layer. `target` is opaque here —
605
- * a WebSocket connection id, a Feishu chat id, a QQ channel id — and is
606
- * interpreted only by the channel that issued it.
607
- */
608
- deliver(target: string, delivery: Delivery): Promise<void>;
609
- }
610
- /** Which of the three delivery modes a channel wants
611
- * (`ChannelCapabilities.deliveryMode`). */
612
- type DeliveryMode = 'stream' | 'edit-draft' | 'final-only';
613
- interface ChannelCapabilities {
614
- /**
615
- * Which of the three delivery modes this channel wants; the access layer
616
- * reads it to decide what to fold and when to send it.
617
- * `edit-draft` is part of the union because the port has to be able to
618
- * express it, but no channel folds deltas into throttled drafts yet — its
619
- * throttle interval and single-flight window need a real platform's rate
620
- * limit to calibrate against, and none is implemented by this change.
621
- * A channel that declares `edit-draft` is rejected at registration time
622
- * rather than accepted and silently fed nothing.
623
- */
624
- readonly deliveryMode: DeliveryMode;
625
- /** Throttle interval for `edit-draft`, in milliseconds. Ignored by the
626
- * other two modes. */
627
- readonly draftThrottleMs?: number;
628
- /** Per-message cap, counted in UTF-16 code units — how every platform's
629
- * own limit is specified. The access layer splits what is over it; a
630
- * channel never has to slice its own messages. */
631
- readonly maxMessageLength?: number;
632
- /** Whether anything can still be pushed to this channel after a turn ends.
633
- * `false` marks a stateless request/response channel whose outbound leg
634
- * closes with the turn — any delivery attempted after that point cannot
635
- * arrive. */
636
- readonly asyncDelivery: boolean;
637
- }
638
- type Delivery = {
639
- readonly kind: 'frame';
640
- readonly frame: SessionFrame;
641
- } | {
642
- readonly kind: 'draft';
643
- readonly draftId: string;
644
- readonly text: string;
645
- readonly final: boolean;
646
- } | {
647
- readonly kind: 'final';
648
- readonly text: string;
649
- };
650
- /**
651
- * The access layer's own operations, handed to a channel as `ctx`. gateway
652
- * implements this with `RuntimePort` underneath and keeps the
653
- * `target -> watched session` table itself — there is no folding code inside
654
- * a channel; the reduction from deltas to whatever a channel's `deliveryMode`
655
- * wants happens once, here, not once per channel.
656
- */
657
- /** Who spoke, as a channel identifies them: an id stable within that
658
- * channel, a display name of 1 to 64 characters, and whether they are the
659
- * owner at the moment they speak. */
660
- interface ChannelSender {
661
- readonly id: string;
662
- readonly name: string;
663
- readonly role: 'owner' | 'member';
664
- }
665
- interface ChannelContext {
666
- /** Reads confirmed global limits through controlled configuration recovery. */
667
- getLimits(): SessionLimits;
668
- /** Saves a complete limits replacement for future turns. */
669
- setLimits(limits: SessionLimits): SessionLimits;
670
- /** Lists bounded summaries without allocating drivers or decoding raw model parameters. */
671
- listReadingSessions(): Promise<readonly WatchSessionSummary[]>;
672
- /** Reads one prepared bounded summary without decoding business parameter sources. */
673
- getReadingSessionSummary(sessionId: string): WatchSessionSummary | undefined;
674
- /** Reads a durable fork or rewind result using bounded refill descriptors. */
675
- getReadingSessionOperation(operationId: string, ownerId?: string): ReadingSessionOperationResult;
676
- /** Completes bounded derived reading preparation without allocating a driver. */
677
- ensureReadingReady(sessionId: string, options?: {
678
- readonly readingLeaseId?: string;
679
- readonly ownerId?: string;
680
- readonly signal?: AbortSignal;
681
- readonly wait?: boolean;
682
- }): Promise<void>;
683
- /** Returns one bounded effective-history window. */
684
- historyPage(params: ParamsOf<'session.historyPage'>): ResultMap['session.historyPage'];
685
- /** Returns one bounded page of original part descriptors. */
686
- messageParts(params: ParamsOf<'session.messageParts'>): ResultMap['session.messageParts'];
687
- /** Reads one bounded range in an authorized source namespace. */
688
- messageContent(params: ParamsOf<'session.messageContent'>, ownerId?: string): ResultMap['session.messageContent'];
689
- /** Returns one bounded page of control or history annotations. */
690
- livePage(params: ParamsOf<'session.livePage'>): ResultMap['session.livePage'];
691
- /** Releases a cold reading reservation held by this consumer. */
692
- releaseReadingLease(id: string, ownerId?: string): void;
693
- /** Reads original message parts through authenticated bounded descriptors and ranges. */
694
- readMessage(sessionId: string, messageId: string, historyGeneration: number): Promise<Message>;
695
- /** Reads the host's non-browser facts, resolving retained widget references through indexed history. */
696
- readMessageText(sessionId: string, messageId: string, historyGeneration: number): Promise<string>;
697
- /** Pure readable facts from the already authorized effective transcript. */
698
- readonly renderMessageText: MessageTextRenderer;
699
- /** Reads managed instruction sources for a session's Agent address. */
700
- sessionInstructions(sessionId: string): ResultMap['session.instructions'];
701
- /** The `std.*` family: the standard library a client gets from the process
702
- * hosting it. Nested rather than flattened into methods here, because for
703
- * a library the wire's own shape is the vocabulary — which is what makes
704
- * where a new `std.*` method goes obvious. */
705
- readonly std: StdPort;
706
- listSessions(): readonly SessionSummary[];
707
- createSession(input: {
708
- /** Stable key for an externally created agent session; omit for local-user creation. */
709
- readonly creationKey?: string;
710
- readonly agentId: string;
711
- readonly workspaceId: string;
712
- readonly title?: string;
713
- }): SessionSummary;
714
- /** Creates an independent session before the named effective user message. */
715
- forkSession(input: ParamsOf<'session.fork'>): ForkResult;
716
- /** Reads one durable history-operation result after an uncertain response. */
717
- getSessionOperation(operationId: string): SessionOperationResult;
718
- /** Reads an unloaded session off disk and folds it. Called before `watch`
719
- * for a session nothing has opened yet. */
720
- load(sessionId: string): Promise<void>;
721
- /**
722
- * Synchronous. `target` starts watching this session in the same
723
- * uninterrupted call that hands back its snapshot, so no frame arrives
724
- * twice and none is lost between the two — that atomicity lives here, not
725
- * in the channel.
726
- */
727
- watch(target: string, sessionId: string, readingLeaseId?: string): {
728
- readonly snapshot: SessionSnapshot;
729
- readonly unwatch: () => void;
730
- };
731
- /** Takes the message and returns; never waits for the turn. A running
732
- * session holds it as a steer, named by `steerId`. `sender` is who spoke,
733
- * as this channel identifies them; it is recorded on the message only
734
- * when the channel declares a `label`. */
735
- send(target: string, sessionId: string, input: SessionRegularSendInput, sender?: ChannelSender): {
736
- readonly steerId?: string;
737
- };
738
- /** Waits for rewind preparation and acceptance, preserving this channel's attribution. */
739
- rewindSend(target: string, sessionId: string, input: SessionRewindSendInput, options?: {
740
- readonly signal?: AbortSignal;
741
- }, sender?: ChannelSender): Promise<RewindSendResult>;
742
- /** Called with a session's summary whenever it changes — archived, named,
743
- * a turn ended — for every session, watched or not: the same moment the
744
- * built-in channel broadcasts `session.updated`. A listener that throws is
745
- * logged and changes nothing else. */
746
- onSessionUpdated(listener: (session: WatchSessionSummary) => void): Dispose;
747
- /** This instance's WebUI address, without any credential: where a link
748
- * that opens a session in the product points. */
749
- readonly webuiUrl: string;
750
- /** Takes a steer back before its step claims it. */
751
- withdraw(sessionId: string, steerId: string): Message;
752
- /** One reply to a request the session is waiting on — taken, or refused
753
- * synchronously with nothing taken. */
754
- answer(sessionId: string, reply: HumanReply): void;
755
- cancel(sessionId: string): Promise<void>;
756
- /** Moves a session to a model. Not nullable: a session is an instance
757
- * rather than an override, so there is nothing to un-set it back to. */
758
- setSessionModel(sessionId: string, model: ModelRef): Promise<SessionSummary>;
759
- /** The settings this session will use for one model, whole rather than a
760
- * difference. */
761
- setSessionModelParams(sessionId: string, model: ModelRef, params: Readonly<Record<string, unknown>>): SessionSummary;
762
- /** Files a session away, or takes it back out. Idempotent, and it leaves
763
- * `updatedAt` alone. Throws when nothing is known under that id. */
764
- setSessionArchived(sessionId: string, archived: boolean): SessionSummary;
765
- /** Sets or clears a person's name for the session. */
766
- setSessionName(sessionId: string, name: string): SessionSummary;
767
- joinSession(sessionId: string): Promise<SessionSummary>;
768
- leaveSession(sessionId: string): Promise<SessionSummary>;
769
- joinBeforeSend(sessionId: string): Promise<void>;
770
- /** Refuses business operations while generic configuration recovery remains incomplete. */
771
- assertConfigurationReady(): void;
772
- listAgents(): readonly AgentSummary[];
773
- /** Read-only journal of persistent edits to this definition. */
774
- /** Lists successful configuration snapshots. */
775
- checkAgentRevision(id: string, revision: number, hash: string): void;
776
- agentRevisions(agentId: string, limit?: number, cursor?: string): AgentRevisionPage;
777
- /** Compares two retained versions. */
778
- compareAgentRevisions(agentId: string, from: number, to: number): AgentRevisionComparison;
779
- /** Validates a historical configuration without writing it. */
780
- previewAgentRestore(agentId: string, target: number): AgentRestorePreview;
781
- /** Saves a historical configuration once per confirmation id. */
782
- restoreAgentRevision(agentId: string, input: AgentRestoreInput): AgentRestoreResult;
783
- createAgent(input: {
784
- readonly name: string;
785
- }): AgentSummary;
786
- listPromptSlots(): readonly PromptSlot[];
787
- updateAgent(agentId: string, changes: {
788
- readonly name?: string;
789
- readonly description?: string;
790
- readonly tools?: readonly string[] | null;
791
- readonly skills?: readonly string[];
792
- readonly startsSessions?: boolean;
793
- }): AgentSummary;
794
- setAgentPromptSlot(agentId: string, slot: 'identity' | 'instructions' | 'style' | 'reminder', text: string): AgentSummary;
795
- agentPromptSlots(agentId: string): AgentPromptSlots;
796
- setAgentAvatar(agentId: string, image: string | null): AgentSummary;
797
- agentAvatar(agentId: string): AvatarImage | null;
798
- saveAgent(agentId: string, save: AgentSaveInput): AgentSummary;
799
- removeAgent(agentId: string): void;
800
- /** Every tool an agent can see, and whether it is permitted. Needs no session. */
801
- listTools(agentId: string): Toolset;
802
- listWorkspaces(): readonly WorkspaceSummary[];
803
- createWorkspace(input: {
804
- readonly name: string;
805
- }): WorkspaceSummary;
806
- updateWorkspace(workspaceId: string, input: {
807
- readonly name?: string;
808
- }): WorkspaceSummary;
809
- /** Sets or, with `null`, removes a workspace's picture. */
810
- setWorkspaceAvatar(workspaceId: string, image: string | null): WorkspaceSummary;
811
- /** The picture's bytes, or `null` when the workspace has none. */
812
- workspaceAvatar(workspaceId: string): AvatarImage | null;
813
- /** A work directory carries no mode: it is always readable. */
814
- addDirectory(workspaceId: string, path: string): WorkspaceSummary;
815
- removeDirectory(workspaceId: string, path: string): WorkspaceSummary;
816
- /** Lists access records with ownership; omitted scope filters include all records. */
817
- listAccessGrants(): {
818
- readonly grants: readonly AuthorizationRecord[];
819
- };
820
- /** Adds validated global resource permissions atomically. */
821
- addAccessGrant(input: AuthorizationInput): {
822
- readonly grants: readonly AuthorizationRecord[];
823
- };
824
- /** Removes one permission. `revoked: false` for one that was never there,
825
- * rather than a throw — the broadcast for a change comes from
826
- * `RuntimePort.onAccessChanged` alone, never from here. */
827
- revokeAccessGrant(input: AccessRevokeInput): {
828
- readonly revoked: boolean;
829
- };
830
- /** A plugin's credentials. No broadcast from here: `config.credentialChanged`
831
- * comes from `RuntimePort.onCredentialChanged` alone. */
832
- credentialStatus(plugin: string, scope: string): readonly CredentialStatus[];
833
- setCredential(plugin: string, scope: string, name: string, value: string): readonly CredentialStatus[];
834
- clearCredential(plugin: string, scope: string, name?: string): readonly CredentialStatus[];
835
- listInbox(): readonly InboxItem[];
836
- readInbox(ids: readonly string[]): void;
837
- readInboxSession(sessionId: string): void;
838
- clearInbox(ids: readonly string[]): void;
839
- clearReadInbox(): void;
840
- listTriggers(workspaceId?: string): readonly TriggerSummary[];
841
- /** Refuses with the rule's or the scope's reason and writes nothing. */
842
- createTrigger(input: TriggerInput & {
843
- readonly source: string;
844
- }): TriggerSummary;
845
- updateTrigger(id: string, input: TriggerInput): TriggerSummary;
846
- setTriggerEnabled(id: string, enabled: boolean): TriggerSummary;
847
- removeTrigger(id: string): boolean;
848
- triggerRuns(id: string): readonly TriggerRun[];
849
- listSubprocesses(): readonly SubprocessSummary[];
850
- stopSubprocess(processId: string): Promise<SubprocessSummary>;
851
- readSubprocessOutput(read: {
852
- readonly processId: string;
853
- readonly stream: 'stdout' | 'stderr';
854
- readonly offset?: number;
855
- readonly limit?: number;
856
- }): Promise<SubprocessBytes$1>;
857
- listPlugins(): readonly PluginSummary[];
858
- installPlugin(spec: string, config?: Record<string, unknown>): Promise<PluginSummary>;
859
- /** Installs a shared root batch and reports each actual result. */
860
- installPluginBatch(items: readonly {
861
- spec: string;
862
- config?: Record<string, unknown>;
863
- }[]): Promise<ResultOf<'plugin.installBatch'>>;
864
- /** Previews a complete activation union. */
865
- previewSetPluginEnabledBatch(names: readonly string[], enabled: boolean): Promise<PluginActivationBatchPlan>;
866
- /** Commits the current activation union once. */
867
- setPluginEnabledBatch(names: readonly string[], enabled: boolean, token: string): Promise<readonly PluginSummary[]>;
868
- /** Previews a complete uninstall union, refusing protected owners. */
869
- previewRemovePluginBatch(names: readonly string[]): Promise<PluginRemovalBatchPlan>;
870
- /** Uninstalls the current union in one physical mutation. */
871
- removePluginBatch(names: readonly string[], token: string): Promise<ResultOf<'plugin.removeBatch'>>;
872
- /** Previews changed owners without importing modules or modifying state. */
873
- previewSetPluginEnabled(name: string, enabled: boolean): Promise<PluginActivationPlan>;
874
- /** Changes activation; a supplied stale preview token rejects before mutation. */
875
- setPluginEnabled(name: string, enabled: boolean, token?: string): Promise<readonly PluginSummary[]>;
876
- /** Reads the plugin's declared JSON configuration. */
877
- getPluginConfig(name: string): Record<string, unknown>;
878
- /** Saves configuration and reloads the affected active plugins. */
879
- setPluginConfig(name: string, config: Record<string, unknown>): Promise<readonly PluginSummary[]>;
880
- /** Previews the complete installed dependant cascade without mutation. */
881
- previewRemovePlugin(name: string): Promise<PluginRemovalPlan>;
882
- removePlugin(name: string, token: string): Promise<{
883
- readonly removed: readonly string[];
884
- readonly disabled?: readonly string[];
885
- }>;
886
- /** What plugins have declared on the client surface, and one call into a
887
- * plugin's own handler. Both pass straight through to the runtime: a
888
- * channel reads a name, never a shape. */
889
- pluginSurface(): PluginSurface;
890
- invokePlugin(method: string, params: unknown, options?: {
891
- readonly signal?: AbortSignal;
892
- }): Promise<unknown>;
893
- /** Validates and dispatches a declared owner resource without raw transport access. */
894
- invokePluginResource: RuntimePort['invokePluginResource'];
895
- /** Opens a validated owner stream bound to this transport connection. */
896
- openPluginStream: RuntimePort['openPluginStream'];
897
- /** The bytes of one plugin's browser module, addressed exactly as
898
- * `plugin.surface` published it. Synchronous and holding no file: a
899
- * channel that serves this is copying bytes the host already read, and
900
- * `undefined` covers every way there are none — no such owner, no module,
901
- * plugin unloaded, revision superseded. */
902
- pluginModule(owner: string, rev: string): Uint8Array | undefined;
903
- /** Stores one upload in the session's workspace as it arrives; refuses with
904
- * an error named `FileRefusal` whose `kind` says why. */
905
- putFile(sessionId: string, name: string, source: AsyncIterable<Uint8Array>): Promise<{
906
- readonly file: FileRef;
907
- }>;
908
- /** One stored file's bytes; throws `file not found` for one the session's
909
- * workspace does not hold. */
910
- readFile(sessionId: string, fileId: string, variant: 'model' | 'original'): Promise<{
911
- readonly mediaType: string;
912
- readonly bytes: Uint8Array;
913
- }>;
914
- }
915
- //#endregion
916
- //#region src/index.d.ts
917
- interface SubprocessStartSpec {
918
- /** The complete argv, which must be what `Sandbox.prepare` returned. A tool
919
- * handing anything else is refused before a spawn happens. */
920
- readonly argv: readonly string[];
921
- /** The one line a person and the model read. This is what the registry
922
- * and the metadata record; the sandbox argv carries the whole profile
923
- * and every authorized path, and is recorded nowhere. */
924
- readonly command: string;
925
- readonly cwd: string;
926
- readonly env: Readonly<Record<string, string>>;
927
- readonly sessionId: string;
928
- readonly agentId: string;
929
- readonly workspaceId: string;
930
- /** The grants this call was planned against, resolved. The revoke
931
- * surface compares its own rows against these to say which running
932
- * processes still hold a permission. */
933
- readonly held: readonly SubprocessHeld[];
934
- /** This call's temporary directory. Ownership moves here the moment
935
- * `start` resolves: one place removes it, once the group is empty. */
936
- readonly tempDir: string;
937
- /** Terminates the group when it elapses, and only while `command` has
938
- * not settled. A process outliving its call is past every deadline the
939
- * call had. */
940
- readonly timeoutMs?: number;
941
- /** Synchronous host validation immediately before spawn; a throw starts no process. */
942
- readonly beforeSpawn?: () => void;
943
- }
944
- interface SubprocessHeld {
945
- readonly path: string;
946
- readonly access: 'read' | 'write';
947
- }
948
- interface SubprocessHandle {
949
- readonly processId: string;
950
- /** The log files, absolute. They lie inside the session's workspace
951
- * directory, so the model reads them with the file tools it already
952
- * has. */
953
- readonly logs: SubprocessLogs;
954
- /**
955
- * Settles when the child process emits `exit`.
956
- *
957
- * **Not `close`, and not the group being empty.** `close` waits for every
958
- * inherited stdio stream to end, and a process the command put in the
959
- * background holds its pipe open — waiting for `close` would hang the
960
- * tool until its timeout. This is the moment a tool returns.
961
- */
962
- readonly command: Promise<{
963
- readonly code: number | null;
964
- readonly signal: string | null;
965
- /** Present when the program itself never started — a missing binary, a
966
- * directory that is not there. The command did not run, which is a
967
- * different answer from a command that ran and failed. */
968
- readonly error?: string;
969
- }>;
970
- /** The in-memory window — head 48 KB plus tail 16 KB — which is what a
971
- * tool result and a run section carry. The whole of it is on disk. */
972
- output(): SubprocessWindow;
973
- /** What this host asked this process to end as, as soon as the signals
974
- * have gone out and before the group is empty. `null` while nobody has
975
- * asked. It exists so a caller can say *why* a command ended — a timeout
976
- * and an outside `kill` both surface as `SIGTERM` otherwise. */
977
- reason(): SubprocessEnding | null;
978
- /** Ends the group by the standard ladder. `why` is what the record will
979
- * say it ended as: a turn that was cancelled is not the same event as a
980
- * person or the model stopping something deliberately, and the session is
981
- * told which. */
982
- stop(why?: 'stopped' | 'cancelled'): Promise<SubprocessEnding>;
983
- }
984
- interface SubprocessLogs {
985
- readonly stdout: string;
986
- readonly stderr: string;
987
- readonly meta: string;
988
- }
989
- interface SubprocessWindow {
990
- readonly stdout: SubprocessStreamWindow;
991
- readonly stderr: SubprocessStreamWindow;
992
- }
993
- /** One stream, as far as memory kept it. `total` is everything that went
994
- * past, `dropped` the middle the window did not keep — the difference is
995
- * what a reader needs in order to know it is looking at a window. */
996
- interface SubprocessStreamWindow {
997
- readonly text: string;
998
- readonly total: number;
999
- readonly dropped: number;
1000
- }
1001
- interface SubprocessRead {
1002
- readonly stream: 'stdout' | 'stderr';
1003
- /** Where to start, in bytes. Absent is the beginning. */
1004
- readonly offset?: number;
1005
- readonly limit?: number;
1006
- /** Blocks until a byte past `offset` arrives or this elapses, whichever
1007
- * comes first, and returns at once for a process that has ended. The
1008
- * host clamps it. */
1009
- readonly waitMs?: number;
1010
- }
1011
- interface SubprocessBytes {
1012
- readonly stream: 'stdout' | 'stderr';
1013
- readonly bytes: string;
1014
- /** The first raw log byte represented by this UTF-8-safe page. */
1015
- readonly startOffset: number;
1016
- /** Where a next read starts. */
1017
- readonly offset: number;
1018
- /** Everything this stream holds, so a caller knows what it skipped. */
1019
- readonly total: number;
1020
- readonly state: SubprocessState;
1021
- readonly ending: SubprocessEnding | null;
1022
- }
1023
- type SubprocessState = 'running' | 'ending' | 'ended';
1024
- /** How it ended. Derived rather than reported: a process that took SIGKILL
1025
- * leaves no last words, so `stopped` is distinguished from `signalled` by
1026
- * whether this host asked for it. */
1027
- type SubprocessEnding = {
1028
- readonly kind: 'exited';
1029
- readonly code: number;
1030
- } | {
1031
- readonly kind: 'signalled';
1032
- readonly signal: string;
1033
- } | {
1034
- readonly kind: 'stopped';
1035
- } | {
1036
- readonly kind: 'timed-out';
1037
- } | {
1038
- readonly kind: 'cancelled';
1039
- } | {
1040
- readonly kind: 'shutdown';
1041
- };
1042
- interface SubprocessRecord {
1043
- readonly processId: string;
1044
- readonly sessionId: string;
1045
- readonly agentId: string;
1046
- readonly workspaceId: string;
1047
- readonly command: string;
1048
- readonly startedAt: number;
1049
- readonly state: SubprocessState;
1050
- readonly ending: SubprocessEnding | null;
1051
- readonly held: readonly SubprocessHeld[];
1052
- readonly logs: SubprocessLogs;
1053
- /** Whether this ending's message reached the session that started it.
1054
- * `null` while it is still running, or when the starter sent no message
1055
- * for this ending. */
1056
- readonly notified: boolean | null;
1057
- }
1058
- //#endregion
1059
- //#region node_modules/.cache/dts/plugin/src/platform-resources.d.ts
1060
- type SecretBoxState = {
1061
- readonly kind: 'ready';
1062
- } | {
1063
- readonly kind: 'unavailable';
1064
- readonly reason: string;
1065
- };
1066
- interface SecretBox {
1067
- /** Whether stored ciphertext can be opened right now. Read per use: the
1068
- * answer changes when somebody deletes or `chmod`s the key file. */
1069
- state(): SecretBoxState;
1070
- /** Encrypts, creating the master key on first use. Throws when the key
1071
- * exists and cannot be used — a credential that would be written under a
1072
- * key nobody can rely on is worse than a refused write. */
1073
- seal(plaintext: string, aad: string): string;
1074
- /** Decrypts. Throws when the key is unavailable, when `sealed` is not this
1075
- * format, or when authentication fails — which includes a value sealed
1076
- * for another address. */
1077
- open(sealed: string, aad: string): string;
1078
- }
1079
- interface SubprocessManagerOptions {
1080
- /** Other host-owned process groups, counted against the machine-wide budget. */
1081
- readonly otherActive?: () => number;
1082
- /** Where this workspace's own directory is. The manager asks for it per
1083
- * call rather than holding the work root, so the one place that knows the
1084
- * layout stays `roots.ts`. */
1085
- readonly workspaceDirectory: (workspaceId: string) => string;
1086
- /** Announced whenever the table changes, so the gateway can broadcast. */
1087
- readonly onChanged?: () => void;
1088
- /** Told when a process that outlived the call which started it has
1089
- * ended and its starter said so to the session — a background process. */
1090
- readonly onOutlived?: (ended: {
1091
- readonly processId: string;
1092
- readonly sessionId: string;
1093
- readonly command: string;
1094
- readonly ending: SubprocessEnding;
1095
- }) => void;
1096
- /** Per stream, in bytes. Defaults to the product's 64 MB; a test lowers it
1097
- * rather than writing that much. */
1098
- readonly logLimitBytes?: number;
1099
- }
1100
- interface SubprocessManager {
1101
- start(spec: SubprocessStartSpec, onExit: (ending: SubprocessEnding) => boolean | void | Promise<boolean | void>): Promise<SubprocessHandle>;
1102
- list(sessionId?: string): readonly SubprocessRecord[];
1103
- stop(processId: string): Promise<SubprocessEnding>;
1104
- read(processId: string, read: SubprocessRead): Promise<SubprocessBytes>;
1105
- /** Ends every registered group and settles once each one is empty. The
1106
- * gateway awaits this before the process exits, which is the only reason
1107
- * `yaoguang stop` leaves nothing behind. */
1108
- shutdown(): Promise<void>;
1109
- /** Marks whether the exit message reached the session, for the interface
1110
- * to show. Called by whoever sent it. */
1111
- recordNotified(processId: string, notified: boolean): void;
1112
- }
1113
- //#endregion
1114
- export { Channel as a, Delivery as c, SubprocessManagerOptions as i, Dispose as l, SecretBoxState as n, ChannelCapabilities as o, SubprocessManager as r, ChannelContext as s, SecretBox as t };