@odingard/guardian-sdk 0.0.0-stage → 0.1.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 +201 -0
- package/README.md +67 -2
- package/dist/index.js +3248 -0
- package/dist-dts/__tests__/client.test.d.ts +1 -0
- package/dist-dts/client.d.ts +80 -0
- package/dist-dts/contracts/action-parameters.d.ts +34 -0
- package/dist-dts/contracts/action-registry.d.ts +197 -0
- package/dist-dts/contracts/action.d.ts +967 -0
- package/dist-dts/contracts/api.d.ts +78 -0
- package/dist-dts/contracts/approval.d.ts +206 -0
- package/dist-dts/contracts/authority-state.d.ts +93 -0
- package/dist-dts/contracts/authority.d.ts +313 -0
- package/dist-dts/contracts/calendar.d.ts +146 -0
- package/dist-dts/contracts/canonical-json.d.ts +4 -0
- package/dist-dts/contracts/capability.d.ts +28 -0
- package/dist-dts/contracts/commerce.d.ts +133 -0
- package/dist-dts/contracts/digest.d.ts +2 -0
- package/dist-dts/contracts/email.d.ts +45 -0
- package/dist-dts/contracts/evidence.d.ts +1030 -0
- package/dist-dts/contracts/execution.d.ts +1338 -0
- package/dist-dts/contracts/files.d.ts +61 -0
- package/dist-dts/contracts/identifiers.d.ts +33 -0
- package/dist-dts/contracts/index.d.ts +19 -0
- package/dist-dts/contracts/protected-data.d.ts +93 -0
- package/dist-dts/contracts/tools.d.ts +187 -0
- package/dist-dts/index.d.ts +1 -0
- package/dist-dts/proposal.d.ts +25 -0
- package/package.json +50 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { type AgentExecutionReceipt, type McpInstallParametersV1 } from "./contracts/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* WO-015 developer SDK — a thin typed client over the Guardian agent REST
|
|
4
|
+
* surface. External agents call this instead of hand-rolling envelopes: the
|
|
5
|
+
* request, claim and execute calls produce the same canonical action
|
|
6
|
+
* envelopes the gateway/kernel/capability path already governs.
|
|
7
|
+
*
|
|
8
|
+
* Repo-level client + docs; NOT a published package (no SDK SLA).
|
|
9
|
+
*/
|
|
10
|
+
export type GuardianClientConfig = Readonly<{
|
|
11
|
+
/** e.g. https://guardian-api-staging.odingard.com */
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
/** Agent credential (gac1.…). */
|
|
14
|
+
credential: string;
|
|
15
|
+
/** Adapter audience for executes; defaults to the tool adapter. */
|
|
16
|
+
adapterId?: string;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
}>;
|
|
19
|
+
export type GuardianToolInvocation = Readonly<{
|
|
20
|
+
action: "tool.invoke";
|
|
21
|
+
connectionId: string;
|
|
22
|
+
toolName: string;
|
|
23
|
+
arguments: Record<string, unknown>;
|
|
24
|
+
adapterId?: string;
|
|
25
|
+
purpose?: string;
|
|
26
|
+
}>;
|
|
27
|
+
export type GuardianMcpInvocation = Readonly<{
|
|
28
|
+
action: "mcp.install";
|
|
29
|
+
connectionId: string;
|
|
30
|
+
tool: McpInstallParametersV1["tool"];
|
|
31
|
+
adapterId?: string;
|
|
32
|
+
purpose?: string;
|
|
33
|
+
}> | Readonly<{
|
|
34
|
+
action: "mcp.enable";
|
|
35
|
+
connectionId: string;
|
|
36
|
+
toolName: string;
|
|
37
|
+
adapterId?: string;
|
|
38
|
+
purpose?: string;
|
|
39
|
+
}>;
|
|
40
|
+
export type GuardianRequestResult = {
|
|
41
|
+
ok: true;
|
|
42
|
+
requestId: string;
|
|
43
|
+
decision: "ALLOW" | "ASK" | "DENY";
|
|
44
|
+
capabilityToken?: string;
|
|
45
|
+
reasonCode?: string;
|
|
46
|
+
} | {
|
|
47
|
+
ok: false;
|
|
48
|
+
reasonCode: string;
|
|
49
|
+
};
|
|
50
|
+
export interface GuardianClient {
|
|
51
|
+
/**
|
|
52
|
+
* Request a capability for a tool/MCP action. ALLOW returns a
|
|
53
|
+
* capabilityToken immediately; ASK returns decision "ASK" and the human
|
|
54
|
+
* approves out-of-band (then call `claim`); DENY refuses.
|
|
55
|
+
*/
|
|
56
|
+
request(invocation: GuardianToolInvocation | GuardianMcpInvocation): Promise<GuardianRequestResult>;
|
|
57
|
+
/** Collect a capability after human approval of a prior ASK. */
|
|
58
|
+
claim(requestId: string): Promise<GuardianRequestResult>;
|
|
59
|
+
/** Execute a held capability; resolves to the execution receipt. */
|
|
60
|
+
execute(input: {
|
|
61
|
+
requestId: string;
|
|
62
|
+
capabilityToken: string;
|
|
63
|
+
}): Promise<{
|
|
64
|
+
ok: true;
|
|
65
|
+
receipt: AgentExecutionReceipt;
|
|
66
|
+
} | {
|
|
67
|
+
ok: false;
|
|
68
|
+
reasonCode: string;
|
|
69
|
+
}>;
|
|
70
|
+
/** Machine-readable proof for a request (WO-015 developer receipts). */
|
|
71
|
+
receipts(requestId: string): Promise<{
|
|
72
|
+
ok: true;
|
|
73
|
+
requestId: string;
|
|
74
|
+
receipts: readonly unknown[];
|
|
75
|
+
} | {
|
|
76
|
+
ok: false;
|
|
77
|
+
reasonCode: string;
|
|
78
|
+
}>;
|
|
79
|
+
}
|
|
80
|
+
export declare function createGuardianClient(config: GuardianClientConfig): GuardianClient;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ActionDefinition, type ActionRegistry } from "./action-registry.js";
|
|
2
|
+
import type { TaskId } from "./identifiers.js";
|
|
3
|
+
export type ActionParameterValidation = {
|
|
4
|
+
ok: true;
|
|
5
|
+
kind: string;
|
|
6
|
+
definition: ActionDefinition;
|
|
7
|
+
params: unknown;
|
|
8
|
+
} | {
|
|
9
|
+
ok: true;
|
|
10
|
+
kind: "generic";
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
};
|
|
14
|
+
type FactInput = {
|
|
15
|
+
valueCents?: number | undefined;
|
|
16
|
+
merchantId?: string | undefined;
|
|
17
|
+
merchantCategory?: string | undefined;
|
|
18
|
+
recurring?: boolean | undefined;
|
|
19
|
+
taskId?: TaskId | undefined;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Generic parameter gate (GUA-UNIVERSAL-001 §11/K15): resolves the action
|
|
23
|
+
* through the Universal Action Registry and applies only action-agnostic
|
|
24
|
+
* checks — capability uses, declared monetary facts vs derived facts, and
|
|
25
|
+
* the `${resourceType}:${connectionId}` resource binding. Action semantics
|
|
26
|
+
* live in the registered definition's hooks.
|
|
27
|
+
*/
|
|
28
|
+
export declare function validateActionParameters(input: {
|
|
29
|
+
action: string;
|
|
30
|
+
resource: string;
|
|
31
|
+
uses: number;
|
|
32
|
+
materialParameters: unknown;
|
|
33
|
+
} & FactInput, registry?: ActionRegistry): ActionParameterValidation;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { type ActionAuthorityFacts } from "./commerce.js";
|
|
2
|
+
import { type ProtectedCatalogEntry } from "./protected-data.js";
|
|
3
|
+
import { type ToolDescriptor } from "./tools.js";
|
|
4
|
+
/**
|
|
5
|
+
* GUA-UNIVERSAL-001 §7 — Universal Action Registry.
|
|
6
|
+
*
|
|
7
|
+
* Every consequential action is registered independently of provider. The
|
|
8
|
+
* authority kernel resolves an action_id to an ActionDefinition and invokes
|
|
9
|
+
* its hooks uniformly; it never branches on action/provider identity (K15).
|
|
10
|
+
* Adding a new action means adding a registry definition plus an adapter —
|
|
11
|
+
* no kernel change.
|
|
12
|
+
*/
|
|
13
|
+
export type Reversibility = "reversible" | "limited" | "difficult" | "destructive" | "safety-sensitive";
|
|
14
|
+
export type RiskClass = "R0" | "R1" | "R2" | "R3" | "R4" | "R5";
|
|
15
|
+
/** The connection facts an action definition may bind against. */
|
|
16
|
+
export type ActionConnectionBinding = Readonly<{
|
|
17
|
+
provider: string;
|
|
18
|
+
mailboxAddress?: string;
|
|
19
|
+
endpointAllowlist?: readonly string[];
|
|
20
|
+
/** Provider "tool" connections carry the installed tool-server catalog. */
|
|
21
|
+
toolServer?: Readonly<{
|
|
22
|
+
serverName: string;
|
|
23
|
+
serverVersion: string;
|
|
24
|
+
tools: readonly ToolDescriptor[];
|
|
25
|
+
}>;
|
|
26
|
+
/** Tool names enabled for the requesting agent (agent_tools registry). */
|
|
27
|
+
enabledToolNames?: readonly string[];
|
|
28
|
+
calendarId?: string;
|
|
29
|
+
/** Canonical path prefixes file ops may touch (files provider). */
|
|
30
|
+
pathAllowlist?: readonly string[];
|
|
31
|
+
/** Canonical path prefixes a file may be shared from (files provider). */
|
|
32
|
+
shareAllowlist?: readonly string[];
|
|
33
|
+
/** Declared protected fields for this connection (protected_data). */
|
|
34
|
+
protectedCatalog?: readonly ProtectedCatalogEntry[];
|
|
35
|
+
}>;
|
|
36
|
+
export type ActionBindingResult = Readonly<{
|
|
37
|
+
ok: true;
|
|
38
|
+
}> | Readonly<{
|
|
39
|
+
ok: false;
|
|
40
|
+
reasonCode: string;
|
|
41
|
+
}>;
|
|
42
|
+
export interface ActionDefinition<P = unknown> {
|
|
43
|
+
readonly actionId: string;
|
|
44
|
+
readonly schemaVersion: 1;
|
|
45
|
+
readonly actionFamily: string;
|
|
46
|
+
readonly humanLabel: string;
|
|
47
|
+
readonly description: string;
|
|
48
|
+
/** Typed kind returned to the pipeline after parameter validation. */
|
|
49
|
+
readonly parametersKind: string;
|
|
50
|
+
/** Raw field names, for rendering + policy primitives. */
|
|
51
|
+
readonly requiredParameters: readonly string[];
|
|
52
|
+
/** Fields bound into the material-parameter digest (TOCTOU, §27). */
|
|
53
|
+
readonly materialParameters: readonly string[];
|
|
54
|
+
/** Resource pattern: `${resourceType}:${connectionId}`. */
|
|
55
|
+
readonly resourceType: string;
|
|
56
|
+
/** Providers a connection may use for this action. */
|
|
57
|
+
readonly providers: readonly string[];
|
|
58
|
+
readonly counterpartyRules: string;
|
|
59
|
+
readonly dataEffects: string;
|
|
60
|
+
readonly reversibility: Reversibility;
|
|
61
|
+
readonly riskClass: RiskClass;
|
|
62
|
+
readonly defaultDecisionPosture: "allow" | "ask" | "deny";
|
|
63
|
+
/** Generic fields the Authority Slip renders. */
|
|
64
|
+
readonly approvalPresentationSchema: readonly string[];
|
|
65
|
+
readonly capabilityRequirements: Readonly<{
|
|
66
|
+
uses: number;
|
|
67
|
+
}>;
|
|
68
|
+
readonly executionContract: string;
|
|
69
|
+
readonly verificationContract: Readonly<{
|
|
70
|
+
level: string;
|
|
71
|
+
}>;
|
|
72
|
+
readonly evidenceRequirements: readonly string[];
|
|
73
|
+
readonly version: 1;
|
|
74
|
+
readonly status: "active" | "deprecated" | "disabled";
|
|
75
|
+
/**
|
|
76
|
+
* When true the action is capability-expanding: authority derivation never
|
|
77
|
+
* auto-includes it in a grant's action set. It can only enter a grant when
|
|
78
|
+
* a human selects it explicitly (WO-015 self-serve-escalation denial).
|
|
79
|
+
*/
|
|
80
|
+
readonly requiresExplicitGrant?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Action-specific logic lives HERE — inside the registered definition —
|
|
83
|
+
* never inside the kernel. Hooks receive only kernel-verified inputs.
|
|
84
|
+
*/
|
|
85
|
+
validateParameters(materialParameters: unknown): Readonly<{
|
|
86
|
+
ok: true;
|
|
87
|
+
params: P;
|
|
88
|
+
} | {
|
|
89
|
+
ok: false;
|
|
90
|
+
}>;
|
|
91
|
+
/** Pre-execution binding the agent's params to the leased connection. */
|
|
92
|
+
validateBinding(input: {
|
|
93
|
+
params: P;
|
|
94
|
+
connection: ActionConnectionBinding;
|
|
95
|
+
}): ActionBindingResult;
|
|
96
|
+
/** Canonical projection whose digest the verified outcome must match. */
|
|
97
|
+
verificationProjection(params: P): unknown;
|
|
98
|
+
/** Envelope projection recorded at reservation time. */
|
|
99
|
+
envelopeProjection(params: P): unknown;
|
|
100
|
+
/**
|
|
101
|
+
* Generic monetary-authority facts derived from validated parameters
|
|
102
|
+
* (WO-014). When present, the envelope's declared facts must equal the
|
|
103
|
+
* derived values, so an agent cannot understate an amount or smuggle a
|
|
104
|
+
* merchant/category/recurrence fact past the kernel.
|
|
105
|
+
*/
|
|
106
|
+
authorityFacts?(params: P): ActionAuthorityFacts;
|
|
107
|
+
}
|
|
108
|
+
export type ActionRegistry = Readonly<{
|
|
109
|
+
get(actionId: string): ActionDefinition | undefined;
|
|
110
|
+
entries(): readonly ActionDefinition[];
|
|
111
|
+
}>;
|
|
112
|
+
export declare function createActionRegistry(definitions: readonly ActionDefinition[]): ActionRegistry;
|
|
113
|
+
export declare const EMAIL_SEND_DEFINITION: ActionDefinition<{
|
|
114
|
+
schema: "odingard.guardian.email.send.v1";
|
|
115
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
116
|
+
from: string;
|
|
117
|
+
to: string[];
|
|
118
|
+
cc: string[];
|
|
119
|
+
bcc: string[];
|
|
120
|
+
replyTo: never[];
|
|
121
|
+
subject: string;
|
|
122
|
+
body: {
|
|
123
|
+
format: "text/plain";
|
|
124
|
+
text: string;
|
|
125
|
+
};
|
|
126
|
+
attachments: never[];
|
|
127
|
+
inReplyTo: null;
|
|
128
|
+
}>;
|
|
129
|
+
export declare const API_REQUEST_DEFINITION: ActionDefinition<{
|
|
130
|
+
schema: "odingard.guardian.api.request.v1";
|
|
131
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
132
|
+
method: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
133
|
+
url: string;
|
|
134
|
+
headers: {
|
|
135
|
+
name: string;
|
|
136
|
+
value: string;
|
|
137
|
+
}[];
|
|
138
|
+
body?: string | undefined;
|
|
139
|
+
idempotencyKey?: string | undefined;
|
|
140
|
+
}>;
|
|
141
|
+
export declare const TOOL_INVOKE_DEFINITION: ActionDefinition<{
|
|
142
|
+
schema: "odingard.guardian.tool.invoke.v1";
|
|
143
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
144
|
+
toolName: string;
|
|
145
|
+
arguments: Record<string, unknown>;
|
|
146
|
+
}>;
|
|
147
|
+
export declare const MCP_INSTALL_DEFINITION: ActionDefinition<{
|
|
148
|
+
schema: "odingard.guardian.mcp.install.v1";
|
|
149
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
150
|
+
tool: {
|
|
151
|
+
name: string;
|
|
152
|
+
method: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
153
|
+
url: string;
|
|
154
|
+
description?: string | undefined;
|
|
155
|
+
};
|
|
156
|
+
}>;
|
|
157
|
+
export declare const MCP_ENABLE_DEFINITION: ActionDefinition<{
|
|
158
|
+
schema: "odingard.guardian.mcp.enable.v1";
|
|
159
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
160
|
+
toolName: string;
|
|
161
|
+
}>;
|
|
162
|
+
export declare const COMMERCE_PURCHASE_DEFINITION: ActionDefinition<{
|
|
163
|
+
schema: "commerce.purchase.v1";
|
|
164
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
165
|
+
merchantId: string;
|
|
166
|
+
merchantCategory: string;
|
|
167
|
+
amountCents: number;
|
|
168
|
+
currency: "USD";
|
|
169
|
+
orderDescription: string;
|
|
170
|
+
idempotencyKey: string;
|
|
171
|
+
taskId?: (string & import("zod").$brand<"TaskId">) | undefined;
|
|
172
|
+
}>;
|
|
173
|
+
export declare const COMMERCE_REFUND_DEFINITION: ActionDefinition<{
|
|
174
|
+
schema: "commerce.refund.v1";
|
|
175
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
176
|
+
chargeId: string;
|
|
177
|
+
reason: string;
|
|
178
|
+
amountCents?: number | undefined;
|
|
179
|
+
}>;
|
|
180
|
+
export declare const COMMERCE_RETURN_DEFINITION: ActionDefinition<{
|
|
181
|
+
schema: "commerce.return.v1";
|
|
182
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
183
|
+
chargeId: string;
|
|
184
|
+
reason: string;
|
|
185
|
+
}>;
|
|
186
|
+
export declare const SUBSCRIPTION_CREATE_DEFINITION: ActionDefinition<{
|
|
187
|
+
schema: "subscription.create.v1";
|
|
188
|
+
connectionId: string & import("zod").$brand<"ConnectionId">;
|
|
189
|
+
merchantId: string;
|
|
190
|
+
planId: string;
|
|
191
|
+
amountCents: number;
|
|
192
|
+
currency: "USD";
|
|
193
|
+
interval: "week" | "month" | "year";
|
|
194
|
+
idempotencyKey: string;
|
|
195
|
+
}>;
|
|
196
|
+
/** The shipped registry: enforced surfaces as first-class definitions. */
|
|
197
|
+
export declare const universalActionRegistry: ActionRegistry;
|