@fangorn-network/sdk 2026.7.12 → 2026.7.14

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.
Files changed (72) hide show
  1. package/README.md +104 -69
  2. package/lib/cli/cli.js +26 -19
  3. package/lib/cli/index.d.ts +13 -13
  4. package/lib/config.d.ts +93 -92
  5. package/lib/contracts/data-registry/abi.d.ts +207 -35
  6. package/lib/contracts/data-registry/index.js +4 -4
  7. package/lib/contracts/index.d.ts +3 -1
  8. package/lib/contracts/index.js +3 -1
  9. package/lib/contracts/settlement-registry/abi.d.ts +47 -0
  10. package/lib/contracts/settlement-registry/abi.js +48 -0
  11. package/lib/contracts/settlement-registry/index.d.ts +25 -0
  12. package/lib/contracts/settlement-registry/index.js +40 -0
  13. package/lib/crypto/aes.d.ts +1 -8
  14. package/lib/crypto/aes.js +2 -34
  15. package/lib/crypto/encryption.d.ts +112 -26
  16. package/lib/crypto/encryption.js +105 -21
  17. package/lib/engine/car.d.ts +10 -0
  18. package/lib/engine/car.js +37 -0
  19. package/lib/engine/graph.d.ts +70 -0
  20. package/lib/engine/graph.js +73 -0
  21. package/lib/engine/index.d.ts +109 -70
  22. package/lib/engine/index.js +296 -226
  23. package/lib/engine/test-helpers.d.ts +43 -0
  24. package/lib/engine/test-helpers.js +69 -0
  25. package/lib/fangorn.d.ts +28 -25
  26. package/lib/fangorn.js +118 -83
  27. package/lib/harness/index.d.ts +4 -3
  28. package/lib/harness/index.js +9 -3
  29. package/lib/index.d.ts +3 -3
  30. package/lib/index.js +2 -2
  31. package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/_polyval.js +1 -1
  32. package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/aes.js +1 -1
  33. package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/utils.js +1 -1
  34. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/curve.js +1 -1
  35. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/edwards.js +1 -1
  36. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/modular.js +1 -1
  37. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/montgomery.js +1 -1
  38. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/ed25519.js +1 -1
  39. package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/utils.js +1 -1
  40. package/lib/providers/storage/car.js +2 -1
  41. package/lib/providers/storage/pinata.d.ts +16 -9
  42. package/lib/providers/storage/pinata.js +34 -25
  43. package/lib/providers/storage/types.d.ts +18 -8
  44. package/lib/{roles/repo → repo}/index.d.ts +1 -1
  45. package/lib/{roles/repo → repo}/index.js +1 -1
  46. package/lib/test/testbed.d.ts +9 -7
  47. package/lib/test/testbed.js +3 -2
  48. package/package.json +3 -9
  49. package/lib/ crypto/constants.d.ts +0 -4
  50. package/lib/ crypto/constants.js +0 -5
  51. package/lib/ crypto/merkle.d.ts +0 -10
  52. package/lib/ crypto/merkle.js +0 -34
  53. package/lib/ crypto/utils.d.ts +0 -1
  54. package/lib/ crypto/utils.js +0 -1
  55. package/lib/builders/a2aCardBuilder.d.ts +0 -28
  56. package/lib/builders/a2aCardBuilder.js +0 -105
  57. package/lib/engine/blockstore.d.ts +0 -24
  58. package/lib/engine/blockstore.js +0 -85
  59. package/lib/roles/index.d.ts +0 -1
  60. package/lib/roles/index.js +0 -1
  61. package/lib/test/car_smoke.d.ts +0 -1
  62. package/lib/test/car_smoke.js +0 -81
  63. package/lib/test/cleanup-embeddings-testdata.d.ts +0 -1
  64. package/lib/test/cleanup-embeddings-testdata.js +0 -75
  65. package/lib/test/index.d.ts +0 -10
  66. package/lib/test/index.js +0 -27
  67. package/lib/test/setup-embeddings-testdata.d.ts +0 -11
  68. package/lib/test/setup-embeddings-testdata.js +0 -155
  69. package/lib/utils/index.d.ts +0 -11
  70. package/lib/utils/index.js +0 -29
  71. package/lib/utils/manifest.d.ts +0 -23
  72. package/lib/utils/manifest.js +0 -77
