scoped-execution-protocol 0.0.0-stage → 2.0.0-rc.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SXP Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/apps.d.ts ADDED
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Native Agent-to-App Connector primitives for SXP (Scoped Execution Protocol) v0.2.
3
+ * - Progressive App Discovery (L0/L1/L2 manifest REF handle)
4
+ * - URI-Addressed Resources + live change notifications (AssumptionLease invalidation)
5
+ * - Mid-call ElicitationNeeded pause for OAuth consent, 2FA, or disambiguation
6
+ * - Edge-resolved scoped CredentialVault (secrets never enter prompts or envelopes)
7
+ */
8
+ import { type CapabilityToken, type Clearance, type DataPolicy, type EffectClass } from "./types.js";
9
+ import { ResultProjection } from "./policy.js";
10
+ export declare class ElicitationNeeded extends Error {
11
+ readonly kind: "disambiguate" | "consent" | "2fa" | "input";
12
+ readonly inputSchema: Record<string, unknown>;
13
+ constructor(prompt: string, opts?: {
14
+ kind?: "disambiguate" | "consent" | "2fa" | "input";
15
+ inputSchema?: Record<string, unknown>;
16
+ });
17
+ }
18
+ export interface AppActionConfig {
19
+ name: string;
20
+ fn: (args: Record<string, unknown>, credential?: unknown) => unknown | Promise<unknown>;
21
+ description?: string;
22
+ effect?: EffectClass;
23
+ inputSchema?: Record<string, unknown>;
24
+ untrusted?: boolean;
25
+ requiresHumanApproval?: boolean;
26
+ requiredScopes?: string[];
27
+ stateSnapshot?: (args: Record<string, unknown>) => unknown;
28
+ outputPolicy?: DataPolicy;
29
+ metadataPolicy?: DataPolicy;
30
+ sinkClearance?: Clearance;
31
+ externalEgress?: boolean;
32
+ resultProjection?: ResultProjection;
33
+ previewRequiresEffect?: boolean;
34
+ }
35
+ export interface AppResourceConfig {
36
+ uri: string;
37
+ readFn: () => unknown | Promise<unknown>;
38
+ description?: string;
39
+ mimeType?: string;
40
+ untrusted?: boolean;
41
+ subscribable?: boolean;
42
+ requiredScopes?: string[];
43
+ dataPolicy?: DataPolicy;
44
+ }
45
+ export declare class AppConnector {
46
+ readonly appId: string;
47
+ readonly summary: string;
48
+ readonly version: string;
49
+ readonly untrusted: boolean;
50
+ /** Opt in for a server whose tool descriptions must be treated as untrusted data when the model reads them. */
51
+ readonly taintOnCatalogRead: boolean;
52
+ readonly actions: Map<string, AppActionConfig>;
53
+ readonly resources: Map<string, AppResourceConfig>;
54
+ private observers;
55
+ constructor(appId: string, opts?: {
56
+ summary?: string;
57
+ version?: string;
58
+ untrusted?: boolean;
59
+ taintOnCatalogRead?: boolean;
60
+ });
61
+ action(cfg: AppActionConfig): this;
62
+ resource(cfg: AppResourceConfig): this;
63
+ maxEffect(): EffectClass;
64
+ l0CatalogSummary(): string;
65
+ manifestL1(): Record<string, unknown>;
66
+ manifestL2(): Record<string, unknown>;
67
+ onResourceChanged(fn: (uri: string, newValue: unknown) => void): void;
68
+ notifyResourceChanged(uri: string, newValue: unknown): void;
69
+ }
70
+ /** Host callback that fetches or refreshes a token at call time. It supplies token material, never authority. */
71
+ export type TokenProvider = (subject: string, target: string, scopes: string[]) => unknown | Promise<unknown>;
72
+ export declare class CredentialVault {
73
+ private entries;
74
+ /** Consulted after the taint, credential_ref and capability-scope gates, so it cannot widen a capability. */
75
+ tokenProvider?: TokenProvider;
76
+ constructor(opts?: {
77
+ tokenProvider?: TokenProvider;
78
+ });
79
+ /** Resolve the credential for one call, using `tokenProvider` when one is set. */
80
+ resolve(cap: CapabilityToken, appId: string, requiredScopes: string[], target: string, nowMs?: number): Promise<unknown>;
81
+ register(credentialRef: string, secretMaterial: unknown, opts?: {
82
+ allowedApps?: string[];
83
+ allowedScopes?: string[];
84
+ expiresAtMs?: number | null;
85
+ }): void;
86
+ revoke(credentialRef: string): void;
87
+ resolveForTransport(cap: CapabilityToken, appId: string, requiredScopes?: string[], nowMs?: number): unknown;
88
+ activeSecretStrings(): string[];
89
+ scrubSecrets(value: unknown, credential?: unknown): unknown;
90
+ }
package/dist/apps.js ADDED
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Native Agent-to-App Connector primitives for SXP (Scoped Execution Protocol) v0.2.
3
+ * - Progressive App Discovery (L0/L1/L2 manifest REF handle)
4
+ * - URI-Addressed Resources + live change notifications (AssumptionLease invalidation)
5
+ * - Mid-call ElicitationNeeded pause for OAuth consent, 2FA, or disambiguation
6
+ * - Edge-resolved scoped CredentialVault (secrets never enter prompts or envelopes)
7
+ */
8
+ import { AuthRequiredError, EFFECT_RANK, InsufficientScopeError, SXPError } from "./types.js";
9
+ import { ResultProjection } from "./policy.js";
10
+ export class ElicitationNeeded extends Error {
11
+ kind;
12
+ inputSchema;
13
+ constructor(prompt, opts) {
14
+ super(prompt);
15
+ this.kind = opts?.kind ?? "input";
16
+ this.inputSchema = opts?.inputSchema ?? {};
17
+ }
18
+ }
19
+ export class AppConnector {
20
+ appId;
21
+ summary;
22
+ version;
23
+ untrusted;
24
+ /** Opt in for a server whose tool descriptions must be treated as untrusted data when the model reads them. */
25
+ taintOnCatalogRead;
26
+ actions = new Map();
27
+ resources = new Map();
28
+ observers = [];
29
+ constructor(appId, opts) {
30
+ this.taintOnCatalogRead = opts?.taintOnCatalogRead === true;
31
+ this.appId = appId;
32
+ this.summary = opts?.summary ?? `SXP app '${appId}'`;
33
+ this.version = opts?.version ?? "0.2.0";
34
+ this.untrusted = opts?.untrusted ?? true;
35
+ }
36
+ action(cfg) {
37
+ if (cfg.resultProjection !== undefined && !(cfg.resultProjection instanceof ResultProjection)) {
38
+ throw new TypeError("Expected a compiled ResultProjection.");
39
+ }
40
+ this.actions.set(cfg.name, { effect: "read", untrusted: this.untrusted, ...cfg });
41
+ return this;
42
+ }
43
+ resource(cfg) {
44
+ this.resources.set(cfg.uri, { mimeType: "application/json", untrusted: this.untrusted, subscribable: true, ...cfg });
45
+ return this;
46
+ }
47
+ maxEffect() {
48
+ let best = "read";
49
+ for (const a of this.actions.values()) {
50
+ const e = a.effect ?? "read";
51
+ if (EFFECT_RANK[e] > EFFECT_RANK[best])
52
+ best = e;
53
+ }
54
+ return best;
55
+ }
56
+ l0CatalogSummary() {
57
+ return `app:${this.appId} v${this.version} (${this.actions.size} actions, ${this.resources.size} resources | max_effect: ${this.maxEffect()}) — ${this.summary}`;
58
+ }
59
+ manifestL1() {
60
+ return {
61
+ app_id: this.appId,
62
+ version: this.version,
63
+ summary: this.summary,
64
+ max_effect: this.maxEffect(),
65
+ actions: [...this.actions.values()].map((action) => {
66
+ const required = action.inputSchema?.required;
67
+ const hasRequiredArgs = Array.isArray(required) && required.length > 0 && required.every((name) => typeof name === "string");
68
+ return {
69
+ target: `${this.appId}.${action.name}`,
70
+ effect: action.effect ?? "read",
71
+ requires_human_approval: Boolean(action.requiresHumanApproval),
72
+ required_scopes: action.requiredScopes ?? [],
73
+ description: action.description ?? "",
74
+ ...(hasRequiredArgs ? { required_args: [...required] } : {}),
75
+ };
76
+ }),
77
+ resources: [...this.resources.values()].map((r) => ({
78
+ uri: r.uri,
79
+ mime_type: r.mimeType ?? "application/json",
80
+ subscribable: r.subscribable ?? true,
81
+ description: r.description ?? "",
82
+ })),
83
+ };
84
+ }
85
+ manifestL2() {
86
+ const actions = {};
87
+ for (const a of this.actions.values()) {
88
+ actions[`${this.appId}.${a.name}`] = {
89
+ effect: a.effect ?? "read",
90
+ requires_human_approval: Boolean(a.requiresHumanApproval),
91
+ required_scopes: a.requiredScopes ?? [],
92
+ description: a.description ?? "",
93
+ input_schema: a.inputSchema ?? { type: "object" },
94
+ };
95
+ }
96
+ const resources = {};
97
+ for (const r of this.resources.values()) {
98
+ resources[r.uri] = {
99
+ mime_type: r.mimeType ?? "application/json",
100
+ subscribable: r.subscribable ?? true,
101
+ required_scopes: r.requiredScopes ?? [],
102
+ description: r.description ?? "",
103
+ };
104
+ }
105
+ return { app_id: this.appId, version: this.version, summary: this.summary, max_effect: this.maxEffect(), actions, resources };
106
+ }
107
+ onResourceChanged(fn) {
108
+ this.observers.push(fn);
109
+ }
110
+ notifyResourceChanged(uri, newValue) {
111
+ for (const fn of this.observers)
112
+ fn(uri, newValue);
113
+ }
114
+ }
115
+ export class CredentialVault {
116
+ entries = new Map();
117
+ /** Consulted after the taint, credential_ref and capability-scope gates, so it cannot widen a capability. */
118
+ tokenProvider;
119
+ constructor(opts) {
120
+ this.tokenProvider = opts?.tokenProvider;
121
+ }
122
+ /** Resolve the credential for one call, using `tokenProvider` when one is set. */
123
+ async resolve(cap, appId, requiredScopes, target, nowMs = Date.now()) {
124
+ const provider = this.tokenProvider;
125
+ if (!provider)
126
+ return this.resolveForTransport(cap, appId, requiredScopes, nowMs);
127
+ const scopes = [...new Set(requiredScopes)].sort();
128
+ if (cap.taint === "untrusted_data") {
129
+ throw new SXPError("CAPABILITY_ESCALATION", `Tainted branch cannot access credentials for '${appId}'.`);
130
+ }
131
+ if (!cap.credential_ref) {
132
+ throw new SXPError("CAPABILITY_ESCALATION", `App '${appId}' requires credentials, but capability has no credential_ref.`);
133
+ }
134
+ const held = new Set(cap.credential_scopes ?? []);
135
+ if (!held.has("*")) {
136
+ const missing = scopes.filter((scope) => !held.has(scope));
137
+ if (missing.length)
138
+ throw new SXPError("CAPABILITY_ESCALATION", `Capability lacks required credential_scope '${missing[0]}'.`);
139
+ }
140
+ let token;
141
+ try {
142
+ token = await provider(cap.subject, target, scopes);
143
+ }
144
+ catch (err) {
145
+ // Provider messages can embed the token it just handled, so keep only the typed scope metadata.
146
+ const hinted = err instanceof AuthRequiredError || err instanceof InsufficientScopeError ? err.requiredScopes : scopes;
147
+ if (err instanceof InsufficientScopeError)
148
+ throw new InsufficientScopeError(`The credential for '${target}' lacks required scopes.`, hinted.length ? hinted : scopes, { target });
149
+ throw new AuthRequiredError(`No credential is available for '${target}'.`, hinted.length ? hinted : scopes, { target });
150
+ }
151
+ if (token === undefined || token === null || token === "" || (typeof token === "object" && Object.keys(token).length === 0)) {
152
+ throw new AuthRequiredError(`No credential is available for '${target}'.`, scopes, { target });
153
+ }
154
+ return token;
155
+ }
156
+ register(credentialRef, secretMaterial, opts) {
157
+ this.entries.set(credentialRef, {
158
+ secretMaterial,
159
+ allowedApps: new Set(opts?.allowedApps ?? ["*"]),
160
+ allowedScopes: new Set(opts?.allowedScopes ?? ["*"]),
161
+ expiresAtMs: opts?.expiresAtMs ?? null,
162
+ });
163
+ }
164
+ revoke(credentialRef) {
165
+ this.entries.delete(credentialRef);
166
+ }
167
+ resolveForTransport(cap, appId, requiredScopes = [], nowMs = Date.now()) {
168
+ if (cap.taint === "untrusted_data") {
169
+ throw new SXPError("CAPABILITY_ESCALATION", `Tainted branch cannot access credentials for '${appId}'.`);
170
+ }
171
+ if (!cap.credential_ref) {
172
+ throw new SXPError("CAPABILITY_ESCALATION", `App '${appId}' requires credentials, but capability has no credential_ref.`);
173
+ }
174
+ const entry = this.entries.get(cap.credential_ref);
175
+ if (!entry)
176
+ throw new SXPError("CAPABILITY_ESCALATION", `Credential ref '${cap.credential_ref}' not found or revoked.`);
177
+ if (entry.expiresAtMs !== null && nowMs > entry.expiresAtMs) {
178
+ throw new SXPError("CAPABILITY_ESCALATION", `Credential ref '${cap.credential_ref}' expired.`);
179
+ }
180
+ if (!entry.allowedApps.has("*") && !entry.allowedApps.has(appId)) {
181
+ throw new SXPError("CAPABILITY_ESCALATION", `Credential ref not authorized for app '${appId}'.`);
182
+ }
183
+ const capScopes = new Set(cap.credential_scopes ?? []);
184
+ for (const sc of requiredScopes) {
185
+ if (!entry.allowedScopes.has("*") && !entry.allowedScopes.has(sc)) {
186
+ throw new SXPError("CAPABILITY_ESCALATION", `Vault credential lacks required scope '${sc}'.`);
187
+ }
188
+ if (!capScopes.has("*") && !capScopes.has(sc)) {
189
+ throw new SXPError("CAPABILITY_ESCALATION", `Capability lacks required credential_scope '${sc}'.`);
190
+ }
191
+ }
192
+ return entry.secretMaterial;
193
+ }
194
+ activeSecretStrings() {
195
+ const out = [];
196
+ const collect = (val) => {
197
+ if (typeof val === "string" && val.length >= 6) {
198
+ out.push(val);
199
+ }
200
+ else if (Array.isArray(val)) {
201
+ for (const item of val)
202
+ collect(item);
203
+ }
204
+ else if (val !== null && typeof val === "object") {
205
+ for (const v of Object.values(val))
206
+ collect(v);
207
+ }
208
+ };
209
+ for (const entry of this.entries.values())
210
+ collect(entry.secretMaterial);
211
+ return out;
212
+ }
213
+ scrubSecrets(value, credential) {
214
+ const literals = (v) => {
215
+ if (typeof v === "string")
216
+ return v ? [v] : [];
217
+ return v && typeof v === "object" ? Object.values(v).flatMap(literals) : [];
218
+ };
219
+ const secrets = [...new Set(literals(credential))].sort((a, b) => b.length - a.length);
220
+ const scrub = (v) => {
221
+ if (typeof v === "string")
222
+ return secrets.reduce((s, token) => s.split(token).join("[REDACTED_SECRET]"), v);
223
+ if (Array.isArray(v))
224
+ return v.map(scrub);
225
+ if (v && typeof v === "object")
226
+ return Object.fromEntries(Object.entries(v).map(([k, item]) => [scrub(k), scrub(item)]));
227
+ return v;
228
+ };
229
+ return secrets.length ? scrub(value) : value;
230
+ }
231
+ }
@@ -0,0 +1,55 @@
1
+ import { type AgentKernel, type TargetConfig } from "../kernel.js";
2
+ import { type Clearance } from "../types.js";
3
+ export declare function generateA2AAgentCard(kernel: AgentKernel, baseUrl?: string, clearance?: Clearance, protocolVersion?: "1.0" | "0.3" | "0.3.0"): Record<string, unknown>;
4
+ export declare function wrapA2APeer(agentName: string, sendTaskFn: (args: Record<string, unknown>) => unknown | Promise<unknown>, opts: {
5
+ peerOrigin: string;
6
+ mutating?: boolean;
7
+ description?: string;
8
+ sinkClearance?: Clearance;
9
+ }): TargetConfig;
10
+ interface A2ATaskRecord {
11
+ taskId: string;
12
+ contextId: string;
13
+ target: string;
14
+ previewWrites: boolean;
15
+ args: Record<string, unknown>;
16
+ state: "working" | "input-required" | "completed" | "failed" | "canceled";
17
+ message: string;
18
+ artifacts: Array<Record<string, unknown>>;
19
+ pendingElicitId?: string;
20
+ pendingConfirmToken?: string;
21
+ compensateHandles: string[];
22
+ updatedAtMs: number;
23
+ }
24
+ export declare class A2ABridge {
25
+ readonly kernel: AgentKernel;
26
+ readonly baseUrl: string;
27
+ readonly callerClearance: Clearance;
28
+ readonly tasks: Map<string, A2ATaskRecord>;
29
+ private readonly trustedInput;
30
+ private readonly maxTasks;
31
+ private readonly retentionMs;
32
+ private readonly messages;
33
+ private readonly namespace;
34
+ constructor(kernel: AgentKernel, opts?: {
35
+ baseUrl?: string;
36
+ callerClearance?: Clearance;
37
+ trustedInput?: boolean;
38
+ maxTasks?: number;
39
+ retentionMs?: number;
40
+ });
41
+ private pruneTasks;
42
+ generateAgentCard(protocolVersion?: "1.0" | "0.3" | "0.3.0"): Record<string, unknown>;
43
+ private messageParams;
44
+ handleJsonRpc(request: {
45
+ id?: unknown;
46
+ method: string;
47
+ params?: Record<string, unknown>;
48
+ }): Promise<Record<string, unknown>>;
49
+ private sendMessage;
50
+ approveTask(taskId: string): void;
51
+ streamSse(params: Record<string, unknown>): Promise<string[]>;
52
+ private handleSend;
53
+ private executeTask;
54
+ }
55
+ export {};