@oobe-protocol-labs/synapse-sap-sdk 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 +21 -0
- package/README.md +882 -0
- package/dist/cjs/constants/index.js +43 -0
- package/dist/cjs/constants/index.js.map +1 -0
- package/dist/cjs/constants/limits.js +161 -0
- package/dist/cjs/constants/limits.js.map +1 -0
- package/dist/cjs/constants/programs.js +78 -0
- package/dist/cjs/constants/programs.js.map +1 -0
- package/dist/cjs/constants/seeds.js +57 -0
- package/dist/cjs/constants/seeds.js.map +1 -0
- package/dist/cjs/core/client.js +391 -0
- package/dist/cjs/core/client.js.map +1 -0
- package/dist/cjs/core/connection.js +319 -0
- package/dist/cjs/core/connection.js.map +1 -0
- package/dist/cjs/core/index.js +24 -0
- package/dist/cjs/core/index.js.map +1 -0
- package/dist/cjs/errors/index.js +334 -0
- package/dist/cjs/errors/index.js.map +1 -0
- package/dist/cjs/events/index.js +136 -0
- package/dist/cjs/events/index.js.map +1 -0
- package/dist/cjs/idl/index.js +63 -0
- package/dist/cjs/idl/index.js.map +1 -0
- package/dist/cjs/idl/synapse_agent_sap.json +9710 -0
- package/dist/cjs/index.js +147 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/modules/agent.js +272 -0
- package/dist/cjs/modules/agent.js.map +1 -0
- package/dist/cjs/modules/attestation.js +147 -0
- package/dist/cjs/modules/attestation.js.map +1 -0
- package/dist/cjs/modules/base.js +128 -0
- package/dist/cjs/modules/base.js.map +1 -0
- package/dist/cjs/modules/escrow.js +246 -0
- package/dist/cjs/modules/escrow.js.map +1 -0
- package/dist/cjs/modules/feedback.js +166 -0
- package/dist/cjs/modules/feedback.js.map +1 -0
- package/dist/cjs/modules/index.js +35 -0
- package/dist/cjs/modules/index.js.map +1 -0
- package/dist/cjs/modules/indexing.js +375 -0
- package/dist/cjs/modules/indexing.js.map +1 -0
- package/dist/cjs/modules/ledger.js +234 -0
- package/dist/cjs/modules/ledger.js.map +1 -0
- package/dist/cjs/modules/tools.js +319 -0
- package/dist/cjs/modules/tools.js.map +1 -0
- package/dist/cjs/modules/vault.js +410 -0
- package/dist/cjs/modules/vault.js.map +1 -0
- package/dist/cjs/pda/index.js +377 -0
- package/dist/cjs/pda/index.js.map +1 -0
- package/dist/cjs/plugin/index.js +934 -0
- package/dist/cjs/plugin/index.js.map +1 -0
- package/dist/cjs/plugin/protocols.js +282 -0
- package/dist/cjs/plugin/protocols.js.map +1 -0
- package/dist/cjs/plugin/schemas.js +831 -0
- package/dist/cjs/plugin/schemas.js.map +1 -0
- package/dist/cjs/postgres/adapter.js +715 -0
- package/dist/cjs/postgres/adapter.js.map +1 -0
- package/dist/cjs/postgres/index.js +50 -0
- package/dist/cjs/postgres/index.js.map +1 -0
- package/dist/cjs/postgres/serializers.js +381 -0
- package/dist/cjs/postgres/serializers.js.map +1 -0
- package/dist/cjs/postgres/sync.js +221 -0
- package/dist/cjs/postgres/sync.js.map +1 -0
- package/dist/cjs/postgres/types.js +44 -0
- package/dist/cjs/postgres/types.js.map +1 -0
- package/dist/cjs/registries/builder.js +414 -0
- package/dist/cjs/registries/builder.js.map +1 -0
- package/dist/cjs/registries/discovery.js +362 -0
- package/dist/cjs/registries/discovery.js.map +1 -0
- package/dist/cjs/registries/index.js +51 -0
- package/dist/cjs/registries/index.js.map +1 -0
- package/dist/cjs/registries/session.js +433 -0
- package/dist/cjs/registries/session.js.map +1 -0
- package/dist/cjs/registries/x402.js +577 -0
- package/dist/cjs/registries/x402.js.map +1 -0
- package/dist/cjs/types/accounts.js +13 -0
- package/dist/cjs/types/accounts.js.map +1 -0
- package/dist/cjs/types/common.js +13 -0
- package/dist/cjs/types/common.js.map +1 -0
- package/dist/cjs/types/enums.js +174 -0
- package/dist/cjs/types/enums.js.map +1 -0
- package/dist/cjs/types/index.js +36 -0
- package/dist/cjs/types/index.js.map +1 -0
- package/dist/cjs/types/instructions.js +92 -0
- package/dist/cjs/types/instructions.js.map +1 -0
- package/dist/cjs/utils/hash.js +58 -0
- package/dist/cjs/utils/hash.js.map +1 -0
- package/dist/cjs/utils/index.js +27 -0
- package/dist/cjs/utils/index.js.map +1 -0
- package/dist/cjs/utils/serialization.js +105 -0
- package/dist/cjs/utils/serialization.js.map +1 -0
- package/dist/cjs/utils/validation.js +36 -0
- package/dist/cjs/utils/validation.js.map +1 -0
- package/dist/esm/constants/index.js +29 -0
- package/dist/esm/constants/index.js.map +1 -0
- package/dist/esm/constants/limits.js +158 -0
- package/dist/esm/constants/limits.js.map +1 -0
- package/dist/esm/constants/programs.js +75 -0
- package/dist/esm/constants/programs.js.map +1 -0
- package/dist/esm/constants/seeds.js +54 -0
- package/dist/esm/constants/seeds.js.map +1 -0
- package/dist/esm/core/client.js +384 -0
- package/dist/esm/core/client.js.map +1 -0
- package/dist/esm/core/connection.js +315 -0
- package/dist/esm/core/connection.js.map +1 -0
- package/dist/esm/core/index.js +19 -0
- package/dist/esm/core/index.js.map +1 -0
- package/dist/esm/errors/index.js +325 -0
- package/dist/esm/errors/index.js.map +1 -0
- package/dist/esm/events/index.js +132 -0
- package/dist/esm/events/index.js.map +1 -0
- package/dist/esm/idl/index.js +57 -0
- package/dist/esm/idl/index.js.map +1 -0
- package/dist/esm/idl/synapse_agent_sap.json +9710 -0
- package/dist/esm/index.js +70 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/modules/agent.js +268 -0
- package/dist/esm/modules/agent.js.map +1 -0
- package/dist/esm/modules/attestation.js +143 -0
- package/dist/esm/modules/attestation.js.map +1 -0
- package/dist/esm/modules/base.js +124 -0
- package/dist/esm/modules/base.js.map +1 -0
- package/dist/esm/modules/escrow.js +242 -0
- package/dist/esm/modules/escrow.js.map +1 -0
- package/dist/esm/modules/feedback.js +162 -0
- package/dist/esm/modules/feedback.js.map +1 -0
- package/dist/esm/modules/index.js +23 -0
- package/dist/esm/modules/index.js.map +1 -0
- package/dist/esm/modules/indexing.js +371 -0
- package/dist/esm/modules/indexing.js.map +1 -0
- package/dist/esm/modules/ledger.js +230 -0
- package/dist/esm/modules/ledger.js.map +1 -0
- package/dist/esm/modules/tools.js +315 -0
- package/dist/esm/modules/tools.js.map +1 -0
- package/dist/esm/modules/vault.js +406 -0
- package/dist/esm/modules/vault.js.map +1 -0
- package/dist/esm/pda/index.js +357 -0
- package/dist/esm/pda/index.js.map +1 -0
- package/dist/esm/plugin/index.js +927 -0
- package/dist/esm/plugin/index.js.map +1 -0
- package/dist/esm/plugin/protocols.js +279 -0
- package/dist/esm/plugin/protocols.js.map +1 -0
- package/dist/esm/plugin/schemas.js +828 -0
- package/dist/esm/plugin/schemas.js.map +1 -0
- package/dist/esm/postgres/adapter.js +678 -0
- package/dist/esm/postgres/adapter.js.map +1 -0
- package/dist/esm/postgres/index.js +27 -0
- package/dist/esm/postgres/index.js.map +1 -0
- package/dist/esm/postgres/serializers.js +362 -0
- package/dist/esm/postgres/serializers.js.map +1 -0
- package/dist/esm/postgres/sync.js +217 -0
- package/dist/esm/postgres/sync.js.map +1 -0
- package/dist/esm/postgres/types.js +41 -0
- package/dist/esm/postgres/types.js.map +1 -0
- package/dist/esm/registries/builder.js +410 -0
- package/dist/esm/registries/builder.js.map +1 -0
- package/dist/esm/registries/discovery.js +358 -0
- package/dist/esm/registries/discovery.js.map +1 -0
- package/dist/esm/registries/index.js +44 -0
- package/dist/esm/registries/index.js.map +1 -0
- package/dist/esm/registries/session.js +429 -0
- package/dist/esm/registries/session.js.map +1 -0
- package/dist/esm/registries/x402.js +573 -0
- package/dist/esm/registries/x402.js.map +1 -0
- package/dist/esm/types/accounts.js +12 -0
- package/dist/esm/types/accounts.js.map +1 -0
- package/dist/esm/types/common.js +12 -0
- package/dist/esm/types/common.js.map +1 -0
- package/dist/esm/types/enums.js +171 -0
- package/dist/esm/types/enums.js.map +1 -0
- package/dist/esm/types/index.js +25 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/types/instructions.js +89 -0
- package/dist/esm/types/instructions.js.map +1 -0
- package/dist/esm/utils/hash.js +53 -0
- package/dist/esm/utils/hash.js.map +1 -0
- package/dist/esm/utils/index.js +19 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/dist/esm/utils/serialization.js +98 -0
- package/dist/esm/utils/serialization.js.map +1 -0
- package/dist/esm/utils/validation.js +33 -0
- package/dist/esm/utils/validation.js.map +1 -0
- package/dist/types/constants/index.d.ts +27 -0
- package/dist/types/constants/index.d.ts.map +1 -0
- package/dist/types/constants/limits.d.ts +149 -0
- package/dist/types/constants/limits.d.ts.map +1 -0
- package/dist/types/constants/programs.d.ts +69 -0
- package/dist/types/constants/programs.d.ts.map +1 -0
- package/dist/types/constants/seeds.d.ts +61 -0
- package/dist/types/constants/seeds.d.ts.map +1 -0
- package/dist/types/core/client.d.ts +323 -0
- package/dist/types/core/client.d.ts.map +1 -0
- package/dist/types/core/connection.d.ts +279 -0
- package/dist/types/core/connection.d.ts.map +1 -0
- package/dist/types/core/index.d.ts +20 -0
- package/dist/types/core/index.d.ts.map +1 -0
- package/dist/types/errors/index.d.ts +276 -0
- package/dist/types/errors/index.d.ts.map +1 -0
- package/dist/types/events/index.d.ts +248 -0
- package/dist/types/events/index.d.ts.map +1 -0
- package/dist/types/idl/index.d.ts +70 -0
- package/dist/types/idl/index.d.ts.map +1 -0
- package/dist/types/index.d.ts +68 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/modules/agent.d.ts +166 -0
- package/dist/types/modules/agent.d.ts.map +1 -0
- package/dist/types/modules/attestation.d.ts +96 -0
- package/dist/types/modules/attestation.d.ts.map +1 -0
- package/dist/types/modules/base.d.ts +126 -0
- package/dist/types/modules/base.d.ts.map +1 -0
- package/dist/types/modules/escrow.d.ts +151 -0
- package/dist/types/modules/escrow.d.ts.map +1 -0
- package/dist/types/modules/feedback.d.ts +105 -0
- package/dist/types/modules/feedback.d.ts.map +1 -0
- package/dist/types/modules/index.d.ts +24 -0
- package/dist/types/modules/index.d.ts.map +1 -0
- package/dist/types/modules/indexing.d.ts +200 -0
- package/dist/types/modules/indexing.d.ts.map +1 -0
- package/dist/types/modules/ledger.d.ts +150 -0
- package/dist/types/modules/ledger.d.ts.map +1 -0
- package/dist/types/modules/tools.d.ts +182 -0
- package/dist/types/modules/tools.d.ts.map +1 -0
- package/dist/types/modules/vault.d.ts +240 -0
- package/dist/types/modules/vault.d.ts.map +1 -0
- package/dist/types/pda/index.d.ts +296 -0
- package/dist/types/pda/index.d.ts.map +1 -0
- package/dist/types/plugin/index.d.ts +171 -0
- package/dist/types/plugin/index.d.ts.map +1 -0
- package/dist/types/plugin/protocols.d.ts +152 -0
- package/dist/types/plugin/protocols.d.ts.map +1 -0
- package/dist/types/plugin/schemas.d.ts +823 -0
- package/dist/types/plugin/schemas.d.ts.map +1 -0
- package/dist/types/postgres/adapter.d.ts +355 -0
- package/dist/types/postgres/adapter.d.ts.map +1 -0
- package/dist/types/postgres/index.d.ts +24 -0
- package/dist/types/postgres/index.d.ts.map +1 -0
- package/dist/types/postgres/serializers.d.ts +30 -0
- package/dist/types/postgres/serializers.d.ts.map +1 -0
- package/dist/types/postgres/sync.d.ts +132 -0
- package/dist/types/postgres/sync.d.ts.map +1 -0
- package/dist/types/postgres/types.d.ts +167 -0
- package/dist/types/postgres/types.d.ts.map +1 -0
- package/dist/types/registries/builder.d.ts +340 -0
- package/dist/types/registries/builder.d.ts.map +1 -0
- package/dist/types/registries/discovery.d.ts +333 -0
- package/dist/types/registries/discovery.d.ts.map +1 -0
- package/dist/types/registries/index.d.ts +48 -0
- package/dist/types/registries/index.d.ts.map +1 -0
- package/dist/types/registries/session.d.ts +323 -0
- package/dist/types/registries/session.d.ts.map +1 -0
- package/dist/types/registries/x402.d.ts +463 -0
- package/dist/types/registries/x402.d.ts.map +1 -0
- package/dist/types/types/accounts.d.ts +565 -0
- package/dist/types/types/accounts.d.ts.map +1 -0
- package/dist/types/types/common.d.ts +166 -0
- package/dist/types/types/common.d.ts.map +1 -0
- package/dist/types/types/enums.d.ts +238 -0
- package/dist/types/types/enums.d.ts.map +1 -0
- package/dist/types/types/index.d.ts +28 -0
- package/dist/types/types/index.d.ts.map +1 -0
- package/dist/types/types/instructions.d.ts +366 -0
- package/dist/types/types/instructions.d.ts.map +1 -0
- package/dist/types/utils/hash.d.ts +48 -0
- package/dist/types/utils/hash.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +19 -0
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/serialization.d.ts +69 -0
- package/dist/types/utils/serialization.d.ts.map +1 -0
- package/dist/types/utils/validation.d.ts +29 -0
- package/dist/types/utils/validation.d.ts.map +1 -0
- package/package.json +178 -0
- package/src/constants/index.ts +44 -0
- package/src/constants/limits.ts +165 -0
- package/src/constants/programs.ts +83 -0
- package/src/constants/seeds.ts +66 -0
- package/src/core/client.ts +416 -0
- package/src/core/connection.ts +409 -0
- package/src/core/index.ts +20 -0
- package/src/errors/index.ts +346 -0
- package/src/events/index.ts +335 -0
- package/src/idl/index.ts +76 -0
- package/src/idl/synapse_agent_sap.json +9710 -0
- package/src/index.ts +253 -0
- package/src/modules/agent.ts +319 -0
- package/src/modules/attestation.ts +168 -0
- package/src/modules/base.ts +158 -0
- package/src/modules/escrow.ts +308 -0
- package/src/modules/feedback.ts +186 -0
- package/src/modules/index.ts +24 -0
- package/src/modules/indexing.ts +444 -0
- package/src/modules/ledger.ts +262 -0
- package/src/modules/tools.ts +411 -0
- package/src/modules/vault.ts +533 -0
- package/src/pda/index.ts +512 -0
- package/src/plugin/index.ts +1202 -0
- package/src/plugin/protocols.ts +404 -0
- package/src/plugin/schemas.ts +909 -0
- package/src/postgres/adapter.ts +904 -0
- package/src/postgres/index.ts +59 -0
- package/src/postgres/schema.sql +683 -0
- package/src/postgres/serializers.ts +485 -0
- package/src/postgres/sync.ts +254 -0
- package/src/postgres/types.ts +245 -0
- package/src/registries/builder.ts +607 -0
- package/src/registries/discovery.ts +572 -0
- package/src/registries/index.ts +77 -0
- package/src/registries/session.ts +613 -0
- package/src/registries/x402.ts +906 -0
- package/src/types/accounts.ts +618 -0
- package/src/types/common.ts +187 -0
- package/src/types/enums.ts +214 -0
- package/src/types/index.ts +92 -0
- package/src/types/instructions.ts +413 -0
- package/src/utils/hash.ts +57 -0
- package/src/utils/index.ts +19 -0
- package/src/utils/serialization.ts +98 -0
- package/src/utils/validation.ts +36 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module constants/limits
|
|
3
|
+
* @description Protocol size limits, version constants, and enum numeric values.
|
|
4
|
+
*
|
|
5
|
+
* All values mirror the on-chain Rust constraints exactly.
|
|
6
|
+
* Used for client-side validation before sending transactions.
|
|
7
|
+
*
|
|
8
|
+
* @category Constants
|
|
9
|
+
* @since v0.1.0
|
|
10
|
+
*/
|
|
11
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
12
|
+
// Size Limits (mirrors Rust impl blocks)
|
|
13
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
14
|
+
/**
|
|
15
|
+
* Protocol size constraints mirroring the Rust `impl` blocks.
|
|
16
|
+
*
|
|
17
|
+
* Use these values for client-side validation before submitting
|
|
18
|
+
* transactions — exceeding any limit will cause an on-chain error.
|
|
19
|
+
*
|
|
20
|
+
* @name LIMITS
|
|
21
|
+
* @description A frozen object containing all protocol-enforced size and length bounds.
|
|
22
|
+
* @category Constants
|
|
23
|
+
* @since v0.1.0
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { LIMITS } from "@synapse-sap/sdk/constants";
|
|
27
|
+
*
|
|
28
|
+
* if (name.length > LIMITS.MAX_NAME_LEN) {
|
|
29
|
+
* throw new Error("Agent name too long");
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export const LIMITS = {
|
|
34
|
+
/** Max agent name length in bytes. */
|
|
35
|
+
MAX_NAME_LEN: 64,
|
|
36
|
+
/** Max agent description length in bytes. */
|
|
37
|
+
MAX_DESC_LEN: 256,
|
|
38
|
+
/** Max URI length (agent_uri, x402_endpoint). */
|
|
39
|
+
MAX_URI_LEN: 256,
|
|
40
|
+
/** Max agent DID-style identifier length. */
|
|
41
|
+
MAX_AGENT_ID_LEN: 128,
|
|
42
|
+
/** Max capabilities per agent. */
|
|
43
|
+
MAX_CAPABILITIES: 10,
|
|
44
|
+
/** Max pricing tiers per agent. */
|
|
45
|
+
MAX_PRICING_TIERS: 5,
|
|
46
|
+
/** Max protocol strings per agent. */
|
|
47
|
+
MAX_PROTOCOLS: 5,
|
|
48
|
+
/** Max active plugins per agent. */
|
|
49
|
+
MAX_PLUGINS: 5,
|
|
50
|
+
/** Max volume curve breakpoints per tier. */
|
|
51
|
+
MAX_VOLUME_CURVE_POINTS: 5,
|
|
52
|
+
/** Max feedback tag length. */
|
|
53
|
+
MAX_TAG_LEN: 32,
|
|
54
|
+
/** Max agents in a capability/protocol index. */
|
|
55
|
+
MAX_AGENTS_PER_INDEX: 100,
|
|
56
|
+
/** Max tool name length. */
|
|
57
|
+
MAX_TOOL_NAME_LEN: 32,
|
|
58
|
+
/** Max tools in a category index. */
|
|
59
|
+
MAX_TOOLS_PER_CATEGORY: 100,
|
|
60
|
+
/** Max attestation type length. */
|
|
61
|
+
MAX_ATTESTATION_TYPE_LEN: 32,
|
|
62
|
+
/** Max inscription size (encrypted_data per fragment). */
|
|
63
|
+
MAX_INSCRIPTION_SIZE: 750,
|
|
64
|
+
/** Inscriptions per epoch page. */
|
|
65
|
+
INSCRIPTIONS_PER_EPOCH: 1000,
|
|
66
|
+
/** Max memory chunk size (legacy). */
|
|
67
|
+
MAX_CHUNK_SIZE: 900,
|
|
68
|
+
/** Max write size per buffer append (legacy). */
|
|
69
|
+
MAX_BUFFER_WRITE_SIZE: 750,
|
|
70
|
+
/** Max total buffer page size (legacy). */
|
|
71
|
+
MAX_BUFFER_TOTAL_SIZE: 10_000,
|
|
72
|
+
/** Ring buffer capacity for MemoryLedger. */
|
|
73
|
+
RING_CAPACITY: 4096,
|
|
74
|
+
/** Max ledger write size per call. */
|
|
75
|
+
MAX_LEDGER_WRITE_SIZE: 750,
|
|
76
|
+
/** Max settlements in a batch. */
|
|
77
|
+
MAX_BATCH_SETTLEMENTS: 10,
|
|
78
|
+
/** Feedback score range: 0–1000. */
|
|
79
|
+
MAX_FEEDBACK_SCORE: 1000,
|
|
80
|
+
};
|
|
81
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
82
|
+
// Protocol Versions
|
|
83
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
84
|
+
/**
|
|
85
|
+
* Current on-chain protocol version for `AgentAccount`.
|
|
86
|
+
*
|
|
87
|
+
* @name AGENT_VERSION
|
|
88
|
+
* @description Integer version stamped into every agent account on registration.
|
|
89
|
+
* @category Constants
|
|
90
|
+
* @since v0.1.0
|
|
91
|
+
*/
|
|
92
|
+
export const AGENT_VERSION = 1;
|
|
93
|
+
/**
|
|
94
|
+
* Current on-chain protocol version for `MemoryVault`.
|
|
95
|
+
*
|
|
96
|
+
* @name VAULT_PROTOCOL_VERSION
|
|
97
|
+
* @description Integer version stamped into every vault account on initialisation.
|
|
98
|
+
* @category Constants
|
|
99
|
+
* @since v0.1.0
|
|
100
|
+
*/
|
|
101
|
+
export const VAULT_PROTOCOL_VERSION = 1;
|
|
102
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
103
|
+
// Numeric Enum Values
|
|
104
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
105
|
+
/**
|
|
106
|
+
* Tool category to `u8` discriminant mapping.
|
|
107
|
+
*
|
|
108
|
+
* Mirrors the Rust `ToolCategory` enum ordinals. Use these values
|
|
109
|
+
* when constructing or filtering tool-related instructions.
|
|
110
|
+
*
|
|
111
|
+
* @name TOOL_CATEGORY_VALUES
|
|
112
|
+
* @description Frozen mapping of tool category names to their on-chain `u8` discriminants.
|
|
113
|
+
* @category Constants
|
|
114
|
+
* @since v0.1.0
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* import { TOOL_CATEGORY_VALUES } from "@synapse-sap/sdk/constants";
|
|
118
|
+
*
|
|
119
|
+
* const categoryByte = TOOL_CATEGORY_VALUES.Swap; // 0
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export const TOOL_CATEGORY_VALUES = {
|
|
123
|
+
Swap: 0,
|
|
124
|
+
Lend: 1,
|
|
125
|
+
Stake: 2,
|
|
126
|
+
Nft: 3,
|
|
127
|
+
Payment: 4,
|
|
128
|
+
Data: 5,
|
|
129
|
+
Governance: 6,
|
|
130
|
+
Bridge: 7,
|
|
131
|
+
Analytics: 8,
|
|
132
|
+
Custom: 9,
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* HTTP method to `u8` discriminant mapping.
|
|
136
|
+
*
|
|
137
|
+
* Mirrors the Rust `HttpMethod` enum ordinals. Used when publishing
|
|
138
|
+
* or filtering tool endpoints.
|
|
139
|
+
*
|
|
140
|
+
* @name HTTP_METHOD_VALUES
|
|
141
|
+
* @description Frozen mapping of HTTP method names to their on-chain `u8` discriminants.
|
|
142
|
+
* @category Constants
|
|
143
|
+
* @since v0.1.0
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* import { HTTP_METHOD_VALUES } from "@synapse-sap/sdk/constants";
|
|
147
|
+
*
|
|
148
|
+
* const method = HTTP_METHOD_VALUES.Post; // 1
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export const HTTP_METHOD_VALUES = {
|
|
152
|
+
Get: 0,
|
|
153
|
+
Post: 1,
|
|
154
|
+
Put: 2,
|
|
155
|
+
Delete: 3,
|
|
156
|
+
Compound: 4,
|
|
157
|
+
};
|
|
158
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limits.js","sourceRoot":"","sources":["../../../src/constants/limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,sEAAsE;AACtE,0CAA0C;AAC1C,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,sCAAsC;IACtC,YAAY,EAAE,EAAE;IAChB,6CAA6C;IAC7C,YAAY,EAAE,GAAG;IACjB,iDAAiD;IACjD,WAAW,EAAE,GAAG;IAChB,6CAA6C;IAC7C,gBAAgB,EAAE,GAAG;IACrB,kCAAkC;IAClC,gBAAgB,EAAE,EAAE;IACpB,mCAAmC;IACnC,iBAAiB,EAAE,CAAC;IACpB,sCAAsC;IACtC,aAAa,EAAE,CAAC;IAChB,oCAAoC;IACpC,WAAW,EAAE,CAAC;IACd,6CAA6C;IAC7C,uBAAuB,EAAE,CAAC;IAC1B,+BAA+B;IAC/B,WAAW,EAAE,EAAE;IACf,iDAAiD;IACjD,oBAAoB,EAAE,GAAG;IACzB,4BAA4B;IAC5B,iBAAiB,EAAE,EAAE;IACrB,qCAAqC;IACrC,sBAAsB,EAAE,GAAG;IAC3B,mCAAmC;IACnC,wBAAwB,EAAE,EAAE;IAC5B,0DAA0D;IAC1D,oBAAoB,EAAE,GAAG;IACzB,mCAAmC;IACnC,sBAAsB,EAAE,IAAI;IAC5B,sCAAsC;IACtC,cAAc,EAAE,GAAG;IACnB,iDAAiD;IACjD,qBAAqB,EAAE,GAAG;IAC1B,2CAA2C;IAC3C,qBAAqB,EAAE,MAAM;IAC7B,6CAA6C;IAC7C,aAAa,EAAE,IAAI;IACnB,sCAAsC;IACtC,qBAAqB,EAAE,GAAG;IAC1B,kCAAkC;IAClC,qBAAqB,EAAE,EAAE;IACzB,oCAAoC;IACpC,kBAAkB,EAAE,IAAI;CAChB,CAAC;AAEX,sEAAsE;AACtE,qBAAqB;AACrB,sEAAsE;AAEtE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC;AAE/B;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,sEAAsE;AACtE,uBAAuB;AACvB,sEAAsE;AAEtE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;IACP,KAAK,EAAE,CAAC;IACR,GAAG,EAAE,CAAC;IACN,OAAO,EAAE,CAAC;IACV,IAAI,EAAE,CAAC;IACP,UAAU,EAAE,CAAC;IACb,MAAM,EAAE,CAAC;IACT,SAAS,EAAE,CAAC;IACZ,MAAM,EAAE,CAAC;CACD,CAAC;AAEX;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,GAAG,EAAE,CAAC;IACN,IAAI,EAAE,CAAC;IACP,GAAG,EAAE,CAAC;IACN,MAAM,EAAE,CAAC;IACT,QAAQ,EAAE,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module constants/programs
|
|
3
|
+
* @description SAP v2 program IDs for each Solana cluster.
|
|
4
|
+
*
|
|
5
|
+
* The canonical program address is shared across mainnet, devnet,
|
|
6
|
+
* and localnet. If you deploy a custom instance, override the
|
|
7
|
+
* program ID in `SapClient.from(provider, customProgramId)`.
|
|
8
|
+
*
|
|
9
|
+
* @category Constants
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
*/
|
|
12
|
+
import { PublicKey } from "@solana/web3.js";
|
|
13
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
14
|
+
// Program Address
|
|
15
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
16
|
+
/**
|
|
17
|
+
* SAP v2 program address string (base58).
|
|
18
|
+
*
|
|
19
|
+
* Vanity keypair derived from the `SAPTU7a…` prefix.
|
|
20
|
+
*
|
|
21
|
+
* @name SAP_PROGRAM_ADDRESS
|
|
22
|
+
* @description The canonical on-chain program address shared by all Solana clusters.
|
|
23
|
+
* @category Constants
|
|
24
|
+
* @since v0.1.0
|
|
25
|
+
* @see {@link SAP_PROGRAM_ID}
|
|
26
|
+
*/
|
|
27
|
+
export const SAP_PROGRAM_ADDRESS = "SAPTU7aUXk2AaAdktexae1iuxXpokxzNDBAYYhaVyQL";
|
|
28
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
29
|
+
// Per-Network PublicKeys
|
|
30
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
31
|
+
/**
|
|
32
|
+
* SAP v2 mainnet-beta program ID.
|
|
33
|
+
*
|
|
34
|
+
* @name MAINNET_SAP_PROGRAM_ID
|
|
35
|
+
* @description `PublicKey` instance of {@link SAP_PROGRAM_ADDRESS} for mainnet-beta.
|
|
36
|
+
* @category Constants
|
|
37
|
+
* @since v0.1.0
|
|
38
|
+
* @see {@link SAP_PROGRAM_ADDRESS}
|
|
39
|
+
*/
|
|
40
|
+
export const MAINNET_SAP_PROGRAM_ID = new PublicKey(SAP_PROGRAM_ADDRESS);
|
|
41
|
+
/**
|
|
42
|
+
* SAP v2 devnet program ID.
|
|
43
|
+
*
|
|
44
|
+
* @name DEVNET_SAP_PROGRAM_ID
|
|
45
|
+
* @description `PublicKey` instance of {@link SAP_PROGRAM_ADDRESS} for devnet.
|
|
46
|
+
* @category Constants
|
|
47
|
+
* @since v0.1.0
|
|
48
|
+
* @see {@link SAP_PROGRAM_ADDRESS}
|
|
49
|
+
*/
|
|
50
|
+
export const DEVNET_SAP_PROGRAM_ID = new PublicKey(SAP_PROGRAM_ADDRESS);
|
|
51
|
+
/**
|
|
52
|
+
* Localnet / solana-test-validator program ID.
|
|
53
|
+
*
|
|
54
|
+
* Override with your own keypair if deploying locally at a different address.
|
|
55
|
+
*
|
|
56
|
+
* @name LOCALNET_SAP_PROGRAM_ID
|
|
57
|
+
* @description `PublicKey` instance of {@link SAP_PROGRAM_ADDRESS} for localnet / `solana-test-validator`.
|
|
58
|
+
* @category Constants
|
|
59
|
+
* @since v0.1.0
|
|
60
|
+
* @see {@link SAP_PROGRAM_ADDRESS}
|
|
61
|
+
*/
|
|
62
|
+
export const LOCALNET_SAP_PROGRAM_ID = new PublicKey(SAP_PROGRAM_ADDRESS);
|
|
63
|
+
/**
|
|
64
|
+
* Default program ID used by `SapClient.from()` when no explicit ID is provided.
|
|
65
|
+
*
|
|
66
|
+
* Alias for {@link MAINNET_SAP_PROGRAM_ID}.
|
|
67
|
+
*
|
|
68
|
+
* @name SAP_PROGRAM_ID
|
|
69
|
+
* @description Convenience alias pointing to the mainnet-beta program ID.
|
|
70
|
+
* @category Constants
|
|
71
|
+
* @since v0.1.0
|
|
72
|
+
* @see {@link MAINNET_SAP_PROGRAM_ID}
|
|
73
|
+
*/
|
|
74
|
+
export const SAP_PROGRAM_ID = MAINNET_SAP_PROGRAM_ID;
|
|
75
|
+
//# sourceMappingURL=programs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"programs.js","sourceRoot":"","sources":["../../../src/constants/programs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,sEAAsE;AACtE,mBAAmB;AACnB,sEAAsE;AAEtE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAC9B,6CAA6C,CAAC;AAEhD,sEAAsE;AACtE,0BAA0B;AAC1B,sEAAsE;AAEtE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAExE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAE1E;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module constants/seeds
|
|
3
|
+
* @description PDA seed prefix constants.
|
|
4
|
+
*
|
|
5
|
+
* Every seed string mirrors the Rust `#[account(seeds = [...])]` definitions.
|
|
6
|
+
*
|
|
7
|
+
* @category Constants
|
|
8
|
+
* @since v0.1.0
|
|
9
|
+
*/
|
|
10
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
11
|
+
// PDA Seed Prefixes
|
|
12
|
+
// ═══════════════════════════════════════════════════════════════════
|
|
13
|
+
/**
|
|
14
|
+
* PDA seed prefix lookup table.
|
|
15
|
+
*
|
|
16
|
+
* Each key corresponds to an on-chain account type, and the value is the
|
|
17
|
+
* UTF-8 string used as the first seed segment in
|
|
18
|
+
* `PublicKey.findProgramAddressSync`.
|
|
19
|
+
*
|
|
20
|
+
* @name SEEDS
|
|
21
|
+
* @description Maps logical account names to their Rust-defined PDA seed prefix strings.
|
|
22
|
+
* @category Constants
|
|
23
|
+
* @since v0.1.0
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts
|
|
26
|
+
* import { SEEDS } from "@synapse-sap/sdk/constants";
|
|
27
|
+
*
|
|
28
|
+
* Buffer.from(SEEDS.AGENT); // => "sap_agent"
|
|
29
|
+
* ```
|
|
30
|
+
* @see {@link SeedKey}
|
|
31
|
+
*/
|
|
32
|
+
export const SEEDS = {
|
|
33
|
+
AGENT: "sap_agent",
|
|
34
|
+
FEEDBACK: "sap_feedback",
|
|
35
|
+
CAPABILITY_INDEX: "sap_cap_idx",
|
|
36
|
+
PROTOCOL_INDEX: "sap_proto_idx",
|
|
37
|
+
GLOBAL: "sap_global",
|
|
38
|
+
PLUGIN: "sap_plugin",
|
|
39
|
+
MEMORY: "sap_memory",
|
|
40
|
+
MEMORY_CHUNK: "sap_mem_chunk",
|
|
41
|
+
VAULT: "sap_vault",
|
|
42
|
+
SESSION: "sap_session",
|
|
43
|
+
EPOCH: "sap_epoch",
|
|
44
|
+
DELEGATE: "sap_delegate",
|
|
45
|
+
TOOL: "sap_tool",
|
|
46
|
+
CHECKPOINT: "sap_checkpoint",
|
|
47
|
+
ESCROW: "sap_escrow",
|
|
48
|
+
STATS: "sap_stats",
|
|
49
|
+
TOOL_CATEGORY: "sap_tool_cat",
|
|
50
|
+
ATTESTATION: "sap_attest",
|
|
51
|
+
LEDGER: "sap_ledger",
|
|
52
|
+
LEDGER_PAGE: "sap_page",
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=seeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"seeds.js","sourceRoot":"","sources":["../../../src/constants/seeds.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,sEAAsE;AACtE,qBAAqB;AACrB,sEAAsE;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,cAAc;IACxB,gBAAgB,EAAE,aAAa;IAC/B,cAAc,EAAE,eAAe;IAC/B,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,MAAM,EAAE,YAAY;IACpB,YAAY,EAAE,eAAe;IAC7B,KAAK,EAAE,WAAW;IAClB,OAAO,EAAE,aAAa;IACtB,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,cAAc;IACxB,IAAI,EAAE,UAAU;IAChB,UAAU,EAAE,gBAAgB;IAC5B,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,aAAa,EAAE,cAAc;IAC7B,WAAW,EAAE,YAAY;IACzB,MAAM,EAAE,YAAY;IACpB,WAAW,EAAE,UAAU;CACf,CAAC"}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module core/client
|
|
3
|
+
* @description Core SapClient — thin wrapper around the Anchor program
|
|
4
|
+
* that wires up provider, IDL, and exposes typed module accessors.
|
|
5
|
+
*
|
|
6
|
+
* This is the primary entry point for the `@synapse-sap/sdk` package.
|
|
7
|
+
* All protocol domains (agent lifecycle, reputation, vault, escrow, etc.)
|
|
8
|
+
* are available as lazily-instantiated, strongly-typed module accessors.
|
|
9
|
+
*
|
|
10
|
+
* @since v0.1.0
|
|
11
|
+
* @category Core
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { SapClient } from "@synapse-sap/sdk";
|
|
16
|
+
*
|
|
17
|
+
* const client = SapClient.from(provider); // auto-IDL
|
|
18
|
+
* const client = SapClient.fromProgram(program); // existing program
|
|
19
|
+
*
|
|
20
|
+
* // Use domain modules:
|
|
21
|
+
* await client.agent.register({ ... });
|
|
22
|
+
* await client.vault.initVault(vaultNonce);
|
|
23
|
+
* const escrow = await client.escrow.fetch(escrowPda);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
import { Program } from "@coral-xyz/anchor";
|
|
27
|
+
import { SAP_PROGRAM_ID } from "../constants";
|
|
28
|
+
import { AgentModule } from "../modules/agent";
|
|
29
|
+
import { FeedbackModule } from "../modules/feedback";
|
|
30
|
+
import { IndexingModule } from "../modules/indexing";
|
|
31
|
+
import { ToolsModule } from "../modules/tools";
|
|
32
|
+
import { VaultModule } from "../modules/vault";
|
|
33
|
+
import { EscrowModule } from "../modules/escrow";
|
|
34
|
+
import { AttestationModule } from "../modules/attestation";
|
|
35
|
+
import { LedgerModule } from "../modules/ledger";
|
|
36
|
+
import { EventParser } from "../events";
|
|
37
|
+
import { DiscoveryRegistry } from "../registries/discovery";
|
|
38
|
+
import { X402Registry } from "../registries/x402";
|
|
39
|
+
import { SessionManager } from "../registries/session";
|
|
40
|
+
import { AgentBuilder } from "../registries/builder";
|
|
41
|
+
// IDL is embedded inside the SDK — no external workspace dependency
|
|
42
|
+
import idl from "../idl/synapse_agent_sap.json";
|
|
43
|
+
/**
|
|
44
|
+
* @name SapClient
|
|
45
|
+
* @description Root entry point for the Solana Agent Protocol v2 TypeScript SDK.
|
|
46
|
+
*
|
|
47
|
+
* Each protocol domain is exposed as a lazily-instantiated module:
|
|
48
|
+
* `agent`, `feedback`, `indexing`, `tools`, `vault`, `escrow`,
|
|
49
|
+
* `attestation`, `ledger`, `events`.
|
|
50
|
+
*
|
|
51
|
+
* Higher-level abstractions (`discovery`, `x402`, `session`, `builder`)
|
|
52
|
+
* compose the low-level modules into ergonomic workflows.
|
|
53
|
+
*
|
|
54
|
+
* Instantiate via the static factory methods {@link SapClient.from} or
|
|
55
|
+
* {@link SapClient.fromProgram} — the constructor is private.
|
|
56
|
+
*
|
|
57
|
+
* @category Core
|
|
58
|
+
* @since v0.1.0
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* import { SapClient } from "@synapse-sap/sdk";
|
|
63
|
+
* import { AnchorProvider } from "@coral-xyz/anchor";
|
|
64
|
+
*
|
|
65
|
+
* const provider = AnchorProvider.env();
|
|
66
|
+
* const client = SapClient.from(provider);
|
|
67
|
+
*
|
|
68
|
+
* // Register an agent
|
|
69
|
+
* await client.agent.register({
|
|
70
|
+
* name: "SwapBot",
|
|
71
|
+
* description: "AI-powered swap agent",
|
|
72
|
+
* });
|
|
73
|
+
*
|
|
74
|
+
* // Discover agents
|
|
75
|
+
* const agents = await client.discovery.findAgentsByProtocol("jupiter");
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export class SapClient {
|
|
79
|
+
/**
|
|
80
|
+
* @name program
|
|
81
|
+
* @description The underlying Anchor `Program` instance used for all RPC
|
|
82
|
+
* calls and account deserialization.
|
|
83
|
+
* @readonly
|
|
84
|
+
* @category Core
|
|
85
|
+
* @since v0.1.0
|
|
86
|
+
*/
|
|
87
|
+
program;
|
|
88
|
+
/**
|
|
89
|
+
* @name walletPubkey
|
|
90
|
+
* @description The provider wallet's public key, extracted from the
|
|
91
|
+
* Anchor provider for convenience. This is the default authority /
|
|
92
|
+
* payer used by module instructions unless overridden.
|
|
93
|
+
* @readonly
|
|
94
|
+
* @category Core
|
|
95
|
+
* @since v0.1.0
|
|
96
|
+
*/
|
|
97
|
+
walletPubkey;
|
|
98
|
+
// ── Lazy module singletons ────────────────────────
|
|
99
|
+
#agent;
|
|
100
|
+
#feedback;
|
|
101
|
+
#indexing;
|
|
102
|
+
#tools;
|
|
103
|
+
#vault;
|
|
104
|
+
#escrow;
|
|
105
|
+
#attestation;
|
|
106
|
+
#ledger;
|
|
107
|
+
#events;
|
|
108
|
+
// ── Lazy registry singletons ──────────────────────
|
|
109
|
+
#discovery;
|
|
110
|
+
#x402;
|
|
111
|
+
#session;
|
|
112
|
+
constructor(program) {
|
|
113
|
+
this.program = program;
|
|
114
|
+
this.walletPubkey = program.provider.wallet.publicKey;
|
|
115
|
+
}
|
|
116
|
+
// ═════════════════════════════════════════════
|
|
117
|
+
// Factory Methods
|
|
118
|
+
// ═════════════════════════════════════════════
|
|
119
|
+
/**
|
|
120
|
+
* @name from
|
|
121
|
+
* @description Create a {@link SapClient} from an `AnchorProvider`.
|
|
122
|
+
* Automatically loads the embedded IDL shipped with the SDK.
|
|
123
|
+
*
|
|
124
|
+
* @param provider - A configured `AnchorProvider` with wallet and connection.
|
|
125
|
+
* @param programId - Optional override for the SAP program ID.
|
|
126
|
+
* Defaults to `SAP_PROGRAM_ID` from `@synapse-sap/sdk/constants`.
|
|
127
|
+
* @returns A fully-initialised `SapClient` ready for use.
|
|
128
|
+
*
|
|
129
|
+
* @category Core
|
|
130
|
+
* @since v0.1.0
|
|
131
|
+
* @see {@link SapClient.fromProgram} for an alternative accepting a pre-built `Program`.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { SapClient } from "@synapse-sap/sdk";
|
|
136
|
+
* import { AnchorProvider } from "@coral-xyz/anchor";
|
|
137
|
+
*
|
|
138
|
+
* const provider = AnchorProvider.env();
|
|
139
|
+
* const client = SapClient.from(provider);
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @example Custom program ID (e.g. localnet)
|
|
143
|
+
* ```ts
|
|
144
|
+
* const client = SapClient.from(provider, myLocalProgramId);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
static from(provider, programId = SAP_PROGRAM_ID) {
|
|
148
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
149
|
+
const program = new Program(idl, provider);
|
|
150
|
+
// Override program ID if non-default
|
|
151
|
+
if (!programId.equals(SAP_PROGRAM_ID)) {
|
|
152
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
153
|
+
program.programId = programId;
|
|
154
|
+
}
|
|
155
|
+
return new SapClient(program);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* @name fromProgram
|
|
159
|
+
* @description Create a {@link SapClient} from an existing Anchor `Program`
|
|
160
|
+
* instance. Useful when the caller already has a configured program or
|
|
161
|
+
* needs full control over IDL resolution.
|
|
162
|
+
*
|
|
163
|
+
* @param program - A pre-built Anchor `Program` targeting the SAP program.
|
|
164
|
+
* @returns A fully-initialised `SapClient` wrapping the supplied program.
|
|
165
|
+
*
|
|
166
|
+
* @category Core
|
|
167
|
+
* @since v0.1.0
|
|
168
|
+
* @see {@link SapClient.from} for the convenience factory that auto-loads the IDL.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* import { Program } from "@coral-xyz/anchor";
|
|
173
|
+
* import { SapClient } from "@synapse-sap/sdk";
|
|
174
|
+
*
|
|
175
|
+
* const program = new Program(idl, provider);
|
|
176
|
+
* const client = SapClient.fromProgram(program);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
static fromProgram(program) {
|
|
180
|
+
return new SapClient(program);
|
|
181
|
+
}
|
|
182
|
+
// ═════════════════════════════════════════════
|
|
183
|
+
// Module Accessors (lazy singletons)
|
|
184
|
+
// ═════════════════════════════════════════════
|
|
185
|
+
/**
|
|
186
|
+
* @name agent
|
|
187
|
+
* @description Agent lifecycle: register, update, deactivate, close, and
|
|
188
|
+
* query agent metrics on-chain.
|
|
189
|
+
* @returns {AgentModule} The lazily-instantiated `AgentModule` singleton.
|
|
190
|
+
* @category Modules
|
|
191
|
+
* @since v0.1.0
|
|
192
|
+
* @see {@link AgentModule}
|
|
193
|
+
*/
|
|
194
|
+
get agent() {
|
|
195
|
+
return (this.#agent ??= new AgentModule(this.program));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @name feedback
|
|
199
|
+
* @description Trustless reputation: give, update, revoke, and close
|
|
200
|
+
* on-chain feedback entries for agents.
|
|
201
|
+
* @returns {FeedbackModule} The lazily-instantiated `FeedbackModule` singleton.
|
|
202
|
+
* @category Modules
|
|
203
|
+
* @since v0.1.0
|
|
204
|
+
* @see {@link FeedbackModule}
|
|
205
|
+
*/
|
|
206
|
+
get feedback() {
|
|
207
|
+
return (this.#feedback ??= new FeedbackModule(this.program));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* @name indexing
|
|
211
|
+
* @description Scalable discovery: capability, protocol, and tool-category
|
|
212
|
+
* on-chain indexes for agent search.
|
|
213
|
+
* @returns {IndexingModule} The lazily-instantiated `IndexingModule` singleton.
|
|
214
|
+
* @category Modules
|
|
215
|
+
* @since v0.1.0
|
|
216
|
+
* @see {@link IndexingModule}
|
|
217
|
+
*/
|
|
218
|
+
get indexing() {
|
|
219
|
+
return (this.#indexing ??= new IndexingModule(this.program));
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* @name tools
|
|
223
|
+
* @description Tool schema registry: publish, inscribe, update, and close
|
|
224
|
+
* on-chain tool definitions.
|
|
225
|
+
* @returns {ToolsModule} The lazily-instantiated `ToolsModule` singleton.
|
|
226
|
+
* @category Modules
|
|
227
|
+
* @since v0.1.0
|
|
228
|
+
* @see {@link ToolsModule}
|
|
229
|
+
*/
|
|
230
|
+
get tools() {
|
|
231
|
+
return (this.#tools ??= new ToolsModule(this.program));
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @name vault
|
|
235
|
+
* @description Encrypted memory vault: initialise vaults, manage sessions,
|
|
236
|
+
* inscribe data, and delegate access.
|
|
237
|
+
* @returns {VaultModule} The lazily-instantiated `VaultModule` singleton.
|
|
238
|
+
* @category Modules
|
|
239
|
+
* @since v0.1.0
|
|
240
|
+
* @see {@link VaultModule}
|
|
241
|
+
*/
|
|
242
|
+
get vault() {
|
|
243
|
+
return (this.#vault ??= new VaultModule(this.program));
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @name escrow
|
|
247
|
+
* @description x402 escrow settlement: create escrow accounts, deposit
|
|
248
|
+
* funds, settle payments, and withdraw balances.
|
|
249
|
+
* @returns {EscrowModule} The lazily-instantiated `EscrowModule` singleton.
|
|
250
|
+
* @category Modules
|
|
251
|
+
* @since v0.1.0
|
|
252
|
+
* @see {@link EscrowModule}
|
|
253
|
+
*/
|
|
254
|
+
get escrow() {
|
|
255
|
+
return (this.#escrow ??= new EscrowModule(this.program));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @name attestation
|
|
259
|
+
* @description Web of trust: create, revoke, and close on-chain
|
|
260
|
+
* attestations between agents.
|
|
261
|
+
* @returns {AttestationModule} The lazily-instantiated `AttestationModule` singleton.
|
|
262
|
+
* @category Modules
|
|
263
|
+
* @since v0.1.0
|
|
264
|
+
* @see {@link AttestationModule}
|
|
265
|
+
*/
|
|
266
|
+
get attestation() {
|
|
267
|
+
return (this.#attestation ??= new AttestationModule(this.program));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* @name ledger
|
|
271
|
+
* @description Unified on-chain memory: initialise ledger accounts, write
|
|
272
|
+
* entries, seal pages, and close ledgers.
|
|
273
|
+
* @returns {LedgerModule} The lazily-instantiated `LedgerModule` singleton.
|
|
274
|
+
* @category Modules
|
|
275
|
+
* @since v0.1.0
|
|
276
|
+
* @see {@link LedgerModule}
|
|
277
|
+
*/
|
|
278
|
+
get ledger() {
|
|
279
|
+
return (this.#ledger ??= new LedgerModule(this.program));
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* @name events
|
|
283
|
+
* @description Decode SAP protocol events from on-chain transaction logs.
|
|
284
|
+
* @returns {EventParser} The lazily-instantiated `EventParser` singleton.
|
|
285
|
+
* @category Modules
|
|
286
|
+
* @since v0.1.0
|
|
287
|
+
* @see {@link EventParser}
|
|
288
|
+
*/
|
|
289
|
+
get events() {
|
|
290
|
+
return (this.#events ??= new EventParser(this.program));
|
|
291
|
+
}
|
|
292
|
+
// ═════════════════════════════════════════════
|
|
293
|
+
// Registry Accessors (high-level abstractions)
|
|
294
|
+
// ═════════════════════════════════════════════
|
|
295
|
+
/**
|
|
296
|
+
* @name discovery
|
|
297
|
+
* @description Agent & tool discovery across the SAP network.
|
|
298
|
+
* Provides high-level queries for locating agents by capability,
|
|
299
|
+
* protocol, or wallet address.
|
|
300
|
+
*
|
|
301
|
+
* @returns {DiscoveryRegistry} The lazily-instantiated `DiscoveryRegistry` singleton.
|
|
302
|
+
* @category Registries
|
|
303
|
+
* @since v0.1.0
|
|
304
|
+
* @see {@link DiscoveryRegistry}
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```ts
|
|
308
|
+
* const agents = await client.discovery.findAgentsByProtocol("jupiter");
|
|
309
|
+
* const profile = await client.discovery.getAgentProfile(wallet);
|
|
310
|
+
* ```
|
|
311
|
+
*/
|
|
312
|
+
get discovery() {
|
|
313
|
+
return (this.#discovery ??= new DiscoveryRegistry(this.program));
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* @name x402
|
|
317
|
+
* @description x402 micropayment lifecycle — pricing, escrow, headers,
|
|
318
|
+
* and settlement. Orchestrates the full pay-per-call flow between
|
|
319
|
+
* consumer and agent.
|
|
320
|
+
*
|
|
321
|
+
* @returns {X402Registry} The lazily-instantiated `X402Registry` singleton.
|
|
322
|
+
* @category Registries
|
|
323
|
+
* @since v0.1.0
|
|
324
|
+
* @see {@link X402Registry}
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* const ctx = await client.x402.preparePayment(agentWallet, { ... });
|
|
329
|
+
* const headers = client.x402.buildPaymentHeaders(ctx);
|
|
330
|
+
* const receipt = await client.x402.settle(depositor, 5, serviceData);
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
get x402() {
|
|
334
|
+
return (this.#x402 ??= new X402Registry(this.program));
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* @name session
|
|
338
|
+
* @description Unified memory session lifecycle — vault, session, and
|
|
339
|
+
* ledger management. Provides a single interface for starting
|
|
340
|
+
* conversations, writing messages, and reading back history.
|
|
341
|
+
*
|
|
342
|
+
* @returns {SessionManager} The lazily-instantiated `SessionManager` singleton.
|
|
343
|
+
* @category Registries
|
|
344
|
+
* @since v0.1.0
|
|
345
|
+
* @see {@link SessionManager}
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```ts
|
|
349
|
+
* const ctx = await client.session.start("conversation-123");
|
|
350
|
+
* await client.session.write(ctx, "Hello from agent");
|
|
351
|
+
* const msgs = await client.session.readLatest(ctx);
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
get session() {
|
|
355
|
+
return (this.#session ??= new SessionManager(this.program));
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* @name builder
|
|
359
|
+
* @description Fluent agent registration builder.
|
|
360
|
+
* Returns a **new** `AgentBuilder` on every access — use for one-shot
|
|
361
|
+
* registration flows. Chain configuration calls and finalise with
|
|
362
|
+
* `.register()`.
|
|
363
|
+
*
|
|
364
|
+
* @returns {AgentBuilder} A fresh `AgentBuilder` instance.
|
|
365
|
+
* @category Registries
|
|
366
|
+
* @since v0.1.0
|
|
367
|
+
* @see {@link AgentBuilder}
|
|
368
|
+
*
|
|
369
|
+
* @example
|
|
370
|
+
* ```ts
|
|
371
|
+
* await client.builder
|
|
372
|
+
* .agent("SwapBot")
|
|
373
|
+
* .description("AI-powered swap agent")
|
|
374
|
+
* .x402Endpoint("https://api.example.com/x402")
|
|
375
|
+
* .addCapability("jupiter:swap", { protocol: "jupiter" })
|
|
376
|
+
* .addPricingTier({ tierId: "standard", pricePerCall: 1000, rateLimit: 60 })
|
|
377
|
+
* .register();
|
|
378
|
+
* ```
|
|
379
|
+
*/
|
|
380
|
+
get builder() {
|
|
381
|
+
return new AgentBuilder(this.program);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
//# sourceMappingURL=client.js.map
|