@aithos/sdk 0.1.0-alpha.36 → 0.1.0-alpha.38

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.
@@ -24,6 +24,23 @@ export interface CreateDataClientArgs {
24
24
  readonly verificationMethod: string;
25
25
  /** Optional fetch implementation. Defaults to globalThis.fetch. */
26
26
  readonly fetch?: typeof fetch;
27
+ /**
28
+ * Optional list of app-defined schema definitions, in addition to
29
+ * the SDK-bundled core schemas (currently `aithos.contacts.v1`).
30
+ *
31
+ * Apps in the vendor namespace (`aithos.x.<vendor>.<name>.v<N>`) or
32
+ * non-`aithos.*` namespaces MUST supply their schemas here so the
33
+ * SDK can split records into indexable metadata vs encrypted payload.
34
+ *
35
+ * When the same schema id appears in both the bundled core registry
36
+ * and this list, the app-supplied definition wins (intentional —
37
+ * allows local overrides for testing, though immutability per spec
38
+ * §3.5 means a published schema id should never change shape).
39
+ *
40
+ * Schemas are scoped to the {@link DataClient} instance — they don't
41
+ * leak to other clients in the same process.
42
+ */
43
+ readonly schemas?: readonly AithosSchemaLite[];
27
44
  }
28
45
  export interface DataClient {
29
46
  /** Get / create a collection handle. */
package/dist/src/data.js CHANGED
@@ -19,10 +19,17 @@
19
19
  * encrypted payload (server-blind), JSON-RPC dispatch.
20
20
  *
21
21
  * It does not (yet) handle: mandate-delegate authentication on the
22
- * caller side (the SDK only signs as owner in v0.1), schema
23
- * publication (only the bundled `aithos.contacts.v1` is recognized),
24
- * forward-secrecy CMK rotation primitives. Those land in later
25
- * Sub-jalons.
22
+ * caller side (the SDK only signs as owner in v0.1), full schema
23
+ * publication (no `registerSchema` RPC yet — that lands with A2b, cf.
24
+ * aithos-protocol/PLAN-A2b-schema-self-registration.md), forward-secrecy
25
+ * CMK rotation primitives. Those land in later Sub-jalons.
26
+ *
27
+ * Apps that need to use a vendor schema (`aithos.x.<vendor>.<name>.v<N>`,
28
+ * or any non-`aithos.*` namespace) pass their schema definitions to
29
+ * `createDataClient({ schemas: [...] })`. The PDS accepts these at face
30
+ * value (no server-side metadata validation pending A2b); the SDK uses
31
+ * the supplied schema definitions to split records into indexable
32
+ * metadata and encrypted payload.
26
33
  *
27
34
  * Spec ref: spec/data/01..10 of the aithos-protocol repo.
28
35
  */
@@ -59,6 +66,13 @@ class DataClientImpl {
59
66
  #seed;
60
67
  #vm;
61
68
  #fetch;
69
+ /**
70
+ * Per-client schema overrides, populated from `args.schemas` at
71
+ * construction. Looked up BEFORE the bundled SCHEMAS map (so an app
72
+ * can override a core schema locally if it really wants to, though
73
+ * the immutability rule of spec §3.5 strongly discourages this).
74
+ */
75
+ #localSchemas;
62
76
  // Per-collection CMK cache: cleared on reset()
63
77
  #cmkCache = new Map();
64
78
  #colCache = new Map();
@@ -68,6 +82,15 @@ class DataClientImpl {
68
82
  this.#seed = args.sphereSeed;
69
83
  this.#vm = args.verificationMethod;
70
84
  this.#fetch = args.fetch ?? globalThis.fetch.bind(globalThis);
85
+ this.#localSchemas = new Map((args.schemas ?? []).map((s) => [s.schema, s]));
86
+ }
87
+ /**
88
+ * Resolve a schema id to its lite definition. App-supplied schemas
89
+ * (via `createDataClient({ schemas })`) take precedence over the
90
+ * SDK-bundled core registry.
91
+ */
92
+ #resolveSchema(schemaId) {
93
+ return this.#localSchemas.get(schemaId) ?? SCHEMAS.get(schemaId) ?? null;
71
94
  }
72
95
  collection(name) {
73
96
  return new DataCollectionImpl(this, name);
@@ -168,9 +191,12 @@ class DataClientImpl {
168
191
  privateKey: ed25519SeedToX25519PrivateKey(this.#seed),
169
192
  });
170
193
  this.#cmkCache.set(name, cmk);
171
- const schema = SCHEMAS.get(meta.schema);
194
+ const schema = this.#resolveSchema(meta.schema);
172
195
  if (!schema) {
173
- throw new Error(`sdk.data: schema "${meta.schema}" not known to the SDK`);
196
+ throw new Error(`sdk.data: schema "${meta.schema}" not known to the SDK. ` +
197
+ `Pass it via createDataClient({ schemas: [...] }) if it's an ` +
198
+ `app-defined (vendor) schema, or upgrade the SDK if it's a core ` +
199
+ `schema added in a later release.`);
174
200
  }
175
201
  const state = { name, urn: meta.urn, schema };
176
202
  this.#colCache.set(name, state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aithos/sdk",
3
- "version": "0.1.0-alpha.36",
3
+ "version": "0.1.0-alpha.38",
4
4
  "description": "Aithos SDK — high-level TypeScript developer kit for building agentic apps on the Aithos protocol. Wraps @aithos/protocol-client and exposes the Aithos compute proxy and wallet (Stripe top-up) endpoints.",
5
5
  "keywords": [
6
6
  "aithos",