@intentic/sandbox-contract 1.374.0 → 1.375.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/dist/contracts/accounts.contract.d.ts +16 -0
- package/dist/contracts/accounts.contract.d.ts.map +1 -1
- package/dist/contracts/capabilities.contract.d.ts +8 -0
- package/dist/contracts/capabilities.contract.d.ts.map +1 -1
- package/dist/contracts/panels.contract.d.ts +14 -0
- package/dist/contracts/panels.contract.d.ts.map +1 -1
- package/dist/contracts/runner.contract.d.ts +123 -123
- package/dist/contracts/sharing.contract.d.ts +58 -0
- package/dist/contracts/sharing.contract.d.ts.map +1 -0
- package/dist/contracts/sharing.contract.js +41 -0
- package/dist/contracts/sharing.contract.js.map +1 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/protocol/raw/raw-json-routes.d.ts +152 -2
- package/dist/protocol/raw/raw-json-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-json-routes.js +6 -1
- package/dist/protocol/raw/raw-json-routes.js.map +1 -1
- package/dist/protocol/raw/raw-routes.d.ts +16 -0
- package/dist/protocol/raw/raw-routes.d.ts.map +1 -1
- package/dist/protocol/raw/raw-routes.js +4 -0
- package/dist/protocol/raw/raw-routes.js.map +1 -1
- package/dist/schemas/capabilities.d.ts +8 -0
- package/dist/schemas/capabilities.d.ts.map +1 -1
- package/dist/schemas/capabilities.js +4 -0
- package/dist/schemas/capabilities.js.map +1 -1
- package/dist/schemas/links.d.ts +29 -2
- package/dist/schemas/links.d.ts.map +1 -1
- package/dist/schemas/links.js +28 -12
- package/dist/schemas/links.js.map +1 -1
- package/dist/schemas/panels.d.ts +36 -0
- package/dist/schemas/panels.d.ts.map +1 -1
- package/dist/schemas/panels.js +17 -2
- package/dist/schemas/panels.js.map +1 -1
- package/dist/schemas/providers/account-sharing.d.ts +275 -0
- package/dist/schemas/providers/account-sharing.d.ts.map +1 -0
- package/dist/schemas/providers/account-sharing.js +68 -0
- package/dist/schemas/providers/account-sharing.js.map +1 -0
- package/dist/schemas/providers/provider-oauth.d.ts +16 -0
- package/dist/schemas/providers/provider-oauth.d.ts.map +1 -1
- package/dist/schemas/providers/provider-oauth.js +4 -0
- package/dist/schemas/providers/provider-oauth.js.map +1 -1
- package/dist/state/definition.d.ts +8 -0
- package/dist/state/definition.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/contracts/sharing.contract.ts +54 -0
- package/src/index.ts +2 -0
- package/src/protocol/raw/raw-json-routes.ts +14 -1
- package/src/protocol/raw/raw-routes.ts +7 -0
- package/src/schemas/capabilities.ts +6 -0
- package/src/schemas/links.ts +39 -14
- package/src/schemas/panels.ts +31 -6
- package/src/schemas/providers/account-sharing.ts +123 -0
- package/src/schemas/providers/provider-oauth.ts +6 -0
|
@@ -80,7 +80,15 @@ import {
|
|
|
80
80
|
ProviderKeysSchema,
|
|
81
81
|
} from "../../state/arrival.js";
|
|
82
82
|
import { DefinitionDiffSchema, DefinitionExportSchema, WorkspacePublishResultSchema, WorkspacePublishSchema, WorkspaceRemoteSchema } from "../../state/definition.js";
|
|
83
|
-
import {
|
|
83
|
+
import {
|
|
84
|
+
RunnerCredentialRefreshRequestSchema,
|
|
85
|
+
RunnerCredentialRefreshSchema,
|
|
86
|
+
RunnerCredentialRequestSchema,
|
|
87
|
+
RunnerCredentialSchema,
|
|
88
|
+
RunnerDefinitionAppliedSchema,
|
|
89
|
+
RunnersListSchema,
|
|
90
|
+
} from "../doors/runner-protocol.js";
|
|
91
|
+
import { LinkAccountCopySchema, LinkAccountsSchema, SharedAccountRefSchema } from "../../schemas/providers/account-sharing.js";
|
|
84
92
|
import type { RawRouteKey } from "./raw-routes.js";
|
|
85
93
|
|
|
86
94
|
// What a raw route that answers plain JSON takes and answers, under its RAW_ROUTES key. `input` is the JSON body a write
|
|
@@ -183,6 +191,11 @@ export const RAW_JSON_ROUTES = {
|
|
|
183
191
|
"POST /link/conversations/{id}/messages": { input: LinkMessageSchema, output: LinkMessageReceiptSchema },
|
|
184
192
|
"POST /link/conversations/{id}/answer": { input: LinkAnswerSchema, output: OkSchema },
|
|
185
193
|
"POST /link/conversations/{id}/stop": { output: LinkTaskStatusSchema },
|
|
194
|
+
// An accounts link: what it may use, one static key's copy, and a lent sign-in's per-turn credential.
|
|
195
|
+
"GET /link/accounts": { output: LinkAccountsSchema },
|
|
196
|
+
"POST /link/accounts/copy": { input: SharedAccountRefSchema, output: LinkAccountCopySchema },
|
|
197
|
+
"POST /link/credentials": { input: RunnerCredentialRequestSchema, output: RunnerCredentialSchema },
|
|
198
|
+
"POST /link/credentials/refresh": { input: RunnerCredentialRefreshRequestSchema, output: RunnerCredentialRefreshSchema },
|
|
186
199
|
"GET /system/control/tokens": { output: ControlTokensListSchema },
|
|
187
200
|
"POST /system/control/tokens": { input: ControlTokenMintSchema, output: ControlTokenMintedSchema },
|
|
188
201
|
"DELETE /system/control/tokens/{id}": { output: OkSchema },
|
|
@@ -272,6 +272,13 @@ export const RAW_ROUTES = {
|
|
|
272
272
|
"POST /link/conversations/{id}/messages": { auth: "door", control: "never" },
|
|
273
273
|
"POST /link/conversations/{id}/answer": { auth: "door", control: "never" },
|
|
274
274
|
"POST /link/conversations/{id}/stop": { auth: "door", control: "never" },
|
|
275
|
+
// An accounts link's doors (schemas/providers/account-sharing.ts): the accounts its terms name, a static key's copy,
|
|
276
|
+
// and a lent sign-in's access token per turn, re-minted mid-turn. The refresh token never leaves; each door checks the
|
|
277
|
+
// link token itself and answers only for what the terms name.
|
|
278
|
+
"GET /link/accounts": { auth: "door", control: "never" },
|
|
279
|
+
"POST /link/accounts/copy": { auth: "door", control: "never" },
|
|
280
|
+
"POST /link/credentials": { auth: "door", control: "never" },
|
|
281
|
+
"POST /link/credentials/refresh": { auth: "door", control: "never" },
|
|
275
282
|
"POST /system/control/tokens": { control: "never" },
|
|
276
283
|
"GET /system/control/tokens": { floor: "maintainer", control: "never" },
|
|
277
284
|
"DELETE /system/control/tokens/{id}": { control: "never" },
|
|
@@ -381,6 +381,12 @@ export const LinkConfigSchema = z.object({
|
|
|
381
381
|
token: z.string().min(1).describe("The link token that sandbox minted for this one. Stored, never echoed back."),
|
|
382
382
|
name: z.string().max(100).optional().describe("What the other sandbox is called, as its owner named it."),
|
|
383
383
|
sandboxId: z.string().max(100).optional().describe("The other sandbox's id on the owner's account."),
|
|
384
|
+
purpose: z
|
|
385
|
+
.enum(["tasks", "accounts"])
|
|
386
|
+
.optional()
|
|
387
|
+
.describe(
|
|
388
|
+
"What the link is for: tasks to hand over (absent), or model accounts this sandbox borrows from that one (schemas/providers/account-sharing.ts), which mounts no delegate tool.",
|
|
389
|
+
),
|
|
384
390
|
});
|
|
385
391
|
export type LinkConfig = z.infer<typeof LinkConfigSchema>;
|
|
386
392
|
export type McpConfig = z.infer<typeof McpConfigSchema>;
|
package/src/schemas/links.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { AskQuestionSchema } from "../events/requests.js";
|
|
3
3
|
import { entryId } from "./internal.js";
|
|
4
|
+
import { SharedAccountRefSchema } from "./providers/account-sharing.js";
|
|
4
5
|
|
|
5
6
|
// LINKED SANDBOXES: one of the owner's sandboxes handing tasks to another. The sandbox that hands work over holds a
|
|
6
7
|
// `link` capability card (schemas/capabilities.ts LinkConfigSchema); the one that takes it holds an inbound link, minted
|
|
@@ -20,7 +21,28 @@ export const LINK_MAX_HOPS = 2;
|
|
|
20
21
|
export const LINK_TURNS_PER_HOUR_MAX = 120;
|
|
21
22
|
export const LINK_TURNS_PER_HOUR_DEFAULT = 20;
|
|
22
23
|
|
|
23
|
-
// THE TERMS, set on the taking side and enforced there: what the asking side is told, never what it decides.
|
|
24
|
+
// THE TERMS, set on the taking side and enforced there: what the asking side is told, never what it decides. Each field
|
|
25
|
+
// is spelled once below, without its default, so a change to the terms (InboundLinkTermsUpdateSchema) can name any of
|
|
26
|
+
// them as optional without zod filling in the rest.
|
|
27
|
+
const approveTerm = z
|
|
28
|
+
.boolean()
|
|
29
|
+
.describe("Each new task waits for this sandbox's owner to allow it before anything runs. Follow-up messages to a task already allowed do not.");
|
|
30
|
+
const turnsPerHourTerm = z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(1)
|
|
34
|
+
.max(LINK_TURNS_PER_HOUR_MAX)
|
|
35
|
+
.describe("How many turns the link may start in an hour, new tasks and follow-ups alike. Words said into a turn already running are not counted.");
|
|
36
|
+
const tasksTerm = z
|
|
37
|
+
.boolean()
|
|
38
|
+
.describe("Whether the link may hand this sandbox tasks at all. An accounts link is minted without: it only borrows and copies the accounts below.");
|
|
39
|
+
const accountsTerm = z
|
|
40
|
+
.array(SharedAccountRefSchema)
|
|
41
|
+
.max(64)
|
|
42
|
+
.describe(
|
|
43
|
+
"The model accounts the asking sandbox may use (schemas/providers/account-sharing.ts): a static key it may copy, a sign-in it borrows turn by turn. Empty lends nothing.",
|
|
44
|
+
);
|
|
45
|
+
|
|
24
46
|
export const LinkTermsSchema = z.object({
|
|
25
47
|
actsAs: entryId
|
|
26
48
|
.optional()
|
|
@@ -33,17 +55,10 @@ export const LinkTermsSchema = z.object({
|
|
|
33
55
|
.describe(
|
|
34
56
|
"The service every task through this link acts as: whose authority it uses, held to that service's access profile. Absent means this sandbox's owner, limited only by the persona.",
|
|
35
57
|
),
|
|
36
|
-
approve:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
turnsPerHour: z
|
|
41
|
-
.number()
|
|
42
|
-
.int()
|
|
43
|
-
.min(1)
|
|
44
|
-
.max(LINK_TURNS_PER_HOUR_MAX)
|
|
45
|
-
.default(LINK_TURNS_PER_HOUR_DEFAULT)
|
|
46
|
-
.describe("How many turns the link may start in an hour, new tasks and follow-ups alike. Words said into a turn already running are not counted."),
|
|
58
|
+
approve: approveTerm.default(false),
|
|
59
|
+
turnsPerHour: turnsPerHourTerm.default(LINK_TURNS_PER_HOUR_DEFAULT),
|
|
60
|
+
tasks: tasksTerm.default(true),
|
|
61
|
+
accounts: accountsTerm.default([]),
|
|
47
62
|
});
|
|
48
63
|
export type LinkTerms = z.infer<typeof LinkTermsSchema>;
|
|
49
64
|
|
|
@@ -91,11 +106,18 @@ export type InboundLinkMint = z.infer<typeof InboundLinkMintSchema>;
|
|
|
91
106
|
export const InboundLinkMintedSchema = z.object({ id: z.string(), token: z.string() });
|
|
92
107
|
export type InboundLinkMinted = z.infer<typeof InboundLinkMintedSchema>;
|
|
93
108
|
// POST /system/links/{id}: new terms, whole fields replaced, the rest kept. `null` on the persona or the service takes it
|
|
94
|
-
// off (2026-10-26): absence keeps a field, so before this neither could be cleared once set.
|
|
95
|
-
|
|
109
|
+
// off (2026-10-26): absence keeps a field, so before this neither could be cleared once set. Spelled field by field rather
|
|
110
|
+
// than as LinkTermsSchema.partial(): zod still fills a partial's inner defaults, so a change naming only `accounts`
|
|
111
|
+
// read as `approve: false, turnsPerHour: 20, tasks: true` and quietly turned an accounts link into one taking tasks
|
|
112
|
+
// (2026-10-29).
|
|
113
|
+
export const InboundLinkTermsUpdateSchema = z.object({
|
|
96
114
|
label: z.string().trim().min(1).max(60).optional(),
|
|
97
115
|
actsAs: entryId.nullable().optional().describe("The persona every task wears; null takes it off."),
|
|
98
116
|
runAs: entryId.nullable().optional().describe("The service every task acts as; null takes it off, so tasks act for this sandbox's owner."),
|
|
117
|
+
approve: approveTerm.optional(),
|
|
118
|
+
turnsPerHour: turnsPerHourTerm.optional(),
|
|
119
|
+
tasks: tasksTerm.optional(),
|
|
120
|
+
accounts: accountsTerm.optional(),
|
|
99
121
|
});
|
|
100
122
|
export type InboundLinkTermsUpdate = z.infer<typeof InboundLinkTermsUpdateSchema>;
|
|
101
123
|
// POST /system/links/{id}/requests/{request}: the owner's answer to one waiting task.
|
|
@@ -112,6 +134,9 @@ export const LinkHelloSchema = z.object({
|
|
|
112
134
|
approve: z.boolean(),
|
|
113
135
|
turnsPerHour: z.number().int(),
|
|
114
136
|
persona: z.string().optional().describe("The name of the persona its tasks wear, when they wear one."),
|
|
137
|
+
// Absent from a sandbox older than accounts links, which takes tasks and lends nothing.
|
|
138
|
+
tasks: z.boolean().optional(),
|
|
139
|
+
accounts: z.number().int().nonnegative().optional().describe("How many accounts the link may use."),
|
|
115
140
|
}),
|
|
116
141
|
maxHops: z.number().int(),
|
|
117
142
|
});
|
package/src/schemas/panels.ts
CHANGED
|
@@ -1,31 +1,44 @@
|
|
|
1
1
|
// panels: per-repository dev servers + the content facts extensions detect on
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
// Every discovered repo under /work is one row: runnable-panel status (a
|
|
4
|
-
//
|
|
5
|
-
// daemon-side so the browser never scans /work.
|
|
3
|
+
// Every discovered repo under /work is one row: runnable-panel status (what Start runs, with a port the daemon assigns,
|
|
4
|
+
// proxied at preview-<panelKey>-<sandboxId>.<zone>, and the windows it opened on the sandbox desktop) plus content facts
|
|
5
|
+
// extensions run detect() over, computed daemon-side so the browser never scans /work.
|
|
6
6
|
|
|
7
7
|
// Between click and first byte; `exited` matters most, since without it "Preparing the preview…" would never end.
|
|
8
8
|
// Absent once something serves.
|
|
9
9
|
export const PanelLaunchSchema = z.enum(["launching", "installing", "starting", "exited"]);
|
|
10
10
|
export type PanelLaunch = z.infer<typeof PanelLaunchSchema>;
|
|
11
11
|
|
|
12
|
+
// Where Start's command came from, first match winning: a root Procfile, operator/'s `dev` script, the root's `dev`,
|
|
13
|
+
// the root's `start`, a Cargo.toml with one binary to run.
|
|
14
|
+
export const PanelStartSourceSchema = z.enum(["procfile", "operator", "dev", "start", "cargo"]);
|
|
15
|
+
export type PanelStartSource = z.infer<typeof PanelStartSourceSchema>;
|
|
16
|
+
|
|
12
17
|
export const PanelSummarySchema = z.object({
|
|
13
18
|
// Root-relative dir under /work; slashes become `--` in the preview subdomain label.
|
|
14
19
|
repo: z.string().describe("Which repository."),
|
|
15
|
-
// A package.json `dev` script at operator/ or the
|
|
20
|
+
// A Procfile, a package.json `dev` script at operator/ or the root, a root `start`, or a Cargo binary.
|
|
16
21
|
hasPanel: z.boolean().describe("Whether it has anything runnable at all."),
|
|
22
|
+
// Optional on the wire: a sandbox older than this field says nothing of what it runs.
|
|
23
|
+
start: z
|
|
24
|
+
.object({
|
|
25
|
+
from: PanelStartSourceSchema.describe("Which file said how to start it."),
|
|
26
|
+
command: z.string().describe("What it runs, as a person would type it: `pnpm dev`, `cargo run`, or a Procfile's entries."),
|
|
27
|
+
})
|
|
28
|
+
.optional()
|
|
29
|
+
.describe("What Start runs. Absent for a repository with nothing to start."),
|
|
17
30
|
running: z.boolean().describe("Whether the sandbox has it running."),
|
|
18
31
|
// True for a repo with nothing runnable — nothing to install for.
|
|
19
32
|
installed: z
|
|
20
33
|
.boolean()
|
|
21
34
|
.describe("Whether its dependencies are installed, which is what decides whether a start takes seconds or an install first."),
|
|
22
35
|
launch: PanelLaunchSchema.optional().describe(
|
|
23
|
-
"Where a start the sandbox is running has got to: its shell coming up, installing, its dev command running with nothing listening yet, or exited back to a prompt. Absent when nothing is starting and once it serves.",
|
|
36
|
+
"Where a start the sandbox is running has got to: its shell coming up, installing, its dev command running with nothing listening yet, or exited back to a prompt. Absent when nothing is starting and once it serves or opens a window.",
|
|
24
37
|
),
|
|
25
38
|
healthy: z
|
|
26
39
|
.boolean()
|
|
27
40
|
.describe(
|
|
28
|
-
"Whether anything it owns is actually answering. A different question: a server still installing is running and not yet healthy, and one somebody started by hand is healthy without the sandbox running it.",
|
|
41
|
+
"Whether anything it owns is actually answering: a server, or a window open on the sandbox desktop. A different question: a server still installing is running and not yet healthy, and one somebody started by hand is healthy without the sandbox running it.",
|
|
29
42
|
),
|
|
30
43
|
port: z
|
|
31
44
|
.number()
|
|
@@ -55,6 +68,18 @@ export const PanelSummarySchema = z.object({
|
|
|
55
68
|
}),
|
|
56
69
|
)
|
|
57
70
|
.describe("Every server this repository is really serving, found by looking at what is listening. Empty when nothing answers."),
|
|
71
|
+
// Optional on the wire, like `start`; absent also while nothing of the repo's has a window open.
|
|
72
|
+
windows: z
|
|
73
|
+
.array(
|
|
74
|
+
z.object({
|
|
75
|
+
id: z.string().describe("The window's id on the sandbox desktop, which is what opening it there takes."),
|
|
76
|
+
title: z.string().describe("Its title."),
|
|
77
|
+
}),
|
|
78
|
+
)
|
|
79
|
+
.optional()
|
|
80
|
+
.describe(
|
|
81
|
+
"The windows its programs have open on the sandbox desktop: how a game or a desktop app shows it is up, since it serves no page. Absent when none is open.",
|
|
82
|
+
),
|
|
58
83
|
// `https://preview-<repo>-<sandboxId>.<zone>`; absent whenever no single hostname could stand for what's running
|
|
59
84
|
// (nothing up, still starting, several servers).
|
|
60
85
|
previewUrl: z
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { EndpointConfigSchema } from "../capabilities.js";
|
|
3
|
+
import { OauthAccountSchema } from "./provider-oauth.js";
|
|
4
|
+
|
|
5
|
+
// SHARING MODEL ACCOUNTS between one owner's sandboxes, over an accounts link (schemas/links.ts, `terms.accounts`).
|
|
6
|
+
// Each account goes the one way that is safe for its credential:
|
|
7
|
+
// - copy: a static key (Cursor, Devin, a minted Z.ai or Muse key, a model endpoint's API key) is read by the target's
|
|
8
|
+
// daemon from the source's over the link and stored as the target's own; nothing ties the two afterwards.
|
|
9
|
+
// - lend: a sign-in whose refresh token rotates (a Claude subscription) stays with the source; the target asks it for
|
|
10
|
+
// an access token each turn. The refresh token never leaves the source, so the two sandboxes never race to renew one
|
|
11
|
+
// login. A subscription the translator holds (Codex, Grok, Kimi, Gemini) is listed as `no` for now: lending it would
|
|
12
|
+
// relay every request through the source's translator, which the target's runtimes do not do yet.
|
|
13
|
+
// - no: what cannot travel either way, with the reason a person reads.
|
|
14
|
+
// Values never ride the editor's wire: the browser sees these rows, and the target's daemon fetches a copy itself.
|
|
15
|
+
|
|
16
|
+
export const ShareModeSchema = z.enum(["copy", "lend", "no"]);
|
|
17
|
+
export type ShareMode = z.infer<typeof ShareModeSchema>;
|
|
18
|
+
|
|
19
|
+
// One account an accounts link names: a provider (an AgentProvider id, `endpoint/<id>` included) and, for a provider
|
|
20
|
+
// holding several of its own, which one. A translator provider is shared whole, since its translator picks among its
|
|
21
|
+
// own subscriptions and takes no account, so `account` is absent there.
|
|
22
|
+
export const SharedAccountRefSchema = z.object({
|
|
23
|
+
provider: z.string().min(1).max(120),
|
|
24
|
+
account: z.string().min(1).max(200).optional(),
|
|
25
|
+
});
|
|
26
|
+
export type SharedAccountRef = z.infer<typeof SharedAccountRefSchema>;
|
|
27
|
+
|
|
28
|
+
export const sameSharedRef = (a: SharedAccountRef, b: SharedAccountRef): boolean => a.provider === b.provider && a.account === b.account;
|
|
29
|
+
|
|
30
|
+
// GET /sharing/accounts on the source: everything it holds, and how each would reach another sandbox.
|
|
31
|
+
export const ShareableAccountSchema = SharedAccountRefSchema.extend({
|
|
32
|
+
label: z.string().describe("What the source calls it."),
|
|
33
|
+
email: z.string().optional(),
|
|
34
|
+
mode: ShareModeSchema,
|
|
35
|
+
reason: z.string().optional().describe("Why it cannot be shared, when `mode` is no."),
|
|
36
|
+
});
|
|
37
|
+
export type ShareableAccount = z.infer<typeof ShareableAccountSchema>;
|
|
38
|
+
export const ShareableAccountsSchema = z.object({
|
|
39
|
+
sandbox: z.string().describe("What the source calls itself."),
|
|
40
|
+
accounts: z.array(ShareableAccountSchema),
|
|
41
|
+
});
|
|
42
|
+
export type ShareableAccounts = z.infer<typeof ShareableAccountsSchema>;
|
|
43
|
+
|
|
44
|
+
// A copy of one static account, the fields every static store keeps. Only the target's daemon ever reads one.
|
|
45
|
+
export const StaticAccountCopySchema = z.object({
|
|
46
|
+
label: z.string().optional(),
|
|
47
|
+
email: z.string().optional(),
|
|
48
|
+
variant: z.string().optional(),
|
|
49
|
+
plan: z.string().optional(),
|
|
50
|
+
apiKey: z.string().min(1),
|
|
51
|
+
apiKeyExpiresAtMs: z.number().optional(),
|
|
52
|
+
backendUrl: z.string().optional(),
|
|
53
|
+
});
|
|
54
|
+
export type StaticAccountCopy = z.infer<typeof StaticAccountCopySchema>;
|
|
55
|
+
|
|
56
|
+
export const AccountCopySchema = z.discriminatedUnion("kind", [
|
|
57
|
+
z.object({ kind: z.literal("account"), account: StaticAccountCopySchema }),
|
|
58
|
+
z.object({ kind: z.literal("endpoint"), id: z.string().min(1), config: EndpointConfigSchema }),
|
|
59
|
+
]);
|
|
60
|
+
export type AccountCopy = z.infer<typeof AccountCopySchema>;
|
|
61
|
+
|
|
62
|
+
/* THE LINK DOORS for accounts, called by the target's daemon with the link token. */
|
|
63
|
+
|
|
64
|
+
// GET /link/accounts: what this link may use, as rows without credentials, each with the source's own usage reading,
|
|
65
|
+
// so the target shows the source's figures instead of measuring the same plan twice.
|
|
66
|
+
export const LinkAccountSchema = OauthAccountSchema.extend({
|
|
67
|
+
provider: z.string(),
|
|
68
|
+
mode: z.enum(["copy", "lend"]),
|
|
69
|
+
});
|
|
70
|
+
export type LinkAccount = z.infer<typeof LinkAccountSchema>;
|
|
71
|
+
export const LinkAccountsSchema = z.object({ accounts: z.array(LinkAccountSchema) });
|
|
72
|
+
export type LinkAccounts = z.infer<typeof LinkAccountsSchema>;
|
|
73
|
+
|
|
74
|
+
// POST /link/accounts/copy: one static account's value, for an account the link names in copy mode only.
|
|
75
|
+
export const LinkAccountCopySchema = z.object({ copy: AccountCopySchema });
|
|
76
|
+
export type LinkAccountCopy = z.infer<typeof LinkAccountCopySchema>;
|
|
77
|
+
|
|
78
|
+
/* THE TARGET'S OWN ROUTES, called by the owner's editor. */
|
|
79
|
+
|
|
80
|
+
// POST /sharing/borrow: bring the named accounts in over the accounts link saved as `card`.
|
|
81
|
+
export const AccountsBorrowSchema = z.object({
|
|
82
|
+
card: z.string().min(1).describe("The link card the editor saved for the source."),
|
|
83
|
+
items: z.array(SharedAccountRefSchema).min(1).max(64),
|
|
84
|
+
});
|
|
85
|
+
export type AccountsBorrow = z.infer<typeof AccountsBorrowSchema>;
|
|
86
|
+
|
|
87
|
+
export const BorrowOutcomeSchema = SharedAccountRefSchema.extend({
|
|
88
|
+
outcome: z.enum(["copied", "borrowed", "failed"]),
|
|
89
|
+
id: z.string().optional().describe("The account's id here, for a copy or a borrow."),
|
|
90
|
+
message: z.string().optional().describe("Why it failed, in words a person can act on."),
|
|
91
|
+
});
|
|
92
|
+
export type BorrowOutcome = z.infer<typeof BorrowOutcomeSchema>;
|
|
93
|
+
export const AccountsBorrowedSchema = z.object({ results: z.array(BorrowOutcomeSchema) });
|
|
94
|
+
export type AccountsBorrowed = z.infer<typeof AccountsBorrowedSchema>;
|
|
95
|
+
|
|
96
|
+
// Where a borrowed account comes from, as a row here says it.
|
|
97
|
+
export const BorrowedFromSchema = z.object({
|
|
98
|
+
name: z.string().describe("What the source calls itself."),
|
|
99
|
+
sandboxId: z.string().optional(),
|
|
100
|
+
});
|
|
101
|
+
export type BorrowedFrom = z.infer<typeof BorrowedFromSchema>;
|
|
102
|
+
|
|
103
|
+
// One account this sandbox borrows: no credential in it, only where to ask. Access tokens are held in memory.
|
|
104
|
+
export const BorrowedAccountSchema = z.object({
|
|
105
|
+
id: z.string().describe("Its id here: what a turn names, and what Stop borrowing takes."),
|
|
106
|
+
card: z.string().describe("The link card it is borrowed through."),
|
|
107
|
+
provider: z.string(),
|
|
108
|
+
remote: z.string().optional().describe("Its id on the source; absent for a translator provider, borrowed whole."),
|
|
109
|
+
label: z.string(),
|
|
110
|
+
email: z.string().optional(),
|
|
111
|
+
organization: z.string().optional(),
|
|
112
|
+
from: BorrowedFromSchema,
|
|
113
|
+
borrowedAt: z.number(),
|
|
114
|
+
});
|
|
115
|
+
export type BorrowedAccount = z.infer<typeof BorrowedAccountSchema>;
|
|
116
|
+
export const BorrowedAccountsSchema = z.object({ accounts: z.array(BorrowedAccountSchema) });
|
|
117
|
+
export type BorrowedAccounts = z.infer<typeof BorrowedAccountsSchema>;
|
|
118
|
+
|
|
119
|
+
export const BorrowedAccountIdSchema = z.object({ id: z.string().min(1) });
|
|
120
|
+
|
|
121
|
+
// The prefix every borrowed account's id here carries, so no store mistakes one for an account of its own.
|
|
122
|
+
export const BORROWED_ID_PREFIX = "lent-";
|
|
123
|
+
export const isBorrowedId = (id: string): boolean => id.startsWith(BORROWED_ID_PREFIX);
|
|
@@ -38,6 +38,12 @@ export const OauthAccountSchema = z.object({
|
|
|
38
38
|
usage: AccountUsageSchema.optional().describe(
|
|
39
39
|
"How full its plan limits were when last measured, so a picker can show what is left before committing work to it. Absent until a reading exists, which reads as unknown rather than as nothing left.",
|
|
40
40
|
),
|
|
41
|
+
borrowedFrom: z
|
|
42
|
+
.object({ name: z.string(), sandboxId: z.string().optional() })
|
|
43
|
+
.optional()
|
|
44
|
+
.describe(
|
|
45
|
+
"Another of the owner's sandboxes holds this sign-in and lends it here turn by turn (schemas/providers/account-sharing.ts). Absent means it is this sandbox's own.",
|
|
46
|
+
),
|
|
41
47
|
});
|
|
42
48
|
export type OauthAccount = z.infer<typeof OauthAccountSchema>;
|
|
43
49
|
export const OauthAccountListSchema = z.object({
|