@sema-agent/sdk 0.0.74 → 0.0.76
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/client.d.ts +48 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +55 -2
- package/dist/client.js.map +1 -1
- package/dist/control-client.d.ts +21 -0
- package/dist/control-client.d.ts.map +1 -1
- package/dist/control-client.js +42 -1
- package/dist/control-client.js.map +1 -1
- package/dist/control-types.d.ts +108 -0
- package/dist/control-types.d.ts.map +1 -1
- package/dist/control-types.js +15 -0
- package/dist/control-types.js.map +1 -1
- package/dist/errors.d.ts +88 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +105 -8
- package/dist/errors.js.map +1 -1
- package/dist/events.d.ts +154 -16
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +1 -0
- package/dist/events.js.map +1 -1
- package/dist/health.d.ts +44 -0
- package/dist/health.d.ts.map +1 -1
- package/dist/health.js +32 -0
- package/dist/health.js.map +1 -1
- package/dist/idempotency.d.ts +8 -0
- package/dist/idempotency.d.ts.map +1 -1
- package/dist/idempotency.js +8 -0
- package/dist/idempotency.js.map +1 -1
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/resources/approvals.d.ts +43 -0
- package/dist/resources/approvals.d.ts.map +1 -1
- package/dist/resources/approvals.js +23 -3
- package/dist/resources/approvals.js.map +1 -1
- package/dist/resources/assistant.d.ts +23 -0
- package/dist/resources/assistant.d.ts.map +1 -1
- package/dist/resources/assistant.js +22 -0
- package/dist/resources/assistant.js.map +1 -1
- package/dist/resources/control/auth-providers.d.ts +17 -0
- package/dist/resources/control/auth-providers.d.ts.map +1 -1
- package/dist/resources/control/auth-providers.js +6 -0
- package/dist/resources/control/auth-providers.js.map +1 -1
- package/dist/resources/control/config.d.ts +22 -0
- package/dist/resources/control/config.d.ts.map +1 -1
- package/dist/resources/control/config.js +12 -0
- package/dist/resources/control/config.js.map +1 -1
- package/dist/resources/control/fleet.d.ts +15 -0
- package/dist/resources/control/fleet.d.ts.map +1 -1
- package/dist/resources/control/fleet.js +8 -0
- package/dist/resources/control/fleet.js.map +1 -1
- package/dist/resources/control/images.d.ts +20 -0
- package/dist/resources/control/images.d.ts.map +1 -1
- package/dist/resources/control/images.js +10 -0
- package/dist/resources/control/images.js.map +1 -1
- package/dist/resources/control/lifecycle.d.ts +8 -0
- package/dist/resources/control/lifecycle.d.ts.map +1 -1
- package/dist/resources/control/lifecycle.js +3 -0
- package/dist/resources/control/lifecycle.js.map +1 -1
- package/dist/resources/control/publish.d.ts +12 -0
- package/dist/resources/control/publish.d.ts.map +1 -1
- package/dist/resources/control/publish.js +6 -0
- package/dist/resources/control/publish.js.map +1 -1
- package/dist/resources/control/secrets.d.ts +28 -0
- package/dist/resources/control/secrets.d.ts.map +1 -1
- package/dist/resources/control/secrets.js +16 -0
- package/dist/resources/control/secrets.js.map +1 -1
- package/dist/resources/control/users.d.ts +22 -0
- package/dist/resources/control/users.d.ts.map +1 -1
- package/dist/resources/control/users.js +12 -0
- package/dist/resources/control/users.js.map +1 -1
- package/dist/resources/control/versioning.d.ts +12 -0
- package/dist/resources/control/versioning.d.ts.map +1 -1
- package/dist/resources/control/versioning.js +6 -0
- package/dist/resources/control/versioning.js.map +1 -1
- package/dist/resources/control/workers.d.ts +14 -0
- package/dist/resources/control/workers.d.ts.map +1 -1
- package/dist/resources/control/workers.js +7 -0
- package/dist/resources/control/workers.js.map +1 -1
- package/dist/resources/elicitations.d.ts +43 -0
- package/dist/resources/elicitations.d.ts.map +1 -1
- package/dist/resources/elicitations.js +8 -0
- package/dist/resources/elicitations.js.map +1 -1
- package/dist/resources/fleet.d.ts +90 -0
- package/dist/resources/fleet.d.ts.map +1 -1
- package/dist/resources/fleet.js +27 -4
- package/dist/resources/fleet.js.map +1 -1
- package/dist/resources/images.d.ts +34 -0
- package/dist/resources/images.d.ts.map +1 -1
- package/dist/resources/images.js +29 -3
- package/dist/resources/images.js.map +1 -1
- package/dist/resources/leader.d.ts +10 -0
- package/dist/resources/leader.d.ts.map +1 -1
- package/dist/resources/leader.js +4 -0
- package/dist/resources/leader.js.map +1 -1
- package/dist/resources/memory.d.ts +37 -0
- package/dist/resources/memory.d.ts.map +1 -1
- package/dist/resources/memory.js +28 -0
- package/dist/resources/memory.js.map +1 -1
- package/dist/resources/models.d.ts +12 -0
- package/dist/resources/models.d.ts.map +1 -1
- package/dist/resources/models.js +4 -0
- package/dist/resources/models.js.map +1 -1
- package/dist/resources/ops.d.ts +16 -0
- package/dist/resources/ops.d.ts.map +1 -1
- package/dist/resources/ops.js +6 -0
- package/dist/resources/ops.js.map +1 -1
- package/dist/resources/policy.d.ts +8 -0
- package/dist/resources/policy.d.ts.map +1 -1
- package/dist/resources/policy.js +1 -0
- package/dist/resources/policy.js.map +1 -1
- package/dist/resources/questions.d.ts +57 -0
- package/dist/resources/questions.d.ts.map +1 -1
- package/dist/resources/questions.js +9 -0
- package/dist/resources/questions.js.map +1 -1
- package/dist/resources/runs.d.ts +143 -0
- package/dist/resources/runs.d.ts.map +1 -1
- package/dist/resources/runs.js +129 -2
- package/dist/resources/runs.js.map +1 -1
- package/dist/resources/session-sync.d.ts +61 -0
- package/dist/resources/session-sync.d.ts.map +1 -1
- package/dist/resources/session-sync.js +54 -1
- package/dist/resources/session-sync.js.map +1 -1
- package/dist/resources/sessions.d.ts +74 -0
- package/dist/resources/sessions.d.ts.map +1 -1
- package/dist/resources/sessions.js +64 -2
- package/dist/resources/sessions.js.map +1 -1
- package/dist/resources/side-query.d.ts +18 -0
- package/dist/resources/side-query.d.ts.map +1 -1
- package/dist/resources/side-query.js +1 -0
- package/dist/resources/side-query.js.map +1 -1
- package/dist/resources/tasks.d.ts +19 -0
- package/dist/resources/tasks.d.ts.map +1 -1
- package/dist/resources/tasks.js +21 -2
- package/dist/resources/tasks.js.map +1 -1
- package/dist/resources/tool-approvals.d.ts +53 -0
- package/dist/resources/tool-approvals.d.ts.map +1 -1
- package/dist/resources/tool-approvals.js +10 -0
- package/dist/resources/tool-approvals.js.map +1 -1
- package/dist/resources/trace.d.ts +23 -0
- package/dist/resources/trace.d.ts.map +1 -1
- package/dist/resources/trace.js +27 -2
- package/dist/resources/trace.js.map +1 -1
- package/dist/resources/usage.d.ts +21 -0
- package/dist/resources/usage.d.ts.map +1 -1
- package/dist/resources/usage.js +8 -0
- package/dist/resources/usage.js.map +1 -1
- package/dist/resources/workflows.d.ts +48 -0
- package/dist/resources/workflows.d.ts.map +1 -1
- package/dist/resources/workflows.js +40 -3
- package/dist/resources/workflows.js.map +1 -1
- package/dist/settings.d.ts +90 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +24 -0
- package/dist/settings.js.map +1 -1
- package/dist/sse.d.ts +36 -0
- package/dist/sse.d.ts.map +1 -1
- package/dist/sse.js +53 -8
- package/dist/sse.js.map +1 -1
- package/dist/sync.d.ts +56 -0
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +48 -4
- package/dist/sync.js.map +1 -1
- package/dist/transport.d.ts +32 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +40 -8
- package/dist/transport.js.map +1 -1
- package/dist/types.d.ts +691 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/health.d.ts
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 免构造工具(SDK 宪法例外①②收编,clay 拍 2026-07-16)—— the TWO sanctioned raw-HTTP shapes that must NOT
|
|
3
|
+
* require an AgentClient:
|
|
4
|
+
*
|
|
5
|
+
* ① {@link probeHealth} — process-noise liveness. `/health` is the worker's UNAUTHENTICATED door
|
|
6
|
+
* (server 1.214 server.js:296 — no token, no principal), and the probe's whole job is "is anything
|
|
7
|
+
* alive there?" BEFORE credentials/TOFU exist (engine spawn wait-loops, port arbitration, dead-engine
|
|
8
|
+
* triage, teardown confirmation — the shell's 6-strong probe family). Constructing a principal-first,
|
|
9
|
+
* token-bearing client to ask that would invert the trust order, so the SDK ships the probe as a STATIC
|
|
10
|
+
* function: zero-throw, judgement-typed, and — deliberately — sending NO credentials ever.
|
|
11
|
+
*
|
|
12
|
+
* ② {@link engineUrl} — the single-source URL builder for the teardown last-resort raw fetch
|
|
13
|
+
* (fire-and-forget on a dying process, where awaiting a Transport is wrong) and for anything else the
|
|
14
|
+
* constitution grudgingly allows raw. One join semantic (identical to Transport's), so a hand-built URL
|
|
15
|
+
* can never drift from what the client would have called.
|
|
16
|
+
*
|
|
17
|
+
* Everything ELSE goes through AgentClient — these two are the WHOLE exception surface (plus labelled
|
|
18
|
+
* contract-probe raws in tests; see the SDK constitution in the repo CLAUDE.md).
|
|
19
|
+
*/
|
|
20
|
+
/** The `/health` 200 body, subset-typed (server 1.214 server.js:296-320 — exact producer; open set for the
|
|
21
|
+
* conditional fields: draining/durable/ready/restartRequired etc. appear only when true/degraded). */
|
|
1
22
|
export interface EngineHealth {
|
|
23
|
+
/** "ok" on the live door — {@link probeHealth} requires it for `alive` (a 200 with anything else is `not_ok`). */
|
|
2
24
|
status: string;
|
|
3
25
|
version?: string;
|
|
4
26
|
model?: string;
|
|
@@ -6,15 +28,24 @@ export interface EngineHealth {
|
|
|
6
28
|
sessions?: number;
|
|
7
29
|
instanceId?: string;
|
|
8
30
|
dataRoot?: string;
|
|
31
|
+
/** sha256[0:16] over the engine's identity config (model/backends/dataRoot/port) — the shell's drift detector. */
|
|
9
32
|
configHash?: string;
|
|
10
33
|
pid?: number;
|
|
11
34
|
port?: number;
|
|
12
35
|
draining?: boolean;
|
|
36
|
+
/** false = model roster pending (first effective-config pull) — alive but not accepting billable submits. */
|
|
13
37
|
ready?: boolean;
|
|
14
38
|
storeDegraded?: boolean;
|
|
15
39
|
restartRequired?: boolean;
|
|
16
40
|
[k: string]: unknown;
|
|
17
41
|
}
|
|
42
|
+
/** Judgement-typed probe outcome. `alive` iff HTTP 200 AND `status === "ok"`; every dead arm carries WHY:
|
|
43
|
+
* - `timeout` — no answer inside the budget (process wedged / port filtered);
|
|
44
|
+
* - `network` — connect refused / DNS / TLS (nothing listening — the common "engine is down");
|
|
45
|
+
* - `http` — the port answered with a non-2xx (`status` = the code; something ELSE squats on the port,
|
|
46
|
+
* or the engine is mid-boot behind a proxy);
|
|
47
|
+
* - `not_ok` — 2xx but not the health contract (`status` field ≠ "ok" or unparseable body — port reuse by
|
|
48
|
+
* a non-engine HTTP server). */
|
|
18
49
|
export type ProbeHealthResult = {
|
|
19
50
|
alive: true;
|
|
20
51
|
health: EngineHealth;
|
|
@@ -26,6 +57,19 @@ export type ProbeHealthResult = {
|
|
|
26
57
|
reason: "http" | "not_ok";
|
|
27
58
|
status: number;
|
|
28
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Zero-throw unauthenticated liveness probe: `GET <baseUrl>/health` with a hard `timeoutMs` budget
|
|
62
|
+
* (default 2000 — process-noise cadence; pass more for slow cold boots). NEVER throws, NEVER sends
|
|
63
|
+
* credentials (TOFU discipline: nothing secret may leave before trust is established — same posture as the
|
|
64
|
+
* shell's probeEngineHealthUrl). Static on purpose: usable before/without an AgentClient (constitution
|
|
65
|
+
* exception ①).
|
|
66
|
+
*/
|
|
29
67
|
export declare function probeHealth(baseUrl: string, timeoutMs?: number, fetchImpl?: typeof fetch): Promise<ProbeHealthResult>;
|
|
68
|
+
/**
|
|
69
|
+
* Single-source engine URL builder (constitution exception ② — the teardown fire-and-forget raw's URL comes
|
|
70
|
+
* from HERE, never hand-concatenated). Join semantic is byte-identical to Transport's:
|
|
71
|
+
* trailing slashes are stripped off `baseUrl`, `path` is used verbatim (a missing leading `/` is added).
|
|
72
|
+
* 🔴 Path SEGMENTS are the caller's to encode (`encodeURIComponent` per segment) — this joins, it does not encode.
|
|
73
|
+
*/
|
|
30
74
|
export declare function engineUrl(baseUrl: string, path: string): string;
|
|
31
75
|
//# sourceMappingURL=health.d.ts.map
|
package/dist/health.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH;uGACuG;AACvG,MAAM,WAAW,YAAY;IAC3B,kHAAkH;IAClH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kHAAkH;IAClH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,6GAA6G;IAC7G,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACtB;AAED;;;;;;gDAMgD;AAChD,MAAM,MAAM,iBAAiB,GACzB;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,MAAM,EAAE,YAAY,CAAA;CAAE,GACrC;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,SAAS,CAAA;CAAE,GAC/C;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEhE;;;;;;GAMG;AACH,wBAAsB,WAAW,CAC/B,OAAO,EAAE,MAAM,EACf,SAAS,SAAO,EAChB,SAAS,GAAE,OAAO,KAAa,GAC9B,OAAO,CAAC,iBAAiB,CAAC,CAqB5B;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAG/D"}
|
package/dist/health.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 免构造工具(SDK 宪法例外①②收编,clay 拍 2026-07-16)—— the TWO sanctioned raw-HTTP shapes that must NOT
|
|
3
|
+
* require an AgentClient:
|
|
4
|
+
*
|
|
5
|
+
* ① {@link probeHealth} — process-noise liveness. `/health` is the worker's UNAUTHENTICATED door
|
|
6
|
+
* (server 1.214 server.js:296 — no token, no principal), and the probe's whole job is "is anything
|
|
7
|
+
* alive there?" BEFORE credentials/TOFU exist (engine spawn wait-loops, port arbitration, dead-engine
|
|
8
|
+
* triage, teardown confirmation — the shell's 6-strong probe family). Constructing a principal-first,
|
|
9
|
+
* token-bearing client to ask that would invert the trust order, so the SDK ships the probe as a STATIC
|
|
10
|
+
* function: zero-throw, judgement-typed, and — deliberately — sending NO credentials ever.
|
|
11
|
+
*
|
|
12
|
+
* ② {@link engineUrl} — the single-source URL builder for the teardown last-resort raw fetch
|
|
13
|
+
* (fire-and-forget on a dying process, where awaiting a Transport is wrong) and for anything else the
|
|
14
|
+
* constitution grudgingly allows raw. One join semantic (identical to Transport's), so a hand-built URL
|
|
15
|
+
* can never drift from what the client would have called.
|
|
16
|
+
*
|
|
17
|
+
* Everything ELSE goes through AgentClient — these two are the WHOLE exception surface (plus labelled
|
|
18
|
+
* contract-probe raws in tests; see the SDK constitution in the repo CLAUDE.md).
|
|
19
|
+
*/
|
|
20
|
+
/**
|
|
21
|
+
* Zero-throw unauthenticated liveness probe: `GET <baseUrl>/health` with a hard `timeoutMs` budget
|
|
22
|
+
* (default 2000 — process-noise cadence; pass more for slow cold boots). NEVER throws, NEVER sends
|
|
23
|
+
* credentials (TOFU discipline: nothing secret may leave before trust is established — same posture as the
|
|
24
|
+
* shell's probeEngineHealthUrl). Static on purpose: usable before/without an AgentClient (constitution
|
|
25
|
+
* exception ①).
|
|
26
|
+
*/
|
|
1
27
|
export async function probeHealth(baseUrl, timeoutMs = 2000, fetchImpl = fetch) {
|
|
2
28
|
const controller = new AbortController();
|
|
3
29
|
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
@@ -24,6 +50,12 @@ export async function probeHealth(baseUrl, timeoutMs = 2000, fetchImpl = fetch)
|
|
|
24
50
|
clearTimeout(timer);
|
|
25
51
|
}
|
|
26
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Single-source engine URL builder (constitution exception ② — the teardown fire-and-forget raw's URL comes
|
|
55
|
+
* from HERE, never hand-concatenated). Join semantic is byte-identical to Transport's:
|
|
56
|
+
* trailing slashes are stripped off `baseUrl`, `path` is used verbatim (a missing leading `/` is added).
|
|
57
|
+
* 🔴 Path SEGMENTS are the caller's to encode (`encodeURIComponent` per segment) — this joins, it does not encode.
|
|
58
|
+
*/
|
|
27
59
|
export function engineUrl(baseUrl, path) {
|
|
28
60
|
const base = baseUrl.replace(/\/+$/, "");
|
|
29
61
|
return path.startsWith("/") ? base + path : `${base}/${path}`;
|
package/dist/health.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAqCH;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,OAAe,EACf,SAAS,GAAG,IAAI,EAChB,YAA0B,KAAK;IAE/B,MAAM,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,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ACH,MAAM,UAAU,SAAS,CAAC,OAAe,EAAE,IAAY;IACrD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzC,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,EAAE,CAAC;AAChE,CAAC"}
|
package/dist/idempotency.d.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency — auto UUID key for submit-class requests (DESIGN §2.3) + the RED LINE: a submit (POST tasks/
|
|
3
|
+
* runs) is retried ONLY when an idempotency key exists. The SDK auto-generates one, so retries are safe by
|
|
4
|
+
* default; a caller that explicitly sets `idempotencyKey: null` to disable it also LOSES auto-retry on submits.
|
|
5
|
+
* (The worker dedups by this key: same key in-flight/settled → reuse, concurrent → 409 — server-verified.)
|
|
6
|
+
*/
|
|
1
7
|
export declare function newIdempotencyKey(): string;
|
|
8
|
+
/** Resolve the effective key: explicit string keeps it; `null` disables (and disables submit retry); undefined
|
|
9
|
+
* → auto-generate. Returned to the transport, which sets the `Idempotency-Key` header and gates retry on it. */
|
|
2
10
|
export declare function resolveIdempotencyKey(explicit: string | null | undefined): string | null;
|
|
3
11
|
//# sourceMappingURL=idempotency.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"idempotency.d.ts","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;iHACiH;AACjH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,GAAG,IAAI,CAGxF"}
|
package/dist/idempotency.js
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Idempotency — auto UUID key for submit-class requests (DESIGN §2.3) + the RED LINE: a submit (POST tasks/
|
|
3
|
+
* runs) is retried ONLY when an idempotency key exists. The SDK auto-generates one, so retries are safe by
|
|
4
|
+
* default; a caller that explicitly sets `idempotencyKey: null` to disable it also LOSES auto-retry on submits.
|
|
5
|
+
* (The worker dedups by this key: same key in-flight/settled → reuse, concurrent → 409 — server-verified.)
|
|
6
|
+
*/
|
|
1
7
|
export function newIdempotencyKey() {
|
|
2
8
|
return crypto.randomUUID();
|
|
3
9
|
}
|
|
10
|
+
/** Resolve the effective key: explicit string keeps it; `null` disables (and disables submit retry); undefined
|
|
11
|
+
* → auto-generate. Returned to the transport, which sets the `Idempotency-Key` header and gates retry on it. */
|
|
4
12
|
export function resolveIdempotencyKey(explicit) {
|
|
5
13
|
if (explicit === null)
|
|
6
14
|
return null;
|
package/dist/idempotency.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"idempotency.js","sourceRoot":"","sources":["../src/idempotency.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,MAAM,CAAC,UAAU,EAAE,CAAC;AAC7B,CAAC;AAED;iHACiH;AACjH,MAAM,UAAU,qBAAqB,CAAC,QAAmC;IACvE,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACnC,OAAO,QAAQ,IAAI,iBAAiB,EAAE,CAAC;AACzC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
/** @sema-agent/sdk — usage-plane SDK (the shared substrate for both doors). Server-side only. */
|
|
1
2
|
export { AgentClient, type AgentClientConfig, type AgentAuthToken } from "./client.js";
|
|
3
|
+
/** Control plane (TOB): sema-registry / config-center `/api/config/*`. A peer client (different backend +
|
|
4
|
+
* secret) for managing the fleet config — see control-client.ts. */
|
|
2
5
|
export { ControlClient, type ControlClientConfig } from "./control-client.js";
|
|
3
6
|
export type { Principal, Scenario, RunStatus, TaskStats, TaskRequest, TaskAgentDefinition, TaskResult, RunReceipt, RunRecord, CancelAck, Artifact, LeaderReceipt, LeaderRecord, Capabilities, ScenarioDetail, PendingCheckpoint, SessionRecord, SkillSpec, MemoryRecord, MemoryWriteAck, TaskSummary, CheckpointGate, TraceTurn, TraceBlock, PromptManifest, PromptEpoch, SessionSummary, SessionListPage, SessionPermissionRules, StoredSessionRules, McpServerStatus, McpStatusPanel, SessionWindow, SessionMessageEnvelope, SyncEntry, SyncSnapshot, SyncAnchor, SessionRulesRecord, SessionManifest, SessionBundle, SyncRelation, SyncConflictRelation, ImportStaged, ImportCommitted, TraceStreamEvent, WorkflowStreamEvent, CheckpointSummary, InboxRow, AssistantGate, AssistantTask, PlanReviewRequest, AssistantTaskStatus, ImageIndexEntry, ImageSelectResult, ModelInfo, UsageInfo, PolicyInfo, WorkflowRunStatus, WorkflowRunSummary, WorkflowRun, WorkflowAgentRow, WorkflowActivityBeat, } from "./types.js";
|
|
7
|
+
/** TOC `settings.json` — the SHARED environment-customization contract (CC-parity v1: permissions/hooks/env/model/
|
|
8
|
+
* outputStyle). ONE schema, two wirings: TOC-local (shell adapter → local Runner) + TOB-fleet (carried to service via
|
|
9
|
+
* {@link TaskRequest.settings}). SDK owns the CONTRACT only — no interpreter, no shell-hook runner. core/search AI
|
|
10
|
+
* 2026-06-27 / research/toc-settings-adapter/01-design.md §5①. */
|
|
4
11
|
export type { SemaSettings, SettingsPermissions, SettingsHooks, SettingsHookMatcher, SettingsHookCommand, SettingsEnv, } from "./settings.js";
|
|
5
12
|
export type { AgentEvent, EventIdentity, BrainStatusPhase } from "./events.js";
|
|
6
13
|
export type { StampedAgentEvent } from "./sse.js";
|
|
@@ -9,25 +16,37 @@ export { MetricsResource, OutcomesResource, SendfileLinksResource, type OutcomeR
|
|
|
9
16
|
export { BakesResource, type BakeClaim } from "./resources/images.js";
|
|
10
17
|
export { type UsageAnalyticsParams, type UsageMetric, type UsageGranularity, type UsageTotals, type UsageSummary, type UsageSeries, type UsageBreakdown, type UsageDimension } from "./resources/usage.js";
|
|
11
18
|
export { APIError, AuthError, RateLimitedError, QuotaExhaustedError, ScenarioNotAllowedError, BudgetExceededError, ConflictError, SyncConflictError, ApprovalStaleError, ApprovalBindingMismatchError, ApprovalConcurrentlyReopenedError, SteeringNotRunningError, SteeringInvalidContentError, PrincipalUnverifiedError, PrincipalUnboundError, ApprovalMacRequiredError, ApprovalMacInvalidError, GateNotResumableError, GateNotPlanReviewError } from "./errors.js";
|
|
19
|
+
/** E4 quota deny (pinned wire shape) — structured detail on the 429 `quota_exhausted` typed error. */
|
|
12
20
|
export type { QuotaExhaustedDetail } from "./errors.js";
|
|
21
|
+
/** 2c session-sync — the NDJSON entry-stream truncation error + the PURE §7 relation classifier (the local peer
|
|
22
|
+
* decides fast-forward/fork BEFORE pulling/pushing). */
|
|
13
23
|
export { SyncTruncatedError } from "./sse.js";
|
|
24
|
+
/** P0-2 S1 — typed heartbeat-silence watchdog error (tasks.stream / readSseFrames). Message literal is FROZEN
|
|
25
|
+
* (`SSE: no data for ${ms}ms (heartbeat silence)`); carries `elapsedMs` for the caller's idle diagnosis. */
|
|
14
26
|
export { SseIdleError } from "./sse.js";
|
|
15
27
|
export { classifySyncRelationshipByIds, pushSessionBundle, pullSessionBundle, importSessionBundle } from "./sync.js";
|
|
28
|
+
/** S2 会话搬运 — the peer-symmetric orchestration verbs over the sync primitives (push local↔cloud both ways). */
|
|
16
29
|
export type { SessionSyncPeer, PushSessionOptions, PushSessionResult, PullSessionOptions, PulledSession } from "./sync.js";
|
|
17
30
|
export { SessionSyncResource } from "./resources/session-sync.js";
|
|
18
31
|
export { SideQueryResource, type SideQueryRequest, type SideQueryResult } from "./resources/side-query.js";
|
|
19
32
|
export type { SubagentSteerReceipt, SubagentOutputResult, CompactAck, DetachAck } from "./resources/runs.js";
|
|
20
33
|
export type { SessionGetParams } from "./resources/sessions.js";
|
|
21
34
|
export type { WorkflowAgentSteerReceipt } from "./resources/workflows.js";
|
|
35
|
+
/** Control-plane (sema-registry) typed errors — distinct hierarchy from the worker APIError tree. */
|
|
22
36
|
export { ControlError, ControlAuthError, ControlForbiddenError, ControlNotFoundError, ControlValidationError, ControlConflictError, toControlError } from "./errors.js";
|
|
37
|
+
/** Control-plane wire types (sema-registry /api/config/*). */
|
|
23
38
|
export type { ConfigDomain, ControlRole, DomainRead, PutResult, BatchChange, BatchResult, ControlIssue, SchemaAll, SchemaOne, ExportResult, ConfigChange, ChangeDiff, RollbackResult, PublishedMeta, PendingPublish, PublishState, PublishResult, ApprovePublishResult, CancelPublishResult, FleetSnapshot, FleetMetrics, SchedulePlan, ScheduleApplyResult, WorkerStatuses, RollResult, RotateResult, CascadeOwnerResult, SweepResult, ControlImageEntry, ControlImageList, ImageListQuery, ImageSelectQuery, ImageSelectResolution, SecretInventory, SecretWriteResult, SecretRotateResult, SecretDeleteResult, SecretRefsResult, AuthProviderConfig, AuthProviderUpsert, AuthProvidersResult, AuthProviderUpsertResult, ControlUser, UsersResult, UserUpsertResult, UserTokenMintResult, UserTokenRevokeResult, } from "./control-types.js";
|
|
24
39
|
export { newIdempotencyKey } from "./idempotency.js";
|
|
40
|
+
/** SDK 宪法例外①②收编(免构造工具)— unauthenticated liveness probe + the single-source URL builder for the
|
|
41
|
+
* teardown fire-and-forget raw. Static on purpose: usable before/without an AgentClient. */
|
|
25
42
|
export { probeHealth, engineUrl } from "./health.js";
|
|
26
43
|
export type { EngineHealth, ProbeHealthResult } from "./health.js";
|
|
27
44
|
export type { ApprovalDecision, ApprovalStreamEvent, ApprovalExemption } from "./resources/approvals.js";
|
|
28
45
|
export type { ElicitationFrame, ElicitResponse, ElicitRespondAck } from "./resources/elicitations.js";
|
|
29
46
|
export type { QuestionFrame, AskQuestion, AskQuestionOption, QuestionAnswer, QuestionAnswerItem, QuestionRespondAck } from "./resources/questions.js";
|
|
30
47
|
export type { ToolApprovalFrame, ToolApprovalDecision, ToolApprovalRespondAck } from "./resources/tool-approvals.js";
|
|
48
|
+
/** MF-Fleet (shell-host data contract) — `client.fleet.stream()` LIVE multi-row fleet view (usage-plane;
|
|
49
|
+
* DISTINCT from the control-plane `ControlClient.fleet`). The SDK produces frames; the consumer keeps state. */
|
|
31
50
|
export { FleetResource } from "./resources/fleet.js";
|
|
32
51
|
export type { FleetTaskRow, FleetWorkflowRow, FleetTaskStatus, FleetFrame, FleetMeta, FleetBgNotification } from "./resources/fleet.js";
|
|
33
52
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,WAAW,EAAE,KAAK,iBAAiB,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AACvF;qEACqE;AACrE,OAAO,EAAE,aAAa,EAAE,KAAK,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,YAAY,EACV,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,mBAAmB,EAAE,UAAU,EACvF,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,EAAE,YAAY,EACvE,YAAY,EAAE,cAAc,EAAE,iBAAiB,EAAE,aAAa,EAAE,SAAS,EAAE,YAAY,EAAE,cAAc,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,cAAc,EAAE,WAAW,EACxL,cAAc,EAAE,eAAe,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,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mB,EAAE,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
/** @sema-agent/sdk — usage-plane SDK (the shared substrate for both doors). Server-side only. */
|
|
1
2
|
export { AgentClient } from "./client.js";
|
|
3
|
+
/** Control plane (TOB): sema-registry / config-center `/api/config/*`. A peer client (different backend +
|
|
4
|
+
* secret) for managing the fleet config — see control-client.ts. */
|
|
2
5
|
export { ControlClient } from "./control-client.js";
|
|
3
6
|
export { assertNever } from "./events.js";
|
|
7
|
+
// SDK 全覆盖批(2026-07-17,clay 令:server API 保证=server AI 直责):运维观测/烧制/用量分析面。
|
|
4
8
|
export { MetricsResource, OutcomesResource, SendfileLinksResource } from "./resources/ops.js";
|
|
5
9
|
export { BakesResource } from "./resources/images.js";
|
|
6
10
|
export { APIError, AuthError, RateLimitedError, QuotaExhaustedError, ScenarioNotAllowedError, BudgetExceededError, ConflictError, SyncConflictError, ApprovalStaleError, ApprovalBindingMismatchError, ApprovalConcurrentlyReopenedError, SteeringNotRunningError, SteeringInvalidContentError, PrincipalUnverifiedError, PrincipalUnboundError, ApprovalMacRequiredError, ApprovalMacInvalidError, GateNotResumableError, GateNotPlanReviewError } from "./errors.js";
|
|
11
|
+
/** 2c session-sync — the NDJSON entry-stream truncation error + the PURE §7 relation classifier (the local peer
|
|
12
|
+
* decides fast-forward/fork BEFORE pulling/pushing). */
|
|
7
13
|
export { SyncTruncatedError } from "./sse.js";
|
|
14
|
+
/** P0-2 S1 — typed heartbeat-silence watchdog error (tasks.stream / readSseFrames). Message literal is FROZEN
|
|
15
|
+
* (`SSE: no data for ${ms}ms (heartbeat silence)`); carries `elapsedMs` for the caller's idle diagnosis. */
|
|
8
16
|
export { SseIdleError } from "./sse.js";
|
|
9
17
|
export { classifySyncRelationshipByIds, pushSessionBundle, pullSessionBundle, importSessionBundle } from "./sync.js";
|
|
10
18
|
export { SessionSyncResource } from "./resources/session-sync.js";
|
|
11
19
|
export { SideQueryResource } from "./resources/side-query.js";
|
|
20
|
+
/** Control-plane (sema-registry) typed errors — distinct hierarchy from the worker APIError tree. */
|
|
12
21
|
export { ControlError, ControlAuthError, ControlForbiddenError, ControlNotFoundError, ControlValidationError, ControlConflictError, toControlError } from "./errors.js";
|
|
13
22
|
export { newIdempotencyKey } from "./idempotency.js";
|
|
23
|
+
/** SDK 宪法例外①②收编(免构造工具)— unauthenticated liveness probe + the single-source URL builder for the
|
|
24
|
+
* teardown fire-and-forget raw. Static on purpose: usable before/without an AgentClient. */
|
|
14
25
|
export { probeHealth, engineUrl } from "./health.js";
|
|
26
|
+
/** MF-Fleet (shell-host data contract) — `client.fleet.stream()` LIVE multi-row fleet view (usage-plane;
|
|
27
|
+
* DISTINCT from the control-plane `ControlClient.fleet`). The SDK produces frames; the consumer keeps state. */
|
|
15
28
|
export { FleetResource } from "./resources/fleet.js";
|
|
16
29
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,WAAW,EAA+C,MAAM,aAAa,CAAC;AACvF;qEACqE;AACrE,OAAO,EAAE,aAAa,EAA4B,MAAM,qBAAqB,CAAC;AAwB9E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,wEAAwE;AACxE,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,qBAAqB,EAAyC,MAAM,oBAAoB,CAAC;AACrI,OAAO,EAAE,aAAa,EAAkB,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,4BAA4B,EAAE,iCAAiC,EAAE,uBAAuB,EAAE,2BAA2B,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAGvc;yDACyD;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C;6GAC6G;AAC7G,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,6BAA6B,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAGrH,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAA+C,MAAM,2BAA2B,CAAC;AAI3G,qGAAqG;AACrG,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAaxK,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD;6FAC6F;AAC7F,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAMrD;iHACiH;AACjH,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -1,41 +1,84 @@
|
|
|
1
|
+
/** approvals — HITL (SERVICE-CORE-CONTEXT §3.4). A run `suspended` event means a human must decide: an F4
|
|
2
|
+
* policy gate (approve/deny a dangerous tool) or an AskUserQuestion (answer). LOAD-BEARING for web frontends
|
|
3
|
+
* (web-native, non-expert users authorizing/answering); also usable by door A. */
|
|
1
4
|
import type { Transport } from "../transport.js";
|
|
2
5
|
import type { PendingCheckpoint } from "../types.js";
|
|
6
|
+
/** One per-session approval exemption ("本会话不再询问", service exemptions ruling — an APPROVAL MEMORY, not a
|
|
7
|
+
* policy loosen: deny/neverAuto always outrank it). Keyed in CANONICAL tool-name space (service
|
|
8
|
+
* `ApprovalExemptionRow`, approval-exemption-store.ts). */
|
|
3
9
|
export interface ApprovalExemption {
|
|
4
10
|
toolName: string;
|
|
11
|
+
/** Principal that granted it; null = ownerless/anonymous grant. */
|
|
5
12
|
grantedBy: string | null;
|
|
13
|
+
/** Epoch MS of the FIRST grant (a re-grant refreshes grantedBy, not this). */
|
|
6
14
|
createdAt: number;
|
|
7
15
|
}
|
|
16
|
+
/** A delta event from `GET /v1/approvals/stream` (native push, service [83]). Open shape — `type` discriminates
|
|
17
|
+
* `pending` / `resolved` / `synced` (initial) / `heartbeat`; payload fields are FORWARD-DRAFT pending service's
|
|
18
|
+
* shape confirmation. A consumer that doesn't parse the delta can treat any non-heartbeat event
|
|
19
|
+
* as a "changed" signal and refetch the authoritative list (`list()`). */
|
|
8
20
|
export interface ApprovalStreamEvent {
|
|
9
21
|
type: "pending" | "resolved" | "synced" | "heartbeat" | (string & {});
|
|
10
22
|
[k: string]: unknown;
|
|
11
23
|
}
|
|
12
24
|
export interface ApprovalDecision {
|
|
13
25
|
decision: "approve" | "deny";
|
|
26
|
+
/** For AskUserQuestion: the operator's answer. Omit for a plain F4 approve/deny. */
|
|
14
27
|
answer?: unknown;
|
|
15
28
|
reason?: string;
|
|
29
|
+
/** @deprecated ASSISTANT-WIRE-CONTRACT §4a:`checkpointToken` 是 server-INTERNAL,**永不**在 `/v1/approvals`
|
|
30
|
+
* 记录上 surface(server 自按 sessionId 解析);合规 client **只发 boundCallId+boundInputHash 两件套**,绝不注入
|
|
31
|
+
* checkpointToken(可选 checkpointToken→409 approval_stale 是 deprecated legacy 路径)。字段保留仅为向后兼容编译,
|
|
32
|
+
* 不应再有来源填它(SDK 富 PendingCheckpoint 已无此字段)。 */
|
|
16
33
|
checkpointToken?: string;
|
|
34
|
+
/** design/80 D-1 — action binding (TOCTOU guard). Read these TWO off the `PendingCheckpoint` the human saw
|
|
35
|
+
* and pass them back VERBATIM; the server resolves THIS exact checkpoint, fail-closed on mismatch
|
|
36
|
+
* (→ `ApprovalBindingMismatchError`). Omit only against a pre-D-1 worker (legacy resolve-by-sessionId).
|
|
37
|
+
* = `toolCallId` of the action the human saw (the bound call). */
|
|
17
38
|
boundCallId?: string;
|
|
39
|
+
/** Echo `PendingCheckpoint.boundInputHash` byte-for-byte — opaque, NEVER hashed/recomputed on the client. */
|
|
18
40
|
boundInputHash?: string;
|
|
41
|
+
/** Approve-with-edit (design/37 last-wins): the operator's rewritten tool args, applied AFTER the binding
|
|
42
|
+
* check. `boundInputHash` STILL binds the ORIGINAL input the human saw — never hash `updatedInput`. */
|
|
19
43
|
updatedInput?: unknown;
|
|
20
44
|
}
|
|
21
45
|
export declare class ApprovalsResource {
|
|
22
46
|
private readonly t;
|
|
23
47
|
constructor(t: Transport);
|
|
48
|
+
/** GET /v1/approvals/:id — 按 id 读单条 durable 审批(server.ts:4342 实拆)。行含完整 tool-call args
|
|
49
|
+
* (高危操作的命令/路径/内容)——owner 边界与列表面同门:operator 跨租户,其余只读本人(非本人=404
|
|
50
|
+
* 无存在性 oracle)。 */
|
|
24
51
|
get(id: string, opts?: {
|
|
25
52
|
signal?: AbortSignal;
|
|
26
53
|
}): Promise<Record<string, unknown>>;
|
|
54
|
+
/** GET /v1/approvals — pending checkpoints (operator-scoped; envelope key `pending`).
|
|
55
|
+
* NEVER returns the capability token. ⚠️ item createdAt/deadline are epoch MS. */
|
|
27
56
|
list(opts?: {
|
|
28
57
|
signal?: AbortSignal;
|
|
29
58
|
}): Promise<PendingCheckpoint[]>;
|
|
59
|
+
/** POST /v1/approvals/:sessionId/decide — resolve a suspend; the resumed run continues its stream.
|
|
60
|
+
* Not a submit → no SDK retry (a decide must not double-act). */
|
|
30
61
|
decide(sessionId: string, decision: ApprovalDecision, opts?: {
|
|
31
62
|
signal?: AbortSignal;
|
|
32
63
|
}): Promise<unknown>;
|
|
64
|
+
/** GET /v1/approvals/:sessionId/exemptions — the session's granted "don't ask again" exemptions (* contract; envelope key `exemptions`). OWNER-GATED with a 404 (no existence oracle): non-owner AND unknown
|
|
65
|
+
* session both 404. A worker without an exemption store backend → 501. */
|
|
33
66
|
listExemptions(sessionId: string, opts?: {
|
|
34
67
|
signal?: AbortSignal;
|
|
35
68
|
}): Promise<ApprovalExemption[]>;
|
|
69
|
+
/** DELETE /v1/approvals/:sessionId/exemptions/:toolName — revoke ONE exemption (the tool asks again).
|
|
70
|
+
* contract. Idempotent at the SDK surface: `true` = revoked; `false` = the service 404'd — nothing to revoke
|
|
71
|
+
* OR not-owner/unknown session (deliberately indistinguishable, no existence oracle). `toolName` should be the
|
|
72
|
+
* canonical name off {@link ApprovalExemption.toolName} (the service canonicalizes, but echo what you listed). */
|
|
36
73
|
revokeExemption(sessionId: string, toolName: string, opts?: {
|
|
37
74
|
signal?: AbortSignal;
|
|
38
75
|
}): Promise<boolean>;
|
|
76
|
+
/** GET /v1/approvals/stream — native push (SSE delta, meta `mode:"approvals-delta"`, service [83]). Replaces
|
|
77
|
+
* BFF-side polling of `list()`. LONG-LIVED + operator-scoped: there is NO terminal event — this reconnects on
|
|
78
|
+
* drops / heartbeat-silence and tails on (uses `readSseFrames`, NOT `parseSse`, which would end on done/failed).
|
|
79
|
+
* A non-`ok` first response (e.g. 404 on a worker without the endpoint) throws → caller falls back to polling.
|
|
80
|
+
* FORWARD-DRAFT: event payloads pending service confirmation — consumers refetch `list()` on
|
|
81
|
+
* any non-heartbeat event rather than trusting an unconfirmed delta shape. */
|
|
39
82
|
stream(opts?: {
|
|
40
83
|
signal?: AbortSignal;
|
|
41
84
|
}): AsyncGenerator<ApprovalStreamEvent>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvals.d.ts","sourceRoot":"","sources":["../../src/resources/approvals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"approvals.d.ts","sourceRoot":"","sources":["../../src/resources/approvals.ts"],"names":[],"mappings":"AAAA;;mFAEmF;AACnF,OAAO,KAAK,EAAE,SAAS,EAA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KzE;sEACkE;IAC5D,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAS9G;+EAC2E;IACrE,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAStG;;;uHAGmH;IAC7G,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAc7G;;;;;mFAK+E;IACxE,MAAM,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,cAAc,CAAC,mBAAmB,CAAC;CA8BpF"}
|
|
@@ -5,13 +5,20 @@ export class ApprovalsResource {
|
|
|
5
5
|
constructor(t) {
|
|
6
6
|
this.t = t;
|
|
7
7
|
}
|
|
8
|
+
/** GET /v1/approvals/:id — 按 id 读单条 durable 审批(server.ts:4342 实拆)。行含完整 tool-call args
|
|
9
|
+
* (高危操作的命令/路径/内容)——owner 边界与列表面同门:operator 跨租户,其余只读本人(非本人=404
|
|
10
|
+
* 无存在性 oracle)。 */
|
|
8
11
|
async get(id, opts) {
|
|
9
12
|
return this.t.request({ method: "GET", path: `/v1/approvals/${encodeURIComponent(id)}`, signal: opts?.signal });
|
|
10
13
|
}
|
|
14
|
+
/** GET /v1/approvals — pending checkpoints (operator-scoped; envelope key `pending`).
|
|
15
|
+
* NEVER returns the capability token. ⚠️ item createdAt/deadline are epoch MS. */
|
|
11
16
|
async list(opts) {
|
|
12
17
|
const r = await this.t.request({ method: "GET", path: "/v1/approvals", signal: opts?.signal });
|
|
13
18
|
return r.pending;
|
|
14
19
|
}
|
|
20
|
+
/** POST /v1/approvals/:sessionId/decide — resolve a suspend; the resumed run continues its stream.
|
|
21
|
+
* Not a submit → no SDK retry (a decide must not double-act). */
|
|
15
22
|
async decide(sessionId, decision, opts) {
|
|
16
23
|
return this.t.request({
|
|
17
24
|
method: "POST",
|
|
@@ -20,6 +27,8 @@ export class ApprovalsResource {
|
|
|
20
27
|
signal: opts?.signal,
|
|
21
28
|
});
|
|
22
29
|
}
|
|
30
|
+
/** GET /v1/approvals/:sessionId/exemptions — the session's granted "don't ask again" exemptions (* contract; envelope key `exemptions`). OWNER-GATED with a 404 (no existence oracle): non-owner AND unknown
|
|
31
|
+
* session both 404. A worker without an exemption store backend → 501. */
|
|
23
32
|
async listExemptions(sessionId, opts) {
|
|
24
33
|
const r = await this.t.request({
|
|
25
34
|
method: "GET",
|
|
@@ -28,6 +37,10 @@ export class ApprovalsResource {
|
|
|
28
37
|
});
|
|
29
38
|
return r.exemptions;
|
|
30
39
|
}
|
|
40
|
+
/** DELETE /v1/approvals/:sessionId/exemptions/:toolName — revoke ONE exemption (the tool asks again).
|
|
41
|
+
* contract. Idempotent at the SDK surface: `true` = revoked; `false` = the service 404'd — nothing to revoke
|
|
42
|
+
* OR not-owner/unknown session (deliberately indistinguishable, no existence oracle). `toolName` should be the
|
|
43
|
+
* canonical name off {@link ApprovalExemption.toolName} (the service canonicalizes, but echo what you listed). */
|
|
31
44
|
async revokeExemption(sessionId, toolName, opts) {
|
|
32
45
|
try {
|
|
33
46
|
await this.t.request({
|
|
@@ -43,6 +56,12 @@ export class ApprovalsResource {
|
|
|
43
56
|
throw e;
|
|
44
57
|
}
|
|
45
58
|
}
|
|
59
|
+
/** GET /v1/approvals/stream — native push (SSE delta, meta `mode:"approvals-delta"`, service [83]). Replaces
|
|
60
|
+
* BFF-side polling of `list()`. LONG-LIVED + operator-scoped: there is NO terminal event — this reconnects on
|
|
61
|
+
* drops / heartbeat-silence and tails on (uses `readSseFrames`, NOT `parseSse`, which would end on done/failed).
|
|
62
|
+
* A non-`ok` first response (e.g. 404 on a worker without the endpoint) throws → caller falls back to polling.
|
|
63
|
+
* FORWARD-DRAFT: event payloads pending service confirmation — consumers refetch `list()` on
|
|
64
|
+
* any non-heartbeat event rather than trusting an unconfirmed delta shape. */
|
|
46
65
|
async *stream(opts) {
|
|
47
66
|
let failures = 0;
|
|
48
67
|
for (;;) {
|
|
@@ -62,16 +81,17 @@ export class ApprovalsResource {
|
|
|
62
81
|
continue;
|
|
63
82
|
}
|
|
64
83
|
if (!res.ok)
|
|
65
|
-
throw toApiError(res.status, await res.json().catch(() => ({})));
|
|
84
|
+
throw toApiError(res.status, await res.json().catch(() => ({}))); // 404/4xx → caller polls
|
|
66
85
|
try {
|
|
67
86
|
for await (const frame of readSseFrames(res, HEARTBEAT_GRACE_MS, opts?.signal)) {
|
|
68
|
-
failures = 0;
|
|
87
|
+
failures = 0; // a frame arrived = progress
|
|
69
88
|
if (!frame.data)
|
|
70
|
-
continue;
|
|
89
|
+
continue; // heartbeat comment
|
|
71
90
|
yield JSON.parse(frame.data);
|
|
72
91
|
}
|
|
73
92
|
}
|
|
74
93
|
catch {
|
|
94
|
+
// mid-stream drop or heartbeat silence → reconnect (long-lived stream has no terminal event)
|
|
75
95
|
}
|
|
76
96
|
finally {
|
|
77
97
|
res.body?.cancel().catch(() => { });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"approvals.js","sourceRoot":"","sources":["../../src/resources/approvals.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA4CpD,MAAM,OAAO,iBAAiB;IACC;IAA7B,YAA6B,CAAY;QAAZ,MAAC,GAAD,CAAC,CAAW;IAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"approvals.js","sourceRoot":"","sources":["../../src/resources/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AE,MAAM,CAAC,CAAC;gBAC7B,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC;gBACxD,SAAS;YACX,CAAC;YACD,IAAI,CAAC,GAAG,CAAC,EAAE;gBAAE,MAAM,UAAU,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,yBAAyB;YACxG,IAAI,CAAC;gBACH,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,aAAa,CAAC,GAAG,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;oBAC/E,QAAQ,GAAG,CAAC,CAAC,CAAC,6BAA6B;oBAC3C,IAAI,CAAC,KAAK,CAAC,IAAI;wBAAE,SAAS,CAAC,oBAAoB;oBAC/C,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAwB,CAAC;gBACtD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,6FAA6F;YAC/F,CAAC;oBAAS,CAAC;gBACT,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;YACrC,CAAC;YACD,IAAI,IAAI,EAAE,MAAM,EAAE,OAAO;gBAAE,OAAO;YAClC,IAAI,EAAE,QAAQ,IAAI,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;QACjG,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,21 +1,44 @@
|
|
|
1
|
+
/** assistant — assistant-scheduler + HITL 决策面(ASSISTANT-WIRE-CONTRACT.md, service main 6cd0164 /
|
|
2
|
+
* core 1.110.0, LIVE on worker)。解锁 CLI 的 severity inbox(N2) / 总览抢占(N4) / plan_review(N3)。
|
|
3
|
+
*
|
|
4
|
+
* 🔴 拓扑铁律: CLI/web 前端 → BFF /api/* → `sdk(principal).assistant.*` → worker(worker token 留 BFF)。
|
|
5
|
+
* SDK 服务端用, 不进浏览器/CLI。withPrincipal 自动重建本 resource —— BFF 的 sdk(principal).assistant.* 天然成立。
|
|
6
|
+
*
|
|
7
|
+
* 🔴 D-G 边界(§6): 这 5 个 verb **不需要**签名证明 —— 走 owner 门(principal header, transport 已注入 x-agent-principal)。
|
|
8
|
+
* 只 /decide 要签名(approvals.decide + BFF 签, 不在本 resource)。owner 非属 → 404(无存在性 oracle)不是 403。 */
|
|
1
9
|
import type { Transport } from "../transport.js";
|
|
2
10
|
import type { InboxRow, AssistantTask, PlanReviewRequest, AssistantTaskStatus } from "../types.js";
|
|
3
11
|
export declare class AssistantResource {
|
|
4
12
|
private readonly t;
|
|
5
13
|
constructor(t: Transport);
|
|
14
|
+
/** §2 GET /v1/assistant/inbox —— 单一 severity-sorted inbox(每用户视图)。operator 可用 `?owner=` 看某 owner,
|
|
15
|
+
* 否则看自己。返回行已由 core listPending 按 severity 排序 —— 消费方**不要再排**(且须容 undefined severity)。
|
|
16
|
+
* 解包 envelope `{inbox:[...]}`。owner query 在此手拼(transport.request 的 path 是裸串直拼, 无 query helper)。 */
|
|
6
17
|
inbox(opts?: {
|
|
7
18
|
owner?: string;
|
|
8
19
|
signal?: AbortSignal;
|
|
9
20
|
}): Promise<InboxRow[]>;
|
|
21
|
+
/** §3 GET /v1/assistant/tasks —— N-task 调度总览(每用户跨任务视图)。Triage 序由 core 给定(needsAttention 优先,
|
|
22
|
+
* 再 severity DESC, 再 spend DESC)—— **不要再排**。需 TiDB run store, 否则 worker 回 `{tasks:[]}`(原样透传)。 */
|
|
10
23
|
tasks(opts?: {
|
|
11
24
|
signal?: AbortSignal;
|
|
12
25
|
}): Promise<AssistantTask[]>;
|
|
26
|
+
/** §4b POST /v1/assistant/tasks/:id/resume(:id = taskId)—— resource_limit CONTINUE。**无 body**。
|
|
27
|
+
* 非 submit → 不重试(一次决策不重放)。🔴 GATE-KIND GUARD: human/policy_ask 门 → 409 gate_not_resumable
|
|
28
|
+
* ("continue" 绝不绕过人审, 那条路是 /decide)。owner 非属 → 404。 */
|
|
13
29
|
resume(taskId: string, opts?: {
|
|
14
30
|
signal?: AbortSignal;
|
|
15
31
|
}): Promise<AssistantTaskStatus>;
|
|
32
|
+
/** §4c POST /v1/assistant/tasks/:id/plan_review(:id = taskId)—— PRE-ACTION plan_review 门的 3-state 决策。
|
|
33
|
+
* body = {decision, editedPlan?, reason?}。approve/edit/reject 全跑模型 → 计费。非 submit → 不重试。
|
|
34
|
+
* 🔴 GATE-KIND GUARD: 非 plan_review 门 → 409 gate_not_plan_review。400: 坏/缺 decision; edit 缺非空 editedPlan;
|
|
35
|
+
* approve/reject 带 editedPlan; reason 非串。owner 非属 → 404。 */
|
|
16
36
|
planReview(taskId: string, req: PlanReviewRequest, opts?: {
|
|
17
37
|
signal?: AbortSignal;
|
|
18
38
|
}): Promise<AssistantTaskStatus>;
|
|
39
|
+
/** §4d POST /v1/assistant/tasks/:id/preempt(:id = taskId)—— 优雅 YIELD(跨副本让位, 与 runs.cancel 的 kill 相反)。
|
|
40
|
+
* **无 body**。202 {status}(terminal → 202 no-op)。非 submit → 不重试。NOT billable。
|
|
41
|
+
* suspended → 409; RESOURCE_SUSPEND off → 501; owner 非属 → 404。 */
|
|
19
42
|
preempt(taskId: string, opts?: {
|
|
20
43
|
signal?: AbortSignal;
|
|
21
44
|
}): Promise<AssistantTaskStatus>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"assistant.d.ts","sourceRoot":"","sources":["../../src/resources/assistant.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"assistant.d.ts","sourceRoot":"","sources":["../../src/resources/assistant.ts"],"names":[],"mappings":"AAAA;;;;;;;+FAO+F;AAC/F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAiB,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAyBlH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,QAAQ,CAAC,CAAC;gBAAD,CAAC,EAAE,SAAS;IAEzC;;wGAEoG;IAC9F,KAAK,CAAC,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;IAiBjF;sGACkG;IAC5F,KAAK,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAYtE;;4DAEwD;IAClD,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAQ3F;;;iEAG6D;IACvD,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,iBAAiB,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;IASvH;;uEAEmE;IAC7D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,mBAAmB,CAAC;CAO7F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** 折 null → OMIT(条件 spread,绝不写显式 undefined;exactOptionalPropertyTypes)。 */
|
|
1
2
|
function normalizeGate(g) {
|
|
2
3
|
return {
|
|
3
4
|
kind: g.kind,
|
|
@@ -14,6 +15,9 @@ export class AssistantResource {
|
|
|
14
15
|
constructor(t) {
|
|
15
16
|
this.t = t;
|
|
16
17
|
}
|
|
18
|
+
/** §2 GET /v1/assistant/inbox —— 单一 severity-sorted inbox(每用户视图)。operator 可用 `?owner=` 看某 owner,
|
|
19
|
+
* 否则看自己。返回行已由 core listPending 按 severity 排序 —— 消费方**不要再排**(且须容 undefined severity)。
|
|
20
|
+
* 解包 envelope `{inbox:[...]}`。owner query 在此手拼(transport.request 的 path 是裸串直拼, 无 query helper)。 */
|
|
17
21
|
async inbox(opts) {
|
|
18
22
|
const q = opts?.owner ? `?owner=${encodeURIComponent(opts.owner)}` : "";
|
|
19
23
|
const r = await this.t.request({
|
|
@@ -21,11 +25,19 @@ export class AssistantResource {
|
|
|
21
25
|
path: `/v1/assistant/inbox${q}`,
|
|
22
26
|
signal: opts?.signal,
|
|
23
27
|
});
|
|
28
|
+
// 🔴 severity 归一:部署的 worker 把 severity 放 riskDescriptor.severity(非顶层标量,违文档;
|
|
29
|
+
// server.ts:1414 inbox handler 直接 spread listPending() 未走 summarizeCheckpoint)。优先顶层标量(文档/未来态),
|
|
30
|
+
// 缺则回退 riskDescriptor.severity(当前 live 态)。service 修 handler 后顶层自动接管,前向兼容。
|
|
24
31
|
return r.inbox.map((row) => row.severity == null && row.riskDescriptor?.severity != null
|
|
25
32
|
? { ...row, severity: row.riskDescriptor.severity }
|
|
26
33
|
: row);
|
|
27
34
|
}
|
|
35
|
+
/** §3 GET /v1/assistant/tasks —— N-task 调度总览(每用户跨任务视图)。Triage 序由 core 给定(needsAttention 优先,
|
|
36
|
+
* 再 severity DESC, 再 spend DESC)—— **不要再排**。需 TiDB run store, 否则 worker 回 `{tasks:[]}`(原样透传)。 */
|
|
28
37
|
async tasks(opts) {
|
|
38
|
+
// wire gate 的 severity/spentMicroUsd/deadline 形如 `4 | null`(§3),但 AssistantGate 把它们规约为 `?:number`
|
|
39
|
+
// (缺/null 都容忍, OMIT 优先)。这里把 null 折成 OMIT —— 否则 raw 透传会把 wire 的 null 漏进 `?:number` 字段,
|
|
40
|
+
// 违反 exactOptionalPropertyTypes 的契约(消费方按 `number | undefined` 用,绝不该见 null)。
|
|
29
41
|
const r = await this.t.request({
|
|
30
42
|
method: "GET",
|
|
31
43
|
path: "/v1/assistant/tasks",
|
|
@@ -33,6 +45,9 @@ export class AssistantResource {
|
|
|
33
45
|
});
|
|
34
46
|
return r.tasks.map((t) => normalizeTask(t));
|
|
35
47
|
}
|
|
48
|
+
/** §4b POST /v1/assistant/tasks/:id/resume(:id = taskId)—— resource_limit CONTINUE。**无 body**。
|
|
49
|
+
* 非 submit → 不重试(一次决策不重放)。🔴 GATE-KIND GUARD: human/policy_ask 门 → 409 gate_not_resumable
|
|
50
|
+
* ("continue" 绝不绕过人审, 那条路是 /decide)。owner 非属 → 404。 */
|
|
36
51
|
async resume(taskId, opts) {
|
|
37
52
|
return this.t.request({
|
|
38
53
|
method: "POST",
|
|
@@ -40,6 +55,10 @@ export class AssistantResource {
|
|
|
40
55
|
signal: opts?.signal,
|
|
41
56
|
});
|
|
42
57
|
}
|
|
58
|
+
/** §4c POST /v1/assistant/tasks/:id/plan_review(:id = taskId)—— PRE-ACTION plan_review 门的 3-state 决策。
|
|
59
|
+
* body = {decision, editedPlan?, reason?}。approve/edit/reject 全跑模型 → 计费。非 submit → 不重试。
|
|
60
|
+
* 🔴 GATE-KIND GUARD: 非 plan_review 门 → 409 gate_not_plan_review。400: 坏/缺 decision; edit 缺非空 editedPlan;
|
|
61
|
+
* approve/reject 带 editedPlan; reason 非串。owner 非属 → 404。 */
|
|
43
62
|
async planReview(taskId, req, opts) {
|
|
44
63
|
return this.t.request({
|
|
45
64
|
method: "POST",
|
|
@@ -48,6 +67,9 @@ export class AssistantResource {
|
|
|
48
67
|
signal: opts?.signal,
|
|
49
68
|
});
|
|
50
69
|
}
|
|
70
|
+
/** §4d POST /v1/assistant/tasks/:id/preempt(:id = taskId)—— 优雅 YIELD(跨副本让位, 与 runs.cancel 的 kill 相反)。
|
|
71
|
+
* **无 body**。202 {status}(terminal → 202 no-op)。非 submit → 不重试。NOT billable。
|
|
72
|
+
* suspended → 409; RESOURCE_SUSPEND off → 501; owner 非属 → 404。 */
|
|
51
73
|
async preempt(taskId, opts) {
|
|
52
74
|
return this.t.request({
|
|
53
75
|
method: "POST",
|