@vorim/sdk 3.11.0 → 3.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/integrations/cloudflare.cjs +134 -0
- package/dist/integrations/cloudflare.cjs.map +1 -0
- package/dist/integrations/cloudflare.d.cts +93 -0
- package/dist/integrations/cloudflare.d.ts +93 -0
- package/dist/integrations/cloudflare.js +108 -0
- package/dist/integrations/cloudflare.js.map +1 -0
- package/dist/integrations/coinbase-cdp.cjs +230 -0
- package/dist/integrations/coinbase-cdp.cjs.map +1 -0
- package/dist/integrations/coinbase-cdp.d.cts +169 -0
- package/dist/integrations/coinbase-cdp.d.ts +169 -0
- package/dist/integrations/coinbase-cdp.js +204 -0
- package/dist/integrations/coinbase-cdp.js.map +1 -0
- package/dist/integrations/fhir.cjs +304 -0
- package/dist/integrations/fhir.cjs.map +1 -0
- package/dist/integrations/fhir.d.cts +185 -0
- package/dist/integrations/fhir.d.ts +185 -0
- package/dist/integrations/fhir.js +278 -0
- package/dist/integrations/fhir.js.map +1 -0
- package/dist/integrations/guidewire.cjs +363 -0
- package/dist/integrations/guidewire.cjs.map +1 -0
- package/dist/integrations/guidewire.d.cts +258 -0
- package/dist/integrations/guidewire.d.ts +258 -0
- package/dist/integrations/guidewire.js +337 -0
- package/dist/integrations/guidewire.js.map +1 -0
- package/dist/integrations/legal.cjs +339 -0
- package/dist/integrations/legal.cjs.map +1 -0
- package/dist/integrations/legal.d.cts +225 -0
- package/dist/integrations/legal.d.ts +225 -0
- package/dist/integrations/legal.js +313 -0
- package/dist/integrations/legal.js.map +1 -0
- package/dist/integrations/life-sciences.cjs +335 -0
- package/dist/integrations/life-sciences.cjs.map +1 -0
- package/dist/integrations/life-sciences.d.cts +214 -0
- package/dist/integrations/life-sciences.d.ts +214 -0
- package/dist/integrations/life-sciences.js +309 -0
- package/dist/integrations/life-sciences.js.map +1 -0
- package/dist/integrations/lithic.cjs +290 -0
- package/dist/integrations/lithic.cjs.map +1 -0
- package/dist/integrations/lithic.d.cts +130 -0
- package/dist/integrations/lithic.d.ts +130 -0
- package/dist/integrations/lithic.js +264 -0
- package/dist/integrations/lithic.js.map +1 -0
- package/dist/integrations/marqeta.cjs +285 -0
- package/dist/integrations/marqeta.cjs.map +1 -0
- package/dist/integrations/marqeta.d.cts +121 -0
- package/dist/integrations/marqeta.d.ts +121 -0
- package/dist/integrations/marqeta.js +259 -0
- package/dist/integrations/marqeta.js.map +1 -0
- package/dist/integrations/ramp.cjs +206 -0
- package/dist/integrations/ramp.cjs.map +1 -0
- package/dist/integrations/ramp.d.cts +139 -0
- package/dist/integrations/ramp.d.ts +139 -0
- package/dist/integrations/ramp.js +180 -0
- package/dist/integrations/ramp.js.map +1 -0
- package/dist/integrations/shopify.cjs +203 -0
- package/dist/integrations/shopify.cjs.map +1 -0
- package/dist/integrations/shopify.d.cts +175 -0
- package/dist/integrations/shopify.d.ts +175 -0
- package/dist/integrations/shopify.js +177 -0
- package/dist/integrations/shopify.js.map +1 -0
- package/dist/integrations/stripe-issuing.cjs +316 -0
- package/dist/integrations/stripe-issuing.cjs.map +1 -0
- package/dist/integrations/stripe-issuing.d.cts +154 -0
- package/dist/integrations/stripe-issuing.d.ts +154 -0
- package/dist/integrations/stripe-issuing.js +290 -0
- package/dist/integrations/stripe-issuing.js.map +1 -0
- package/dist/integrations/web-bot-auth.cjs +143 -0
- package/dist/integrations/web-bot-auth.cjs.map +1 -0
- package/dist/integrations/web-bot-auth.d.cts +51 -0
- package/dist/integrations/web-bot-auth.d.ts +51 -0
- package/dist/integrations/web-bot-auth.js +108 -0
- package/dist/integrations/web-bot-auth.js.map +1 -0
- package/package.json +121 -1
package/dist/index.cjs
CHANGED
|
@@ -124,7 +124,7 @@ async function prepareReplayContext(inputs) {
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
// src/index.ts
|
|
127
|
-
var SDK_VERSION = true ? "3.
|
|
127
|
+
var SDK_VERSION = true ? "3.15.0" : "0.0.0";
|
|
128
128
|
var USER_AGENT = `vorim-sdk/${SDK_VERSION}`;
|
|
129
129
|
function sleep(ms) {
|
|
130
130
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ async function prepareReplayContext(inputs) {
|
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
// src/index.ts
|
|
78
|
-
var SDK_VERSION = true ? "3.
|
|
78
|
+
var SDK_VERSION = true ? "3.15.0" : "0.0.0";
|
|
79
79
|
var USER_AGENT = `vorim-sdk/${SDK_VERSION}`;
|
|
80
80
|
function sleep(ms) {
|
|
81
81
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/integrations/cloudflare.ts
|
|
21
|
+
var cloudflare_exports = {};
|
|
22
|
+
__export(cloudflare_exports, {
|
|
23
|
+
VorimCloudflare: () => VorimCloudflare,
|
|
24
|
+
createVorimCloudflare: () => createVorimCloudflare
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(cloudflare_exports);
|
|
27
|
+
var VorimCloudflare = class {
|
|
28
|
+
sdk;
|
|
29
|
+
agentId;
|
|
30
|
+
humanId;
|
|
31
|
+
scope;
|
|
32
|
+
minTrustScore;
|
|
33
|
+
onError;
|
|
34
|
+
constructor(sdk, config) {
|
|
35
|
+
if (!config?.agentId) throw new Error("[vorim] Cloudflare integration requires an agentId.");
|
|
36
|
+
this.sdk = sdk;
|
|
37
|
+
this.agentId = config.agentId;
|
|
38
|
+
this.humanId = config.humanId;
|
|
39
|
+
this.scope = config.scope ?? "agent:read";
|
|
40
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
41
|
+
this.onError = config.onError ?? "closed";
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Check whether the acting agent is authorized to take a browsing action,
|
|
45
|
+
* before it runs. Returns { authorized, reason }.
|
|
46
|
+
*/
|
|
47
|
+
async authorize(action) {
|
|
48
|
+
try {
|
|
49
|
+
if (this.minTrustScore > 0) {
|
|
50
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
51
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
52
|
+
return { authorized: false, reason: `trust score below ${this.minTrustScore}` };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const perm = await this.sdk.check(this.agentId, this.scope);
|
|
56
|
+
return perm.allowed ? { authorized: true } : { authorized: false, reason: perm.reason ?? `missing scope ${this.scope}` };
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}` };
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Emit a source-signed audit event for a browsing action and return the
|
|
63
|
+
* receipt. Called after the action runs (or after a denial). The event names
|
|
64
|
+
* the agent and the human it acts for, so the record is attributable to a
|
|
65
|
+
* person and independently verifiable offline.
|
|
66
|
+
*/
|
|
67
|
+
async record(action, result, reason) {
|
|
68
|
+
try {
|
|
69
|
+
await this.sdk.emit({
|
|
70
|
+
agent_id: this.agentId,
|
|
71
|
+
event_type: "api_request",
|
|
72
|
+
action: `browse:${action.action} ${action.url}`,
|
|
73
|
+
resource: action.url,
|
|
74
|
+
permission: this.scope,
|
|
75
|
+
result,
|
|
76
|
+
input_hash: action.inputHash,
|
|
77
|
+
output_hash: action.outputHash,
|
|
78
|
+
metadata: {
|
|
79
|
+
integration: "cloudflare-browser-run",
|
|
80
|
+
acts_for_human: this.humanId,
|
|
81
|
+
browse_action: action.action,
|
|
82
|
+
...reason ? { reason } : {}
|
|
83
|
+
}
|
|
84
|
+
}, { sign: true });
|
|
85
|
+
return true;
|
|
86
|
+
} catch {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* The full flow for one browsing action: authorize, run it if allowed, sign a
|
|
92
|
+
* receipt either way. If not authorized, `run` is never called. Rethrows an
|
|
93
|
+
* error from `run` after recording it, so your handler still sees failures.
|
|
94
|
+
*/
|
|
95
|
+
async browse(action, run) {
|
|
96
|
+
const auth = await this.authorize(action);
|
|
97
|
+
if (!auth.authorized) {
|
|
98
|
+
const recorded = await this.record(action, "denied", auth.reason);
|
|
99
|
+
return { receipt: this.receipt(action, false, "denied", auth.reason, recorded) };
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
const value = await run();
|
|
103
|
+
const recorded = await this.record(action, "success");
|
|
104
|
+
return { receipt: this.receipt(action, true, "success", void 0, recorded), value };
|
|
105
|
+
} catch (e) {
|
|
106
|
+
const recorded = await this.record(action, "error", e?.message);
|
|
107
|
+
throw Object.assign(e ?? new Error("browse action failed"), {
|
|
108
|
+
vorimReceipt: this.receipt(action, true, "error", e?.message, recorded)
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
receipt(action, authorized, result, reason, recorded) {
|
|
113
|
+
return {
|
|
114
|
+
authorized,
|
|
115
|
+
agentId: this.agentId,
|
|
116
|
+
humanId: this.humanId,
|
|
117
|
+
url: action.url,
|
|
118
|
+
action: action.action,
|
|
119
|
+
result,
|
|
120
|
+
scope: this.scope,
|
|
121
|
+
reason,
|
|
122
|
+
recorded
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
function createVorimCloudflare(sdk, config) {
|
|
127
|
+
return new VorimCloudflare(sdk, config);
|
|
128
|
+
}
|
|
129
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
130
|
+
0 && (module.exports = {
|
|
131
|
+
VorimCloudflare,
|
|
132
|
+
createVorimCloudflare
|
|
133
|
+
});
|
|
134
|
+
//# sourceMappingURL=cloudflare.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/cloudflare.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Cloudflare Workers / Browser Run (kitesurf) Integration\n//\n// Cloudflare's Agent Access Model gives agents short-lived, task-scoped\n// credentials and enforces policy at the mediation layer. It is strong, but by\n// Cloudflare's own account it stops short in a few places: no cryptographic\n// per-action signing at the source, no offline verification (proof needs a live\n// call back to the enforcement point), no attenuated delegation across multiple\n// agent hops, and trust that anchors to Cloudflare's own control plane rather\n// than a portable, independently verifiable proof.\n//\n// This integration adds exactly that layer, in the path the agent already takes\n// on a Worker. For every browsing action (a Browser Run / kitesurf call, or any\n// agent web request), it:\n// 1. checks the acting agent holds the scope BEFORE the action runs,\n// 2. runs the action,\n// 3. emits a source-SIGNED audit event that names the agent AND the human it\n// acts for, and returns a receipt you can verify offline, with no call back\n// to Vorim or Cloudflare.\n//\n// The whole thing runs on the edge: the Vorim SDK signs with Web Crypto\n// (Ed25519), so no Node runtime is needed. Keep the agent private key in a\n// Worker secret; register the agent with vorim.register() and cache the key so\n// emit() auto-signs.\n//\n// Usage (inside a Worker):\n// import createVorim from '@vorim/sdk';\n// import { createVorimCloudflare } from '@vorim/sdk/integrations/cloudflare';\n//\n// const vorim = createVorim({ apiKey: env.VORIM_API_KEY });\n// const guard = createVorimCloudflare(vorim, {\n// agentId: 'agid_browse_bot',\n// humanId: 'user_jane', // the principal the agent acts for\n// scope: 'agent:read', // scope required to browse\n// });\n//\n// export default {\n// async fetch(req, env) {\n// return guard.browse(\n// { url: 'https://example.com', action: 'html_extract' },\n// () => fetch('https://browser.cloudflare.com/...'), // your Browser Run / kitesurf call\n// );\n// },\n// };\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\nexport interface CloudflareGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The human/principal the agent acts for. Recorded in every receipt so an\n * action is attributable to a person, not just a machine. Optional but\n * strongly recommended. */\n humanId?: string;\n /** Scope required before a browsing action runs. Default 'agent:read'. */\n scope?: PermissionScope;\n /** Minimum trust score the acting agent must hold. Default 0 (off). */\n minTrustScore?: number;\n /** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface BrowseAction {\n /** The URL the agent is acting on. */\n url: string;\n /** What the agent is doing: 'html_extract', 'screenshot', 'pdf', 'navigate',\n * or any label meaningful to you. */\n action: string;\n /** Optional: hash of the input/output so the receipt covers content without\n * storing it (pairs with zero-data-retention). */\n inputHash?: string;\n outputHash?: string;\n}\n\n/** An offline-verifiable receipt for one browsing action. */\nexport interface BrowseReceipt {\n authorized: boolean;\n agentId: string;\n humanId?: string;\n url: string;\n action: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n /** Reason a check failed, when authorized is false. */\n reason?: string;\n /** True once the audit event was signed and ingested. */\n recorded: boolean;\n}\n\nexport class VorimCloudflare {\n private sdk: VorimSDK;\n private agentId: string;\n private humanId?: string;\n private scope: PermissionScope;\n private minTrustScore: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: CloudflareGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] Cloudflare integration requires an agentId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.humanId = config.humanId;\n this.scope = config.scope ?? 'agent:read';\n this.minTrustScore = config.minTrustScore ?? 0;\n this.onError = config.onError ?? 'closed';\n }\n\n /**\n * Check whether the acting agent is authorized to take a browsing action,\n * before it runs. Returns { authorized, reason }.\n */\n async authorize(action: BrowseAction): Promise<{ authorized: boolean; reason?: string }> {\n try {\n // Trust floor (optional): refuse low-trust agents up front.\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}` };\n }\n }\n const perm = await this.sdk.check(this.agentId, this.scope);\n return perm.allowed\n ? { authorized: true }\n : { authorized: false, reason: perm.reason ?? `missing scope ${this.scope}` };\n } catch (e: any) {\n // Fail closed by default: a check we could not complete is a deny.\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}` };\n }\n }\n\n /**\n * Emit a source-signed audit event for a browsing action and return the\n * receipt. Called after the action runs (or after a denial). The event names\n * the agent and the human it acts for, so the record is attributable to a\n * person and independently verifiable offline.\n */\n async record(action: BrowseAction, result: 'success' | 'denied' | 'error', reason?: string): Promise<boolean> {\n try {\n await this.sdk.emit({\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `browse:${action.action} ${action.url}`,\n resource: action.url,\n permission: this.scope,\n result,\n input_hash: action.inputHash,\n output_hash: action.outputHash,\n metadata: {\n integration: 'cloudflare-browser-run',\n acts_for_human: this.humanId,\n browse_action: action.action,\n ...(reason ? { reason } : {}),\n },\n }, { sign: true }); // source-signed: the key never leaves the Worker\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * The full flow for one browsing action: authorize, run it if allowed, sign a\n * receipt either way. If not authorized, `run` is never called. Rethrows an\n * error from `run` after recording it, so your handler still sees failures.\n */\n async browse<T>(action: BrowseAction, run: () => Promise<T>): Promise<{ receipt: BrowseReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', auth.reason);\n return { receipt: this.receipt(action, false, 'denied', auth.reason, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success');\n return { receipt: this.receipt(action, true, 'success', undefined, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', e?.message);\n throw Object.assign(e ?? new Error('browse action failed'), {\n vorimReceipt: this.receipt(action, true, 'error', e?.message, recorded),\n });\n }\n }\n\n private receipt(action: BrowseAction, authorized: boolean, result: 'success' | 'denied' | 'error', reason: string | undefined, recorded: boolean): BrowseReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n url: action.url,\n action: action.action,\n result,\n scope: this.scope,\n reason,\n recorded,\n };\n }\n}\n\n/**\n * Factory. Wrap a Vorim SDK instance with the Cloudflare browsing guard.\n *\n * @example\n * import createVorim from '@vorim/sdk';\n * import { createVorimCloudflare } from '@vorim/sdk/integrations/cloudflare';\n *\n * const vorim = createVorim({ apiKey: env.VORIM_API_KEY });\n * const guard = createVorimCloudflare(vorim, { agentId: 'agid_bot', humanId: 'user_jane' });\n * const { receipt, value } = await guard.browse(\n * { url: 'https://example.com', action: 'html_extract' },\n * () => extractHtmlWithKitesurf('https://example.com'),\n * );\n */\nexport function createVorimCloudflare(sdk: VorimSDK, config: CloudflareGuardConfig): VorimCloudflare {\n return new VorimCloudflare(sdk, config);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2FO,IAAM,kBAAN,MAAsB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAA+B;AACxD,QAAI,C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AO,IAAI,gBAAgB,KAAK,MAAM;AACxC;","names":[]}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.cjs';
|
|
2
|
+
import { P as PermissionScope } from '../types-zzK9YOoa.cjs';
|
|
3
|
+
|
|
4
|
+
interface CloudflareGuardConfig {
|
|
5
|
+
/** The acting agent's Vorim id (agid_...). */
|
|
6
|
+
agentId: string;
|
|
7
|
+
/** The human/principal the agent acts for. Recorded in every receipt so an
|
|
8
|
+
* action is attributable to a person, not just a machine. Optional but
|
|
9
|
+
* strongly recommended. */
|
|
10
|
+
humanId?: string;
|
|
11
|
+
/** Scope required before a browsing action runs. Default 'agent:read'. */
|
|
12
|
+
scope?: PermissionScope;
|
|
13
|
+
/** Minimum trust score the acting agent must hold. Default 0 (off). */
|
|
14
|
+
minTrustScore?: number;
|
|
15
|
+
/** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */
|
|
16
|
+
onError?: 'closed' | 'open';
|
|
17
|
+
}
|
|
18
|
+
interface BrowseAction {
|
|
19
|
+
/** The URL the agent is acting on. */
|
|
20
|
+
url: string;
|
|
21
|
+
/** What the agent is doing: 'html_extract', 'screenshot', 'pdf', 'navigate',
|
|
22
|
+
* or any label meaningful to you. */
|
|
23
|
+
action: string;
|
|
24
|
+
/** Optional: hash of the input/output so the receipt covers content without
|
|
25
|
+
* storing it (pairs with zero-data-retention). */
|
|
26
|
+
inputHash?: string;
|
|
27
|
+
outputHash?: string;
|
|
28
|
+
}
|
|
29
|
+
/** An offline-verifiable receipt for one browsing action. */
|
|
30
|
+
interface BrowseReceipt {
|
|
31
|
+
authorized: boolean;
|
|
32
|
+
agentId: string;
|
|
33
|
+
humanId?: string;
|
|
34
|
+
url: string;
|
|
35
|
+
action: string;
|
|
36
|
+
result: 'success' | 'denied' | 'error';
|
|
37
|
+
scope: PermissionScope;
|
|
38
|
+
/** Reason a check failed, when authorized is false. */
|
|
39
|
+
reason?: string;
|
|
40
|
+
/** True once the audit event was signed and ingested. */
|
|
41
|
+
recorded: boolean;
|
|
42
|
+
}
|
|
43
|
+
declare class VorimCloudflare {
|
|
44
|
+
private sdk;
|
|
45
|
+
private agentId;
|
|
46
|
+
private humanId?;
|
|
47
|
+
private scope;
|
|
48
|
+
private minTrustScore;
|
|
49
|
+
private onError;
|
|
50
|
+
constructor(sdk: VorimSDK, config: CloudflareGuardConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Check whether the acting agent is authorized to take a browsing action,
|
|
53
|
+
* before it runs. Returns { authorized, reason }.
|
|
54
|
+
*/
|
|
55
|
+
authorize(action: BrowseAction): Promise<{
|
|
56
|
+
authorized: boolean;
|
|
57
|
+
reason?: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Emit a source-signed audit event for a browsing action and return the
|
|
61
|
+
* receipt. Called after the action runs (or after a denial). The event names
|
|
62
|
+
* the agent and the human it acts for, so the record is attributable to a
|
|
63
|
+
* person and independently verifiable offline.
|
|
64
|
+
*/
|
|
65
|
+
record(action: BrowseAction, result: 'success' | 'denied' | 'error', reason?: string): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* The full flow for one browsing action: authorize, run it if allowed, sign a
|
|
68
|
+
* receipt either way. If not authorized, `run` is never called. Rethrows an
|
|
69
|
+
* error from `run` after recording it, so your handler still sees failures.
|
|
70
|
+
*/
|
|
71
|
+
browse<T>(action: BrowseAction, run: () => Promise<T>): Promise<{
|
|
72
|
+
receipt: BrowseReceipt;
|
|
73
|
+
value?: T;
|
|
74
|
+
}>;
|
|
75
|
+
private receipt;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Factory. Wrap a Vorim SDK instance with the Cloudflare browsing guard.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* import createVorim from '@vorim/sdk';
|
|
82
|
+
* import { createVorimCloudflare } from '@vorim/sdk/integrations/cloudflare';
|
|
83
|
+
*
|
|
84
|
+
* const vorim = createVorim({ apiKey: env.VORIM_API_KEY });
|
|
85
|
+
* const guard = createVorimCloudflare(vorim, { agentId: 'agid_bot', humanId: 'user_jane' });
|
|
86
|
+
* const { receipt, value } = await guard.browse(
|
|
87
|
+
* { url: 'https://example.com', action: 'html_extract' },
|
|
88
|
+
* () => extractHtmlWithKitesurf('https://example.com'),
|
|
89
|
+
* );
|
|
90
|
+
*/
|
|
91
|
+
declare function createVorimCloudflare(sdk: VorimSDK, config: CloudflareGuardConfig): VorimCloudflare;
|
|
92
|
+
|
|
93
|
+
export { type BrowseAction, type BrowseReceipt, type CloudflareGuardConfig, VorimCloudflare, createVorimCloudflare };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { VorimSDK } from '../index.js';
|
|
2
|
+
import { P as PermissionScope } from '../types-zzK9YOoa.js';
|
|
3
|
+
|
|
4
|
+
interface CloudflareGuardConfig {
|
|
5
|
+
/** The acting agent's Vorim id (agid_...). */
|
|
6
|
+
agentId: string;
|
|
7
|
+
/** The human/principal the agent acts for. Recorded in every receipt so an
|
|
8
|
+
* action is attributable to a person, not just a machine. Optional but
|
|
9
|
+
* strongly recommended. */
|
|
10
|
+
humanId?: string;
|
|
11
|
+
/** Scope required before a browsing action runs. Default 'agent:read'. */
|
|
12
|
+
scope?: PermissionScope;
|
|
13
|
+
/** Minimum trust score the acting agent must hold. Default 0 (off). */
|
|
14
|
+
minTrustScore?: number;
|
|
15
|
+
/** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */
|
|
16
|
+
onError?: 'closed' | 'open';
|
|
17
|
+
}
|
|
18
|
+
interface BrowseAction {
|
|
19
|
+
/** The URL the agent is acting on. */
|
|
20
|
+
url: string;
|
|
21
|
+
/** What the agent is doing: 'html_extract', 'screenshot', 'pdf', 'navigate',
|
|
22
|
+
* or any label meaningful to you. */
|
|
23
|
+
action: string;
|
|
24
|
+
/** Optional: hash of the input/output so the receipt covers content without
|
|
25
|
+
* storing it (pairs with zero-data-retention). */
|
|
26
|
+
inputHash?: string;
|
|
27
|
+
outputHash?: string;
|
|
28
|
+
}
|
|
29
|
+
/** An offline-verifiable receipt for one browsing action. */
|
|
30
|
+
interface BrowseReceipt {
|
|
31
|
+
authorized: boolean;
|
|
32
|
+
agentId: string;
|
|
33
|
+
humanId?: string;
|
|
34
|
+
url: string;
|
|
35
|
+
action: string;
|
|
36
|
+
result: 'success' | 'denied' | 'error';
|
|
37
|
+
scope: PermissionScope;
|
|
38
|
+
/** Reason a check failed, when authorized is false. */
|
|
39
|
+
reason?: string;
|
|
40
|
+
/** True once the audit event was signed and ingested. */
|
|
41
|
+
recorded: boolean;
|
|
42
|
+
}
|
|
43
|
+
declare class VorimCloudflare {
|
|
44
|
+
private sdk;
|
|
45
|
+
private agentId;
|
|
46
|
+
private humanId?;
|
|
47
|
+
private scope;
|
|
48
|
+
private minTrustScore;
|
|
49
|
+
private onError;
|
|
50
|
+
constructor(sdk: VorimSDK, config: CloudflareGuardConfig);
|
|
51
|
+
/**
|
|
52
|
+
* Check whether the acting agent is authorized to take a browsing action,
|
|
53
|
+
* before it runs. Returns { authorized, reason }.
|
|
54
|
+
*/
|
|
55
|
+
authorize(action: BrowseAction): Promise<{
|
|
56
|
+
authorized: boolean;
|
|
57
|
+
reason?: string;
|
|
58
|
+
}>;
|
|
59
|
+
/**
|
|
60
|
+
* Emit a source-signed audit event for a browsing action and return the
|
|
61
|
+
* receipt. Called after the action runs (or after a denial). The event names
|
|
62
|
+
* the agent and the human it acts for, so the record is attributable to a
|
|
63
|
+
* person and independently verifiable offline.
|
|
64
|
+
*/
|
|
65
|
+
record(action: BrowseAction, result: 'success' | 'denied' | 'error', reason?: string): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* The full flow for one browsing action: authorize, run it if allowed, sign a
|
|
68
|
+
* receipt either way. If not authorized, `run` is never called. Rethrows an
|
|
69
|
+
* error from `run` after recording it, so your handler still sees failures.
|
|
70
|
+
*/
|
|
71
|
+
browse<T>(action: BrowseAction, run: () => Promise<T>): Promise<{
|
|
72
|
+
receipt: BrowseReceipt;
|
|
73
|
+
value?: T;
|
|
74
|
+
}>;
|
|
75
|
+
private receipt;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Factory. Wrap a Vorim SDK instance with the Cloudflare browsing guard.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* import createVorim from '@vorim/sdk';
|
|
82
|
+
* import { createVorimCloudflare } from '@vorim/sdk/integrations/cloudflare';
|
|
83
|
+
*
|
|
84
|
+
* const vorim = createVorim({ apiKey: env.VORIM_API_KEY });
|
|
85
|
+
* const guard = createVorimCloudflare(vorim, { agentId: 'agid_bot', humanId: 'user_jane' });
|
|
86
|
+
* const { receipt, value } = await guard.browse(
|
|
87
|
+
* { url: 'https://example.com', action: 'html_extract' },
|
|
88
|
+
* () => extractHtmlWithKitesurf('https://example.com'),
|
|
89
|
+
* );
|
|
90
|
+
*/
|
|
91
|
+
declare function createVorimCloudflare(sdk: VorimSDK, config: CloudflareGuardConfig): VorimCloudflare;
|
|
92
|
+
|
|
93
|
+
export { type BrowseAction, type BrowseReceipt, type CloudflareGuardConfig, VorimCloudflare, createVorimCloudflare };
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// src/integrations/cloudflare.ts
|
|
2
|
+
var VorimCloudflare = class {
|
|
3
|
+
sdk;
|
|
4
|
+
agentId;
|
|
5
|
+
humanId;
|
|
6
|
+
scope;
|
|
7
|
+
minTrustScore;
|
|
8
|
+
onError;
|
|
9
|
+
constructor(sdk, config) {
|
|
10
|
+
if (!config?.agentId) throw new Error("[vorim] Cloudflare integration requires an agentId.");
|
|
11
|
+
this.sdk = sdk;
|
|
12
|
+
this.agentId = config.agentId;
|
|
13
|
+
this.humanId = config.humanId;
|
|
14
|
+
this.scope = config.scope ?? "agent:read";
|
|
15
|
+
this.minTrustScore = config.minTrustScore ?? 0;
|
|
16
|
+
this.onError = config.onError ?? "closed";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Check whether the acting agent is authorized to take a browsing action,
|
|
20
|
+
* before it runs. Returns { authorized, reason }.
|
|
21
|
+
*/
|
|
22
|
+
async authorize(action) {
|
|
23
|
+
try {
|
|
24
|
+
if (this.minTrustScore > 0) {
|
|
25
|
+
const trust = await this.sdk.verify(this.agentId);
|
|
26
|
+
if ((trust?.trust_score ?? 0) < this.minTrustScore) {
|
|
27
|
+
return { authorized: false, reason: `trust score below ${this.minTrustScore}` };
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const perm = await this.sdk.check(this.agentId, this.scope);
|
|
31
|
+
return perm.allowed ? { authorized: true } : { authorized: false, reason: perm.reason ?? `missing scope ${this.scope}` };
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return this.onError === "open" ? { authorized: true, reason: "vorim unreachable, failed open" } : { authorized: false, reason: `vorim unreachable: ${e?.message ?? "error"}` };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Emit a source-signed audit event for a browsing action and return the
|
|
38
|
+
* receipt. Called after the action runs (or after a denial). The event names
|
|
39
|
+
* the agent and the human it acts for, so the record is attributable to a
|
|
40
|
+
* person and independently verifiable offline.
|
|
41
|
+
*/
|
|
42
|
+
async record(action, result, reason) {
|
|
43
|
+
try {
|
|
44
|
+
await this.sdk.emit({
|
|
45
|
+
agent_id: this.agentId,
|
|
46
|
+
event_type: "api_request",
|
|
47
|
+
action: `browse:${action.action} ${action.url}`,
|
|
48
|
+
resource: action.url,
|
|
49
|
+
permission: this.scope,
|
|
50
|
+
result,
|
|
51
|
+
input_hash: action.inputHash,
|
|
52
|
+
output_hash: action.outputHash,
|
|
53
|
+
metadata: {
|
|
54
|
+
integration: "cloudflare-browser-run",
|
|
55
|
+
acts_for_human: this.humanId,
|
|
56
|
+
browse_action: action.action,
|
|
57
|
+
...reason ? { reason } : {}
|
|
58
|
+
}
|
|
59
|
+
}, { sign: true });
|
|
60
|
+
return true;
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* The full flow for one browsing action: authorize, run it if allowed, sign a
|
|
67
|
+
* receipt either way. If not authorized, `run` is never called. Rethrows an
|
|
68
|
+
* error from `run` after recording it, so your handler still sees failures.
|
|
69
|
+
*/
|
|
70
|
+
async browse(action, run) {
|
|
71
|
+
const auth = await this.authorize(action);
|
|
72
|
+
if (!auth.authorized) {
|
|
73
|
+
const recorded = await this.record(action, "denied", auth.reason);
|
|
74
|
+
return { receipt: this.receipt(action, false, "denied", auth.reason, recorded) };
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const value = await run();
|
|
78
|
+
const recorded = await this.record(action, "success");
|
|
79
|
+
return { receipt: this.receipt(action, true, "success", void 0, recorded), value };
|
|
80
|
+
} catch (e) {
|
|
81
|
+
const recorded = await this.record(action, "error", e?.message);
|
|
82
|
+
throw Object.assign(e ?? new Error("browse action failed"), {
|
|
83
|
+
vorimReceipt: this.receipt(action, true, "error", e?.message, recorded)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
receipt(action, authorized, result, reason, recorded) {
|
|
88
|
+
return {
|
|
89
|
+
authorized,
|
|
90
|
+
agentId: this.agentId,
|
|
91
|
+
humanId: this.humanId,
|
|
92
|
+
url: action.url,
|
|
93
|
+
action: action.action,
|
|
94
|
+
result,
|
|
95
|
+
scope: this.scope,
|
|
96
|
+
reason,
|
|
97
|
+
recorded
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
function createVorimCloudflare(sdk, config) {
|
|
102
|
+
return new VorimCloudflare(sdk, config);
|
|
103
|
+
}
|
|
104
|
+
export {
|
|
105
|
+
VorimCloudflare,
|
|
106
|
+
createVorimCloudflare
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=cloudflare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/cloudflare.ts"],"sourcesContent":["// ============================================================================\n// Vorim AI — Cloudflare Workers / Browser Run (kitesurf) Integration\n//\n// Cloudflare's Agent Access Model gives agents short-lived, task-scoped\n// credentials and enforces policy at the mediation layer. It is strong, but by\n// Cloudflare's own account it stops short in a few places: no cryptographic\n// per-action signing at the source, no offline verification (proof needs a live\n// call back to the enforcement point), no attenuated delegation across multiple\n// agent hops, and trust that anchors to Cloudflare's own control plane rather\n// than a portable, independently verifiable proof.\n//\n// This integration adds exactly that layer, in the path the agent already takes\n// on a Worker. For every browsing action (a Browser Run / kitesurf call, or any\n// agent web request), it:\n// 1. checks the acting agent holds the scope BEFORE the action runs,\n// 2. runs the action,\n// 3. emits a source-SIGNED audit event that names the agent AND the human it\n// acts for, and returns a receipt you can verify offline, with no call back\n// to Vorim or Cloudflare.\n//\n// The whole thing runs on the edge: the Vorim SDK signs with Web Crypto\n// (Ed25519), so no Node runtime is needed. Keep the agent private key in a\n// Worker secret; register the agent with vorim.register() and cache the key so\n// emit() auto-signs.\n//\n// Usage (inside a Worker):\n// import createVorim from '@vorim/sdk';\n// import { createVorimCloudflare } from '@vorim/sdk/integrations/cloudflare';\n//\n// const vorim = createVorim({ apiKey: env.VORIM_API_KEY });\n// const guard = createVorimCloudflare(vorim, {\n// agentId: 'agid_browse_bot',\n// humanId: 'user_jane', // the principal the agent acts for\n// scope: 'agent:read', // scope required to browse\n// });\n//\n// export default {\n// async fetch(req, env) {\n// return guard.browse(\n// { url: 'https://example.com', action: 'html_extract' },\n// () => fetch('https://browser.cloudflare.com/...'), // your Browser Run / kitesurf call\n// );\n// },\n// };\n// ============================================================================\n\nimport type { VorimSDK } from '../index.js';\nimport type { PermissionScope } from '../types.js';\n\nexport interface CloudflareGuardConfig {\n /** The acting agent's Vorim id (agid_...). */\n agentId: string;\n /** The human/principal the agent acts for. Recorded in every receipt so an\n * action is attributable to a person, not just a machine. Optional but\n * strongly recommended. */\n humanId?: string;\n /** Scope required before a browsing action runs. Default 'agent:read'. */\n scope?: PermissionScope;\n /** Minimum trust score the acting agent must hold. Default 0 (off). */\n minTrustScore?: number;\n /** Fail closed (deny on any Vorim error) or fail open. Default 'closed'. */\n onError?: 'closed' | 'open';\n}\n\nexport interface BrowseAction {\n /** The URL the agent is acting on. */\n url: string;\n /** What the agent is doing: 'html_extract', 'screenshot', 'pdf', 'navigate',\n * or any label meaningful to you. */\n action: string;\n /** Optional: hash of the input/output so the receipt covers content without\n * storing it (pairs with zero-data-retention). */\n inputHash?: string;\n outputHash?: string;\n}\n\n/** An offline-verifiable receipt for one browsing action. */\nexport interface BrowseReceipt {\n authorized: boolean;\n agentId: string;\n humanId?: string;\n url: string;\n action: string;\n result: 'success' | 'denied' | 'error';\n scope: PermissionScope;\n /** Reason a check failed, when authorized is false. */\n reason?: string;\n /** True once the audit event was signed and ingested. */\n recorded: boolean;\n}\n\nexport class VorimCloudflare {\n private sdk: VorimSDK;\n private agentId: string;\n private humanId?: string;\n private scope: PermissionScope;\n private minTrustScore: number;\n private onError: 'closed' | 'open';\n\n constructor(sdk: VorimSDK, config: CloudflareGuardConfig) {\n if (!config?.agentId) throw new Error('[vorim] Cloudflare integration requires an agentId.');\n this.sdk = sdk;\n this.agentId = config.agentId;\n this.humanId = config.humanId;\n this.scope = config.scope ?? 'agent:read';\n this.minTrustScore = config.minTrustScore ?? 0;\n this.onError = config.onError ?? 'closed';\n }\n\n /**\n * Check whether the acting agent is authorized to take a browsing action,\n * before it runs. Returns { authorized, reason }.\n */\n async authorize(action: BrowseAction): Promise<{ authorized: boolean; reason?: string }> {\n try {\n // Trust floor (optional): refuse low-trust agents up front.\n if (this.minTrustScore > 0) {\n const trust = await this.sdk.verify(this.agentId);\n if ((trust?.trust_score ?? 0) < this.minTrustScore) {\n return { authorized: false, reason: `trust score below ${this.minTrustScore}` };\n }\n }\n const perm = await this.sdk.check(this.agentId, this.scope);\n return perm.allowed\n ? { authorized: true }\n : { authorized: false, reason: perm.reason ?? `missing scope ${this.scope}` };\n } catch (e: any) {\n // Fail closed by default: a check we could not complete is a deny.\n return this.onError === 'open'\n ? { authorized: true, reason: 'vorim unreachable, failed open' }\n : { authorized: false, reason: `vorim unreachable: ${e?.message ?? 'error'}` };\n }\n }\n\n /**\n * Emit a source-signed audit event for a browsing action and return the\n * receipt. Called after the action runs (or after a denial). The event names\n * the agent and the human it acts for, so the record is attributable to a\n * person and independently verifiable offline.\n */\n async record(action: BrowseAction, result: 'success' | 'denied' | 'error', reason?: string): Promise<boolean> {\n try {\n await this.sdk.emit({\n agent_id: this.agentId,\n event_type: 'api_request',\n action: `browse:${action.action} ${action.url}`,\n resource: action.url,\n permission: this.scope,\n result,\n input_hash: action.inputHash,\n output_hash: action.outputHash,\n metadata: {\n integration: 'cloudflare-browser-run',\n acts_for_human: this.humanId,\n browse_action: action.action,\n ...(reason ? { reason } : {}),\n },\n }, { sign: true }); // source-signed: the key never leaves the Worker\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * The full flow for one browsing action: authorize, run it if allowed, sign a\n * receipt either way. If not authorized, `run` is never called. Rethrows an\n * error from `run` after recording it, so your handler still sees failures.\n */\n async browse<T>(action: BrowseAction, run: () => Promise<T>): Promise<{ receipt: BrowseReceipt; value?: T }> {\n const auth = await this.authorize(action);\n if (!auth.authorized) {\n const recorded = await this.record(action, 'denied', auth.reason);\n return { receipt: this.receipt(action, false, 'denied', auth.reason, recorded) };\n }\n try {\n const value = await run();\n const recorded = await this.record(action, 'success');\n return { receipt: this.receipt(action, true, 'success', undefined, recorded), value };\n } catch (e: any) {\n const recorded = await this.record(action, 'error', e?.message);\n throw Object.assign(e ?? new Error('browse action failed'), {\n vorimReceipt: this.receipt(action, true, 'error', e?.message, recorded),\n });\n }\n }\n\n private receipt(action: BrowseAction, authorized: boolean, result: 'success' | 'denied' | 'error', reason: string | undefined, recorded: boolean): BrowseReceipt {\n return {\n authorized,\n agentId: this.agentId,\n humanId: this.humanId,\n url: action.url,\n action: action.action,\n result,\n scope: this.scope,\n reason,\n recorded,\n };\n }\n}\n\n/**\n * Factory. Wrap a Vorim SDK instance with the Cloudflare browsing guard.\n *\n * @example\n * import createVorim from '@vorim/sdk';\n * import { createVorimCloudflare } from '@vorim/sdk/integrations/cloudflare';\n *\n * const vorim = createVorim({ apiKey: env.VORIM_API_KEY });\n * const guard = createVorimCloudflare(vorim, { agentId: 'agid_bot', humanId: 'user_jane' });\n * const { receipt, value } = await guard.browse(\n * { url: 'https://example.com', action: 'html_extract' },\n * () => extractHtmlWithKitesurf('https://example.com'),\n * );\n */\nexport function createVorimCloudflare(sdk: VorimSDK, config: CloudflareGuardConfig): VorimCloudflare {\n return new VorimCloudflare(sdk, config);\n}\n"],"mappings":";AA2FO,IAAM,kBAAN,MAAsB;AAAA,EACnB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,YAAY,KAAe,QAA+B;AACxD,QAAI,CAAC,QAAQ,QAAS,OAAM,IAAI,MAAM,qDAAqD;AAC3F,SAAK,MAAM;AACX,SAAK,UAAU,OAAO;AACtB,SAAK,UAAU,OAAO;AACtB,SAAK,QAAQ,OAAO,SAAS;AAC7B,SAAK,gBAAgB,OAAO,iBAAiB;AAC7C,SAAK,UAAU,OAAO,WAAW;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,UAAU,QAAyE;AACvF,QAAI;AAEF,UAAI,KAAK,gBAAgB,GAAG;AAC1B,cAAM,QAAQ,MAAM,KAAK,IAAI,OAAO,KAAK,OAAO;AAChD,aAAK,OAAO,eAAe,KAAK,KAAK,eAAe;AAClD,iBAAO,EAAE,YAAY,OAAO,QAAQ,qBAAqB,KAAK,aAAa,GAAG;AAAA,QAChF;AAAA,MACF;AACA,YAAM,OAAO,MAAM,KAAK,IAAI,MAAM,KAAK,SAAS,KAAK,KAAK;AAC1D,aAAO,KAAK,UACR,EAAE,YAAY,KAAK,IACnB,EAAE,YAAY,OAAO,QAAQ,KAAK,UAAU,iBAAiB,KAAK,KAAK,GAAG;AAAA,I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