@aithos/sdk 0.1.0-alpha.4 → 0.1.0-alpha.40

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 (62) hide show
  1. package/README.md +211 -7
  2. package/dist/src/assets.d.ts +207 -0
  3. package/dist/src/assets.js +533 -0
  4. package/dist/src/auth-api.d.ts +138 -0
  5. package/dist/src/auth-api.js +168 -0
  6. package/dist/src/auth.d.ts +536 -119
  7. package/dist/src/auth.js +1207 -152
  8. package/dist/src/compute.d.ts +221 -9
  9. package/dist/src/compute.js +293 -16
  10. package/dist/src/data-schema-contacts-v1.d.ts +14 -0
  11. package/dist/src/data-schema-contacts-v1.js +28 -0
  12. package/dist/src/data.d.ts +153 -0
  13. package/dist/src/data.js +670 -0
  14. package/dist/src/endpoints.d.ts +9 -0
  15. package/dist/src/endpoints.js +5 -0
  16. package/dist/src/ethos.d.ts +202 -1
  17. package/dist/src/ethos.js +821 -16
  18. package/dist/src/index.d.ts +16 -6
  19. package/dist/src/index.js +33 -6
  20. package/dist/src/internal/delegate-bundle.d.ts +18 -0
  21. package/dist/src/internal/delegate-bundle.js +94 -0
  22. package/dist/src/internal/delegate-state.d.ts +45 -0
  23. package/dist/src/internal/delegate-state.js +120 -0
  24. package/dist/src/internal/envelope.d.ts +77 -0
  25. package/dist/src/internal/envelope.js +154 -0
  26. package/dist/src/internal/owner-signers.d.ts +78 -0
  27. package/dist/src/internal/owner-signers.js +179 -0
  28. package/dist/src/internal/protocol-client-bridge.d.ts +8 -0
  29. package/dist/src/internal/protocol-client-bridge.js +20 -0
  30. package/dist/src/internal/recovery-file.d.ts +29 -0
  31. package/dist/src/internal/recovery-file.js +98 -0
  32. package/dist/src/internal/signer.d.ts +59 -0
  33. package/dist/src/internal/signer.js +86 -0
  34. package/dist/src/key-store.d.ts +128 -0
  35. package/dist/src/key-store.js +244 -0
  36. package/dist/src/mandates.d.ts +163 -1
  37. package/dist/src/mandates.js +286 -8
  38. package/dist/src/react/AithosAsset.d.ts +66 -0
  39. package/dist/src/react/AithosAsset.js +67 -0
  40. package/dist/src/react/context.d.ts +29 -0
  41. package/dist/src/react/context.js +31 -0
  42. package/dist/src/react/index.d.ts +28 -0
  43. package/dist/src/react/index.js +30 -0
  44. package/dist/src/react/use-aithos-asset.d.ts +39 -0
  45. package/dist/src/react/use-aithos-asset.js +118 -0
  46. package/dist/src/sdk.d.ts +39 -3
  47. package/dist/src/sdk.js +36 -23
  48. package/dist/src/wallet.d.ts +4 -6
  49. package/dist/src/wallet.js +18 -8
  50. package/dist/src/web.d.ts +279 -0
  51. package/dist/src/web.js +186 -0
  52. package/package.json +18 -3
  53. package/dist/test/auth.test.d.ts +0 -2
  54. package/dist/test/auth.test.js +0 -175
  55. package/dist/test/compute.test.d.ts +0 -2
  56. package/dist/test/compute.test.js +0 -179
  57. package/dist/test/endpoints.test.d.ts +0 -2
  58. package/dist/test/endpoints.test.js +0 -43
  59. package/dist/test/sdk.test.d.ts +0 -2
  60. package/dist/test/sdk.test.js +0 -86
  61. package/dist/test/wallet.test.d.ts +0 -2
  62. package/dist/test/wallet.test.js +0 -110
@@ -4,11 +4,16 @@
4
4
  export const DEFAULT_SDK_ENDPOINTS = {
5
5
  compute: "https://compute.aithos.be",
6
6
  wallet: "https://wallet.aithos.be",
7
+ web: "https://extract.aithos.be",
7
8
  };
8
9
  /** Compose the full compute-invoke URL: `${compute}/v1/invoke`. */
9
10
  export function computeInvokeUrl(endpoints) {
10
11
  return `${trimSlash(endpoints.compute)}/v1/invoke`;
11
12
  }
13
+ /** Compose the full web-extract URL: `${web}/v1/invoke`. */
14
+ export function webInvokeUrl(endpoints) {
15
+ return `${trimSlash(endpoints.web)}/v1/invoke`;
16
+ }
12
17
  /** Compose the full top-up-checkout URL: `${wallet}/v1/wallet/topup/checkout`. */
