@aithos/sdk 0.1.0-alpha.6 → 0.1.0-alpha.60

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 (105) hide show
  1. package/README.md +202 -7
  2. package/dist/src/agent-dispatch.d.ts +18 -0
  3. package/dist/src/agent-dispatch.js +178 -0
  4. package/dist/src/agent-loop.d.ts +94 -0
  5. package/dist/src/agent-loop.js +95 -0
  6. package/dist/src/agent-tools.d.ts +24 -0
  7. package/dist/src/agent-tools.js +147 -0
  8. package/dist/src/apps.d.ts +224 -0
  9. package/dist/src/apps.js +432 -0
  10. package/dist/src/assets.d.ts +225 -0
  11. package/dist/src/assets.js +534 -0
  12. package/dist/src/auth-api.d.ts +219 -0
  13. package/dist/src/auth-api.js +248 -0
  14. package/dist/src/auth.d.ts +591 -0
  15. package/dist/src/auth.js +947 -31
  16. package/dist/src/compute.d.ts +674 -6
  17. package/dist/src/compute.js +968 -20
  18. package/dist/src/data-schema-contacts-v1.d.ts +14 -0
  19. package/dist/src/data-schema-contacts-v1.js +28 -0
  20. package/dist/src/data.d.ts +368 -0
  21. package/dist/src/data.js +1124 -0
  22. package/dist/src/endpoints.d.ts +43 -0
  23. package/dist/src/endpoints.js +23 -0
  24. package/dist/src/ethos.d.ts +85 -0
  25. package/dist/src/ethos.js +463 -7
  26. package/dist/src/index.d.ts +22 -4
  27. package/dist/src/index.js +47 -2
  28. package/dist/src/internal/cmk-wrap.d.ts +41 -0
  29. package/dist/src/internal/cmk-wrap.js +132 -0
  30. package/dist/src/internal/delegate-bundle.js +7 -2
  31. package/dist/src/internal/envelope.d.ts +93 -0
  32. package/dist/src/internal/envelope.js +59 -0
  33. package/dist/src/internal/owner-signers.d.ts +5 -2
  34. package/dist/src/internal/owner-signers.js +22 -1
  35. package/dist/src/internal/recovery-file.d.ts +2 -0
  36. package/dist/src/internal/recovery-file.js +7 -0
  37. package/dist/src/key-store.d.ts +10 -0
  38. package/dist/src/key-store.js +6 -0
  39. package/dist/src/mandates.d.ts +58 -1
  40. package/dist/src/mandates.js +46 -3
  41. package/dist/src/migrate.d.ts +105 -0
  42. package/dist/src/migrate.js +367 -0
  43. package/dist/src/react/AithosAsset.d.ts +66 -0
  44. package/dist/src/react/AithosAsset.js +67 -0
  45. package/dist/src/react/context.d.ts +29 -0
  46. package/dist/src/react/context.js +31 -0
  47. package/dist/src/react/index.d.ts +29 -0
  48. package/dist/src/react/index.js +31 -0
  49. package/dist/src/react/use-aithos-asset.d.ts +39 -0
  50. package/dist/src/react/use-aithos-asset.js +118 -0
  51. package/dist/src/react/use-transcribe-pending.d.ts +21 -0
  52. package/dist/src/react/use-transcribe-pending.js +47 -0
  53. package/dist/src/rotate.d.ts +94 -0
  54. package/dist/src/rotate.js +298 -0
  55. package/dist/src/sdk.d.ts +36 -2
  56. package/dist/src/sdk.js +72 -1
  57. package/dist/src/transcribe-resilience.d.ts +57 -0
  58. package/dist/src/transcribe-resilience.js +203 -0
  59. package/dist/src/web.d.ts +279 -0
  60. package/dist/src/web.js +186 -0
  61. package/dist/test/agent-dispatch.test.d.ts +2 -0
  62. package/dist/test/agent-dispatch.test.js +222 -0
  63. package/dist/test/agent-loop.test.d.ts +2 -0
  64. package/dist/test/agent-loop.test.js +117 -0
  65. package/dist/test/agent-tools.test.d.ts +2 -0
  66. package/dist/test/agent-tools.test.js +50 -0
  67. package/dist/test/auth-j3.test.js +32 -1
  68. package/dist/test/canonical-conformance.test.d.ts +2 -0
  69. package/dist/test/canonical-conformance.test.js +86 -0
  70. package/dist/test/compute-delegate-path.test.d.ts +2 -0
  71. package/dist/test/compute-delegate-path.test.js +183 -0
  72. package/dist/test/compute.test.js +4 -0
  73. package/dist/test/converse.test.d.ts +2 -0
  74. package/dist/test/converse.test.js +162 -0
  75. package/dist/test/data-sphere.test.d.ts +2 -0
  76. package/dist/test/data-sphere.test.js +57 -0
  77. package/dist/test/endpoints.test.js +40 -1
  78. package/dist/test/envelope-core-conformance.test.d.ts +2 -0
  79. package/dist/test/envelope-core-conformance.test.js +75 -0
  80. package/dist/test/envelope.test.d.ts +2 -0
  81. package/dist/test/envelope.test.js +318 -0
  82. package/dist/test/ethos-first-edition.test.d.ts +2 -0
  83. package/dist/test/ethos-first-edition.test.js +371 -0
  84. package/dist/test/invoke-turn-sdk.test.d.ts +2 -0
  85. package/dist/test/invoke-turn-sdk.test.js +177 -0
  86. package/dist/test/migrate.test.d.ts +2 -0
  87. package/dist/test/migrate.test.js +340 -0
  88. package/dist/test/owner-data-client.test.d.ts +2 -0
  89. package/dist/test/owner-data-client.test.js +88 -0
  90. package/dist/test/rotate-ethos.test.d.ts +2 -0
  91. package/dist/test/rotate-ethos.test.js +151 -0
  92. package/dist/test/rotate.test.d.ts +2 -0
  93. package/dist/test/rotate.test.js +63 -0
  94. package/dist/test/schema-autoresolve.test.d.ts +2 -0
  95. package/dist/test/schema-autoresolve.test.js +146 -0
  96. package/dist/test/sdk.test.js +11 -2
  97. package/dist/test/signup-bootstrap.test.d.ts +2 -0
  98. package/dist/test/signup-bootstrap.test.js +311 -0
  99. package/dist/test/transcribe-invoke.test.d.ts +2 -0
  100. package/dist/test/transcribe-invoke.test.js +204 -0
  101. package/dist/test/transcribe.test.d.ts +2 -0
  102. package/dist/test/transcribe.test.js +186 -0
  103. package/dist/test/web.test.d.ts +2 -0
  104. package/dist/test/web.test.js +270 -0
  105. package/package.json +20 -3
