@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
@@ -1,16 +1,34 @@
1
1
  import type { AithosAuth } from "./auth.js";
2
2
  import { type AithosSdkEndpoints } from "./endpoints.js";
3
+ import { type LocalPendingEntry, type TranscribeDraftMeta, type TranscribeDraftRecord } from "./transcribe-resilience.js";
4
+ import { type AgentMessage, type AgentToolSpec, type AgentTurnStopReason, type ContentBlock, type LoopStopReason, type ToolCallTrace } from "./agent-loop.js";
5
+ import { type DataProvider } from "./agent-dispatch.js";
3
6
  export interface ComputeMessage {
4
7
  readonly role: "user" | "assistant";
5
8
  readonly content: string;
6
9
  }
7
10
  export interface InvokeBedrockArgs {
8
- /** Mandate ID granting this app the right to spend the user's wallet. */
9
- readonly mandateId: string;
11
+ /**
12
+ * Mandate ID under which this call should be attributed.
13
+ *
14
+ * - **Owner sessions**: optional. The SDK uses the owner's own DID
15
+ * as a sentinel "self" mandate id — the proxy skips all
16
+ * mandate-related checks (scope, allowed_models, caps) when the
17
+ * envelope is owner-signed, so the value is informational only.
18
+ * - **Delegate sessions**: required. Must reference the imported
19
+ * mandate bundle the SDK signs with (the proxy enforces
20
+ * `compute.invoke` scope and any `allowed_models` filter).
21
+ */
22
+ readonly mandateId?: string;
10
23
  /**
11
24
  * Model id. Today the proxy accepts the canonical Aithos identifiers:
12
- * `claude-sonnet-4-6`, `claude-haiku-4-5`, `claude-opus-4-7`.
25
+ * `claude-sonnet-4-6`, `claude-haiku-4-5`, `claude-opus-4-6`.
13
26
  * The proxy maps these to Bedrock cross-region inference profiles.
27
+ *
28
+ * NOTE: `claude-opus-4-7` is also provisioned on the Bedrock account
29
+ * but commercial access is gated behind an AWS Sales unlock (as of
30
+ * May 2026) — InvokeModel returns AccessDeniedException pointing to
31
+ * AWS Sales. Stick with `claude-opus-4-6` until the unlock lands.
14
32
  */
15
33
  readonly model: string;
16
34
  /** Conversation messages (user / assistant turns). */
@@ -43,6 +61,459 @@ export interface InvokeBedrockResult {
43
61
  readonly walletBalance: number;
44
62
  /** Audit log id for traceability. */
45
63
  readonly auditId: string;
64
+ /**
65
+ * Which wallet was actually debited (draft §13.8, V0.1 sponsorship).
66
+ * - `"sponsored"` — the app developer's wallet (free trial / promo).
67
+ * - `"grant"` — the user's grant bucket (Aithos-donated credits).
68
+ * - `"purchase"` — the user's own paid credits.
69
+ * Absent on legacy server responses (pre-2026-05-27).
70
+ */
71
+ readonly fundedBy?: "sponsored" | "grant" | "purchase";
72
+ /**
73
+ * If `fundedBy === "sponsored"`, the sponsor's DID (= the developer
74
+ * who pre-paid the pool). Absent otherwise.
75
+ */
76
+ readonly sponsoredBy?: string;
77
+ /**
78
+ * If sponsored, the signed `ConsumptionReceipt` id (`rcpt_…`) the
79
+ * authority issued for this debit. The receipt itself can be fetched
80
+ * later via the receipts API (V0.2). Present on every signed call
81
+ * when the authority is configured, regardless of `fundedBy`.
82
+ */
83
+ readonly receiptId?: string;
84
+ /**
85
+ * If sponsored, remaining microcredits for THIS consumer in this
86
+ * sponsorship pool. Useful for displaying "X free calls remaining"
87
+ * without an extra round-trip. May be `0` even when the user can
88
+ * still consume — when the authority can't compute the remainder
89
+ * cheaply (e.g. windowed caps), the SDK gets a conservative 0 and
90
+ * the SPA should fall back to calling `sdk.apps.getSponsorshipStatusForUser`
91
+ * (V0.2).
92
+ */
93
+ readonly sponsoredRemainingForUser?: number;
94
+ }
95
+ /** A decrypted ethos section in the working-set. */
96
+ export interface WorkingSetSection {
97
+ readonly id: string;
98
+ readonly title: string;
99
+ readonly body: string;
100
+ }
101
+ /**
102
+ * Client-decrypted data the agentic loop may read server-side. Built in the
103
+ * browser (where the keys live) from exactly the zones / collections the
104
+ * mandate grants — the proxy never holds a standing decryption key
105
+ * (see PLATFORM-COMPUTE-AGENTIC-MCP.md §4). Use {@link ComputeNamespace}
106
+ * with a `mcp` reference + this working-set.
107
+ */
108
+ export interface ComputeWorkingSet {
109
+ /** Decrypted ethos sections, per zone. Only granted zones appear. */
110
+ readonly ethos?: {
111
+ readonly public?: readonly WorkingSetSection[];
112
+ readonly circle?: readonly WorkingSetSection[];
113
+ readonly self?: readonly WorkingSetSection[];
114
+ };
115
+ /** Decrypted structured data, per collection name. */
116
+ readonly data?: Record<string, readonly Record<string, unknown>[]>;
117
+ }
118
+ /** A tool invocation the loop performed (trace for UI / debugging). */
119
+ export interface ConverseToolCall {
120
+ readonly name: string;
121
+ readonly ok: boolean;
122
+ readonly turn: number;
123
+ }
124
+ export type ConverseStopReason = "end_turn" | "max_tokens" | "stop_sequence" | "max_iterations" | "budget_exhausted";
125
+ export interface RunConversationArgs {
126
+ /** Mandate id — optional for owner sessions, required for delegate sessions. */
127
+ readonly mandateId?: string;
128
+ /** Claude model id (text or vision). */
129
+ readonly model: string;
130
+ /** Initial conversation. The loop's internal tool turns are server-side. */
131
+ readonly messages: readonly ComputeMessage[];
132
+ /** Optional system prompt. */
133
+ readonly system?: string;
134
+ /**
135
+ * MCP tools to expose to the model. v1 only supports the Aithos server.
136
+ * Omit `tools` to expose the full Aithos catalogue; pass a subset to narrow.
137
+ */
138
+ readonly mcp?: {
139
+ readonly server: "aithos";
140
+ readonly tools?: readonly string[];
141
+ };
142
+ /**
143
+ * Client-decrypted working-set the tools read from. Build it with
144
+ * {@link ComputeNamespace.buildWorkingSet}. Required for any tool that
145
+ * touches private (circle/self) or structured data.
146
+ */
147
+ readonly workingSet?: ComputeWorkingSet;
148
+ /** Cap on Bedrock turns. Server clamps to its own hard cap. Default 6. */
149
+ readonly maxIterations?: number;
150
+ /** Per-turn output token cap. */
151
+ readonly maxTokens?: number;
152
+ readonly temperature?: number;
153
+ /** Idempotency key for the WHOLE conversation (generated if omitted). */
154
+ readonly idempotencyKey?: string;
155
+ readonly signal?: AbortSignal;
156
+ }
157
+ export interface RunConversationResult {
158
+ /** Final assistant text. */
159
+ readonly content: string;
160
+ readonly stopReason: ConverseStopReason;
161
+ /** Number of Bedrock turns performed (each was a billed call). */
162
+ readonly iterations: number;
163
+ /** Token usage summed over all turns. */
164
+ readonly usage: {
165
+ readonly inputTokens: number;
166
+ readonly outputTokens: number;
167
+ };
168
+ /** Trace of the tool calls the loop made. */
169
+ readonly toolCalls: readonly ConverseToolCall[];
170
+ /** Total microcredits debited for the whole conversation. */
171
+ readonly creditsCharged: number;
172
+ readonly walletBalance: number;
173
+ readonly auditId: string;
174
+ readonly fundedBy?: "sponsored" | "grant" | "purchase";
175
+ readonly receiptId?: string;
176
+ readonly sponsoredBy?: string;
177
+ }
178
+ export interface InvokeTurnArgs {
179
+ /** Mandate id — optional for owner sessions, required for delegate sessions. */
180
+ readonly mandateId?: string;
181
+ readonly model: string;
182
+ /** Running conversation. `content` may be a string OR Anthropic blocks. */
183
+ readonly messages: readonly AgentMessage[];
184
+ /** Anthropic tool specs to expose this turn. */
185
+ readonly tools: readonly AgentToolSpec[];
186
+ readonly system?: string;
187
+ readonly maxTokens?: number;
188
+ readonly temperature?: number;
189
+ readonly idempotencyKey?: string;
190
+ readonly signal?: AbortSignal;
191
+ }
192
+ export interface InvokeTurnResult {
193
+ /** Raw content blocks (text + tool_use) — the caller detects tool calls. */
194
+ readonly content: readonly ContentBlock[];
195
+ readonly stopReason: AgentTurnStopReason;
196
+ readonly usage: {
197
+ readonly inputTokens: number;
198
+ readonly outputTokens: number;
199
+ };
200
+ /** Microcredits charged for THIS single turn. */
201
+ readonly creditsCharged: number;
202
+ readonly walletBalance: number;
203
+ readonly auditId: string;
204
+ readonly fundedBy?: "sponsored" | "grant" | "purchase";
205
+ readonly receiptId?: string;
206
+ readonly sponsoredBy?: string;
207
+ }
208
+ export interface RunConversationLocalArgs {
209
+ /** Mandate id — optional for owner sessions, required for delegate sessions. */
210
+ readonly mandateId?: string;
211
+ /**
212
+ * Subject DID whose ethos the agent reads/writes. Defaults to the signed-in
213
+ * owner, or (delegate session) the mandate's subject.
214
+ */
215
+ readonly subjectDid?: string;
216
+ readonly model: string;
217
+ /** Initial conversation (plain string turns). */
218
+ readonly messages: readonly ComputeMessage[];
219
+ readonly system?: string;
220
+ /**
221
+ * Subset of Aithos tool names to expose. Omit for the full catalogue
222
+ * (read + write). Ignored when `readOnly` is set.
223
+ */
224
+ readonly tools?: readonly string[];
225
+ /** Expose only the read family (no mutations). */
226
+ readonly readOnly?: boolean;
227
+ /** Cap on proxy turns (each is a billed call). Default 6, hard max 12. */
228
+ readonly maxIterations?: number;
229
+ readonly maxTokens?: number;
230
+ readonly temperature?: number;
231
+ /** Optional gamma reader powering `data_query`. Absent → that tool errors. */
232
+ readonly dataProvider?: DataProvider;
233
+ readonly idempotencyKey?: string;
234
+ readonly signal?: AbortSignal;
235
+ }
236
+ export interface RunConversationLocalResult {
237
+ readonly content: string;
238
+ readonly stopReason: LoopStopReason;
239
+ readonly iterations: number;
240
+ readonly usage: {
241
+ readonly inputTokens: number;
242
+ readonly outputTokens: number;
243
+ };
244
+ readonly toolCalls: readonly ToolCallTrace[];
245
+ /** Sum of per-turn charges (HANDOFF §1: per-turn cumulative billing). */
246
+ readonly creditsCharged: number;
247
+ readonly walletBalance: number;
248
+ /** Audit id of the LAST turn. */
249
+ readonly auditId: string;
250
+ readonly fundedBy?: "sponsored" | "grant" | "purchase";
251
+ readonly receiptId?: string;
252
+ }
253
+ /**
254
+ * Stable cross-provider image model ids supported by the Aithos compute
255
+ * proxy. New models can be added on the server side without an SDK
256
+ * release — but tagging the namespaced literal here gives consumers
257
+ * autocomplete + type-checking.
258
+ *
259
+ * The `image:` prefix is part of the wire contract: the server uses it
260
+ * to disambiguate text and image dispatch when a mandate's
261
+ * `allowed_models` mixes both.
262
+ */
263
+ export type ImageModelId = "image:flux-schnell" | "image:flux-dev" | "image:flux-pro-1.1" | "image:flux-pro-1.1-ultra" | "image:imagen-3" | "image:imagen-4" | "image:nano-banana";
264
+ /** Aspect ratios accepted by `invokeImage`. */
265
+ export type ImageAspectRatio = "1:1" | "16:9" | "9:16" | "4:3" | "3:4" | "21:9";
266
+ export interface InvokeImageArgs {
267
+ /**
268
+ * Mandate ID under which this call should be attributed.
269
+ *
270
+ * - **Owner sessions**: optional. The SDK uses the owner's own DID
271
+ * as a sentinel "self" mandate id — the proxy skips all
272
+ * mandate-related checks when the envelope is owner-signed.
273
+ * - **Delegate sessions**: required. Must reference the imported
274
+ * mandate bundle the SDK signs with.
275
+ */
276
+ readonly mandateId?: string;
277
+ /**
278
+ * Image model id. Defaults to `"image:flux-pro-1.1"` on the SDK side
279
+ * if omitted — the server allowlist is the source of truth for which
280
+ * ones actually work.
281
+ */
282
+ readonly model?: ImageModelId;
283
+ /** What to draw. */
284
+ readonly prompt: string;
285
+ /** Optional comma-separated list of things to avoid (e.g. "blurry, watermark"). */
286
+ readonly negativePrompt?: string;
287
+ /** Default 1:1. */
288
+ readonly aspectRatio?: ImageAspectRatio;
289
+ /** Deterministic seed (re-rolls). Omit for random. */
290
+ readonly seed?: number;
291
+ /** Number of images to generate. Default 1, max 4. */
292
+ readonly numberOfImages?: number;
293
+ /** Idempotency key for retries (generated if omitted). */
294
+ readonly idempotencyKey?: string;
295
+ /** Abort signal to cancel the request (network + provider call). */
296
+ readonly signal?: AbortSignal;
297
+ }
298
+ export interface InvokeImageImage {
299
+ /** Base64-encoded image bytes (raw, no data: URI prefix). */
300
+ readonly base64: string;
301
+ /** "image/png" | "image/jpeg". */
302
+ readonly contentType: string;
303
+ readonly width: number;
304
+ readonly height: number;
305
+ }
306
+ export interface InvokeImageResult {
307
+ readonly images: readonly InvokeImageImage[];
308
+ /** Seed actually used by the provider (echoed back even when caller didn't set one). */
309
+ readonly seed: number;
310
+ /** Microcredits debited from the wallet (exact — no reconcile path for images). */
311
+ readonly creditsCharged: number;
312
+ /** Wallet balance after debit. */
313
+ readonly walletBalance: number;
314
+ /** Audit log id for traceability. */
315
+ readonly auditId: string;
316
+ }
317
+ export interface InvokeBedrockVisionArgs {
318
+ readonly mandateId?: string;
319
+ /**
320
+ * Model id. Sonnet 4.6 is the default — it's vision-capable and
321
+ * returns reliable structured JSON when prompted.
322
+ */
323
+ readonly model?: string;
324
+ /** Source image — Blob (recommended) or raw base64. */
325
+ readonly image: Blob | {
326
+ readonly base64: string;
327
+ readonly contentType: string;
328
+ };
329
+ /** Text prompt accompanying the image. */
330
+ readonly prompt: string;
331
+ /** Optional system prompt. */
332
+ readonly system?: string;
333
+ readonly maxTokens?: number;
334
+ readonly temperature?: number;
335
+ readonly idempotencyKey?: string;
336
+ readonly signal?: AbortSignal;
337
+ }
338
+ export interface InvokeBedrockVisionResult {
339
+ readonly content: string;
340
+ readonly stopReason: StopReason;
341
+ readonly usage: {
342
+ readonly inputTokens: number;
343
+ readonly outputTokens: number;
344
+ };
345
+ readonly creditsCharged: number;
346
+ readonly walletBalance: number;
347
+ readonly auditId: string;
348
+ }
349
+ export interface InvokeSegmentationArgs {
350
+ /** Mandate id (optional for owner sessions — see InvokeImageArgs). */
351
+ readonly mandateId?: string;
352
+ /** Source image. Blob (recommended) or raw base64. */
353
+ readonly image: Blob | {
354
+ readonly base64: string;
355
+ readonly contentType: string;
356
+ };
357
+ /**
358
+ * Text phrase describing what to segment. Florence-2 is robust with
359
+ * natural-language descriptions: "the torso of the robot", "the
360
+ * dog's head", "the chest of the character".
361
+ */
362
+ readonly textInput: string;
363
+ readonly idempotencyKey?: string;
364
+ readonly signal?: AbortSignal;
365
+ }
366
+ export interface SegmentPolygon {
367
+ readonly points: ReadonlyArray<{
368
+ readonly x: number;
369
+ readonly y: number;
370
+ }>;
371
+ }
372
+ export interface InvokeSegmentationResult {
373
+ /** All polygons Florence-2 returned (typically 1, sometimes a few when the prompt matches multiple regions). */
374
+ readonly polygons: readonly SegmentPolygon[];
375
+ /** Bbox of the first polygon for callers that only need a coarse target. */
376
+ readonly bbox: {
377
+ readonly left: number;
378
+ readonly top: number;
379
+ readonly right: number;
380
+ readonly bottom: number;
381
+ } | null;
382
+ readonly creditsCharged: number;
383
+ readonly walletBalance: number;
384
+ readonly auditId: string;
385
+ }
386
+ /**
387
+ * Stable cross-provider transcription model ids. The `transcribe:` prefix
388
+ * is part of the wire contract (mirrors `image:` for image models). New
389
+ * models can be added server-side without an SDK release; the union here
390
+ * gives autocomplete + type-checking for the common ones.
391
+ */
392
+ export type TranscribeModelId = "transcribe:aws-fr-standard" | "transcribe:aws-en-standard";
393
+ /** Progress callback states emitted by {@link ComputeNamespace.invokeTranscribe}. */
394
+ export type TranscribeProgressState = {
395
+ readonly phase: "queued";
396
+ } | {
397
+ readonly phase: "uploading";
398
+ readonly bytesUploaded: number;
399
+ readonly totalBytes: number;
400
+ } | {
401
+ readonly phase: "starting";
402
+ } | {
403
+ readonly phase: "processing";
404
+ readonly elapsedSec: number;
405
+ } | {
406
+ readonly phase: "completed";
407
+ };
408
+ export interface TranscribeSegment {
409
+ readonly start_sec: number;
410
+ readonly end_sec: number;
411
+ readonly text: string;
412
+ readonly speaker_label?: string;
413
+ }
414
+ export interface TranscribeWord {
415
+ readonly start_sec: number;
416
+ readonly end_sec: number;
417
+ readonly content: string;
418
+ readonly confidence: number;
419
+ }
420
+ /** High-level args for the one-call {@link ComputeNamespace.invokeTranscribe}. */
421
+ export interface InvokeTranscribeArgs {
422
+ /** Mandate id — optional for owner sessions, required for delegate sessions. */
423
+ readonly mandateId?: string;
424
+ /** The audio to transcribe. `Blob` is supported in both Node 18+ and browsers. */
425
+ readonly audio: Blob;
426
+ /** Model alias. Default `"transcribe:aws-fr-standard"`. */
427
+ readonly model?: TranscribeModelId;
428
+ /** AWS language code override (e.g. `"fr-FR"`). Defaults to the model alias's language. */
429
+ readonly languageCode?: string;
430
+ /** Speaker diarization. Default `false`. */
431
+ readonly diarization?: boolean;
432
+ /**
433
+ * Audio duration in seconds. REQUIRED on backends / non-browser runtimes
434
+ * (used for the wallet pre-debit estimate). In a browser it is probed
435
+ * automatically from the Blob when omitted; if probing fails the SDK
436
+ * falls back to a server-reconciled estimate of 0.
437
+ */
438
+ readonly durationSecOverride?: number;
439
+ /** Idempotency key for replay-safe retries (generated if omitted). */
440
+ readonly idempotencyKey?: string;
441
+ /** Progress callback (upload bytes, processing elapsed, …). */
442
+ readonly onProgress?: (state: TranscribeProgressState) => void;
443
+ /** Abort signal — cancels upload + polling. */
444
+ readonly signal?: AbortSignal;
445
+ /**
446
+ * Polling cadence override (ms) for the status loop. Defaults to an
447
+ * exponential backoff 2s → 15s. Mainly for tests.
448
+ */
449
+ readonly pollIntervalMs?: number;
450
+ }
451
+ export interface InvokeTranscribeResult {
452
+ readonly text: string;
453
+ readonly segments: readonly TranscribeSegment[];
454
+ readonly words: readonly TranscribeWord[];
455
+ readonly durationSec: number;
456
+ readonly languageCode: string;
457
+ readonly creditsCharged: number;
458
+ readonly walletBalance: number;
459
+ readonly auditId: string;
460
+ readonly jobId: string;
461
+ readonly fundedBy?: "sponsored" | "grant" | "purchase";
462
+ readonly sponsoredBy?: string;
463
+ readonly receiptId?: string;
464
+ }
465
+ export interface PrepareTranscribeArgs {
466
+ readonly contentType: string;
467
+ readonly durationSecEstimate?: number;
468
+ /** Selects the delegate signer for delegate sessions (not sent on the wire). */
469
+ readonly mandateId?: string;
470
+ readonly signal?: AbortSignal;
471
+ }
472
+ export interface PrepareTranscribeResult {
473
+ readonly jobId: string;
474
+ readonly uploadUrl: string;
475
+ readonly s3ObjectKey: string;
476
+ readonly expiresAt: number;
477
+ }
478
+ export interface StartTranscribeArgs {
479
+ readonly jobId: string;
480
+ readonly mandateId?: string;
481
+ readonly model: TranscribeModelId | string;
482
+ readonly durationSec: number;
483
+ readonly languageCode?: string;
484
+ readonly diarization?: boolean;
485
+ readonly idempotencyKey?: string;
486
+ readonly signal?: AbortSignal;
487
+ }
488
+ export interface StartTranscribeResult {
489
+ readonly jobId: string;
490
+ readonly status: "running";
491
+ readonly estimatedCredits: number;
492
+ readonly walletBalance: number;
493
+ readonly fundedBy?: "sponsored" | "grant" | "purchase";
494
+ readonly receiptId?: string;
495
+ }
496
+ export type TranscribeStatusResult = {
497
+ readonly jobId: string;
498
+ readonly status: "running";
499
+ readonly elapsedSec: number;
500
+ } | ({
501
+ readonly jobId: string;
502
+ readonly status: "completed";
503
+ } & InvokeTranscribeResult) | {
504
+ readonly jobId: string;
505
+ readonly status: "failed";
506
+ readonly error: {
507
+ readonly code: string;
508
+ readonly message: string;
509
+ };
510
+ };
511
+ export interface TranscribeJobSummary {
512
+ readonly jobId: string;
513
+ readonly status: "prepared" | "running" | "completed" | "failed";
514
+ readonly createdAt: number;
515
+ readonly estimatedCredits?: number;
516
+ readonly creditsCharged?: number;
46
517
  }
47
518
  export interface ComputeNamespaceDeps {
48
519
  readonly auth: AithosAuth;
@@ -63,11 +534,208 @@ export declare class ComputeNamespace {
63
534
  * Invoke a Bedrock model through the compute proxy. See
64
535
  * {@link InvokeBedrockArgs} and {@link InvokeBedrockResult}.
65
536
  *
537
+ * Two signer paths are supported:
538
+ *
539
+ * - **Owner**: when the caller is signed in as an owner, the
540
+ * envelope is signed with the owner's `#public` sphere key and
541
+ * no mandate is attached (the proxy resolves the mandate
542
+ * server-side from `params.mandate_id`).
543
+ * - **Delegate**: when the caller is delegate-only (mandate
544
+ * imported via `auth.importMandate`), the envelope is signed
545
+ * with the delegate's bound keypair and the full SignedMandate
546
+ * is attached so the proxy can verify both signature and
547
+ * authorisation in one pass. The mandate must carry the
548
+ * `compute.invoke` scope and the proxy enforces its constraints
549
+ * (caps, allowed models, …) at server-side.
550
+ *
551
+ * Owner takes precedence: if a session has BOTH an owner and a
552
+ * matching delegate session, we use the owner key (more flexible —
553
+ * the mandate is dereferenced via `mandate_id` and there's no
554
+ * lifetime cliff if the delegate seed has been wiped).
555
+ *
66
556
  * @throws {AithosSDKError} on protocol errors. The `code` field is one of
67
- * `sdk_no_owner`, `network`, `http`, `empty`, or any code returned by
68
- * the proxy (`quota_exceeded`, `mandate_revoked`, `insufficient_credits`,
69
- * …).
557
+ * `sdk_no_signer`, `sdk_no_delegate_for_mandate`, `network`, `http`,
558
+ * `empty`, or any code returned by the proxy (`quota_exceeded`,
559
+ * `mandate_revoked`, `insufficient_credits`, …).
70
560
  */
71
561
  invokeBedrock(args: InvokeBedrockArgs): Promise<InvokeBedrockResult>;
562
+ /**
563
+ * Run an agentic conversation: a multi-turn Bedrock tool-calling loop that
564
+ * runs server-side in a single POST and is billed once for the cumulative
565
+ * token usage. Tools come from the Aithos MCP (declared via `mcp`); the
566
+ * model reads private user data from the client-decrypted `workingSet`.
567
+ *
568
+ * The loop, tool dispatch, and billing all happen on the proxy — the SDK
569
+ * makes ONE signed request and gets the final answer. Same signer paths as
570
+ * {@link invokeBedrock} (owner direct or delegate-under-mandate).
571
+ *
572
+ * @throws {AithosSDKError} `sdk_no_signer`, `sdk_no_delegate_for_mandate`,
573
+ * `network`, `http`, `empty`, or any proxy code (`quota_exceeded`,
574
+ * `mandate_revoked`, `insufficient_credits`, …).
575
+ */
576
+ runConversation(args: RunConversationArgs): Promise<RunConversationResult>;
577
+ /**
578
+ * Run ONE Bedrock turn with tool-calling through the proxy
579
+ * (`aithos.compute_invoke_turn`). Returns the raw content blocks — including
580
+ * any `tool_use` — so the caller can dispatch tools and loop. This is the
581
+ * per-turn primitive the CLIENT-SIDE agentic loop is built on; most callers
582
+ * want {@link runConversationLocal} instead, which drives the loop and
583
+ * dispatches Aithos tools locally.
584
+ *
585
+ * Same signer paths and billing as {@link invokeBedrock}; billed once per
586
+ * turn.
587
+ */
588
+ invokeTurn(args: InvokeTurnArgs): Promise<InvokeTurnResult>;
589
+ /**
590
+ * Run a CLIENT-SIDE agentic conversation with tool-calling: a multi-turn
591
+ * loop where each turn is one signed proxy call ({@link invokeTurn}) and the
592
+ * tools the model requests are dispatched LOCALLY against the user's own
593
+ * ethos (reads decrypt locally; writes stage + sign + publish locally). The
594
+ * proxy does pure per-turn inference and never holds a decryption key — keys,
595
+ * data, and dispatch all stay on the client (HANDOFF-AGENT-WRITE-MODE.md
596
+ * §1/§3).
597
+ *
598
+ * Authorisation: an owner has full authority over their own ethos; a
599
+ * delegate is bounded by the mandate's `ethos.read.*` / `ethos.write.*`
600
+ * scopes (a tool out of scope returns an error to the model — nothing is
601
+ * published). The spend capability (`compute.invoke`) is checked server-side
602
+ * on every turn.
603
+ *
604
+ * Billing is PER-TURN cumulative: each turn is billed once and the result's
605
+ * `creditsCharged` is the sum across turns.
606
+ *
607
+ * @throws {AithosSDKError} `sdk_no_signer`, `sdk_no_delegate_for_mandate`,
608
+ * `network`, `http`, `empty`, or any proxy code. Tool-level failures do
609
+ * NOT throw — they are fed back to the model as errors.
610
+ */
611
+ runConversationLocal(args: RunConversationLocalArgs): Promise<RunConversationLocalResult>;
612
+ /**
613
+ * Multimodal Bedrock invoke — image + text → text response.
614
+ * Default model: `claude-sonnet-4-6` (vision-capable, reliable JSON).
615
+ *
616
+ * Use when you need a VLM to reason about an image: locating
617
+ * features, structured extraction, semantic Q&A. Prompt the model
618
+ * to return JSON if you need structured output (the API itself is
619
+ * unstructured).
620
+ */
621
+ invokeBedrockVision(args: InvokeBedrockVisionArgs): Promise<InvokeBedrockVisionResult>;
622
+ /**
623
+ * Generate one or more images through the Aithos compute proxy
624
+ * (currently powered by fal.ai FLUX models). Spec mirror of
625
+ * {@link invokeBedrock}: same envelope, same wallet path, same
626
+ * mandate-scope gate (`compute.invoke` + `allowed_models`). The
627
+ * separation at the JSON-RPC method level (`aithos.compute_invoke_image`
628
+ * vs `aithos.compute_invoke`) commits each envelope to a specific
629
+ * modality so a stolen text-invoke envelope cannot be replayed
630
+ * against the image endpoint.
631
+ *
632
+ * Default model: `"image:flux-pro-1.1"`. Default aspect ratio: 1:1.
633
+ * Default count: 1 image.
634
+ *
635
+ * Pricing is per image and deterministic (no token-based reconcile):
636
+ * - flux-schnell: 3 000 mc + fee per image
637
+ * - flux-dev: 25 000 mc + fee per image
638
+ * - flux-pro-1.1: 40 000 mc + fee per image
639
+ * - flux-pro-1.1-ultra: 60 000 mc + fee per image
640
+ */
641
+ invokeImage(args: InvokeImageArgs): Promise<InvokeImageResult>;
642
+ /**
643
+ * Run text-prompted segmentation (Florence-2 referring-expression)
644
+ * on a source image. Returns one or more polygons hugging the
645
+ * region matching the text prompt.
646
+ *
647
+ * Use cases: locate the chest/torso area of a generated mascot
648
+ * for logo compositing, find the face zone for a thumbnail crop,
649
+ * extract a product from a marketing shot — anything that needs
650
+ * a precise mask + bbox from natural-language description.
651
+ *
652
+ * Pricing: flat 5 000 mc per call (~$0.005 — Florence-2 is cheap).
653
+ */
654
+ invokeSegmentation(args: InvokeSegmentationArgs): Promise<InvokeSegmentationResult>;
655
+ /**
656
+ * Provision a transcription job and get a pre-signed S3 URL to PUT the
657
+ * audio to. No wallet debit. `mandateId` only selects the delegate
658
+ * signer (it is not part of the wire params for prepare).
659
+ */
660
+ prepareTranscribe(args: PrepareTranscribeArgs): Promise<PrepareTranscribeResult>;
661
+ /**
662
+ * Verify the uploaded audio, pre-debit the wallet, and launch the AWS
663
+ * Transcribe job. Returns immediately with `status: "running"`.
664
+ */
665
+ startTranscribe(args: StartTranscribeArgs): Promise<StartTranscribeResult>;
666
+ /**
667
+ * Poll a job's status. On completion the server finalises (reconcile +
668
+ * audit) and returns the transcript; a resumed poll after reconnect
669
+ * re-reads the transcript while it's still in the 24h output window.
670
+ */
671
+ getTranscribeStatus(args: {
672
+ readonly jobId: string;
673
+ readonly mandateId?: string;
674
+ readonly signal?: AbortSignal;
675
+ }): Promise<TranscribeStatusResult>;
676
+ /**
677
+ * List the caller's transcription jobs. Excludes terminal `completed`
678
+ * jobs unless `includeCompleted` is set — the resilience "what's still
679
+ * pending server-side" query.
680
+ */
681
+ listPendingTranscribes(args?: {
682
+ readonly includeCompleted?: boolean;
683
+ readonly mandateId?: string;
684
+ readonly signal?: AbortSignal;
685
+ }): Promise<{
686
+ readonly jobs: readonly TranscribeJobSummary[];
687
+ }>;
688
+ /**
689
+ * Transcribe an audio Blob to text in one call. Composes the four
690
+ * low-level methods: prepare → direct S3 upload → start → poll. Returns
691
+ * the transcript and stores NOTHING server-side beyond the ephemeral
692
+ * job — the consumer decides what to do with the result.
693
+ *
694
+ * Isomorphic: depends only on `Blob`, `fetch`/`XMLHttpRequest` and
695
+ * timers. On a backend, pass `durationSecOverride` (no Blob duration
696
+ * probing is possible without a DOM); in a browser the duration is
697
+ * probed automatically when omitted.
698
+ *
699
+ * Resilience: the job id is recorded in a localStorage tracker (browser)
700
+ * before upload, so `listLocalPendingTranscribes()` / `resumeTranscribe()`
701
+ * can recover a job whose result never arrived. In Node the tracker is a
702
+ * harmless in-memory no-op.
703
+ */
704
+ invokeTranscribe(args: InvokeTranscribeArgs): Promise<InvokeTranscribeResult>;
705
+ /**
706
+ * Resume polling an in-flight job by id — for recovery after a reload or
707
+ * crash. Returns the final result and clears the job from the local
708
+ * pending tracker. Throws if the job has already failed.
709
+ */
710
+ resumeTranscribe(jobId: string, opts?: {
711
+ readonly mandateId?: string;
712
+ readonly onProgress?: (state: TranscribeProgressState) => void;
713
+ readonly signal?: AbortSignal;
714
+ readonly pollIntervalMs?: number;
715
+ }): Promise<InvokeTranscribeResult>;
716
+ /** Snapshot of locally-tracked in-flight jobs (stable ref between mutations). */
717
+ listLocalPendingTranscribes(): readonly LocalPendingEntry[];
718
+ /** Stable snapshot for `useSyncExternalStore`-style consumers. */
719
+ getLocalPendingTranscribesSnapshot(): readonly LocalPendingEntry[];
720
+ /**
721
+ * Subscribe to changes in the local pending-jobs registry. Returns an
722
+ * unsubscribe function. Framework-agnostic: wrap it in a React
723
+ * `useSyncExternalStore`, a Vue effect, a Svelte store, etc.
724
+ */
725
+ subscribeLocalPendingTranscribes(listener: () => void): () => void;
726
+ /**
727
+ * IndexedDB-backed draft queue: persist a recording before any network
728
+ * call, upload it when the user confirms. Browser-only (methods reject
729
+ * with TranscribeDraftUnavailableError when IndexedDB is absent).
730
+ */
731
+ get transcribeDraft(): {
732
+ readonly save: (blob: Blob, meta?: TranscribeDraftMeta) => Promise<{
733
+ readonly draftId: string;
734
+ }>;
735
+ readonly list: () => Promise<readonly TranscribeDraftRecord[]>;
736
+ readonly get: (draftId: string) => Promise<TranscribeDraftRecord | null>;
737
+ readonly delete: (draftId: string) => Promise<void>;
738
+ readonly upload: (draftId: string, args: Omit<InvokeTranscribeArgs, "audio">) => Promise<InvokeTranscribeResult>;
739
+ };
72
740
  }
73
741
  //# sourceMappingURL=compute.d.ts.map