402mob-runtime 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -7
- package/SOURCE.json +97 -0
- package/THIRD-PARTY-NOTICES.txt +79 -0
- package/checks/block-network.cjs +15 -0
- package/checks/recovery.mjs +31942 -0
- package/dist/runtime/agent-tools.d.ts +104 -0
- package/dist/runtime/agent-tools.js +30215 -0
- package/dist/runtime/cli.js +10055 -4228
- package/guides/prepared-exchange.md +190 -0
- package/package.json +19 -2
- package/public/wallet/app.js +1 -1
- package/public/wallet/index.html +1 -1
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export interface BuyerConnection {
|
|
2
|
+
gateway: string;
|
|
3
|
+
token: string;
|
|
4
|
+
}
|
|
5
|
+
/** Portable declaration: consumers need no internal runtime modules or schema-library dependency. */
|
|
6
|
+
export interface BuyerConnectionCapabilities {
|
|
7
|
+
protocol: '402mob.connection-capabilities.v1';
|
|
8
|
+
commandContractHash: string;
|
|
9
|
+
role: 'buyer' | 'observer';
|
|
10
|
+
delegationId: string;
|
|
11
|
+
connectionId: string;
|
|
12
|
+
observedAt: string;
|
|
13
|
+
expiresAt: string | null;
|
|
14
|
+
delegationState: 'active' | 'revoked' | 'expired';
|
|
15
|
+
spendingAuthority: 'delegated' | 'inactive' | 'none';
|
|
16
|
+
policy: {
|
|
17
|
+
name: string;
|
|
18
|
+
maxTotalUSDC?: string | undefined;
|
|
19
|
+
merchantId?: string | undefined;
|
|
20
|
+
payee?: string | undefined;
|
|
21
|
+
capability?: 'text-statistics-v1' | 'json-normalize-v1' | 'prepared-artifact-v1' | undefined;
|
|
22
|
+
maxPerPaymentUSDC?: string | undefined;
|
|
23
|
+
expiresAt?: string | undefined;
|
|
24
|
+
} | null;
|
|
25
|
+
resources: {
|
|
26
|
+
scope: 'owned_delegation' | 'selected_resources';
|
|
27
|
+
taskIds: string[];
|
|
28
|
+
sessionIds: string[];
|
|
29
|
+
subscriptionIds: string[];
|
|
30
|
+
accounting: boolean;
|
|
31
|
+
};
|
|
32
|
+
commands: Array<{
|
|
33
|
+
name: string;
|
|
34
|
+
effect: string;
|
|
35
|
+
access: 'local' | 'delegation_checked' | 'scoped' | 'denied';
|
|
36
|
+
scope: 'none' | 'delegation' | 'connection' | 'tasks' | 'sessions' | 'subscriptions' | 'selected_accounting';
|
|
37
|
+
reason: 'buyer_connection_required' | 'accounting_not_granted' | 'no_selected_resource' | null;
|
|
38
|
+
}>;
|
|
39
|
+
semantics: 'permission_snapshot_not_execution_readiness';
|
|
40
|
+
authorizesPayment: false;
|
|
41
|
+
}
|
|
42
|
+
export interface SpendRequest<Context> {
|
|
43
|
+
command: string;
|
|
44
|
+
effect: 'spend';
|
|
45
|
+
input: Readonly<Record<string, unknown>>;
|
|
46
|
+
context: Context;
|
|
47
|
+
}
|
|
48
|
+
export interface BuyerToolOptions<Context> {
|
|
49
|
+
/** Called once per invocation; derive the identity from trusted host context, never model arguments. */
|
|
50
|
+
resolveConnection: (context: Context) => BuyerConnection | Promise<BuyerConnection>;
|
|
51
|
+
/** Explicit true is required for spending, including recurring resume. Omission denies spending. */
|
|
52
|
+
authorizeSpend?: (request: SpendRequest<Context>) => boolean | Promise<boolean>;
|
|
53
|
+
/** Exact trusted remote HTTPS origins. Without this, only loopback gateways are accepted. */
|
|
54
|
+
allowedRemoteOrigins?: readonly string[];
|
|
55
|
+
/** Optional command allowlist; unknown and seller-only commands fail at construction. */
|
|
56
|
+
include?: readonly string[];
|
|
57
|
+
fetch?: typeof globalThis.fetch;
|
|
58
|
+
}
|
|
59
|
+
export interface BuyerTool<Context> {
|
|
60
|
+
name: string;
|
|
61
|
+
description: string;
|
|
62
|
+
effect: string;
|
|
63
|
+
inputSchema: Record<string, unknown>;
|
|
64
|
+
outputSchema: Record<string, unknown>;
|
|
65
|
+
execute: (input: unknown, context: Context) => Promise<unknown>;
|
|
66
|
+
}
|
|
67
|
+
/** Safe model-visible errors. Never serialize exception messages, causes or host credentials. */
|
|
68
|
+
export interface BuyerToolError {
|
|
69
|
+
error: string;
|
|
70
|
+
preserveTask: true;
|
|
71
|
+
httpStatus?: number;
|
|
72
|
+
validation?: Record<string, unknown>;
|
|
73
|
+
authorizationRemediation?: Record<string, unknown>;
|
|
74
|
+
retryAdvice?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
export declare function buyerToolError(error: unknown): BuyerToolError;
|
|
77
|
+
/** Framework-neutral tools: no environment credentials, shared HTTP client, owner keys or shell execution. */
|
|
78
|
+
export declare function createBuyerTools<Context>(options: BuyerToolOptions<Context>): Record<string, BuyerTool<Context>>;
|
|
79
|
+
export interface SavedPurchaseResult {
|
|
80
|
+
taskId: string;
|
|
81
|
+
merchantId: string;
|
|
82
|
+
offerId: string | null;
|
|
83
|
+
path: string;
|
|
84
|
+
sha256: string;
|
|
85
|
+
bytes: number;
|
|
86
|
+
contentType: string;
|
|
87
|
+
operationId: string;
|
|
88
|
+
transaction: string;
|
|
89
|
+
payment: 'settled';
|
|
90
|
+
verification: 'accepted';
|
|
91
|
+
receiptRecorded: true;
|
|
92
|
+
reused: boolean;
|
|
93
|
+
}
|
|
94
|
+
/** Host-only file export. Directory is configured by the application, not exposed as model tool input. */
|
|
95
|
+
export declare function retrievePurchaseResult<Context>(tools: Record<string, BuyerTool<Context>>, input: {
|
|
96
|
+
id: string;
|
|
97
|
+
}, context: Context, directory: string): Promise<SavedPurchaseResult>;
|
|
98
|
+
/** Host-only opt-in discovery. Build per agent/context; re-run after changing connections or grants.
|
|
99
|
+
* Selection is a snapshot. Every later invocation still resolves credentials anew and the gateway enforces access.
|
|
100
|
+
*/
|
|
101
|
+
export declare function createConnectionBuyerTools<Context>(options: BuyerToolOptions<Context>, context: Context): Promise<{
|
|
102
|
+
capabilities: BuyerConnectionCapabilities;
|
|
103
|
+
tools: Record<string, BuyerTool<Context>>;
|
|
104
|
+
}>;
|