@@ -6,7 +6,8 @@ import { CarWriter } from "@ipld/car";
6
6
  const enc = new TextEncoder();
7
7
  /** Filenames inside the CAR's UnixFS directory; ':' is legal but we keep it tidy. */
8
8
  function sanitize(name) {
9
- return name.replace(/[/\x00]/g, "_");
9
+ const sanitizeRegex = new RegExp("[/\\x00]", "g");
10
+ return name.replace(sanitizeRegex, "_");
10
11
  }
11
12
  /**
12
13
  * Pack named payloads into a SINGLE CAR with a UnixFS directory root.
@@ -19,21 +19,28 @@ declare class PinataBackend implements MetadataStorage {
19
19
  name: string;
20
20
  }[]): Promise<Record<string, string>>;
21
21
  /**
22
- * Upload precomputed (cid, bytes) blocks, each as its own plain-file pin,
23
- * so every block is individually addressable on the dedicated gateway
24
- * (see RAW_CODE comment above for why this can't go through `.car()`).
25
- * A single pail commit can touch many shard blocks at once (pail shards
26
- * key-by-character over shared prefixes, so one write under a namespace
27
- * that already has sibling keys can split into a whole chain of shard
28
- * blocks) — upload with bounded concurrency rather than one at a time.
22
+ * Upload ONE precomputed (cid, bytes) block as a plain-file pin so it's
23
+ * individually addressable on the dedicated gateway via its raw-codec
24
+ * sibling CID (see RAW_CODE comment above for why this can't go through
25
+ * `.car()`). Only commit blocks take this path — one small upload per
26
+ * commit; everything else travels inside the commit's CAR via putFile().
29
27
  */
30
- putBlocks(blocks: RawBlock[]): Promise<void>;
28
+ putBlock(block: RawBlock): Promise<void>;
29
+ /**
30
+ * Store opaque bytes (a commit's CAR file) as a single plain-file pin.
31
+ * Deliberately NOT `.car()`: the CAR is a packfile we read back whole, so
32
+ * Pinata never needs to understand its inner blocks. Returns the file's
33
+ * CID as the URI handle.
34
+ */
35
+ putFile(bytes: Uint8Array, name: string): Promise<string>;
36
+ /** Fetch back the exact bytes stored via putFile(). */
37
+ getFile(uri: string): Promise<Uint8Array>;
31
38
  get<T>(uri: string): Promise<T>;
32
39
  /** Raw bytes for a block CID, with no decoding — what blockstore traversal needs. */
33
40
  getRawBlock(uri: string): Promise<Uint8Array>;
34
41
  /**
35
42
  * Shared fetch-with-retry: resolves the raw-codec sibling CID for blocks
36
- * uploaded via putBlocks(), fetches from the dedicated gateway, and returns
43
+ * uploaded via putBlock(), fetches from the dedicated gateway, and returns
37
44
  * the exact bytes (never pre-decoded) plus enough context for get<T>() to
38
45
  * decide how to decode them.
39
46
  */
@@ -74,27 +74,35 @@ var PinataBackend = class {
74
74
  return uriByName;
75
75
  }
76
76
  /**
77
- * Upload precomputed (cid, bytes) blocks, each as its own plain-file pin,
78
- * so every block is individually addressable on the dedicated gateway
79
- * (see RAW_CODE comment above for why this can't go through `.car()`).
80
- * A single pail commit can touch many shard blocks at once (pail shards
81
- * key-by-character over shared prefixes, so one write under a namespace
82
- * that already has sibling keys can split into a whole chain of shard
83
- * blocks) — upload with bounded concurrency rather than one at a time.
77
+ * Upload ONE precomputed (cid, bytes) block as a plain-file pin so it's
78
+ * individually addressable on the dedicated gateway via its raw-codec
79
+ * sibling CID (see RAW_CODE comment above for why this can't go through
80
+ * `.car()`). Only commit blocks take this path — one small upload per
81
+ * commit; everything else travels inside the commit's CAR via putFile().
84
82
  */