@@ -0,0 +1,147 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ // Copyright 2026 Mathieu Colla
3
+ /* ----------------------------------- read ---------------------------------- */
4
+ export const TOOL_ETHOS_LIST_SECTIONS = "ethos_list_sections";
5
+ export const TOOL_ETHOS_READ_SECTION = "ethos_read_section";
6
+ export const TOOL_DATA_QUERY = "data_query";
7
+ /* ---------------------------------- write ---------------------------------- */
8
+ export const TOOL_ETHOS_ADD_SECTION = "ethos_add_section";
9
+ export const TOOL_ETHOS_UPDATE_SECTION = "ethos_update_section";
10
+ export const TOOL_ETHOS_DELETE_SECTION = "ethos_delete_section";
11
+ /** The ethos zones a section can live in. */
12
+ const ZONE_ENUM = ["public", "circle", "self"];
13
+ export const AITHOS_AGENT_READ_TOOLS = [
14
+ {
15
+ name: TOOL_ETHOS_LIST_SECTIONS,
16
+ description: "Liste les sections disponibles de l'ethos de l'utilisateur (zone, id, " +
17
+ "titre), SANS leur contenu. À appeler en premier pour découvrir ce qui " +
18
+ "est lisible, puis utiliser ethos_read_section pour obtenir le détail.",
19
+ input_schema: { type: "object", properties: {}, additionalProperties: false },
20
+ },
21
+ {
22
+ name: TOOL_ETHOS_READ_SECTION,
23
+ description: "Renvoie le contenu (titre + corps) d'une section de l'ethos, " +
24
+ "identifiée par son id obtenu via ethos_list_sections.",
25
+ input_schema: {
26
+ type: "object",
27
+ properties: {
28
+ section_id: { type: "string", description: "id de la section à lire" },
29
+ },
30
+ required: ["section_id"],
31
+ additionalProperties: false,
32
+ },
33
+ },
34
+ {
35
+ name: TOOL_DATA_QUERY,
36
+ description: "Renvoie les enregistrements d'une collection de données structurées " +
37
+ "de l'utilisateur (zone gamma).",
38
+ input_schema: {
39
+ type: "object",
40
+ properties: {
41
+ collection: { type: "string", description: "nom de la collection" },
42
+ limit: {
43
+ type: "integer",
44
+ minimum: 1,
45
+ maximum: 100,
46
+ description: "nombre maximum d'enregistrements (défaut 20)",
47
+ },
48
+ },
49
+ required: ["collection"],
50
+ additionalProperties: false,
51
+ },
52
+ },
53
+ ];
54
+ export const AITHOS_AGENT_WRITE_TOOLS = [
55
+ {
56
+ name: TOOL_ETHOS_ADD_SECTION,
57
+ description: "Ajoute une NOUVELLE section à l'ethos de l'utilisateur dans la zone " +
58
+ "indiquée. À n'utiliser que si l'information n'existe pas déjà (vérifier " +
59
+ "avec ethos_list_sections d'abord pour éviter les doublons). La " +
60
+ "modification est signée et publiée localement avec les clés de " +
61
+ "l'utilisateur.",
62
+ input_schema: {
63
+ type: "object",
64
+ properties: {
65
+ zone: {
66
+ type: "string",
67
+ enum: [...ZONE_ENUM],
68
+ description: "zone de l'ethos : 'public' (visible de tous), 'circle' (cercle " +
69
+ "de confiance), 'self' (privé). Choisir selon la sensibilité.",
70
+ },
71
+ title: { type: "string", description: "titre de la section" },
72
+ body: { type: "string", description: "contenu (texte) de la section" },
73
+ },
74
+ required: ["zone", "title", "body"],
75
+ additionalProperties: false,
76
+ },
77
+ },
78
+ {
79
+ name: TOOL_ETHOS_UPDATE_SECTION,
80
+ description: "Met à jour une section existante de l'ethos (titre et/ou corps), " +
81
+ "identifiée par son id (obtenu via ethos_list_sections). Ne modifier " +
82
+ "que ce qui doit changer.",
83
+ input_schema: {
84
+ type: "object",
85
+ properties: {
86
+ section_id: {
87
+ type: "string",
88
+ description: "id de la section à modifier",
89
+ },
90
+ title: { type: "string", description: "nouveau titre (optionnel)" },
91
+ body: { type: "string", description: "nouveau corps (optionnel)" },
92
+ },
93
+ required: ["section_id"],
94
+ additionalProperties: false,
95
+ },
96
+ },
97
+ {
98
+ name: TOOL_ETHOS_DELETE_SECTION,
99
+ description: "Supprime une section de l'ethos, identifiée par son id. Action " +
100
+ "irréversible une fois publiée — n'utiliser que si la suppression est " +
101
+ "explicitement justifiée.",
102
+ input_schema: {
103
+ type: "object",
104
+ properties: {
105
+ section_id: {
106
+ type: "string",
107
+ description: "id de la section à supprimer",
108
+ },
109
+ },
110
+ required: ["section_id"],
111
+ additionalProperties: false,
112
+ },
113
+ },
114
+ ];
115
+ export const AITHOS_AGENT_TOOLS = [
116
+ ...AITHOS_AGENT_READ_TOOLS,
117
+ ...AITHOS_AGENT_WRITE_TOOLS,
118
+ ];
119
+ const TOOL_BY_NAME = new Map(AITHOS_AGENT_TOOLS.map((t) => [t.name, t]));
120
+ export function isWriteTool(name) {
121
+ return (name === TOOL_ETHOS_ADD_SECTION ||
122
+ name === TOOL_ETHOS_UPDATE_SECTION ||
123
+ name === TOOL_ETHOS_DELETE_SECTION);
124
+ }
125
+ /**
126
+ * Resolve the tool specs to forward to the proxy.
127
+ *
128
+ * - `undefined` / empty → the full catalogue (read + write).
129
+ * - a list of names → exactly those (unknown names ignored).
130
+ * - `{ readOnly: true }` → only the read family (a caller that wants a
131
+ * strictly non-mutating agent).
132
+ */
133
+ export function selectAgentTools(opts) {
134
+ if (opts?.readOnly)
135
+ return AITHOS_AGENT_READ_TOOLS;
136
+ const requested = opts?.tools;
137
+ if (!requested || requested.length === 0)
138
+ return AITHOS_AGENT_TOOLS;
139
+ const out = [];
140
+ for (const name of requested) {
141
+ const spec = TOOL_BY_NAME.get(name);
142
+ if (spec)
143
+ out.push(spec);
144
+ }
145
+ return out;
146
+ }
147
+ //# sourceMappingURL=agent-tools.js.map
@@ -0,0 +1,224 @@
1
+ import type { AithosAuth } from "./auth.js";
2
+ import type { AithosSdkEndpoints } from "./endpoints.js";
3
+ /**
4
+ * The audience set scopes which consumers are eligible. `"open"` lets
5
+ * any DID invoke the app; `"list"` restricts to an explicit allowlist.
6
+ */
7
+ export type AudienceSet = "open" | "list";
8
+ export interface SponsorshipBudgetInput {
9
+ /**
10
+ * Authority-interpreted unit of account. Default `"aithos.mc"` (the
11
+ * platform microcredit, ≈ €0.001 of AWS pass-through cost). Authorities
12
+ * MAY accept other units — see draft §13.3.4.
13
+ */
14
+ readonly unit?: string;
15
+ /** Lifetime cap per consumer, in `unit`. */
16
+ readonly perUserCap: number;
17
+ /** If set, the per-user cap applies over a sliding window. */
18
+ readonly perUserWindowSeconds?: number | null;
19
+ /** UTC-day cap on total sponsored consumption across all consumers. */
20
+ readonly perDayTotalCap: number;
21
+ /** Lifetime pool cap across all consumers. `null` ≡ no cap. */
22
+ readonly poolCapTotal?: number | null;
23
+ }
24
+ export interface SponsorshipAudienceInput {
25
+ /** App DID the sponsorship covers (typically `sdk.appDid`). */
26
+ readonly appDid: string;
27
+ readonly audienceSet: AudienceSet;
28
+ /** Required iff `audienceSet === "list"`. */
29
+ readonly consumers?: readonly string[];
30
+ }
31
+ export interface SponsorshipAccountingAuthorityInput {
32
+ readonly did: string;
33
+ readonly endpoint: string;
34
+ }
35
+ export interface CreateSponsorshipMandateArgs {
36
+ readonly audience: SponsorshipAudienceInput;
37
+ readonly scopes: readonly string[];
38
+ readonly allowedMethods: readonly string[];
39
+ readonly allowedModels?: readonly string[];
40
+ readonly budget: SponsorshipBudgetInput;
41
+ readonly accountingAuthority: SponsorshipAccountingAuthorityInput;
42
+ /** Defaults to now. */
43
+ readonly notBefore?: Date;
44
+ /** Defaults to 365 days. */
45
+ readonly ttlSeconds?: number;
46
+ }
47
+ /**
48
+ * Signed sponsorship mandate, ready to seed into the authority's
49
+ * `aithos-app-sponsorships` table. Same shape as
50
+ * `@aithos/protocol-core`'s `SponsorshipMandate`.
51
+ */
52
+ export interface SignedSponsorshipMandate {
53
+ readonly "aithos-sponsorship-mandate": "0.1.0";
54
+ readonly id: string;
55
+ readonly issuer: string;
56
+ readonly issued_by_key: string;
57
+ readonly audience: {
58
+ readonly app_did: string;
59
+ readonly audience_set: AudienceSet;
60
+ readonly consumers?: readonly string[];
61
+ };
62
+ readonly scopes: readonly string[];
63
+ readonly allowed_methods: readonly string[];
64
+ readonly allowed_models?: readonly string[];
65
+ readonly budget: {
66
+ readonly unit: string;
67
+ readonly per_user_cap: number;
68
+ readonly per_user_window_seconds: number | null;
69
+ readonly per_day_total_cap: number;
70
+ readonly pool_cap_total: number | null;
71
+ };
72
+ readonly accounting_authority: {
73
+ readonly did: string;
74
+ readonly endpoint: string;
75
+ };
76
+ readonly not_before: string;
77
+ readonly not_after: string;
78
+ readonly issued_at: string;
79
+ readonly nonce: string;
80
+ readonly signature: {
81
+ readonly alg: "ed25519";
82
+ readonly key: string;
83
+ readonly value: string;
84
+ };
85
+ }
86
+ export interface SignedSponsorshipRevocation {
87
+ readonly "aithos-revocation": "0.1.0";
88
+ readonly mandate_id: string;
89
+ readonly mandate_kind: "sponsorship-mandate";
90
+ readonly issuer: string;
91
+ readonly issued_by_key: string;
92
+ readonly revoked_at: string;
93
+ readonly reason: string;
94
+ readonly signature: {
95
+ readonly alg: "ed25519";
96
+ readonly key: string;
97
+ readonly value: string;
98
+ };
99
+ }
100
+ export type AppCreditPackId = "app-credits-10k" | "app-credits-50k" | "app-credits-200k";
101
+ export interface CreateAppTopupSessionArgs {
102
+ /** Which app-credits pack to purchase. */
103
+ readonly packId: AppCreditPackId;
104
+ /** Where Stripe redirects after a successful payment. */
105
+ readonly successUrl: string;
106
+ /** Where Stripe redirects if the user cancels. */
107
+ readonly cancelUrl: string;
108
+ /** Abort signal to cancel the request. */
109
+ readonly signal?: AbortSignal;
110
+ }
111
+ export interface CreateAppTopupSessionResult {
112
+ readonly checkoutUrl: string;
113
+ readonly sessionId: string;
114
+ }
115
+ export interface AppsNamespaceDeps {
116
+ readonly auth: AithosAuth;
117
+ readonly appDid: string;
118
+ readonly endpoints: AithosSdkEndpoints;
119
+ readonly fetch: typeof fetch;
120
+ }
121
+ export declare class AppsNamespace {
122
+ #private;
123
+ constructor(deps: AppsNamespaceDeps);
124
+ /**
125
+ * Build and sign a `SponsorshipMandate` as the calling owner. The
126
+ * returned JSON is signed by the owner's `#public` sphere key, ready
127
+ * to be seeded into the authority's `aithos-app-sponsorships` table.
128
+ *
129
+ * V0.1 has no server endpoint — get the row into DDB via:
130
+ * 1. `aws dynamodb put-item --table-name aithos-app-sponsorships
131
+ * --item file://mandate.json` (raw), or
132
+ * 2. The ops bootstrap script in
133
+ * `innoesate/aithos/platform/scripts/seed-sponsorship.mjs`
134
+ * (planned for V0.2).
135
+ *
136
+ * Hash with `sponsorshipMandateHash()` from `@aithos/protocol-core`
137
+ * if you need to embed it in an envelope's `sponsorship.hash` field.
138
+ */
139
+ createSponsorshipMandate(args: CreateSponsorshipMandateArgs): Promise<SignedSponsorshipMandate>;
140
+ /**
141
+ * Build and sign a §4.6 revocation document targeting a sponsorship
142
+ * mandate. Same upload caveat as `createSponsorshipMandate`.
143
+ */
144
+ revokeSponsorshipMandate(mandate: SignedSponsorshipMandate, reason: string): Promise<SignedSponsorshipRevocation>;
145
+ /**
146
+ * Stripe Checkout session for an `app-credits-*` pack. The session is
147
+ * bound to the calling owner's DID (which is treated as the app's
148
+ * funding DID — Option A unified wallet, see plan §3.4).
149
+ *
150
+ * Same endpoint and auth pattern as `sdk.wallet.createTopupSession`,
151
+ * just with the app-credits pack id family.
152
+ */
153
+ createAppTopupSession(args: CreateAppTopupSessionArgs): Promise<CreateAppTopupSessionResult>;
154
+ /**
155
+ * Build, sign, and PUBLISH a SponsorshipMandate to the authority's
156
+ * `aithos-app-sponsorships` table via `aithos.sponsorship_create`.
157
+ *
158
+ * Combines local signing (see {@link createSponsorshipMandate}) with the
159
+ * server upload step. After this resolves, the sponsorship is active —
160
+ * the next `sdk.compute.invokeBedrock` call targeting `args.audience.appDid`
161
+ * may be sponsored (subject to caps).
162
+ *
163
+ * Requires that the calling owner is the registered `owner_did` of
164
+ * `args.audience.appDid` in `aithos-auth-apps`; otherwise the server
165
+ * rejects with `-32042` "not the owner".
166
+ */
167
+ publishSponsorship(args: CreateSponsorshipMandateArgs): Promise<{
168
+ mandate: SignedSponsorshipMandate;
169
+ sponsorshipId: string;
170
+ mandateHash: string;
171
+ status: "active";
172
+ createdAt: number;
173
+ }>;
174
+ /**
175
+ * Read the active sponsorship for an app. Open endpoint (no envelope
176
+ * required): the mandate is publicly signed and resolvable anyway.
177
+ *
178
+ * Returns `{ exists: false }` when no row exists for the app.
179
+ */
180
+ getSponsorship(args: {
181
+ appDid: string;
182
+ signal?: AbortSignal;
183
+ }): Promise<{
184
+ exists: false;
185
+ } | {
186
+ exists: true;
187
+ sponsorshipId: string;
188
+ mandate: SignedSponsorshipMandate;
189
+ mandateHash: string;
190
+ status: "active" | "paused" | "depleted" | "expired" | "revoked";
191
+ poolConsumedLifetime: number;
192
+ createdAt: number;
193
+ lastUpdatedAt: number;
194
+ }>;
195
+ /**
196
+ * Revoke a published sponsorship by `app_did` + `sponsorship_id`. The
197
+ * row is marked `status: "revoked"` server-side; the routing cache is
198
+ * invalidated so the next compute call falls back to the user wallet.
199
+ */
200
+ revokeSponsorship(args: {
201
+ appDid: string;
202
+ sponsorshipId: string;
203
+ reason: string;
204
+ signal?: AbortSignal;
205
+ }): Promise<{
206
+ status: "revoked";
207
+ }>;
208
+ /**
209
+ * Read the app's wallet balance (= the sponsor pool). Requires owner
210
+ * signature.
211
+ */
212
+ getAppWalletBalance(args: {
213
+ appDid: string;
214
+ signal?: AbortSignal;
215
+ }): Promise<{
216
+ appDid: string;
217
+ exists: boolean;
218
+ balance: number;
219
+ balancePurchase: number;
220
+ balanceGrant: number;
221
+ dailySpent: number;
222
+ }>;
223
+ }
224
+ //# sourceMappingURL=apps.d.ts.map