@intentic/extension-api 1.431.0 → 1.433.0
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 +138 -4
- package/dist/api.d.ts +1 -0
- package/dist/api.d.ts.map +1 -1
- package/dist/backend-reach.d.ts +24 -0
- package/dist/backend-reach.d.ts.map +1 -0
- package/dist/backend-reach.js +262 -0
- package/dist/backend-reach.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +12 -2
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +111 -132
- package/dist/runtime.js.map +1 -1
- package/dist/server-reach.d.ts +72 -0
- package/dist/server-reach.d.ts.map +1 -0
- package/dist/server-reach.js +2 -0
- package/dist/server-reach.js.map +1 -0
- package/dist/server.d.ts +190 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/sleep-fake.d.ts +15 -0
- package/dist/sleep-fake.d.ts.map +1 -0
- package/dist/sleep-fake.js +99 -0
- package/dist/sleep-fake.js.map +1 -0
- package/dist/sleep-reach.d.ts +7 -0
- package/dist/sleep-reach.d.ts.map +1 -0
- package/dist/sleep-reach.js +104 -0
- package/dist/sleep-reach.js.map +1 -0
- package/dist/testing.d.ts +82 -9
- package/dist/testing.d.ts.map +1 -1
- package/dist/testing.js +367 -13
- package/dist/testing.js.map +1 -1
- package/dist/turn-reach.d.ts +7 -0
- package/dist/turn-reach.d.ts.map +1 -0
- package/dist/turn-reach.js +140 -0
- package/dist/turn-reach.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/dist/wire.d.ts +1 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +2 -0
- package/dist/wire.js.map +1 -1
- package/package.json +4 -4
- package/src/api.ts +3 -0
- package/src/backend-reach.integration.test.ts +203 -0
- package/src/backend-reach.ts +365 -0
- package/src/caller.integration.test.ts +108 -0
- package/src/index.ts +1 -0
- package/src/runtime.ts +185 -157
- package/src/server-reach.ts +138 -0
- package/src/server.ts +374 -3
- package/src/sleep-fake.ts +140 -0
- package/src/sleep-reach.integration.test.ts +119 -0
- package/src/sleep-reach.ts +147 -0
- package/src/surface.json +15583 -0
- package/src/testing.ts +601 -23
- package/src/turn-reach.integration.test.ts +166 -0
- package/src/turn-reach.ts +198 -0
- package/src/version.ts +129 -1
- package/src/wire.ts +4 -0
package/src/server.ts
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
1
|
import type { sandboxContract } from "@intentic/sandbox-contract";
|
|
2
2
|
import type { Conversion, Granularity } from "@intentic/sandbox-contract/documents";
|
|
3
3
|
import type { ToolEffect } from "@intentic/sandbox-contract/peer-mcp-server";
|
|
4
|
+
import type { PasskeyCosign } from "@intentic/sandbox-contract/s2s";
|
|
5
|
+
import type { WebhookSignatureScheme } from "@intentic/sandbox-contract/schemas/automations";
|
|
6
|
+
import type { MemberTier } from "@intentic/sandbox-contract/schemas/shared";
|
|
4
7
|
import type { ContractRouterClient } from "@orpc/contract";
|
|
5
8
|
import type { Disposable } from "./disposable.js";
|
|
9
|
+
import type {
|
|
10
|
+
ActivityRow,
|
|
11
|
+
CiFeedEvent,
|
|
12
|
+
ExecOptions,
|
|
13
|
+
ExecResult,
|
|
14
|
+
IdentityReach,
|
|
15
|
+
RunSettled,
|
|
16
|
+
SandboxActivity,
|
|
17
|
+
SleepBoot,
|
|
18
|
+
SleepHandler,
|
|
19
|
+
SleepHeardMessage,
|
|
20
|
+
} from "./server-reach.js";
|
|
6
21
|
|
|
7
22
|
// The effect vocabulary the daemon's own tools and every device's tools declare, re-exported so a tool here says what it
|
|
8
23
|
// does in the same words.
|
|
@@ -31,12 +46,105 @@ export interface ToolResult {
|
|
|
31
46
|
readonly isError?: boolean;
|
|
32
47
|
}
|
|
33
48
|
|
|
49
|
+
// (2026-11-26) A sandbox browser account the calling turn holds (a browser card, or an identity's own browser): its id,
|
|
50
|
+
// which `api.browser.call` names, and the sites it signs in on, the only ones an extension drives its browser on (its
|
|
51
|
+
// sign-in and home pages' hosts, widened to the operator's sign-in family: x.com stands for twitter.com too).
|
|
52
|
+
export interface ToolGrantAccount {
|
|
53
|
+
readonly id: string;
|
|
54
|
+
readonly kind: "browser" | "identity";
|
|
55
|
+
readonly sites: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// (2026-11-26) What the turn that called a tool holds, read by the daemon from that turn's own grants (its role, and the
|
|
59
|
+
// reach of the people it is for): never a credential, never more than the turn holds.
|
|
60
|
+
export interface ToolCallGrants {
|
|
61
|
+
// The sandbox's signed-in browser accounts, for `api.browser.call`.
|
|
62
|
+
readonly accounts: readonly ToolGrantAccount[];
|
|
63
|
+
// The owner's own browsers (their `webext` cards), for `api.ownerBrowser.call`.
|
|
64
|
+
readonly browsers: readonly string[];
|
|
65
|
+
// The cards of this extension's own kinds the turn holds.
|
|
66
|
+
readonly cards: readonly string[];
|
|
67
|
+
}
|
|
68
|
+
|
|
34
69
|
// What one call is handed beside its arguments.
|
|
35
70
|
export interface ToolCallContext {
|
|
36
71
|
// Aborted when the agent's client gives up on the call, or the host's deadline for it passes.
|
|
37
72
|
readonly signal: AbortSignal;
|
|
38
73
|
// The conversation the calling turn belongs to, when it has one.
|
|
39
74
|
readonly conversationId?: string | undefined;
|
|
75
|
+
// (2026-11-26) What the calling turn holds, so a tool can refuse itself ("this turn holds no chatgpt.com account");
|
|
76
|
+
// the daemon refuses anything outside it anyway. Absent where no daemon told it (a test, a daemon before 2.55.0).
|
|
77
|
+
readonly grants?: ToolCallGrants | undefined;
|
|
78
|
+
// (2026-11-26) This call's ticket onto its turn, minted by the daemon for this extension and this call and good only
|
|
79
|
+
// while it runs: what `api.browser.call`, `api.ownerBrowser.call` and `api.jobs.start` hand back. Opaque.
|
|
80
|
+
readonly ticket?: string | undefined;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// (2026-11-26) What reaches the calling turn's grants: a tool's call while it runs (its ToolCallContext), or a job it
|
|
84
|
+
// started (RunningJob) for as long as the job runs.
|
|
85
|
+
export interface TurnStanding {
|
|
86
|
+
readonly grants?: ToolCallGrants | undefined;
|
|
87
|
+
readonly ticket?: string | undefined;
|
|
88
|
+
// Ends the request when aborted.
|
|
89
|
+
readonly signal?: AbortSignal | undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// (2026-11-26) One call of a page tool in the sandbox's signed-in browser of an account the turn holds: `tool` as the
|
|
93
|
+
// agent's `browser` server names it (`browser_navigate`, `browser_evaluate`, `browser_click`, …), `args` its arguments
|
|
94
|
+
// without `account`. Only the page's own tools, and only on the account's sites: a navigation elsewhere is refused, a
|
|
95
|
+
// call on a page elsewhere is refused, and a call that leaves them has its answer withheld.
|
|
96
|
+
export interface BrowserCall {
|
|
97
|
+
readonly account: string;
|
|
98
|
+
readonly tool: string;
|
|
99
|
+
readonly args?: ToolArguments | undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// (2026-11-26) One call of a tool of the owner's own browser the turn holds (`open`, `read`, `click`, …, as the agent's
|
|
103
|
+
// server for that browser names them), through the same door as the agent's: the browser's own site switches apply.
|
|
104
|
+
export interface OwnerBrowserCall {
|
|
105
|
+
readonly browser: string;
|
|
106
|
+
readonly tool: string;
|
|
107
|
+
readonly args?: ToolArguments | undefined;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A tool's arguments, as a tool of the agent's is called with them.
|
|
111
|
+
export type ToolArguments = Parameters<ToolDefinition["call"]>[0];
|
|
112
|
+
|
|
113
|
+
// (2026-11-26) What a job's work came to: `output` is what `wait` and the conversation's wake hand the agent, cut in the
|
|
114
|
+
// middle past the job's bound.
|
|
115
|
+
export interface JobEnd {
|
|
116
|
+
readonly ok: boolean;
|
|
117
|
+
readonly output: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// (2026-11-26) A job's work while it runs: its id, the grants and ticket of the call that started it (good for as long
|
|
121
|
+
// as the job runs; the sandbox's own browsers only while that call's turn still runs, the owner's browser throughout),
|
|
122
|
+
// and a line onto what the job shows meanwhile. `signal` aborts once the job is stopped, by the agent or a person.
|
|
123
|
+
export interface RunningJob {
|
|
124
|
+
readonly id: string;
|
|
125
|
+
readonly grants: ToolCallGrants;
|
|
126
|
+
readonly ticket: string;
|
|
127
|
+
readonly signal: AbortSignal;
|
|
128
|
+
say(line: string): void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// (2026-11-26) A background job a tool starts in the calling conversation, as a `run_in_background` command is one:
|
|
132
|
+
// `command` is how `wait` and the transcript name it, `description` what the conversation's card shows, `started` its
|
|
133
|
+
// output until it ends (what it is doing, and what to do if a restart takes it down meanwhile). In a `lane`, at most
|
|
134
|
+
// `most` (1 when absent) of that lane run at once, first come first served, and never two naming one `key` at once.
|
|
135
|
+
export interface JobSpec {
|
|
136
|
+
readonly command: string;
|
|
137
|
+
readonly description: string;
|
|
138
|
+
readonly started: string;
|
|
139
|
+
readonly lane?: { readonly name: string; readonly key?: string | undefined; readonly most?: number | undefined } | undefined;
|
|
140
|
+
// The work, run once the job's turn in its lane comes; a throw ends the job as failed with its message.
|
|
141
|
+
readonly run: (job: RunningJob) => Promise<JobEnd>;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// (2026-11-26) A job filed: its id, which the agent's `wait` takes, and how many runs of its lane were ahead of it.
|
|
145
|
+
export interface StartedJob {
|
|
146
|
+
readonly id: string;
|
|
147
|
+
readonly ahead: number;
|
|
40
148
|
}
|
|
41
149
|
|
|
42
150
|
export interface ToolDefinition {
|
|
@@ -57,6 +165,73 @@ export interface ToolDefinition {
|
|
|
57
165
|
// the host answers 404.
|
|
58
166
|
export type BackendRouteHandler = (request: Request) => Promise<Response | undefined>;
|
|
59
167
|
|
|
168
|
+
// (2026-11-26) Who is calling through `/x/<id>`, as the daemon verified them (`api.caller(request)`): a person signed in,
|
|
169
|
+
// a repository's operator panel, a program holding a control token, another extension's backend, or nobody at all on a
|
|
170
|
+
// sandbox that runs without sign-in. Read off an assertion the daemon minted for this extension and this request, good
|
|
171
|
+
// for two minutes, which no extension can mint: `asCaller` hands it back to the daemon to act as that person.
|
|
172
|
+
export type ExtensionCallerWho =
|
|
173
|
+
| {
|
|
174
|
+
readonly kind: "person";
|
|
175
|
+
readonly email: string;
|
|
176
|
+
readonly name?: string | undefined;
|
|
177
|
+
// Their access tier: guest, viewer, collaborator, writer, maintainer or owner.
|
|
178
|
+
readonly tier: MemberTier;
|
|
179
|
+
// The area ids their access is fenced to; absent for the whole workspace.
|
|
180
|
+
readonly areas?: readonly string[] | undefined;
|
|
181
|
+
// The parts of the sandbox they were given to run (people, secrets, privacy, ownAccounts).
|
|
182
|
+
readonly manages?: readonly string[] | undefined;
|
|
183
|
+
}
|
|
184
|
+
| { readonly kind: "panel" }
|
|
185
|
+
| { readonly kind: "program"; readonly id: string; readonly label: string }
|
|
186
|
+
| { readonly kind: "extension"; readonly id: string }
|
|
187
|
+
| { readonly kind: "local" };
|
|
188
|
+
|
|
189
|
+
export type ExtensionCaller = ExtensionCallerWho & {
|
|
190
|
+
// The workspace folders (relative to `workspaceRoot`) this caller may read: absent for the whole workspace, empty for
|
|
191
|
+
// none of it. Only a person with areas is fenced; every other kind reads it whole, as the daemon's own routes answer it.
|
|
192
|
+
readonly folders?: readonly string[] | undefined;
|
|
193
|
+
// Whether a workspace-relative path is inside `folders`, by segment (`app2` is not inside `app`); a path that climbs
|
|
194
|
+
// out of the workspace is inside nothing.
|
|
195
|
+
readonly reaches: (path: string) => boolean;
|
|
196
|
+
// When the assertion stops being believed (ms); `asCaller` past it is refused.
|
|
197
|
+
readonly expiresAt: number;
|
|
198
|
+
// The assertion itself, as the daemon minted it.
|
|
199
|
+
readonly assertion: string;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
// (2026-11-26) What the daemon checked of a call through one of this extension's public routes before handing it over
|
|
203
|
+
// (`contributes.publicRoutes`), as `api.publicRoutes.serve` hears it.
|
|
204
|
+
export interface PublicRouteVerification {
|
|
205
|
+
// The declared route it landed on, as the manifest spells its path.
|
|
206
|
+
readonly route: string;
|
|
207
|
+
// The automation an automation-scoped route is for: on this extension's own listener provider, and switched on.
|
|
208
|
+
readonly automationId?: string | undefined;
|
|
209
|
+
// The browser's Origin, on the automation's allowed origins when the route checks them.
|
|
210
|
+
readonly origin?: string | undefined;
|
|
211
|
+
// Admitted by the automation's door key in place of a listed Origin; the key itself is not handed on.
|
|
212
|
+
readonly keyed?: boolean | undefined;
|
|
213
|
+
// Signed by the provider with the route's secret under this scheme, and the provider's id for the delivery, which no
|
|
214
|
+
// earlier call the door took carried.
|
|
215
|
+
readonly signature?: { readonly scheme: WebhookSignatureScheme; readonly deliveryId?: string | undefined } | undefined;
|
|
216
|
+
// The caller id a solved proof-of-work challenge was signed to.
|
|
217
|
+
readonly proofOfWork?: { readonly caller: string } | undefined;
|
|
218
|
+
// (2026-11-26) A Cloudflare Turnstile token passed, verified by the daemon with Cloudflare under the route's secret.
|
|
219
|
+
readonly turnstile?: true | undefined;
|
|
220
|
+
// The caller's address as the edge forwarded it: advisory, never an identity.
|
|
221
|
+
readonly remoteIp?: string | undefined;
|
|
222
|
+
// When the daemon took it (ms).
|
|
223
|
+
readonly at: number;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// (2026-11-27) What `api.sleep` hands its callers (server-reach.ts).
|
|
227
|
+
export type { SleepBoot, SleepHandler, SleepHeardMessage, SleepNotice } from "./server-reach.js";
|
|
228
|
+
// (2026-11-28) What `api.identity` hands its callers (server-reach.ts).
|
|
229
|
+
export type { IdentityPayload, IdentityReach, IdentitySigned, SandboxIdentity } from "./server-reach.js";
|
|
230
|
+
|
|
231
|
+
// One call through a public route, path relative to /door/<id>, its door key (if any) already taken off. Return
|
|
232
|
+
// `undefined` for "not mine": the host answers 404.
|
|
233
|
+
export type PublicRouteHandler = (request: Request, verified: PublicRouteVerification) => Promise<Response | undefined> | Response | undefined;
|
|
234
|
+
|
|
60
235
|
// An action in the approvals queue that names this extension as its `performer`, handed over by the daemon only after
|
|
61
236
|
// it found a person's yes on record matching the item as it stands, and spent that yes. The workspace file is never
|
|
62
237
|
// what decides: an item marked approved without a recorded yes, or changed since, never reaches the backend.
|
|
@@ -76,6 +251,9 @@ export interface ApprovedAction {
|
|
|
76
251
|
// The sandbox's action rules as the daemon reads them now, organisation pins applied: a rule set to deny after the
|
|
77
252
|
// yes still refuses.
|
|
78
253
|
readonly actionRules: Readonly<Record<string, string>>;
|
|
254
|
+
// (2026-11-28) Their passkey over exactly this (sandbox, `id`, `digest`), when approved with one; one filed `required`
|
|
255
|
+
// checks it is here (a turn can rewrite the item) with `verifyPasskeyCosign`. Anyone may check it once published.
|
|
256
|
+
readonly cosign?: PasskeyCosign | undefined;
|
|
79
257
|
}
|
|
80
258
|
|
|
81
259
|
// What carrying out an approved action came to, in the three states the queue keeps apart.
|
|
@@ -90,6 +268,81 @@ export type ApprovedActionOutcome =
|
|
|
90
268
|
|
|
91
269
|
export type ApprovedActionHandler = (action: ApprovedAction, context: { readonly signal: AbortSignal }) => Promise<ApprovedActionOutcome>;
|
|
92
270
|
|
|
271
|
+
// (2026-11-26) A post in the approvals queue for a platform one of this extension's cards publishes on
|
|
272
|
+
// (`channel.publish`, the post's `platform` naming the card's id), handed over by the daemon's approvals executor only
|
|
273
|
+
// after it found a person's yes on record matching the post as it stands, and spent that yes. Its words are the ones the
|
|
274
|
+
// person approved: publish them as they are, or refuse.
|
|
275
|
+
export interface ApprovedPost {
|
|
276
|
+
// The item's id in the approvals queue.
|
|
277
|
+
readonly id: string;
|
|
278
|
+
// The card id the post names, lowercased (`discord`).
|
|
279
|
+
readonly platform: string;
|
|
280
|
+
// Exactly what to publish.
|
|
281
|
+
readonly content: string;
|
|
282
|
+
// A headline, where the post carries one.
|
|
283
|
+
readonly title?: string | undefined;
|
|
284
|
+
// Where it goes, matching the card's declared `channel.publish.target` pattern.
|
|
285
|
+
readonly target: string;
|
|
286
|
+
// Who said yes (their sign-in) and when, as the daemon recorded it, as for an action.
|
|
287
|
+
readonly approver?: string | undefined;
|
|
288
|
+
readonly approvedAt: number;
|
|
289
|
+
// The sandbox's action rules as the daemon reads them now, organisation pins applied.
|
|
290
|
+
readonly actionRules: Readonly<Record<string, string>>;
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// What publishing it came to, in the queue's three states; a `done` result is the row's link (the message's URL) or line.
|
|
294
|
+
export type ApprovedPostHandler = (post: ApprovedPost, context: { readonly signal: AbortSignal }) => Promise<ApprovedActionOutcome>;
|
|
295
|
+
|
|
296
|
+
// (2026-11-26) One automation's fire, handed to the handler its target names: an automation saved with
|
|
297
|
+
// `target: { kind: "extension", extension: "<publisher.name>", handler }` by this extension itself fires it on its trigger,
|
|
298
|
+
// under the scheduler's admission, held wakes and fire journal, with no agent. `id` is the same on every try: a handler
|
|
299
|
+
// told twice (the daemon stopped before it heard the answer) can tell.
|
|
300
|
+
export interface AutomationFire {
|
|
301
|
+
readonly id: string;
|
|
302
|
+
readonly automationId: string;
|
|
303
|
+
readonly handler: string;
|
|
304
|
+
// When the automation fired (ms). A fire made while the backend was down is handed over once it is back, late.
|
|
305
|
+
readonly firedAt: number;
|
|
306
|
+
// How many earlier fires of the same automation this one stands for, fired while the backend was down.
|
|
307
|
+
readonly coalesced: number;
|
|
308
|
+
// The trigger's payload (a webhook's body, a workspace event) and what the automation's check saw, when there.
|
|
309
|
+
readonly payload?: string | undefined;
|
|
310
|
+
readonly observed?: string | undefined;
|
|
311
|
+
// The automation's own words (its `prompt`).
|
|
312
|
+
readonly prompt: string;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Answers once the fire is taken; a throw is recorded on the automation's run as an error and the fire is not tried
|
|
316
|
+
// again. Bounded by the daemon's ten-minute deadline: long work holds itself (`api.work.hold`) and returns.
|
|
317
|
+
export type AutomationFireHandler = (fire: AutomationFire, context: { readonly signal: AbortSignal }) => void | Promise<void>;
|
|
318
|
+
|
|
319
|
+
// (2026-11-26) One check of a watch kind this extension declares (`contributes.watchKinds`), handed to the handler
|
|
320
|
+
// `api.checks.serve` registered for it, from the daemon's automations engine alone through a door of the backend host no
|
|
321
|
+
// person's, panel's or agent's token reaches: on an automation's trigger, when the composer's Check now is pressed, and
|
|
322
|
+
// when an agent proposes a watch of this kind.
|
|
323
|
+
export interface WatchCheck {
|
|
324
|
+
readonly kind: string;
|
|
325
|
+
// The source's parameters as the automation stores them, already checked against the kind's declared fields.
|
|
326
|
+
readonly params: Readonly<Record<string, string | boolean>>;
|
|
327
|
+
// What the last passing check saw, cut to the daemon's bound: a check that words what changed reads it. Absent
|
|
328
|
+
// before the first pass, and for a check tried by hand.
|
|
329
|
+
readonly last?: string | undefined;
|
|
330
|
+
// The credential-gateway addresses of the cards the kind names in `capabilities`, as the automation's role reaches
|
|
331
|
+
// them, under the names a turn's shell sees them by (`GITHUB_API_URL_<CARD>`). Never a credential: the gateway signs
|
|
332
|
+
// what is sent through them. Empty when no such card is connected, or the role reaches none.
|
|
333
|
+
readonly reach: Readonly<Record<string, string>>;
|
|
334
|
+
// The automation it checks for; absent for a check tried by hand.
|
|
335
|
+
readonly automationId?: string | undefined;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// What a check came to. A pass carries what it saw: what `fireOn: change` compares and the wake is told, so only what
|
|
339
|
+
// names the thing watched belongs in it (a release's tag, not its notes). A miss carries what it is still waiting for, in
|
|
340
|
+
// a sentence the automation's run history shows.
|
|
341
|
+
export type WatchCheckAnswer = { readonly pass: true; readonly output: string } | { readonly pass: false; readonly detail: string };
|
|
342
|
+
|
|
343
|
+
// Answers within the daemon's deadline (a minute); a throw reads as a check that did not pass, its message the detail.
|
|
344
|
+
export type WatchCheckHandler = (check: WatchCheck, context: { readonly signal: AbortSignal }) => WatchCheckAnswer | Promise<WatchCheckAnswer>;
|
|
345
|
+
|
|
93
346
|
// An extension's own setting values, keyed as its manifest's `contributes.settings` declares them.
|
|
94
347
|
export type ExtensionSettingValues = Readonly<Record<string, string | number | boolean>>;
|
|
95
348
|
|
|
@@ -178,11 +431,84 @@ export interface ExtensionServerApi {
|
|
|
178
431
|
// The repository set itself moved (a clone, a scaffold, a delete); answers the whole set.
|
|
179
432
|
onDidChangeRepos(listener: (repos: readonly string[]) => void): Disposable;
|
|
180
433
|
};
|
|
434
|
+
// (2026-11-26) What the sandbox tells this extension's code without an agent turn, each kind declared in
|
|
435
|
+
// `permissions.events` (a listener of an undeclared kind throws, naming the field). Over the same stream as
|
|
436
|
+
// `workspace`; a stream that dropped and came back may have missed a run ending, which a reader catches up on by
|
|
437
|
+
// reading the conversation.
|
|
438
|
+
readonly events: {
|
|
439
|
+
// A run ending in a conversation this extension started through POST /agent with its own token (`run`).
|
|
440
|
+
onRunSettled(listener: (run: RunSettled) => void): Disposable;
|
|
441
|
+
// Whether any agent turn is running in the sandbox (`activity`): told as the stream opens, then each time it flips.
|
|
442
|
+
onActivity(listener: (activity: SandboxActivity) => void): Disposable;
|
|
443
|
+
// (2026-11-26) Each run that finished and each job that ended on the workspace's forges, as the core heard it from
|
|
444
|
+
// a webhook or its poller (`ci`): one frame a batch. An empty batch follows a gap in the stream, when frames may
|
|
445
|
+
// have been missed: a reader catches up from the forge's own word (GET /ci/runs) then.
|
|
446
|
+
onCi(listener: (events: readonly CiFeedEvent[]) => void): Disposable;
|
|
447
|
+
};
|
|
448
|
+
// (2026-11-26) Work in flight (`permissions.work`): while a hold stands the sandbox stays awake and an update or a
|
|
449
|
+
// restart waits for it, as for an agent's turn, named by its label. Disposing lets it go, and so does this backend
|
|
450
|
+
// dying; after a daemon restart the runtime holds again. Throws when the manifest does not declare `work`.
|
|
451
|
+
readonly work: {
|
|
452
|
+
hold(label: string): Disposable;
|
|
453
|
+
};
|
|
454
|
+
// (2026-11-26) Runs one command to its end under a workload class the manifest declares (`permissions.exec`),
|
|
455
|
+
// admitted by the sandbox's memory budget, and for `toolchain` queued with every agent's builds and tests, instead
|
|
456
|
+
// of competing with them. Never a shell: `argv` runs as given. Rejects when the class is not declared or the daemon
|
|
457
|
+
// refuses the request; a command that fails answers with its exit code.
|
|
458
|
+
readonly exec: (argv: readonly string[], options?: ExecOptions) => Promise<ExecResult>;
|
|
459
|
+
// (2026-11-26) Rows in the sandbox's activity feed, as this extension's own: the daemon names the extension on each
|
|
460
|
+
// from its token. Reached without declaring anything; rejects with the daemon's words when refused.
|
|
461
|
+
readonly activity: {
|
|
462
|
+
append(row: ActivityRow): Promise<void>;
|
|
463
|
+
};
|
|
464
|
+
// (2026-11-27) Hosted sleep, for code that must hear what arrives while the sandbox sleeps (a chat gateway, a webhook
|
|
465
|
+
// receiver). A sandbox the platform hosts stops when nobody uses it; a request at one of its wake doors starts it
|
|
466
|
+
// again, its sender answered 503 with `Retry-After` while it boots, so only a sender that retries is heard (Slack and
|
|
467
|
+
// Telegram do; GitHub does not redeliver unasked). The backend and every declared process get it, undeclared.
|
|
468
|
+
readonly sleep: {
|
|
469
|
+
// The full public URL of one of this extension's own public routes declaring `wakes: true`, path as the manifest
|
|
470
|
+
// spells it (`*/events`), its `*` filled with `automationId` for an automation's route, and the wake secret in
|
|
471
|
+
// its query (`?wake=`, which the door takes off before the backend hears the call). The same URL on every call
|
|
472
|
+
// and after every restart, so it is the one to paste into a provider's webhook setting (Slack's Request URL,
|
|
473
|
+
// Telegram's setWebhook). A call there wakes the sandbox only while an automation on the extension's listener
|
|
474
|
+
// provider is switched on (the one it names, for an automation's route). Rejects for a route not declared so, and
|
|
475
|
+
// on a sandbox with no public address.
|
|
476
|
+
wakeUrl(route: string, options?: { readonly automationId?: string | undefined }): Promise<string>;
|
|
477
|
+
// Runs `handler` right before the hosted machine sleeps, after the platform has saved its wake doors: the moment
|
|
478
|
+
// to point a provider at a wake URL (Telegram's setWebhook in place of long polling). Every handler of every
|
|
479
|
+
// extension runs at once and all of them share one deadline, `notice.deadline` (ms; about ten seconds), after
|
|
480
|
+
// which the machine stops whether or not they finished. Once asked, the sleep is never called off. Disposing
|
|
481
|
+
// stops hearing; nothing is told on a sandbox that never sleeps (one on somebody's own computer).
|
|
482
|
+
beforeSleep(handler: SleepHandler): Disposable;
|
|
483
|
+
// What this boot follows (`SleepBoot`): whether the last stop was a hosted sleep (the moment to undo what
|
|
484
|
+
// `beforeSleep` did), and whether a request at a wake door started it. Resolves within about fifteen seconds of
|
|
485
|
+
// the daemon's boot; a daemon from before it answers false for both.
|
|
486
|
+
boot(): Promise<SleepBoot>;
|
|
487
|
+
// (2026-11-27, 2.58.0) What the platform heard for this extension's own connections while the sandbox slept,
|
|
488
|
+
// oldest first: a card declaring `sleepWatch` whose owner let the platform hold its credential (Discord's bot)
|
|
489
|
+
// has the platform note where each message for it is. Fetch each one and answer it as if it had just arrived.
|
|
490
|
+
// Handed over once: asking forgets them. Empty on a sandbox the platform does not host; rejects when the
|
|
491
|
+
// platform could not say, leaving them there to ask again.
|
|
492
|
+
heard(): Promise<readonly SleepHeardMessage[]>;
|
|
493
|
+
};
|
|
494
|
+
// (2026-11-28) This sandbox's identity: its public document, and records signed as it with its key, which never
|
|
495
|
+
// reaches this code (server-reach.ts IdentityReach). The backend and every declared process get it.
|
|
496
|
+
readonly identity: IdentityReach;
|
|
181
497
|
readonly routes: {
|
|
182
498
|
// Serves this extension's route namespace; the daemon proxies /x/<id>/* here through its ordinary auth. A
|
|
183
499
|
// second mount replaces the first.
|
|
184
500
|
mount(handler: BackendRouteHandler): void;
|
|
185
501
|
};
|
|
502
|
+
// (2026-11-26) Who a request through `/x/<id>` comes from, as the daemon verified them; undefined for a request the
|
|
503
|
+
// daemon did not attach one to (a daemon from before 2.53.0), one minted for another extension, or one past its
|
|
504
|
+
// window.
|
|
505
|
+
readonly caller: (request: Request) => ExtensionCaller | undefined;
|
|
506
|
+
// (2026-11-26) The routes anyone on the internet may call (`contributes.publicRoutes`), served at /door/<id>/<path>:
|
|
507
|
+
// reached only once the daemon's own protections passed the call, never through `/x/<id>`, whose handler hears only
|
|
508
|
+
// people signed in. A second serve replaces the first.
|
|
509
|
+
readonly publicRoutes: {
|
|
510
|
+
serve(handler: PublicRouteHandler): void;
|
|
511
|
+
};
|
|
186
512
|
// The agent's tools (`contributes.tools`). The host owns the MCP transport, its deadlines and the card lookup: it
|
|
187
513
|
// answers the handshake, lists what `tools` returns for the card a server was mounted for (undefined for an
|
|
188
514
|
// extension-level server), and runs a call with its arguments. `tools` runs per request, so what it returns may
|
|
@@ -194,8 +520,41 @@ export interface ExtensionServerApi {
|
|
|
194
520
|
// `performer` names this extension reaches `perform` from the daemon's approvals executor alone, through a door of
|
|
195
521
|
// the backend host that no /x route, panel or agent token reaches, after the daemon has matched and spent the yes.
|
|
196
522
|
// The credentials stay in the backend, read from the daemon. A second perform replaces the first.
|
|
523
|
+
// (2026-11-26) `publish` is the same door for an approved post on a platform a card of this extension declares it
|
|
524
|
+
// publishes on (`channel.publish`), in place of an agent turn driving the logged-in browser. A second publish
|
|
525
|
+
// replaces the first.
|
|
197
526
|
readonly approvals: {
|
|
198
527
|
perform(handler: ApprovedActionHandler): void;
|
|
528
|
+
publish(handler: ApprovedPostHandler): void;
|
|
529
|
+
};
|
|
530
|
+
// (2026-11-26) The handlers an automation fires in this backend (`permissions.fires` declares each name): reached
|
|
531
|
+
// from the daemon's automations engine alone, through a door of the backend host no /x route, panel or agent token
|
|
532
|
+
// reaches. A second handler for one name replaces the first; registering an undeclared name throws.
|
|
533
|
+
readonly automations: {
|
|
534
|
+
onFire(handler: string, listener: AutomationFireHandler): Disposable;
|
|
535
|
+
};
|
|
536
|
+
// (2026-11-26) What its agent tools may do with the grants of the turn calling them, each a power the manifest declares
|
|
537
|
+
// in `permissions.turn` and the daemon refuses undeclared, and anything the turn does not hold either way. Each takes
|
|
538
|
+
// the call's context (or a running job's), and rejects with the daemon's words when refused.
|
|
539
|
+
// The sandbox's signed-in browser of an account the turn holds, on that account's sites (`browser`). The turn's own
|
|
540
|
+
// browser: the account's page is the one the agent's `browser` tools drive, so a call takes its tab.
|
|
541
|
+
readonly browser: {
|
|
542
|
+
call(standing: TurnStanding, call: BrowserCall): Promise<ToolResult>;
|
|
543
|
+
};
|
|
544
|
+
// The owner's own browser the turn holds (`owner-browser`).
|
|
545
|
+
readonly ownerBrowser: {
|
|
546
|
+
call(standing: TurnStanding, call: OwnerBrowserCall): Promise<ToolResult>;
|
|
547
|
+
};
|
|
548
|
+
// A background job in the calling conversation (`jobs`), answered once filed: its work runs in this backend while
|
|
549
|
+
// the agent goes on, and the agent collects its end with `wait`, or is woken by it.
|
|
550
|
+
readonly jobs: {
|
|
551
|
+
start(standing: TurnStanding, spec: JobSpec): Promise<StartedJob>;
|
|
552
|
+
};
|
|
553
|
+
// (2026-11-26) The checks of the watch kinds this extension declares (`contributes.watchKinds`), one handler per kind:
|
|
554
|
+
// reached from the daemon's automations engine alone, through a door of the backend host. A second handler for one
|
|
555
|
+
// kind replaces the first; serving a kind the manifest does not declare throws.
|
|
556
|
+
readonly checks: {
|
|
557
|
+
serve(kind: string, handler: WatchCheckHandler): Disposable;
|
|
199
558
|
};
|
|
200
559
|
// Authenticated transport to the daemon's own routes; every call is checked against the manifest's
|
|
201
560
|
// `permissions.daemon` allowlist.
|
|
@@ -206,9 +565,17 @@ export interface ExtensionServerApi {
|
|
|
206
565
|
// For what the contract does not carry: bytes (`/workspace/raw`) and the daemon's hand-written routes.
|
|
207
566
|
request(path: string, init?: RequestInit): Promise<Response>;
|
|
208
567
|
json<T>(path: string, init?: RequestInit): Promise<T>;
|
|
568
|
+
// (2026-11-26) The same doors carrying a caller's assertion beside the extension's token, for the routes that act
|
|
569
|
+
// as whoever pressed: POST /agent starts the turn as that person, held to their access as it stands then. Every
|
|
570
|
+
// other route answers by the extension's own reach. The daemon refuses an assertion past its window, minted for
|
|
571
|
+
// another extension or in another sandbox.
|
|
572
|
+
asCaller(caller: ExtensionCaller): DaemonDoors;
|
|
209
573
|
};
|
|
210
574
|
}
|
|
211
575
|
|
|
576
|
+
// Authenticated transport to the daemon's own routes, as `api.daemon` and `api.daemon.asCaller(caller)` both carry it.
|
|
577
|
+
export type DaemonDoors = Omit<ExtensionServerApi["daemon"], "asCaller">;
|
|
578
|
+
|
|
212
579
|
export interface ExtensionServerContext {
|
|
213
580
|
// This extension's routing id, its /x/<id> namespace segment.
|
|
214
581
|
readonly extensionId: string;
|
|
@@ -216,9 +583,13 @@ export interface ExtensionServerContext {
|
|
|
216
583
|
|
|
217
584
|
// What a declared process (`contributes.processes`) gets, from `connectExtensionProcess` in
|
|
218
585
|
// `@intentic/extension-api/runtime`: the backend's api without the halves only the backend host can serve. A process
|
|
219
|
-
// answers on its own port, so it mounts no routes, serves tools there (`contributes.tools.process`)
|
|
220
|
-
// approved action
|
|
221
|
-
|
|
586
|
+
// answers on its own port, so it mounts no routes, serves tools there (`contributes.tools.process`), carries out no
|
|
587
|
+
// approved action, is woken by no automation, answers no watch's check and no public route, hears no `/x` caller, and
|
|
588
|
+
// (serving no tool through the host) reaches no turn; it hears, holds and runs the way the backend does.
|
|
589
|
+
export type ExtensionProcessApi = Omit<
|
|
590
|
+
ExtensionServerApi,
|
|
591
|
+
"routes" | "tools" | "approvals" | "automations" | "checks" | "caller" | "publicRoutes" | "browser" | "ownerBrowser" | "jobs"
|
|
592
|
+
>;
|
|
222
593
|
|
|
223
594
|
// Shape of the manifest `server` bundle's default (or named) export; `activateServer` runs once per activation, which
|
|
224
595
|
// is once per backend-host start unless the extension returns a `deactivate`, after which a change to it alone
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import type { PublicRouteContribution } from "@intentic/extension-manifest";
|
|
2
|
+
import {
|
|
3
|
+
EXTENSION_SLEEP_HOOK_MS,
|
|
4
|
+
type ExtensionSleepBoot,
|
|
5
|
+
type ExtensionSleepFrame,
|
|
6
|
+
type ExtensionSleepHeard,
|
|
7
|
+
ExtensionSleepReadySchema,
|
|
8
|
+
ExtensionWakeUrlAskSchema,
|
|
9
|
+
extensionSleepBootUrl,
|
|
10
|
+
extensionSleepHeardUrl,
|
|
11
|
+
extensionSleepReadyUrl,
|
|
12
|
+
extensionSleepWatchUrl,
|
|
13
|
+
extensionWakeUrlUrl,
|
|
14
|
+
publicDoorPath,
|
|
15
|
+
WAKE_DOOR_PARAM,
|
|
16
|
+
} from "@intentic/sandbox-contract/extension-protocol";
|
|
17
|
+
|
|
18
|
+
// (2026-11-27) The daemon's side of `api.sleep` for `fakeExtensionApi` (testing.ts): wake URLs judged against the
|
|
19
|
+
// manifest's `wakes` routes as the daemon judges them, the boot facts the test sets, and a sleep handed to every
|
|
20
|
+
// before-sleep watch, resolved once each answered ready or the hook's deadline passed, as the daemon waits.
|
|
21
|
+
|
|
22
|
+
// Where the fake sandbox answers, and the wake secret every URL it hands out carries.
|
|
23
|
+
export const FAKE_PUBLIC_URL = "https://sandbox-fake.sbx.test";
|
|
24
|
+
export const FAKE_WAKE_SECRET = "fake-wake-secret";
|
|
25
|
+
|
|
26
|
+
type WakesRoute = Pick<PublicRouteContribution, "path" | "automation" | "wakes">;
|
|
27
|
+
|
|
28
|
+
const json = <T>(body: T, status = 200): Response => Response.json(body, { status });
|
|
29
|
+
|
|
30
|
+
// The concrete path a wake URL names, or why there is none (the daemon's own refusal words).
|
|
31
|
+
const concretePath = (routes: readonly WakesRoute[], route: string, automationId: string | undefined): { readonly path: string } | { readonly error: string } => {
|
|
32
|
+
const declared = routes.find((each) => each.path === route && each.wakes === true);
|
|
33
|
+
if (declared === undefined) {
|
|
34
|
+
return { error: `no public route "${route}" declares \`wakes: true\`` };
|
|
35
|
+
}
|
|
36
|
+
if ((declared.automation === true) !== (automationId !== undefined)) {
|
|
37
|
+
return { error: declared.automation === true ? `the route "${route}" is an automation's: name it` : `the route "${route}" is no automation's` };
|
|
38
|
+
}
|
|
39
|
+
return { path: route.replace("*", automationId ?? "*") };
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export interface FakeSleep {
|
|
43
|
+
// The extension's sleep doors; undefined for a request that is for none of them.
|
|
44
|
+
readonly door: (request: Request, url: URL, signal: AbortSignal | null) => Promise<Response | undefined>;
|
|
45
|
+
// The hosted machine about to sleep now: every before-sleep watch told, resolved once each answered ready or the
|
|
46
|
+
// deadline passed. Answers how many watches answered.
|
|
47
|
+
readonly now: () => Promise<number>;
|
|
48
|
+
// What `api.sleep.boot()` answers; neither by default.
|
|
49
|
+
boot: ExtensionSleepBoot;
|
|
50
|
+
// Every wake URL handed out, in order.
|
|
51
|
+
readonly wakeUrls: readonly string[];
|
|
52
|
+
// (2026-11-27) What `api.sleep.heard()` answers next; it is handed over once, as the platform does, and then empty.
|
|
53
|
+
heard: ExtensionSleepHeard["heard"];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const fakeSleep = (id: string, routes: readonly WakesRoute[]): FakeSleep => {
|
|
57
|
+
const encoder = new TextEncoder();
|
|
58
|
+
const watches = new Set<ReadableStreamDefaultController<Uint8Array>>();
|
|
59
|
+
const waiting = new Map<string, () => void>();
|
|
60
|
+
const wakeUrls: string[] = [];
|
|
61
|
+
let sleeps = 0;
|
|
62
|
+
const write = (watch: ReadableStreamDefaultController<Uint8Array>, frame: ExtensionSleepFrame): void => {
|
|
63
|
+
try {
|
|
64
|
+
watch.enqueue(encoder.encode(`${JSON.stringify(frame)}\n`));
|
|
65
|
+
} catch {
|
|
66
|
+
// allow(silent-catch): a watch the extension already let go of is no longer one to tell
|
|
67
|
+
watches.delete(watch);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const watchStream = (signal: AbortSignal | null): Response => {
|
|
71
|
+
let held: ReadableStreamDefaultController<Uint8Array> | undefined;
|
|
72
|
+
const drop = (): void => {
|
|
73
|
+
if (held !== undefined) {
|
|
74
|
+
watches.delete(held);
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const body = new ReadableStream<Uint8Array>({
|
|
78
|
+
start: (controller) => {
|
|
79
|
+
held = controller;
|
|
80
|
+
watches.add(controller);
|
|
81
|
+
write(controller, { kind: "heartbeat" });
|
|
82
|
+
},
|
|
83
|
+
cancel: drop,
|
|
84
|
+
});
|
|
85
|
+
signal?.addEventListener("abort", drop);
|
|
86
|
+
return new Response(body, { headers: { "content-type": "application/x-ndjson" } });
|
|
87
|
+
};
|
|
88
|
+
const wakeUrl = async (request: Request): Promise<Response> => {
|
|
89
|
+
const asked = ExtensionWakeUrlAskSchema.safeParse(await request.json());
|
|
90
|
+
const named = asked.success ? concretePath(routes, asked.data.route, asked.data.automationId) : { error: "a wake URL is asked for { route, automationId? }" };
|
|
91
|
+
if ("error" in named) {
|
|
92
|
+
return json(named, 400);
|
|
93
|
+
}
|
|
94
|
+
const minted = `${FAKE_PUBLIC_URL}${publicDoorPath(id, named.path)}?${WAKE_DOOR_PARAM}=${FAKE_WAKE_SECRET}`;
|
|
95
|
+
wakeUrls.push(minted);
|
|
96
|
+
return json({ url: minted });
|
|
97
|
+
};
|
|
98
|
+
const ready = async (request: Request): Promise<Response> => {
|
|
99
|
+
const answered = ExtensionSleepReadySchema.safeParse(await request.json());
|
|
100
|
+
if (answered.success) {
|
|
101
|
+
waiting.get(answered.data.id)?.();
|
|
102
|
+
}
|
|
103
|
+
return json({ ok: true });
|
|
104
|
+
};
|
|
105
|
+
// Each door by its `METHOD path`, as the daemon registers them.
|
|
106
|
+
const doors = new Map<string, (request: Request, signal: AbortSignal | null) => Promise<Response> | Response>([
|
|
107
|
+
[`POST ${extensionWakeUrlUrl()}`, wakeUrl],
|
|
108
|
+
[`GET ${extensionSleepBootUrl()}`, () => json(fake.boot)],
|
|
109
|
+
[`POST ${extensionSleepWatchUrl()}`, (_request, signal) => watchStream(signal)],
|
|
110
|
+
[`POST ${extensionSleepReadyUrl()}`, ready],
|
|
111
|
+
[
|
|
112
|
+
`POST ${extensionSleepHeardUrl()}`,
|
|
113
|
+
() => {
|
|
114
|
+
const heard = fake.heard;
|
|
115
|
+
fake.heard = [];
|
|
116
|
+
return json({ heard });
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
]);
|
|
120
|
+
const fake: FakeSleep = {
|
|
121
|
+
boot: { afterSleep: false, requestWake: false },
|
|
122
|
+
wakeUrls,
|
|
123
|
+
heard: [],
|
|
124
|
+
door: async (request, url, signal) => doors.get(`${request.method} ${url.pathname}`)?.(request, signal),
|
|
125
|
+
now: async () => {
|
|
126
|
+
sleeps += 1;
|
|
127
|
+
const told = [...watches].map((watch, index) => {
|
|
128
|
+
const sleepId = `sleep-${sleeps}-${index}`;
|
|
129
|
+
const answered = new Promise<boolean>((resolve) => {
|
|
130
|
+
waiting.set(sleepId, () => resolve(true));
|
|
131
|
+
setTimeout(() => resolve(false), EXTENSION_SLEEP_HOOK_MS).unref();
|
|
132
|
+
});
|
|
133
|
+
write(watch, { kind: "sleep", id: sleepId, deadline: Date.now() + EXTENSION_SLEEP_HOOK_MS });
|
|
134
|
+
return answered;
|
|
135
|
+
});
|
|
136
|
+
return (await Promise.all(told)).filter(Boolean).length;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
return fake;
|
|
140
|
+
};
|