85
- async putBlocks(blocks) {
86
- const queue = [...blocks];
87
- const worker = async () => {
88
- let next;
89
- while (next = queue.shift()) {
90
- const { cid, bytes } = next;
91
- await withUploadRetry(cid.toString(), async () => {
92
- const file = new File([bytes], cid.toString(), { type: "application/octet-stream" });
93
- await this.pinata.upload.public.file(file);
94
- });
95
- }
96
- };
97
- await Promise.all(Array.from({ length: Math.min(8, blocks.length) }, worker));
83
+ async putBlock(block) {
84
+ const { cid, bytes } = block;
85
+ await withUploadRetry(cid.toString(), async () => {
86
+ const file = new File([bytes], cid.toString(), { type: "application/octet-stream" });
87
+ await this.pinata.upload.public.file(file);
88
+ });
89
+ }
90
+ /**
91
+ * Store opaque bytes (a commit's CAR file) as a single plain-file pin.
92
+ * Deliberately NOT `.car()`: the CAR is a packfile we read back whole, so
93
+ * Pinata never needs to understand its inner blocks. Returns the file's
94
+ * CID as the URI handle.
95
+ */
96
+ async putFile(bytes, name) {
97
+ return withUploadRetry(name, async () => {
98
+ const file = new File([bytes], name, { type: "application/octet-stream" });
99
+ return (await this.pinata.upload.public.file(file)).cid;
100
+ });
101
+ }
102
+ /** Fetch back the exact bytes stored via putFile(). */
103
+ async getFile(uri) {
104
+ const { bytes } = await this.fetchRaw(uri);
105
+ return bytes;
98
106
  }
99
107
  async get(uri) {
100
108
  const { bytes, isDagCborCid, contentType } = await this.fetchRaw(uri);
@@ -113,7 +121,7 @@ var PinataBackend = class {
113
121
  }
114
122
  /**
115
123
  * Shared fetch-with-retry: resolves the raw-codec sibling CID for blocks
116
- * uploaded via putBlocks(), fetches from the dedicated gateway, and returns
124
+ * uploaded via putBlock(), fetches from the dedicated gateway, and returns
117
125
  * the exact bytes (never pre-decoded) plus enough context for get<T>() to
118
126
  * decide how to decode them.
119
127
  */
@@ -140,7 +148,8 @@ var PinataBackend = class {
140
148
  if (attempts === 0) break;
141
149
  await new Promise((resolve) => setTimeout(resolve, 1e3));
142
150
  }
143
- throw new Error(`Pinata SDK failed to retrieve block ${uri} after multiple attempts. Internal Error: ${lastError?.message || lastError}`);
151
+ const internalMessage = lastError instanceof Error ? lastError.message : typeof lastError === "string" ? lastError : String(lastError ?? "");
152
+ throw new Error(`Pinata SDK failed to retrieve block ${uri} after multiple attempts. Internal Error: ${internalMessage}`);
144
153
  }
145
154
  static async getStatic(uri, gateway) {
146
155
  return retrieveByCid(uri, gateway);
@@ -149,15 +158,15 @@ var PinataBackend = class {
149
158
  const formattedRoot = stateRoot.toLowerCase();
150
159
  for (let i = 0; i < retries; i++) {
151
160
  const response = await this.pinata.files.public.list().keyvalues({ stateRoot: formattedRoot });
152
- if (response && response.files && response.files.length > 0) return response.files[0].cid;
161
+ if (response.files.length > 0) return response.files[0].cid;
153
162
  if (i < retries - 1) {
154
163
  console.warn(`
155
- [Pinata] Indexing lag detected for root ${formattedRoot}. Retrying in ${delay * (i + 1)}ms...
164
+ [Pinata] Indexing lag detected for root ${formattedRoot}. Retrying in ${(delay * (i + 1)).toString()}ms...
156
165
  `);
157
166
  await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));
158
167
  }
159
168
  }
160
- throw new Error(`No matching IPFS CID found for state root: ${stateRoot} after ${retries} retrieval attempts.`);
169
+ throw new Error(`No matching IPFS CID found for state root: ${stateRoot} after ${retries.toString()} retrieval attempts.`);
161
170
  }