13
18
  export function walletTopupCheckoutUrl(endpoints) {
14
19
  return `${trimSlash(endpoints.wallet)}/v1/wallet/topup/checkout`;
@@ -1,2 +1,203 @@
1
- export { parsePublicZone, type ParsedZone, loadEditSnapshot, publishZoneEdit, publishPublicZoneAsDelegate, publishPrivateZoneAsDelegate, type EditSnapshot, type AddSectionInput, type ModifySectionInput, type PublishEditArgs, type PublishEditResult, addSectionToList, modifySectionInList, deleteSectionFromList, buildSignedFirstEdition, buildSignedNextEdition, type ZoneDoc, type ZoneManifest, type Section, SPHERES, type Sphere, } from "@aithos/protocol-client";
1
+ import { type Section } from "@aithos/protocol-client";
2
+ import type { AithosAuth } from "./auth.js";
3
+ import type { AithosSdkEndpoints } from "./endpoints.js";
4
+ import type { DelegateActor } from "./internal/delegate-state.js";
5
+ import type { OwnerSigners } from "./internal/owner-signers.js";
6
+ export type ZoneName = "public" | "circle" | "self";
7
+ export declare const ZONE_NAMES: readonly ZoneName[];
8
+ export interface AddSectionInput {
9
+ readonly title: string;
10
+ readonly body: string;
11
+ readonly tags?: readonly string[];
12
+ }
13
+ export interface UpdateSectionPatch {
14
+ readonly title?: string;
15
+ readonly body?: string;
16
+ readonly tags?: readonly string[];
17
+ }
18
+ export type StagedChange = {
19
+ readonly kind: "add";
20
+ readonly zone: ZoneName;
21
+ readonly section: Section;
22
+ } | {
23
+ readonly kind: "update";
24
+ readonly zone: ZoneName;
25
+ readonly sectionId: string;
26
+ readonly patch: UpdateSectionPatch;
27
+ } | {
28
+ readonly kind: "delete";
29
+ readonly zone: ZoneName;
30
+ readonly sectionId: string;
31
+ };
32
+ export interface PublishResult {
33
+ /** New manifest height after publish. */
34
+ readonly editionHeight: number;
35
+ /** SHA-256 hex of the canonical manifest. */
36
+ readonly manifestHash: string;
37
+ /** DID of the subject we published for. */
38
+ readonly subjectDid: string;
39
+ /** Zones whose contents changed in this edition. */
40
+ readonly zonesPublished: readonly ZoneName[];
41
+ }
42
+ type ActorOwner = {
43
+ readonly kind: "owner";
44
+ readonly subjectDid: string;
45
+ readonly signers: OwnerSigners;
46
+ };
47
+ type ActorDelegate = {
48
+ readonly kind: "delegate";
49
+ readonly subjectDid: string;
50
+ readonly actor: DelegateActor;
51
+ };
52
+ type ActorAnonymous = {
53
+ readonly kind: "anonymous";
54
+ readonly subjectDid: string;
55
+ };
56
+ type Actor = ActorOwner | ActorDelegate | ActorAnonymous;
57
+ export declare class EthosClient {
58
+ #private;
59
+ readonly subjectDid: string;
60
+ readonly mode: Actor["kind"];
61
+ constructor(actor: Actor);
62
+ /** Return the per-zone proxy. */
63
+ zone(name: ZoneName): EthosZone;
64
+ hasPendingChanges(): boolean;
65
+ pendingChanges(): readonly StagedChange[];
66
+ discard(): void;
67
+ /**
68
+ * Build and publish a new edition with all staged mutations applied.
69
+ * Throws if there's nothing staged. After a successful publish, the
70
+ * mutation buffer is cleared and any cached snapshot is invalidated
71
+ * so the next read picks up the fresh edition.
72
+ */
73
+ publish(): Promise<PublishResult>;
74
+ /**
75
+ * Idempotently ensure the subject's Ethos has at least one published
76
+ * edition. Required because a **delegate** cannot bootstrap a first
77
+ * edition (the first edition's manifest is signed with the owner's
78
+ * public-sphere key, which delegates do not have). Without an initial
79
+ * owner-published edition, subsequent delegate writes via
80
+ * {@link publish} fail with `not found: edition for did:…`.
81
+ *
82
+ * Semantics:
83
+ * - If an edition already exists (owner OR delegate OR anonymous mode),
84
+ * this is a NO-OP and returns `{ alreadyInitialized: true }`.
85
+ * - If no edition exists AND the actor is the owner, this stages and
86
+ * publishes a height=1 edition containing a single sentinel section
87
+ * `aithos-init` in the `public` zone, then returns
88
+ * `{ alreadyInitialized: false, editionHeight: 1 }`. Any previously
89
+ * staged mutations on this client are preserved and NOT auto-flushed.
90
+ * - If no edition exists AND the actor is NOT the owner (delegate or
91
+ * anonymous), throws `ethos_bootstrap_not_owner` — only the owner
92
+ * can sign a first edition.
93
+ *
94
+ * Call site: typically the owner's dashboard, right after sign-in and
95
+ * before any delegate-mode write (e.g. before triggering a backend
96
+ * worker that holds a mandate). Idempotent ⇒ safe to call on every
97
+ * mount.
98
+ *
99
+ * Implementation note: this routes through {@link #publishFirstEditionOwner}
100
+ * which the SDK already uses internally when {@link publish} detects a
101
+ * fresh Ethos with staged owner mutations. ensureInitialized() exposes
102
+ * the same code path as an explicit primitive, so the caller doesn't
103
+ * need to stage a mutation just to trigger first-edition logic.
104
+ */
105
+ ensureInitialized(): Promise<{
106
+ alreadyInitialized: true;
107
+ } | {
108
+ alreadyInitialized: false;
109
+ editionHeight: number;
110
+ manifestHash: string;
111
+ }>;
112
+ _readZone(zone: ZoneName): Promise<readonly Section[]>;
113
+ _stageAdd(zone: ZoneName, input: AddSectionInput): void;
114
+ _stageUpdate(zone: ZoneName, sectionId: string, patch: UpdateSectionPatch): void;
115
+ _stageDelete(zone: ZoneName, sectionId: string): void;
116
+ }
117
+ export declare class EthosZone {
118
+ #private;
119
+ constructor(parent: EthosClient, name: ZoneName);
120
+ get name(): ZoneName;
121
+ /** Effective sections (persisted + staged mutations applied). */
122
+ sections(): Promise<readonly Section[]>;
123
+ addSection(input: AddSectionInput): void;
124
+ updateSection(sectionId: string, patch: UpdateSectionPatch): void;
125
+ deleteSection(sectionId: string): void;
126
+ /**
127
+ * Return every section in this zone whose `title` is exactly `title`.
128
+ *
129
+ * Match is exact and case-sensitive. The result is always an array — it
130
+ * may be empty (no match), have one element (the typical case), or have
131
+ * more than one element when the author has happened to publish two
132
+ * sections with the same title. Section titles are not required by the
133
+ * protocol to be unique within a zone.
134
+ *
135
+ * The order of returned sections is the zone's authored order
136
+ * (`sections()` ordering, spec §2.5.2).
137
+ *
138
+ * @param title Section title to look up — exact, case-sensitive.
139
+ */
140
+ findSectionsByTitle(title: string): Promise<readonly Section[]>;
141
+ /**
142
+ * Stage an update for **every** section in this zone whose `title`
143
+ * matches `title` exactly. Returns the list of section IDs that were
144
+ * staged — empty when nothing matched.
145
+ *
146
+ * Apply with `client.publish()` like any other staged mutation. The
147
+ * staged entries are identical to what `updateSection(id, patch)` would
148
+ * produce, one per matched section, so `pendingChanges()` /
149
+ * `discard()` behave normally.
150
+ *
151
+ * Note: this method does NOT throw when there is no match — it returns
152
+ * `[]`. That's intentional: callers driven by an LLM frequently want to
153
+ * upsert (try update, then fall back to add) and shouldn't have to
154
+ * catch.
155
+ *
156
+ * @param title Section title to look up — exact, case-sensitive.
157
+ * @param patch Same patch shape accepted by `updateSection`.
158
+ * @returns Array of `section.id` strings whose updates were staged.
159
+ */
160
+ updateSectionsByTitle(title: string, patch: UpdateSectionPatch): Promise<readonly string[]>;
161
+ /**
162
+ * Stage a delete for **every** section in this zone whose `title`
163
+ * matches `title` exactly. Returns the list of section IDs that were
164
+ * staged — empty when nothing matched.
165
+ *
166
+ * Same semantics as {@link updateSectionsByTitle}: silent on no-match,
167
+ * apply with `client.publish()`.
168
+ *
169
+ * @param title Section title to look up — exact, case-sensitive.
170
+ * @returns Array of `section.id` strings whose deletes were staged.
171
+ */
172
+ deleteSectionsByTitle(title: string): Promise<readonly string[]>;
173
+ }
174
+ export interface EthosNamespaceDeps {
175
+ readonly auth: AithosAuth;
176
+ readonly endpoints: AithosSdkEndpoints;
177
+ readonly fetch: typeof fetch;
178
+ }
179
+ export declare class EthosNamespace {
180
+ #private;
181
+ constructor(deps: EthosNamespaceDeps);
182
+ /**
183
+ * EthosClient for the currently signed-in owner. Throws if there is
184
+ * no owner — callers should check `auth.canSignAsOwner()` first or
185
+ * surface the error to the user as "please sign in".
186
+ */
187
+ me(): EthosClient;
188
+ /**
189
+ * EthosClient for an arbitrary subject DID. The mode is resolved at
190
+ * construction time:
191
+ * - if `did` matches the currently signed-in owner → owner mode
192
+ * - else if a mandate held by `auth` covers this subject → delegate mode
193
+ * - else → anonymous read-only mode
194
+ *
195
+ * Async signature so future implementations may do an eager manifest
196
+ * fetch (e.g. to fail fast on unknown DIDs); today resolution is sync
197
+ * and the actual fetch happens on the first `sections()` / `publish()`
198
+ * call.
199
+ */
200
+ of(did: string): Promise<EthosClient>;
201
+ }
202
+ export {};
2
203
  //# sourceMappingURL=ethos.d.ts.map