@private.me/xbind 1.3.5 → 3.0.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/LICENSES.md +212 -0
- package/README.md +388 -6
- package/dist-standalone/_deps/mldsa-wasm/dist/mldsa.js +1 -1920
- package/dist-standalone/_deps/shared/cjs/errors.js +1 -639
- package/dist-standalone/_deps/shared/cjs/index.js +1 -496
- package/dist-standalone/_deps/shared/cjs/types.js +1 -317
- package/dist-standalone/_deps/shared/errors.js +1 -255
- package/dist-standalone/_deps/shared/index.js +1 -74
- package/dist-standalone/_deps/shared/types.js +1 -90
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js +1 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js +1 -1
- package/dist-standalone/_deps/ux-helpers/errors.js +1 -1
- package/dist-standalone/_deps/ux-helpers/index.js +1 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js +1 -1
- package/dist-standalone/_deps/ux-helpers/progress.js +1 -1
- package/dist-standalone/_deps/ux-helpers/search.js +1 -1
- package/dist-standalone/_deps/xchange/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/auto-accept.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/index.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/cjs/xchange.js +1 -1
- package/dist-standalone/_deps/xchange/errors.js +1 -1
- package/dist-standalone/_deps/xchange/index.js +1 -1
- package/dist-standalone/_deps/xchange/invite-client.js +1 -1
- package/dist-standalone/_deps/xchange/lazy-init.js +1 -1
- package/dist-standalone/_deps/xchange/trust-integration.js +1 -1
- package/dist-standalone/_deps/xchange/xchange.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/index.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/cjs/types.js +1 -1
- package/dist-standalone/_deps/xregistry/discovery.js +1 -1
- package/dist-standalone/_deps/xregistry/errors.js +1 -1
- package/dist-standalone/_deps/xregistry/index.js +1 -1
- package/dist-standalone/_deps/xregistry/registry.js +1 -1
- package/dist-standalone/_deps/xregistry/schema.js +1 -1
- package/dist-standalone/_deps/xregistry/types.js +1 -1
- package/dist-standalone/agent-call.js +1 -642
- package/dist-standalone/agent-sdk.js +1 -328
- package/dist-standalone/agent.d.ts +95 -5
- package/dist-standalone/agent.js +1 -1545
- package/dist-standalone/approval.js +1 -193
- package/dist-standalone/async-iterators.d.ts +275 -0
- package/dist-standalone/async-iterators.js +1 -0
- package/dist-standalone/auth.js +1 -219
- package/dist-standalone/auto-accept.js +1 -229
- package/dist-standalone/backup-config.js +1 -201
- package/dist-standalone/backup.d.ts +114 -0
- package/dist-standalone/backup.js +1 -0
- package/dist-standalone/batch-operations.d.ts +297 -0
- package/dist-standalone/batch-operations.js +1 -0
- package/dist-standalone/cancellation.d.ts +301 -0
- package/dist-standalone/cancellation.js +1 -0
- package/dist-standalone/checkpoint.js +1 -186
- package/dist-standalone/circuit-breaker.d.ts +351 -0
- package/dist-standalone/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/agent-call.js +1 -651
- package/dist-standalone/cjs/agent-sdk.js +1 -332
- package/dist-standalone/cjs/agent.js +1 -1582
- package/dist-standalone/cjs/approval.js +1 -199
- package/dist-standalone/cjs/async-iterators.js +1 -0
- package/dist-standalone/cjs/auth.js +1 -225
- package/dist-standalone/cjs/auto-accept.js +1 -233
- package/dist-standalone/cjs/backup-config.js +1 -207
- package/dist-standalone/cjs/backup.js +1 -0
- package/dist-standalone/cjs/batch-operations.js +1 -0
- package/dist-standalone/cjs/cancellation.js +1 -0
- package/dist-standalone/cjs/checkpoint.js +1 -193
- package/dist-standalone/cjs/circuit-breaker.js +1 -0
- package/dist-standalone/cjs/cli/init.js +1 -486
- package/dist-standalone/cjs/config-validation.js +1 -0
- package/dist-standalone/cjs/connect.js +1 -312
- package/dist-standalone/cjs/connection-pool.js +1 -0
- package/dist-standalone/cjs/correlation-id.js +1 -339
- package/dist-standalone/cjs/crypto-utils.js +1 -0
- package/dist-standalone/cjs/debug-mode.js +1 -0
- package/dist-standalone/cjs/did-document.js +1 -101
- package/dist-standalone/cjs/did-privateme.js +1 -130
- package/dist-standalone/cjs/did-web.js +1 -201
- package/dist-standalone/cjs/discovery.js +1 -462
- package/dist-standalone/cjs/dual-mode.js +1 -251
- package/dist-standalone/cjs/email-templates.js +1 -313
- package/dist-standalone/cjs/email-transport.js +1 -239
- package/dist-standalone/cjs/envelope.js +1 -510
- package/dist-standalone/cjs/errors.js +1 -826
- package/dist-standalone/cjs/event-emitter.js +1 -0
- package/dist-standalone/cjs/gateway-state.js +1 -55
- package/dist-standalone/cjs/gateway-transport.js +1 -120
- package/dist-standalone/cjs/graceful-degradation.js +1 -0
- package/dist-standalone/cjs/guardrails.js +1 -223
- package/dist-standalone/cjs/health-check.js +1 -0
- package/dist-standalone/cjs/http-compat.js +1 -272
- package/dist-standalone/cjs/http-status-map.js +1 -571
- package/dist-standalone/cjs/identity.js +1 -540
- package/dist-standalone/cjs/index.js +1 -237
- package/dist-standalone/cjs/invitation.js +1 -421
- package/dist-standalone/cjs/invite.js +1 -328
- package/dist-standalone/cjs/key-agreement.js +1 -246
- package/dist-standalone/cjs/lazy-init.js +1 -300
- package/dist-standalone/cjs/logger.js +1 -0
- package/dist-standalone/cjs/mdns-discovery.js +1 -202
- package/dist-standalone/cjs/nonce-store.js +1 -66
- package/dist-standalone/cjs/pairing-manager.js +1 -223
- package/dist-standalone/cjs/plugin-system.js +1 -0
- package/dist-standalone/cjs/plugins/logging.js +1 -0
- package/dist-standalone/cjs/plugins/metrics.js +1 -0
- package/dist-standalone/cjs/plugins/validation.js +1 -0
- package/dist-standalone/cjs/policy.js +1 -320
- package/dist-standalone/cjs/progress-callbacks.js +1 -0
- package/dist-standalone/cjs/redis-nonce-store.js +1 -76
- package/dist-standalone/cjs/registry-middleware.js +1 -50
- package/dist-standalone/cjs/retry-strategies.js +1 -0
- package/dist-standalone/cjs/retry-transport.js +1 -102
- package/dist-standalone/cjs/runtime/browser.js +1 -0
- package/dist-standalone/cjs/runtime/edge.js +1 -0
- package/dist-standalone/cjs/runtime/react-native.js +1 -0
- package/dist-standalone/cjs/security-policy.js +1 -245
- package/dist-standalone/cjs/serialization.js +1 -0
- package/dist-standalone/cjs/split-channel.js +1 -177
- package/dist-standalone/cjs/subscription-proof.js +1 -230
- package/dist-standalone/cjs/succession.js +1 -148
- package/dist-standalone/cjs/timeouts.js +1 -0
- package/dist-standalone/cjs/trace-context.js +1 -0
- package/dist-standalone/cjs/trace-spans.js +1 -0
- package/dist-standalone/cjs/transport.js +1 -63
- package/dist-standalone/cjs/trust-registry.js +1 -742
- package/dist-standalone/cjs/types/error-response.js +1 -56
- package/dist-standalone/cjs/vault-auth.js +1 -0
- package/dist-standalone/cjs/vault-store-loader.js +1 -0
- package/dist-standalone/cjs/verify.js +1 -25
- package/dist-standalone/cjs/version-info.js +1 -0
- package/dist-standalone/cjs/xfetch.js +1 -252
- package/dist-standalone/cli/init.js +1 -449
- package/dist-standalone/cli/setup.js +1 -514
- package/dist-standalone/cli/types.js +1 -27
- package/dist-standalone/cli/xbind.js +1 -148
- package/dist-standalone/config-validation.d.ts +185 -0
- package/dist-standalone/config-validation.js +1 -0
- package/dist-standalone/connect.js +1 -274
- package/dist-standalone/connection-pool.d.ts +251 -0
- package/dist-standalone/connection-pool.js +1 -0
- package/dist-standalone/correlation-id.js +1 -326
- package/dist-standalone/crypto-utils.d.ts +60 -0
- package/dist-standalone/crypto-utils.js +1 -0
- package/dist-standalone/debug-mode.d.ts +286 -0
- package/dist-standalone/debug-mode.js +1 -0
- package/dist-standalone/did-document.js +1 -96
- package/dist-standalone/did-privateme.js +1 -121
- package/dist-standalone/did-web.js +1 -196
- package/dist-standalone/discovery.js +1 -458
- package/dist-standalone/dual-mode.js +1 -247
- package/dist-standalone/email-templates.js +1 -309
- package/dist-standalone/email-transport.js +1 -232
- package/dist-standalone/envelope.d.ts +29 -1
- package/dist-standalone/envelope.js +1 -497
- package/dist-standalone/errors.d.ts +10 -0
- package/dist-standalone/errors.js +1 -811
- package/dist-standalone/event-emitter.d.ts +395 -0
- package/dist-standalone/event-emitter.js +1 -0
- package/dist-standalone/gateway-state.js +1 -51
- package/dist-standalone/gateway-transport.js +1 -116
- package/dist-standalone/graceful-degradation.d.ts +246 -0
- package/dist-standalone/graceful-degradation.js +1 -0
- package/dist-standalone/guardrails.js +1 -216
- package/dist-standalone/health-check.d.ts +150 -0
- package/dist-standalone/health-check.js +1 -0
- package/dist-standalone/http-compat.js +1 -267
- package/dist-standalone/http-status-map.js +1 -561
- package/dist-standalone/identity.d.ts +64 -1
- package/dist-standalone/identity.js +1 -515
- package/dist-standalone/index.d.ts +45 -3
- package/dist-standalone/index.js +1 -52
- package/dist-standalone/invitation.js +1 -415
- package/dist-standalone/invite.js +1 -324
- package/dist-standalone/key-agreement.d.ts +61 -13
- package/dist-standalone/key-agreement.js +1 -236
- package/dist-standalone/lazy-init.js +1 -295
- package/dist-standalone/logger.d.ts +77 -0
- package/dist-standalone/logger.js +1 -0
- package/dist-standalone/mdns-discovery.js +1 -195
- package/dist-standalone/nonce-store.d.ts +16 -3
- package/dist-standalone/nonce-store.js +1 -62
- package/dist-standalone/package.json +0 -1
- package/dist-standalone/pairing-manager.js +1 -219
- package/dist-standalone/plugin-system.d.ts +145 -0
- package/dist-standalone/plugin-system.js +1 -0
- package/dist-standalone/policy.js +1 -315
- package/dist-standalone/progress-callbacks.d.ts +394 -0
- package/dist-standalone/progress-callbacks.js +1 -0
- package/dist-standalone/redis-nonce-store.js +1 -72
- package/dist-standalone/registry-middleware.js +1 -47
- package/dist-standalone/retry-strategies.d.ts +382 -0
- package/dist-standalone/retry-strategies.js +1 -0
- package/dist-standalone/retry-transport.js +1 -98
- package/dist-standalone/security-policy.js +1 -239
- package/dist-standalone/serialization.d.ts +244 -0
- package/dist-standalone/serialization.js +1 -0
- package/dist-standalone/split-channel.d.ts +49 -1
- package/dist-standalone/split-channel.js +1 -171
- package/dist-standalone/subscription-proof.js +1 -224
- package/dist-standalone/succession.js +1 -142
- package/dist-standalone/timeouts.d.ts +275 -0
- package/dist-standalone/timeouts.js +1 -0
- package/dist-standalone/trace-context.d.ts +252 -0
- package/dist-standalone/trace-context.js +1 -0
- package/dist-standalone/trace-spans.d.ts +360 -0
- package/dist-standalone/trace-spans.js +1 -0
- package/dist-standalone/transport.js +1 -59
- package/dist-standalone/trust-registry.d.ts +106 -5
- package/dist-standalone/trust-registry.js +1 -702
- package/dist-standalone/vault-auth.d.ts +91 -0
- package/dist-standalone/vault-auth.js +1 -0
- package/dist-standalone/vault-store-loader.d.ts +110 -0
- package/dist-standalone/vault-store-loader.js +1 -0
- package/dist-standalone/verify.js +1 -16
- package/dist-standalone/version-info.d.ts +259 -0
- package/dist-standalone/version-info.js +1 -0
- package/dist-standalone/xfetch.js +1 -247
- package/llms.txt +1 -0
- package/package.json +65 -5
- package/share1.dat +0 -0
- package/dist-standalone/_deps/crypto/base64.d.ts +0 -29
- package/dist-standalone/_deps/crypto/base64.js +0 -222
- package/dist-standalone/_deps/crypto/cjs/base64.js +0 -665
- package/dist-standalone/_deps/crypto/cjs/errors.js +0 -675
- package/dist-standalone/_deps/crypto/cjs/hmac.js +0 -473
- package/dist-standalone/_deps/crypto/cjs/index.js +0 -852
- package/dist-standalone/_deps/crypto/cjs/package.json +0 -1
- package/dist-standalone/_deps/crypto/cjs/padding.js +0 -511
- package/dist-standalone/_deps/crypto/cjs/share-header.js +0 -372
- package/dist-standalone/_deps/crypto/cjs/shares.js +0 -874
- package/dist-standalone/_deps/crypto/cjs/tlv.js +0 -1021
- package/dist-standalone/_deps/crypto/cjs/uuid.js +0 -443
- package/dist-standalone/_deps/crypto/cjs/verify.js +0 -414
- package/dist-standalone/_deps/crypto/cjs/xorida.js +0 -923
- package/dist-standalone/_deps/crypto/errors.d.ts +0 -51
- package/dist-standalone/_deps/crypto/errors.js +0 -199
- package/dist-standalone/_deps/crypto/hmac.d.ts +0 -39
- package/dist-standalone/_deps/crypto/hmac.js +0 -134
- package/dist-standalone/_deps/crypto/index.d.ts +0 -20
- package/dist-standalone/_deps/crypto/index.js +0 -145
- package/dist-standalone/_deps/crypto/padding.d.ts +0 -19
- package/dist-standalone/_deps/crypto/padding.js +0 -159
- package/dist-standalone/_deps/crypto/share-header.d.ts +0 -44
- package/dist-standalone/_deps/crypto/share-header.js +0 -92
- package/dist-standalone/_deps/crypto/shares.d.ts +0 -27
- package/dist-standalone/_deps/crypto/shares.js +0 -295
- package/dist-standalone/_deps/crypto/tlv.d.ts +0 -26
- package/dist-standalone/_deps/crypto/tlv.js +0 -364
- package/dist-standalone/_deps/crypto/uuid.d.ts +0 -22
- package/dist-standalone/_deps/crypto/uuid.js +0 -136
- package/dist-standalone/_deps/crypto/verify.d.ts +0 -15
- package/dist-standalone/_deps/crypto/verify.js +0 -71
- package/dist-standalone/_deps/crypto/xorida.d.ts +0 -44
- package/dist-standalone/_deps/crypto/xorida.js +0 -366
- package/dist-standalone/_deps/shared/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/errors.js.map +0 -1
- package/dist-standalone/_deps/shared/index.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/index.js.map +0 -1
- package/dist-standalone/_deps/shared/types.d.ts.map +0 -1
- package/dist-standalone/_deps/shared/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/cjs/types.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/errors.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/index.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/pagination.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/progress.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/search.js.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.d.ts.map +0 -1
- package/dist-standalone/_deps/ux-helpers/types.js.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/discovery.js.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/errors.js.map +0 -1
- package/dist-standalone/_deps/xregistry/index.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/index.js.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/registry.js.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/schema.js.map +0 -1
- package/dist-standalone/_deps/xregistry/types.d.ts.map +0 -1
- package/dist-standalone/_deps/xregistry/types.js.map +0 -1
|
@@ -1,332 +1 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* @module agent-sdk
|
|
4
|
-
* Agent builder wrapper for AI-first interface
|
|
5
|
-
*
|
|
6
|
-
* Provides simplified agent creation with ephemeral identities,
|
|
7
|
-
* policy constraints, and automatic lifecycle management.
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.AgentBuilder = void 0;
|
|
11
|
-
const shared_1 = require("../_deps/shared/index.js");
|
|
12
|
-
const identity_js_1 = require("./identity.js");
|
|
13
|
-
const agent_call_js_1 = require("./agent-call.js");
|
|
14
|
-
const agent_call_js_2 = require("./agent-call.js");
|
|
15
|
-
const policy_js_1 = require("./policy.js");
|
|
16
|
-
/**
|
|
17
|
-
* Agent builder - AI-first wrapper for xBind agent creation
|
|
18
|
-
*
|
|
19
|
-
* Provides high-level API for creating agents with automatic
|
|
20
|
-
* identity management, policy enforcement, and lifecycle cleanup.
|
|
21
|
-
*
|
|
22
|
-
* This is the simplified xBind agent builder for AI agents. For full
|
|
23
|
-
* transport-level control, use the Agent class from './agent.js'.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```typescript
|
|
27
|
-
* // Create ephemeral agent (auto-cleanup after 1 hour)
|
|
28
|
-
* const agent = await AgentBuilder.create({
|
|
29
|
-
* name: "invoice-agent",
|
|
30
|
-
* policy: {
|
|
31
|
-
* allowedTools: ["payments:createCharge", "payments:refund"],
|
|
32
|
-
* limits: {
|
|
33
|
-
* amountPerTxn: 1000,
|
|
34
|
-
* dailyAmount: 10000
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* });
|
|
38
|
-
*
|
|
39
|
-
* // Use agent to call tools
|
|
40
|
-
* const result = await agent.call("payments:createCharge", {
|
|
41
|
-
* amount: 100,
|
|
42
|
-
* currency: "USD"
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*/
|
|
46
|
-
class AgentBuilder {
|
|
47
|
-
/** Agent identity (cryptographic keys + DID) */
|
|
48
|
-
_identity;
|
|
49
|
-
/** Agent metadata */
|
|
50
|
-
_metadata;
|
|
51
|
-
/** Policy constraints (optional) */
|
|
52
|
-
_policy;
|
|
53
|
-
/**
|
|
54
|
-
* Create a new AgentBuilder instance.
|
|
55
|
-
*
|
|
56
|
-
* @param identity - Agent identity
|
|
57
|
-
* @param metadata - Agent metadata
|
|
58
|
-
* @param policy - Optional policy constraints
|
|
59
|
-
*/
|
|
60
|
-
constructor(identity, metadata, policy) {
|
|
61
|
-
this._identity = identity;
|
|
62
|
-
this._metadata = metadata;
|
|
63
|
-
this._policy = policy;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Agent DID (decentralized identifier).
|
|
67
|
-
*/
|
|
68
|
-
get did() {
|
|
69
|
-
return this._identity.did;
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Agent name.
|
|
73
|
-
*/
|
|
74
|
-
get name() {
|
|
75
|
-
return this._metadata.name;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Creation timestamp (milliseconds since epoch).
|
|
79
|
-
*/
|
|
80
|
-
get created() {
|
|
81
|
-
return this._metadata.created;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Identity mode ('ephemeral' or 'persistent').
|
|
85
|
-
*/
|
|
86
|
-
get identityMode() {
|
|
87
|
-
return this._metadata.identityMode;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Time-to-live for ephemeral agents (milliseconds).
|
|
91
|
-
* Returns undefined for persistent agents.
|
|
92
|
-
*/
|
|
93
|
-
get ttl() {
|
|
94
|
-
return this._metadata.ttl;
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Time remaining until auto-cleanup (milliseconds).
|
|
98
|
-
* Returns undefined for persistent agents or if already expired.
|
|
99
|
-
*/
|
|
100
|
-
get timeRemaining() {
|
|
101
|
-
if (!this._metadata.ttl)
|
|
102
|
-
return undefined;
|
|
103
|
-
const elapsed = Date.now() - this._metadata.created;
|
|
104
|
-
const remaining = this._metadata.ttl - elapsed;
|
|
105
|
-
return remaining > 0 ? remaining : 0;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Create a new agent instance.
|
|
109
|
-
*
|
|
110
|
-
* @param options - Agent creation options
|
|
111
|
-
* @returns AgentBuilder instance or error
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* // Ephemeral agent (default)
|
|
116
|
-
* const agent = await AgentBuilder.create({
|
|
117
|
-
* name: "task-agent",
|
|
118
|
-
* policy: {
|
|
119
|
-
* allowedTools: ["slack:sendMessage"],
|
|
120
|
-
* limits: { callsPerMinute: 10 }
|
|
121
|
-
* }
|
|
122
|
-
* });
|
|
123
|
-
* ```
|
|
124
|
-
*
|
|
125
|
-
* @example
|
|
126
|
-
* ```typescript
|
|
127
|
-
* // Persistent agent from seed
|
|
128
|
-
* const seed = new Uint8Array(32);
|
|
129
|
-
* crypto.getRandomValues(seed);
|
|
130
|
-
*
|
|
131
|
-
* const agent = await AgentBuilder.create({
|
|
132
|
-
* name: "persistent-agent",
|
|
133
|
-
* identity: seed, // Deterministic DID
|
|
134
|
-
* });
|
|
135
|
-
* ```
|
|
136
|
-
*/
|
|
137
|
-
static async create(options) {
|
|
138
|
-
try {
|
|
139
|
-
// Determine identity mode
|
|
140
|
-
let identity;
|
|
141
|
-
let identityMode;
|
|
142
|
-
if (!options.identity || options.identity === 'ephemeral') {
|
|
143
|
-
// Generate ephemeral identity
|
|
144
|
-
const idResult = await (0, identity_js_1.generateIdentity)();
|
|
145
|
-
if (!idResult.ok) {
|
|
146
|
-
return (0, shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED, 'Failed to generate ephemeral identity', { cause: idResult.error }));
|
|
147
|
-
}
|
|
148
|
-
identity = idResult.value;
|
|
149
|
-
identityMode = 'ephemeral';
|
|
150
|
-
}
|
|
151
|
-
else if (options.identity === 'persistent') {
|
|
152
|
-
// Generate persistent identity
|
|
153
|
-
const idResult = await (0, identity_js_1.generateIdentity)();
|
|
154
|
-
if (!idResult.ok) {
|
|
155
|
-
return (0, shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED, 'Failed to generate persistent identity', { cause: idResult.error }));
|
|
156
|
-
}
|
|
157
|
-
identity = idResult.value;
|
|
158
|
-
identityMode = 'persistent';
|
|
159
|
-
}
|
|
160
|
-
else if (options.identity instanceof Uint8Array) {
|
|
161
|
-
// Deterministic identity from seed
|
|
162
|
-
if (options.identity.length !== 32) {
|
|
163
|
-
return (0, shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.INVALID_PARAMS, 'Identity seed must be exactly 32 bytes', { seedLength: options.identity.length }));
|
|
164
|
-
}
|
|
165
|
-
const idResult = await (0, identity_js_1.identityFromSeed)(options.identity);
|
|
166
|
-
if (!idResult.ok) {
|
|
167
|
-
return (0, shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED, 'Failed to derive identity from seed', { cause: idResult.error }));
|
|
168
|
-
}
|
|
169
|
-
identity = idResult.value;
|
|
170
|
-
identityMode = 'persistent';
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
173
|
-
// Use provided AgentIdentity
|
|
174
|
-
identity = options.identity;
|
|
175
|
-
identityMode = 'persistent';
|
|
176
|
-
}
|
|
177
|
-
// Create metadata
|
|
178
|
-
const metadata = {
|
|
179
|
-
name: options.name,
|
|
180
|
-
did: identity.did,
|
|
181
|
-
created: Date.now(),
|
|
182
|
-
identityMode,
|
|
183
|
-
ttl: identityMode === 'ephemeral' ? (options.ttl ?? 3600000) : undefined,
|
|
184
|
-
};
|
|
185
|
-
// Create agent instance
|
|
186
|
-
const agent = new AgentBuilder(identity, metadata, options.policy);
|
|
187
|
-
// Setup auto-cleanup for ephemeral agents
|
|
188
|
-
if (identityMode === 'ephemeral' && metadata.ttl) {
|
|
189
|
-
metadata.cleanupTimer = setTimeout(() => {
|
|
190
|
-
agent.cleanup();
|
|
191
|
-
}, metadata.ttl);
|
|
192
|
-
}
|
|
193
|
-
return (0, shared_1.ok)(agent);
|
|
194
|
-
}
|
|
195
|
-
catch (error) {
|
|
196
|
-
return (0, shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED, error instanceof Error ? error.message : 'Unknown error during agent creation', { originalError: error }));
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* Call a tool/service via xBind.
|
|
201
|
-
*
|
|
202
|
-
* This method wraps agent-call.ts call() function with agent context
|
|
203
|
-
* and enforces policy constraints defined during agent creation.
|
|
204
|
-
*
|
|
205
|
-
* @param tool - Tool alias (e.g., "stripe:createCharge")
|
|
206
|
-
* @param params - Parameters to pass to the tool
|
|
207
|
-
* @param options - Optional call options (overrides agent policy)
|
|
208
|
-
* @returns Result with response data and audit receipt, or error
|
|
209
|
-
*
|
|
210
|
-
* @example
|
|
211
|
-
* ```typescript
|
|
212
|
-
* const result = await agent.call("payments:createCharge", {
|
|
213
|
-
* amount: 100,
|
|
214
|
-
* currency: "USD"
|
|
215
|
-
* });
|
|
216
|
-
*
|
|
217
|
-
* if (!result.ok) {
|
|
218
|
-
* console.error(`Payment failed: ${result.error.message}`);
|
|
219
|
-
* return;
|
|
220
|
-
* }
|
|
221
|
-
*
|
|
222
|
-
* console.log(`Charge created: ${result.value.data.id}`);
|
|
223
|
-
* console.log(`Audit: ${result.value.audit.timestamp}`);
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
async call(tool, params, options) {
|
|
227
|
-
// Merge agent policy with call-specific options
|
|
228
|
-
const callOptions = {
|
|
229
|
-
...options,
|
|
230
|
-
policy: this._policy ? {
|
|
231
|
-
...this._policy,
|
|
232
|
-
...options?.policy,
|
|
233
|
-
// Merge allowed tools arrays
|
|
234
|
-
allowedTools: options?.policy?.allowedTools
|
|
235
|
-
? [...(this._policy.allowedTools || []), ...options.policy.allowedTools]
|
|
236
|
-
: this._policy.allowedTools,
|
|
237
|
-
// Merge scopes arrays
|
|
238
|
-
scopes: options?.policy?.scopes
|
|
239
|
-
? [...(this._policy.scopes || []), ...options.policy.scopes]
|
|
240
|
-
: this._policy.scopes,
|
|
241
|
-
// Take minimum of limits (most restrictive)
|
|
242
|
-
limits: {
|
|
243
|
-
amountPerTxn: Math.min(this._policy.limits?.amountPerTxn ?? Infinity, options?.policy?.limits?.amountPerTxn ?? Infinity) === Infinity ? undefined : Math.min(this._policy.limits?.amountPerTxn ?? Infinity, options?.policy?.limits?.amountPerTxn ?? Infinity),
|
|
244
|
-
dailyAmount: Math.min(this._policy.limits?.dailyAmount ?? Infinity, options?.policy?.limits?.dailyAmount ?? Infinity) === Infinity ? undefined : Math.min(this._policy.limits?.dailyAmount ?? Infinity, options?.policy?.limits?.dailyAmount ?? Infinity),
|
|
245
|
-
callsPerMinute: Math.min(this._policy.limits?.callsPerMinute ?? Infinity, options?.policy?.limits?.callsPerMinute ?? Infinity) === Infinity ? undefined : Math.min(this._policy.limits?.callsPerMinute ?? Infinity, options?.policy?.limits?.callsPerMinute ?? Infinity),
|
|
246
|
-
},
|
|
247
|
-
} : options?.policy,
|
|
248
|
-
};
|
|
249
|
-
// Delegate to agent-call.ts call() function
|
|
250
|
-
const result = await (0, agent_call_js_1.call)(tool, params, callOptions);
|
|
251
|
-
// Record successful call for rate limiting
|
|
252
|
-
if (result.ok) {
|
|
253
|
-
const policyEngine = (0, policy_js_1.getGlobalPolicyEngine)();
|
|
254
|
-
policyEngine.recordCall(this.did);
|
|
255
|
-
// Record spending if amount is in params
|
|
256
|
-
if (typeof params === 'object' && params !== null) {
|
|
257
|
-
const obj = params;
|
|
258
|
-
const amount = obj.amount ?? obj.value ?? obj.price ?? obj.total;
|
|
259
|
-
if (typeof amount === 'number') {
|
|
260
|
-
policyEngine.recordSpending(this.did, amount);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
return result;
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* Cleanup agent resources.
|
|
268
|
-
*
|
|
269
|
-
* For ephemeral agents, this clears the cleanup timer and marks
|
|
270
|
-
* the agent as cleaned up. For persistent agents, this is a no-op.
|
|
271
|
-
*
|
|
272
|
-
* This method is called automatically when TTL expires for ephemeral agents.
|
|
273
|
-
*/
|
|
274
|
-
cleanup() {
|
|
275
|
-
if (this._metadata.cleanupTimer) {
|
|
276
|
-
clearTimeout(this._metadata.cleanupTimer);
|
|
277
|
-
this._metadata.cleanupTimer = undefined;
|
|
278
|
-
}
|
|
279
|
-
// Reset policy engine state for this agent
|
|
280
|
-
const policyEngine = (0, policy_js_1.getGlobalPolicyEngine)();
|
|
281
|
-
policyEngine.reset(this.did);
|
|
282
|
-
}
|
|
283
|
-
/**
|
|
284
|
-
* Extend TTL for ephemeral agents.
|
|
285
|
-
*
|
|
286
|
-
* @param additionalTime - Additional time in milliseconds
|
|
287
|
-
* @returns true if extended, false if not an ephemeral agent
|
|
288
|
-
*
|
|
289
|
-
* @example
|
|
290
|
-
* ```typescript
|
|
291
|
-
* // Extend by 30 minutes
|
|
292
|
-
* agent.extendTTL(30 * 60 * 1000);
|
|
293
|
-
* ```
|
|
294
|
-
*/
|
|
295
|
-
extendTTL(additionalTime) {
|
|
296
|
-
if (this._metadata.identityMode !== 'ephemeral' || !this._metadata.ttl) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
// Clear existing timer
|
|
300
|
-
if (this._metadata.cleanupTimer) {
|
|
301
|
-
clearTimeout(this._metadata.cleanupTimer);
|
|
302
|
-
}
|
|
303
|
-
// Calculate new TTL (extend the total TTL, not just remaining time)
|
|
304
|
-
const elapsed = Date.now() - this._metadata.created;
|
|
305
|
-
const currentRemaining = this._metadata.ttl - elapsed;
|
|
306
|
-
const newRemaining = currentRemaining + additionalTime;
|
|
307
|
-
// Update the TTL to reflect the extension
|
|
308
|
-
// SAFETY: We're modifying metadata which is intentionally mutable for lifecycle management
|
|
309
|
-
this._metadata.ttl = this._metadata.ttl + additionalTime;
|
|
310
|
-
// Setup new timer
|
|
311
|
-
this._metadata.cleanupTimer = setTimeout(() => {
|
|
312
|
-
this.cleanup();
|
|
313
|
-
}, newRemaining);
|
|
314
|
-
return true;
|
|
315
|
-
}
|
|
316
|
-
/**
|
|
317
|
-
* Convert agent to JSON-serializable format.
|
|
318
|
-
*
|
|
319
|
-
* @returns Agent metadata (without private keys)
|
|
320
|
-
*/
|
|
321
|
-
toJSON() {
|
|
322
|
-
return {
|
|
323
|
-
name: this.name,
|
|
324
|
-
did: this.did,
|
|
325
|
-
created: this.created,
|
|
326
|
-
identityMode: this.identityMode,
|
|
327
|
-
ttl: this.ttl,
|
|
328
|
-
timeRemaining: this.timeRemaining,
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
exports.AgentBuilder = AgentBuilder;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.AgentBuilder=void 0;const shared_1=require("../_deps/shared/index.js"),identity_js_1=require("./identity.js"),agent_call_js_1=require("./agent-call.js"),agent_call_js_2=require("./agent-call.js"),policy_js_1=require("./policy.js");class AgentBuilder{_identity;_metadata;_policy;constructor(t,e,i){this._identity=t,this._metadata=e,this._policy=i}get did(){return this._identity.did}get name(){return this._metadata.name}get created(){return this._metadata.created}get identityMode(){return this._metadata.identityMode}get ttl(){return this._metadata.ttl}get timeRemaining(){if(!this._metadata.ttl)return;const t=Date.now()-this._metadata.created,e=this._metadata.ttl-t;return e>0?e:0}static async create(t){try{let e,i;if(t.identity&&"ephemeral"!==t.identity)if("persistent"===t.identity){const t=await(0,identity_js_1.generateIdentity)();if(!t.ok)return(0,shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED,"Failed to generate persistent identity",{cause:t.error}));e=t.value,i="persistent"}else if(t.identity instanceof Uint8Array){if(32!==t.identity.length)return(0,shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.INVALID_PARAMS,"Identity seed must be exactly 32 bytes",{seedLength:t.identity.length}));const a=await(0,identity_js_1.identityFromSeed)(t.identity);if(!a.ok)return(0,shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED,"Failed to derive identity from seed",{cause:a.error}));e=a.value,i="persistent"}else e=t.identity,i="persistent";else{const t=await(0,identity_js_1.generateIdentity)();if(!t.ok)return(0,shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED,"Failed to generate ephemeral identity",{cause:t.error}));e=t.value,i="ephemeral"}const a={name:t.name,did:e.did,created:Date.now(),identityMode:i,ttl:"ephemeral"===i?t.ttl??36e5:void 0},n=new AgentBuilder(e,a,t.policy);return"ephemeral"===i&&a.ttl&&(a.cleanupTimer=setTimeout(()=>{n.cleanup()},a.ttl)),(0,shared_1.ok)(n)}catch(t){return(0,shared_1.err)(new agent_call_js_2.AgentError(agent_call_js_2.AgentErrorCode.AUTHENTICATION_FAILED,t instanceof Error?t.message:"Unknown error during agent creation",{originalError:t}))}}async call(t,e,i){const a={...i,policy:this._policy?{...this._policy,...i?.policy,allowedTools:i?.policy?.allowedTools?[...this._policy.allowedTools||[],...i.policy.allowedTools]:this._policy.allowedTools,scopes:i?.policy?.scopes?[...this._policy.scopes||[],...i.policy.scopes]:this._policy.scopes,limits:{amountPerTxn:Math.min(this._policy.limits?.amountPerTxn??1/0,i?.policy?.limits?.amountPerTxn??1/0)===1/0?void 0:Math.min(this._policy.limits?.amountPerTxn??1/0,i?.policy?.limits?.amountPerTxn??1/0),dailyAmount:Math.min(this._policy.limits?.dailyAmount??1/0,i?.policy?.limits?.dailyAmount??1/0)===1/0?void 0:Math.min(this._policy.limits?.dailyAmount??1/0,i?.policy?.limits?.dailyAmount??1/0),callsPerMinute:Math.min(this._policy.limits?.callsPerMinute??1/0,i?.policy?.limits?.callsPerMinute??1/0)===1/0?void 0:Math.min(this._policy.limits?.callsPerMinute??1/0,i?.policy?.limits?.callsPerMinute??1/0)}}:i?.policy},n=await(0,agent_call_js_1.call)(t,e,a);if(n.ok){const t=(0,policy_js_1.getGlobalPolicyEngine)();if(t.recordCall(this.did),"object"==typeof e&&null!==e){const i=e,a=i.amount??i.value??i.price??i.total;"number"==typeof a&&t.recordSpending(this.did,a)}}return n}cleanup(){this._metadata.cleanupTimer&&(clearTimeout(this._metadata.cleanupTimer),this._metadata.cleanupTimer=void 0);(0,policy_js_1.getGlobalPolicyEngine)().reset(this.did)}extendTTL(t){if("ephemeral"!==this._metadata.identityMode||!this._metadata.ttl)return!1;this._metadata.cleanupTimer&&clearTimeout(this._metadata.cleanupTimer);const e=Date.now()-this._metadata.created,i=this._metadata.ttl-e+t;return this._metadata.ttl=this._metadata.ttl+t,this._metadata.cleanupTimer=setTimeout(()=>{this.cleanup()},i),!0}toJSON(){return{name:this.name,did:this.did,created:this.created,identityMode:this.identityMode,ttl:this.ttl,timeRemaining:this.timeRemaining}}}exports.AgentBuilder=AgentBuilder;
|