162
171
  async delete(uri) {
163
172
  await this.pinata.files.public.delete([uri]);
@@ -21,26 +21,36 @@ interface MetadataStorage {
21
21
  */
22
22
  put(data: unknown, meta?: StorageMeta): Promise<string>;
23
23
  /**
24
- * Pack multiple items into a single upload
25
- * Returns a map of { name -> identifier } for each item
26
- */
24
+ * Pack multiple items into a single upload
25
+ * Returns a map of { name -> identifier } for each item
26
+ */
27
27
  putMany(items: {
28
28
  data: unknown;
29
29
  name: string;
30
30
  }[]): Promise<Record<string, string>>;
31
31
  /**
32
- * Upload precomputed (cid, bytes) blocks, preserving their exact CIDs so
33
- * they remain retrievable by `get(cid.toString())`.
32
+ * Upload ONE precomputed (cid, bytes) block, preserving its exact CID so it
33
+ * stays retrievable via `getRawBlock(cid.toString())`. Used only for commit
34
+ * blocks — one small upload per commit; bulk data travels inside CAR files
35
+ * via `putFile`.
36
+ */
37
+ putBlock(block: RawBlock): Promise<void>;
38
+ /**
39
+ * Store an opaque byte payload (e.g. a CAR file) and return a URI handle.
40
+ * The backend is NOT expected to understand the contents.
41
+ */
42
+ putFile(bytes: Uint8Array, name: string): Promise<string>;
43
+ /**
44
+ * Retrieve the exact bytes previously stored with putFile().
34
45
  */
35
- putBlocks(blocks: RawBlock[]): Promise<void>;
46
+ getFile(uri: string): Promise<Uint8Array>;
36
47
  /**
37
48
  * Retrieve content by URI previously returned from put().
38
49
  */
39
50
  get<T>(uri: string): Promise<T>;
40
51
  /**
41
52
  * Retrieve the exact raw bytes for a block CID, with no decoding applied —
42
- * what content-addressed tree traversal (e.g. the Pail blockstore adapter)
43
- * needs, as opposed to get()'s already-decoded logical payload.
53
+ * how commit blocks written with putBlock() are read back.
44
54
  */
45
55
  getRawBlock(uri: string): Promise<Uint8Array>;
46
56
  /**
@@ -1,6 +1,6 @@
1
1
  import { Address, Hex } from "viem";
2
2
 
3
- //#region src/roles/repo/index.d.ts
3
+ //#region src/repo/index.d.ts
4
4
 
5
5
  /**
6
6
  * The local working repo — a `.fangorn/` directory, the analogue of `.git/`.
@@ -1,7 +1,7 @@
1
1
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
2
2
  import { join } from "path";
3
3
 
4
- //#region src/roles/repo/index.ts
4
+ //#region src/repo/index.ts
5
5
  /**
6
6
  * The local working repo — a `.fangorn/` directory, the analogue of `.git/`.
7
7
  *
@@ -1,4 +1,4 @@
1
- import { NamespaceContents } from "../engine/index.js";
1
+ import { NamespaceContents, SchemaID } from "../engine/index.js";
2
2
  import { Fangorn } from "../fangorn.js";
3
3
  import { Hex } from "viem";
4
4
 
@@ -21,7 +21,7 @@ declare class TestBed {
21
21
  txHash: `0x${string}`;
22
22
  alreadyInitialized: false;
23
23
  }>;
24
- upload(index: number, namespace: string, payload: any, name: string): Promise<{
24
+ upload(index: number, namespace: string, payload: unknown, name: string): Promise<{
25
25
  payloadCid: string;
26
26
  commitCid: string;
27
27
  txHash: `0x${string}`;
@@ -29,7 +29,7 @@ declare class TestBed {
29
29
  uploadBatch(index: number, namespace: string, vertices: {
30
30
  id: string;
31
31
  tag: string;
32
- payload: any;
32
+ payload: unknown;
33
33
  }[], edges?: {
34
34
  rel: string;
35
35
  from: string;
@@ -37,11 +37,13 @@ declare class TestBed {
37
37
  }[]): Promise<{
38
38
  commitCid: string;
39
39
  txHash: `0x${string}`;
40
- vertexCids: {
41
- [k: string]: string;
42
- };
40
+ vertexCids: Record<string, string>;
41
+ }>;
42
+ fetch(index: number, cid: string): Promise<{
43
+ cid: string;
44
+ schemaId: SchemaID;
45
+ payload: Record<string, unknown>;
43
46
  }>;
44
- fetch(index: number, cid: string): Promise<any>;
45
47
  inspect(index: number, namespace: string): Promise<NamespaceContents>;
46
48
  }
47
49
  //#endregion
@@ -6,7 +6,7 @@ var TestBed = class TestBed {
6
6
  this.f_list = f_list;
7
7
  }
8
8
  static init(sks) {
9
- let f_list = [];
9
+ const f_list = [];
10
10
  sks.forEach((sk) => {
11
11
  f_list.push(Fangorn.create({
12
12
  privateKey: sk,
@@ -46,7 +46,8 @@ var TestBed = class TestBed {
46
46
  return this.getFangorn(index).uploadBatch(namespace, vertices, edges);
47
47
  }
48
48
  async fetch(index, cid) {
49
- return this.getFangorn(index).getStorage().get(cid);
49
+ const fangorn = this.getFangorn(index);
50
+ return fangorn.engine.readVertex(cid, fangorn.getAddress());
50
51
  }
51
52
  async inspect(index, namespace) {
52
53
  return this.getFangorn(index).inspectNamespace(namespace);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@fangorn-network/sdk",
3
- "version": "2026.07.12",
4
- "description": "A zero-knowledge conditional access control framework",
3
+ "version": "2026.07.14",
4
+ "description": "Git for knowledge graphs",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/fangorn-network/fangorn.git"
@@ -66,16 +66,10 @@
66
66
  "@semaphore-protocol/group": "^4.14.2",
67
67
  "@semaphore-protocol/identity": "^4.14.2",
68
68
  "@semaphore-protocol/proof": "^4.14.2",
69
- "@storacha/client": "^2.1.3",
70
- "@web3-storage/pail": "^0.6.2",
71
69
  "agent0-sdk": "^1.5.3",
72
70
  "commander": "^14.0.3",
73
71
  "dotenv": "^17.2.3",
74
72
  "ethers": "^6.16.0",
75
- "interface-blockstore": "^7.0.1",
76
- "interface-store": "^8.0.0",
77
- "ipfs-car": "^3.1.0",
78
- "lmdb": "^3.5.5",
79
73
  "multiformats": "^14.0.0",
80
74
  "pinata": "^2.5.2",
81
75
  "poseidon-lite": "^0.3.0",
@@ -98,4 +92,4 @@
98
92
  }
99
93
  }
100
94
  }
101
- }
95
+ }
@@ -1,4 +0,0 @@
1
- //#region src/ crypto/constants.d.ts
2
- declare const TREE_DEPTH = 8;
3
- //#endregion
4
- export { TREE_DEPTH };
@@ -1,5 +0,0 @@
1
- //#region src/ crypto/constants.ts
2
- const TREE_DEPTH = 8;
3
-
4
- //#endregion
5
- export { TREE_DEPTH };
@@ -1,10 +0,0 @@
1
- //#region src/ crypto/merkle.d.ts
2
- declare function hashCidToField(cid: string): bigint;
3
- declare function getProof(layers: bigint[][], index: number): {
4
- path: bigint[];
5
- indices: number[];
6
- };
7
- declare function fieldToHex(field: bigint): `0x${string}`;
8
- declare function hexToField(hex: string): bigint;
9
- //#endregion
10
- export { fieldToHex, getProof, hashCidToField, hexToField };
@@ -1,34 +0,0 @@
1
- import { TREE_DEPTH } from "./constants.js";
2
-
3
- //#region src/ crypto/merkle.ts
4
- function hashCidToField(cid) {
5
- const bytes = new TextEncoder().encode(cid);
6
- let value = 0n;
7
- for (let i = 0; i < Math.min(bytes.length, 31); i++) value = value << 8n | BigInt(bytes[i]);
8
- return value;
9
- }
10
- function getProof(layers, index) {
11
- const path = [];
12
- const indices = [];
13
- for (let i = 0; i < TREE_DEPTH; i++) {
14
- const isRight = index % 2 === 1;
15
- const siblingIndex = isRight ? index - 1 : index + 1;
16
- path.push(layers[i][siblingIndex] ?? 0n);
17
- indices.push(isRight ? 1 : 0);
18
- index = Math.floor(index / 2);
19
- }
20
- return {
21
- path,
22
- indices
23
- };
24
- }
25
- function fieldToHex(field) {
26
- return `0x${field.toString(16).padStart(64, "0")}`;
27
- }
28
- function hexToField(hex) {
29
- const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
30
- return BigInt(cleanHex);
31
- }
32
-
33
- //#endregion
34
- export { fieldToHex, getProof, hashCidToField, hexToField };
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,28 +0,0 @@
1
- import { AgentCard } from "@a2a-js/sdk";
2
-
3
- //#region src/builders/a2aCardBuilder.d.ts
4
- declare class AgentCardBuilder {
5
- private card;
6
- name(name: string): this;
7
- description(description: string): this;
8
- version(version: string): this;
9
- url(url: string): this;
10
- protocolVersion(protocolVersion: string): this;
11
- capabilities(opts: {
12
- streaming?: boolean;
13
- pushNotifications?: boolean;
14
- stateTransitionHistory?: boolean;
15
- }): this;
16
- streaming(enabled?: boolean): this;
17
- pushNotifications(enabled?: boolean): this;
18
- stateTransitionHistory(enabled?: boolean): this;
19
- inputModes(modes: string[]): this;
20
- outputModes(modes: string[]): this;
21
- addSkill(id: string, name: string, description: string, tags: string[], examples?: string[]): this;
22
- provider(organization: string, url: string): this;
23
- documentationUrl(url: string): this;
24
- build(): AgentCard;
25
- }
26
- declare const agentCardBuilder: () => AgentCardBuilder;
27
- //#endregion
28
- export { AgentCardBuilder, agentCardBuilder };
@@ -1,105 +0,0 @@
1
- //#region src/builders/a2aCardBuilder.ts
2
- var AgentCardBuilder = class {
3
- card = {
4
- capabilities: {
5
- streaming: false,
6
- pushNotifications: false,
7
- stateTransitionHistory: false
8
- },
9
- defaultInputModes: ["text/plain", "application/json"],
10
- defaultOutputModes: ["text/plain", "application/json"],
11
- skills: []
12
- };
13
- name(name) {
14
- this.card.name = name;
15
- return this;
16
- }
17
- description(description) {
18
- this.card.description = description;
19
- return this;
20
- }
21
- version(version) {
22
- this.card.version = version;
23
- return this;
24
- }
25
- url(url) {
26
- this.card.url = url;
27
- return this;
28
- }
29
- protocolVersion(protocolVersion) {
30
- this.card.protocolVersion = protocolVersion;
31
- return this;
32
- }
33
- capabilities(opts) {
34
- this.card.capabilities = {
35
- ...this.card.capabilities,
36
- ...opts
37
- };
38
- return this;
39
- }
40
- streaming(enabled = true) {
41
- this.card.capabilities = {
42
- ...this.card.capabilities,
43
- streaming: enabled
44
- };
45
- return this;
46
- }
47
- pushNotifications(enabled = true) {
48
- this.card.capabilities = {
49
- ...this.card.capabilities,
50
- pushNotifications: enabled
51
- };
52
- return this;
53
- }
54
- stateTransitionHistory(enabled = true) {
55
- this.card.capabilities = {
56
- ...this.card.capabilities,
57
- stateTransitionHistory: enabled
58
- };
59
- return this;
60
- }
61
- inputModes(modes) {
62
- this.card.defaultInputModes = modes;
63
- return this;
64
- }
65
- outputModes(modes) {
66
- this.card.defaultOutputModes = modes;
67
- return this;
68
- }
69
- addSkill(id, name, description, tags, examples) {
70
- const skill = {
71
- id,
72
- name,
73
- description,
74
- tags
75
- };
76
- if (examples) skill.examples = examples;
77
- this.card.skills ??= [];
78
- this.card.skills.push(skill);
79
- return this;
80
- }
81
- provider(organization, url) {
82
- this.card.provider = {
83
- organization,
84
- url
85
- };
86
- return this;
87
- }
88
- documentationUrl(url) {
89
- this.card.documentationUrl = url;
90
- return this;
91
- }
92
- build() {
93
- for (const field of [
94
- "name",
95
- "description",
96
- "version",
97
- "url"
98
- ]) if (!this.card[field]) throw new Error(`AgentCard requires '${field}'`);
99
- return this.card;
100
- }
101
- };
102
- const agentCardBuilder = () => new AgentCardBuilder();
103
-
104
- //#endregion
105
- export { AgentCardBuilder, agentCardBuilder };
@@ -1,24 +0,0 @@
1
- import { MetadataStorage } from "../providers/storage/types.js";
2
- import "../providers/storage/index.js";
3
- import { Blockstore } from "interface-blockstore";
4
-
5
- //#region src/engine/blockstore.d.ts
6
- declare class StorageBlockstoreAdapter implements Blockstore<any, any, any, any, any, any, any, any> {
7
- private storage;
8
- private memoryCache;
9
- private pendingCids;
10
- constructor(storage: MetadataStorage);
11
- put(key: any, val: Uint8Array, options?: any): Promise<any>;
12
- /** Uploads every block written locally since the last flush to the remote backend. */
13
- flush(): Promise<void>;
14
- get(key: any, options?: any): AsyncGenerator<Uint8Array, void, unknown>;
15
- has(key: any, options?: any): Promise<boolean>;
16
- delete(key: any, options?: any): Promise<void>;
17
- putMany(blocks: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
18
- getMany(cids: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
19
- deleteMany(cids: AsyncIterable<any> | Iterable<any>, options?: any): AsyncGenerator<any, void, unknown>;
20
- blocks(options?: any): AsyncGenerator<any, void, unknown>;
21
- getAll(options?: any): AsyncGenerator<any, void, unknown>;
22
- }
23
- //#endregion
24
- export { StorageBlockstoreAdapter };
@@ -1,85 +0,0 @@
1
- import { CID } from "multiformats/cid";
2
-
3
- //#region src/engine/blockstore.ts
4
- var StorageBlockstoreAdapter = class {
5
- memoryCache = /* @__PURE__ */ new Map();
6
- pendingCids = /* @__PURE__ */ new Map();
7
- constructor(storage) {
8
- this.storage = storage;
9
- }
10
- async put(key, val, options) {
11
- const cleanBytes = val.byteOffset === 0 && val.byteLength === val.buffer.byteLength ? val : val.slice();
12
- const cid = key instanceof CID ? key : CID.parse(key.toString());
13
- const lookupKey = cid.toString();
14
- this.memoryCache.set(lookupKey, cleanBytes);
15
- this.pendingCids.set(lookupKey, cid);
16
- return key;
17
- }
18
- /** Uploads every block written locally since the last flush to the remote backend. */
19
- async flush() {
20
- if (this.pendingCids.size === 0) return;
21
- const blocks = Array.from(this.pendingCids.values()).map((cid) => ({
22
- cid,
23
- bytes: this.memoryCache.get(cid.toString())
24
- }));
25
- await this.storage.putBlocks(blocks);
26
- this.pendingCids.clear();
27
- }
28
- async *get(key, options) {
29
- const lookupKey = key instanceof CID ? key.toString() : String(key);
30
- if (this.memoryCache.has(lookupKey)) {
31
- yield this.memoryCache.get(lookupKey);
32
- return;
33
- }
34
- const remoteBytes = await this.storage.getRawBlock(lookupKey);
35
- if (!remoteBytes) throw new Error(`Block payload missing for key: ${lookupKey}`);
36
- this.memoryCache.set(lookupKey, remoteBytes);
37
- yield remoteBytes;
38
- }
39
- async has(key, options) {
40
- const lookupKey = key instanceof CID ? key.toString() : String(key);
41
- if (this.memoryCache.has(lookupKey)) return true;
42
- try {
43
- return !(await this.get(key, options).next()).done;
44
- } catch {
45
- return false;
46
- }
47
- }
48
- async delete(key, options) {
49
- const lookupKey = key instanceof CID ? key.toString() : String(key);
50
- this.memoryCache.delete(lookupKey);
51
- }
52
- async *putMany(blocks, options) {
53
- for await (const { cid, block } of blocks) {
54
- await this.put(cid, block, options);
55
- yield cid;
56
- }
57
- }
58
- async *getMany(cids, options) {
59
- for await (const cid of cids) {
60
- const chunks = [];
61
- for await (const chunk of this.get(cid, options)) chunks.push(chunk);
62
- const flatBytes = new Uint8Array(chunks.reduce((acc, c) => acc + c.length, 0));
63
- let offset = 0;
64
- for (const chunk of chunks) {
65
- flatBytes.set(chunk, offset);
66
- offset += chunk.length;
67
- }
68
- yield {
69
- cid,
70
- block: flatBytes
71
- };
72
- }
73
- }
74
- async *deleteMany(cids, options) {
75
- for await (const cid of cids) {
76
- this.delete(cid);
77
- yield cid;
78
- }
79
- }
80
- async *blocks(options) {}
81
- async *getAll(options) {}
82
- };
83
-
84
- //#endregion
85
- export { StorageBlockstoreAdapter };
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- import "dotenv/config";