@buildaureon/sdk 0.1.8 → 0.1.10

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.
@@ -1,788 +1,788 @@
1
- # Client API Reference
2
-
3
- Complete reference for every public method on `AureonClient` as implemented in
4
- `src/client/aureon-client.ts`, plus factories and the session helper.
5
-
6
- Cross-links: [auth](./auth.md) | [architecture](./architecture.md) | [error-model](./error-model.md) |
7
- [data-contracts](./data-contracts.md) | [transport](./transport.md)
8
-
9
- ---
10
-
11
- ## Table of contents
12
-
13
- 1. [Construction](#1-construction)
14
- 2. [Connectivity](#2-connectivity)
15
- 3. [Authentication](#3-authentication)
16
- 4. [Objectives](#4-objectives)
17
- 5. [Health, timeline, portfolio, overview](#5-health-timeline-portfolio-overview)
18
- 6. [Vault](#6-vault)
19
- 7. [Market and execution](#7-market-and-execution)
20
- 8. [Session helper](#8-session-helper)
21
- 9. [Method → HTTP cheat sheet](#9-method--http-cheat-sheet)
22
- 10. [Common error patterns](#10-common-error-patterns)
23
-
24
- ---
25
-
26
- ## 1. Construction
27
-
28
- ```ts
29
- import {
30
- createAureonClient,
31
- AureonClient,
32
- } from "@buildaureon/sdk";
33
-
34
- const aureon = createAureonClient({
35
- // network defaults to mainnet (4663 / http://127.0.0.1:8788)
36
- // network: "testnet" → public host (still chain 46630)
37
- apiKey: process.env.AUREON_API_KEY,
38
- getAccessToken: () => sessionToken,
39
- timeoutMs: 30_000,
40
- maxRetries: 2,
41
- });
42
- ```
43
-
44
- ### Options reference
45
-
46
- | Option | Required | Default | Description |
47
- |--------|----------|---------|-------------|
48
- | `network` | no | `mainnet` | `mainnet` = 4663 / `http://127.0.0.1:8788`. `testnet` = public host (still 46630). |
49
- | `baseUrl` | no | mainnet local API | Absolute `http://` or `https://` URL. Wins when set; mismatch with `network` throws. |
50
- | `apiKey` | SDK / CLI | N/A | Sent as `X-Aureon-Api-Key`. Issued developer keys also identify the bound wallet (no Bearer required). Env bootstrap keys are product-gate only. Utility uses wallet Bearer only. |
51
- | `getAccessToken` | no | N/A | Optional Bearer getter. Wins over API-key identity when present. |
52
- | `authToken` | no | N/A | Static Bearer string when `getAccessToken` is omitted. |
53
- | `timeoutMs` | no | `30000` | Per-attempt abort timeout. |
54
- | `maxRetries` | no | `0` | Extra attempts after first failure for retryable errors. |
55
- | `retryDelayMs` | no | `250` | Fixed delay between retries. |
56
- | `logger` | no | N/A | `AureonLogger`. |
57
- | `headers` | no | `{}` | Merged into every request. |
58
- | `fetch` | no | `globalThis.fetch` | Custom fetch for unusual runtimes. |
59
-
60
- ### Construction rules
61
-
62
- | Rule | Behavior |
63
- |------|----------|
64
- | Omitted `network` and `baseUrl` | Local mainnet `http://127.0.0.1:8788`, chain 4663 |
65
- | `network: "testnet"` | Public `https://api.aureonlabs.network` (still 46630) |
66
- | Explicit `baseUrl` | Wins; infer network from known hosts |
67
- | `network` + disagreeing `baseUrl` | Throws |
68
- | Invalid `baseUrl` scheme | Throws via `assertBaseUrl` |
69
- | `aureon.network` / `aureon.chainId` | Resolved bundle |
70
- | Both `authToken` and `getAccessToken` | Transport uses `getAccessToken` only |
71
- | `aureon.baseUrl` getter | Returns resolved base (no trailing slash) |
72
-
73
- ```mermaid
74
- flowchart LR
75
- Opts[AureonClientOptions] --> Ctor[constructor]
76
- Ctor --> ResolveToken{getAccessToken_provided}
77
- ResolveToken -->|yes| UseGetter[use_getter]
78
- ResolveToken -->|no_but_authToken| Wrap[wrap_authToken]
79
- ResolveToken -->|neither| NoAuth[no_Bearer]
80
- Ctor --> Transport[TransportOptions]
81
- ```
82
-
83
- ---
84
-
85
- ## 2. Connectivity
86
-
87
- ### `ping()`
88
-
89
- ```ts
90
- async ping(): Promise<{ ok: true; service: string; version: string }>
91
- ```
92
-
93
- | | |
94
- |--|--|
95
- | Auth | No |
96
- | HTTP | `GET /healthz` |
97
- | Use | Boot checks, CLI smoke, CI health gate |
98
- | Errors | `NETWORK_ERROR`, `TIMEOUT`, `SERVER_ERROR` |
99
-
100
- ```ts
101
- const { ok, service, version } = await aureon.ping();
102
- // { ok: true, service: "aureon-backend", version: "0.2.0" }
103
- ```
104
-
105
- ---
106
-
107
- ## 3. Authentication
108
-
109
- Deep narrative: [auth.md](./auth.md). Method cards below.
110
-
111
- ### `getAuthNonce(address)`
112
-
113
- ```ts
114
- async getAuthNonce(address: string): Promise<AuthNonceResponse>
115
- // AuthNonceResponse: { walletAddress, nonce, message, expiresAt }
116
- ```
117
-
118
- | | |
119
- |--|--|
120
- | Auth | No |
121
- | HTTP | `GET /auth/nonce?address=<encoded>` |
122
- | Client validation | Empty/whitespace address → `VALIDATION_ERROR` |
123
- | Notes | Sign the returned `message` **exactly**. Do not build your own challenge. |
124
-
125
- ### `verifyWallet({ address, message, signature })`
126
-
127
- ```ts
128
- async verifyWallet(input: {
129
- address: string;
130
- message: string;
131
- signature: string;
132
- }): Promise<AuthSessionResponse>
133
- // { token, walletAddress, expiresAt, sessionId, mode? }
134
- ```
135
-
136
- | | |
137
- |--|--|
138
- | Auth | No (establishes auth) |
139
- | HTTP | `POST /auth/verify` |
140
- | Client validation | All three fields required after trim |
141
- | Host duty | Store `token`; feed via `getAccessToken` |
142
-
143
- ### `devLogin()`
144
-
145
- ```ts
146
- async devLogin(): Promise<AuthSessionResponse>
147
- ```
148
-
149
- | | |
150
- |--|--|
151
- | Auth | No |
152
- | HTTP | `POST /auth/dev-login` |
153
- | Backend gate | `AUREON_ALLOW_DEV_LOGIN=1` |
154
- | Typical failure | Forbidden / unauthorized when flag off |
155
- | Notes | May include `mode: "dev-bypass"`. Never ship as sole product login. |
156
-
157
- ### `logout()`
158
-
159
- ```ts
160
- async logout(): Promise<{ ok: true }>
161
- ```
162
-
163
- | | |
164
- |--|--|
165
- | Auth | Bearer recommended |
166
- | HTTP | `POST /auth/logout` |
167
- | Host duty | Also `session.clear()` / stop returning token |
168
-
169
- ### `me()`
170
-
171
- ```ts
172
- async me(): Promise<AuthMeResponse>
173
- // { walletAddress: string }
174
- ```
175
-
176
- | | |
177
- |--|--|
178
- | Auth | **Required** |
179
- | HTTP | `GET /auth/me` |
180
- | Use | Session probe after hydrate |
181
- | Errors | `UNAUTHORIZED` when token missing/invalid |
182
-
183
- ---
184
-
185
- ## 4. Objectives
186
-
187
- ### Objective kinds and priorities
188
-
189
- | `ObjectiveKind` | Intent |
190
- |-----------------|--------|
191
- | `stable_allocation` | Hold a target stable weight (e.g. 20% USDG) |
192
- | `balanced_portfolio` | Hold balanced sleeve near a target weight |
193
- | `risk_ceiling` | Keep risk at or below configured ceiling |
194
- | `reward_reinvestment` | Reinvest rewards toward a target sleeve |
195
-
196
- | `ObjectivePriority` | Notes |
197
- |---------------------|-------|
198
- | `low` / `medium` / `high` / `critical` | Influences evaluation ordering when multiple objectives compete. Create defaults to `high`. |
199
-
200
- ### `createObjective(input)`
201
-
202
- ```ts
203
- async createObjective(input: CreateObjectiveInput): Promise<Objective>
204
- ```
205
-
206
- | | |
207
- |--|--|
208
- | Auth | Required |
209
- | HTTP | `POST /objectives` |
210
- | Client validation | Name ≥ 3 chars; kind; `targetWeight` ∈ [0,1]; `tolerance` ∈ [0,0.5]; priority if set |
211
- | Automation | SDK supports **Automatic only**. Defaults **`automationMode: "auto"`**. Omit the field in agent integrations. |
212
- | `targetSymbol` | Required when `kind === "balanced_portfolio"` (uppercased on normalize). |
213
-
214
- **SDK policy:** Automatic mode only. Manual Approve belongs in the operator utility — do not build Manual agent loops with this package.
215
-
216
- ```ts
217
- const objective = await aureon.createObjective({
218
- name: "Maintain 20% Stable Assets",
219
- kind: "stable_allocation",
220
- targetWeight: 0.2,
221
- tolerance: 0.02,
222
- priority: "high",
223
- // automationMode omitted → Automatic
224
- });
225
-
226
- const balanced = await aureon.createObjective({
227
- name: "Hold 30% NVDA sleeve",
228
- kind: "balanced_portfolio",
229
- targetSymbol: "NVDA",
230
- targetWeight: 0.3,
231
- tolerance: 0.05,
232
- });
233
- ```
234
-
235
- ### `listObjectives()`
236
-
237
- ```ts
238
- async listObjectives(): Promise<Objective[]>
239
- ```
240
-
241
- | | |
242
- |--|--|
243
- | Auth | Required |
244
- | HTTP | `GET /objectives` |
245
- | Unwrap | `{ objectives: Objective[] }` → array |
246
-
247
- ### `getObjective(id)`
248
-
249
- ```ts
250
- async getObjective(id: string): Promise<Objective>
251
- ```
252
-
253
- | | |
254
- |--|--|
255
- | Auth | Required |
256
- | HTTP | `GET /objectives/:id` |
257
- | Client validation | Id must be a non-trivial string (`assertId`) |
258
- | Errors | `NOT_FOUND`, `VALIDATION_ERROR` |
259
-
260
- ### `updateObjective(id, input)`
261
-
262
- ```ts
263
- async updateObjective(id: string, input: UpdateObjectiveInput): Promise<Objective>
264
- ```
265
-
266
- | | |
267
- |--|--|
268
- | Auth | Required |
269
- | HTTP | `PATCH /objectives/:id` |
270
- | Body | Partial: name, priority, targetWeight, tolerance, maxRiskScore, reinvestRatio |
271
- | Locked at create | `targetSymbol`, `automationMode` — recreate the objective to change either |
272
-
273
- ### `pauseObjective(id)` / `resumeObjective(id)`
274
-
275
- ```ts
276
- async pauseObjective(id: string): Promise<Objective>
277
- async resumeObjective(id: string): Promise<Objective>
278
- ```
279
-
280
- | | |
281
- |--|--|
282
- | Auth | Required |
283
- | HTTP | `POST /objectives/:id/pause` · `POST /objectives/:id/resume` |
284
- | Effect | Pause stops continuous evaluation; health typically reports `paused` |
285
-
286
- ```mermaid
287
- stateDiagram-v2
288
- [*] --> active: createObjective
289
- active --> paused: pauseObjective
290
- paused --> active: resumeObjective
291
- active --> active: updateObjective
292
- ```
293
-
294
- ---
295
-
296
- ## 5. Health, timeline, portfolio, overview
297
-
298
- ### `getHealth(objectiveId?)`
299
-
300
- ```ts
301
- async getHealth(objectiveId?: string): Promise<ObjectiveHealth[]>
302
- ```
303
-
304
- | | |
305
- |--|--|
306
- | Auth | Required |
307
- | HTTP | `GET /health` optional `?objectiveId=` |
308
- | Unwrap | `{ health }` |
309
- | States | `healthy` · `warning` · `violation` · `paused` |
310
-
311
- ### `getTimeline(objectiveId?)`
312
-
313
- ```ts
314
- async getTimeline(objectiveId?: string): Promise<TimelineEvent[]>
315
- ```
316
-
317
- | | |
318
- |--|--|
319
- | Auth | Required |
320
- | HTTP | `GET /timeline` optional `?objectiveId=` |
321
- | Unwrap | `{ events }` |
322
- | Use | Operator narrative for launch video / audit |
323
-
324
- ### `getPortfolio()`
325
-
326
- ```ts
327
- async getPortfolio(): Promise<PortfolioSnapshot>
328
- ```
329
-
330
- | | |
331
- |--|--|
332
- | Auth | Required |
333
- | HTTP | `GET /portfolio` |
334
- | Empty book | Valid: `positions.length === 0`, notional may be `0` |
335
-
336
- ### `clearPortfolio()`
337
-
338
- ```ts
339
- async clearPortfolio(): Promise<PortfolioSnapshot>
340
- ```
341
-
342
- | | |
343
- |--|--|
344
- | Auth | Required |
345
- | HTTP | `POST /portfolio/clear` |
346
- | Unwrap | `{ portfolio }` → snapshot |
347
- | Notes | Clears wallet positions. Does **not** seed holdings. |
348
-
349
- ### `syncPortfolio()`
350
-
351
- ```ts
352
- async syncPortfolio(): Promise<SyncPortfolioResult>
353
- ```
354
-
355
- | | |
356
- |--|--|
357
- | Auth | API key + Bearer |
358
- | HTTP | `POST /portfolio/sync` |
359
- | Returns | `{ portfolio, chainId, skippedZero }` |
360
- | Notes | On-chain balances for the session wallet. Vault balances merge into the book. Does **not** invent holdings. |
361
-
362
- ### `getOverview()`
363
-
364
- ```ts
365
- async getOverview(): Promise<DashboardOverview>
366
- ```
367
-
368
- | | |
369
- |--|--|
370
- | Auth | Required |
371
- | HTTP | `GET /overview` |
372
- | Contains | Health counts, global score, 24h portfolio change (daily snapshots), evaluation schedule, recent executions + events |
373
-
374
- ### `getAllocationVsTarget()`
375
-
376
- ```ts
377
- async getAllocationVsTarget(): Promise<{
378
- rows: AllocationComparisonRow[];
379
- paradox: PlanParadoxResult;
380
- overview: DashboardOverview;
381
- }>
382
- ```
383
-
384
- | | |
385
- |--|--|
386
- | Auth | Required |
387
- | HTTP | Composite — parallel `GET /overview`, `GET /objectives`, `GET /health` |
388
- | Returns | Per-objective current vs target weights plus a green-book/off-plan paradox flag |
389
- | Use | demo — objective vs actual portfolio without stitching JSON yourself |
390
-
391
- Helpers `buildAllocationComparison()` and `detectPlanParadox()` are exported for custom integrators. See `pnpm example:green-vs-plan`.
392
-
393
- ### `applyFinancialIntent(intent)`
394
-
395
- ```ts
396
- async applyFinancialIntent(intent: FinancialIntent): Promise<ObjectivePortfolioFlow>
397
- ```
398
-
399
- | | |
400
- |--|--|
401
- | Auth | Required |
402
- | HTTP | Composite — `POST /objectives` + watchdog refresh + `GET /health` + `GET /portfolio` |
403
- | Returns | Intent summary, created objective, health, portfolio snapshot, teaching message |
404
- | Use | AI → objective → portfolio in one call |
405
-
406
- ### `getObjectivePortfolioFlow(objectiveId?)`
407
-
408
- ```ts
409
- async getObjectivePortfolioFlow(objectiveId?: string): Promise<ObjectivePortfolioFlow[]>
410
- ```
411
-
412
- | | |
413
- |--|--|
414
- | Auth | Required |
415
- | HTTP | Composite — objectives + health + portfolio |
416
- | Returns | Flow snapshots for active objectives (or one id) |
417
-
418
- Helpers `parseFinancialIntent()`, `resolveObjectiveFromIntent()`, and `buildObjectivePortfolioFlow()` are exported. See `pnpm example:ai-to-objective-to-portfolio`.
419
-
420
- ### `runDriftRestoreDemo()`
421
-
422
- ```ts
423
- async runDriftRestoreDemo(): Promise<DriftRestoreFlow>
424
- ```
425
-
426
- | | |
427
- |--|--|
428
- | Auth | Required |
429
- | HTTP | Composite — portfolio seed, objective create, market event (`autoRestore: false`), restore plan, manual restore |
430
- | Returns | Three-beat `DriftRestoreFlow` — aligned → drift → restored |
431
- | Use | drift → detection → restore teaching demo |
432
-
433
- ### `getDriftRestoreFlow(objectiveId?)`
434
-
435
- ```ts
436
- async getDriftRestoreFlow(objectiveId?: string): Promise<DriftRestoreFlow[]>
437
- ```
438
-
439
- | | |
440
- |--|--|
441
- | Auth | Required |
442
- | HTTP | Composite — objectives + health + allocation + executions (+ restore plan when off-plan) |
443
- | Returns | Inferred drift-restore flows for active objectives |
444
-
445
- Helpers `buildDriftRestoreFlow()`, `buildDriftRestoreFlowFromSnapshot()`, and `inferDriftPhase()` are exported. See `pnpm example:drift-detect-restore`.
446
-
447
- ### `runReceiptVerificationDemo()`
448
-
449
- ```ts
450
- async runReceiptVerificationDemo(): Promise<ReceiptVerificationFlow>
451
- ```
452
-
453
- | | |
454
- |--|--|
455
- | Auth | Required |
456
- | HTTP | Composite — `runDriftRestoreDemo()` + local validation + settlement lookup + timeline |
457
- | Returns | Three-beat `ReceiptVerificationFlow` — claim → validate → verify |
458
- | Use | receipt → verification teaching demo |
459
-
460
- ### `getReceiptVerificationFlow(executionId?)`
461
-
462
- ```ts
463
- async getReceiptVerificationFlow(executionId?: string): Promise<ReceiptVerificationFlow[]>
464
- ```
465
-
466
- | | |
467
- |--|--|
468
- | Auth | Required |
469
- | HTTP | Composite — executions + validation + settlement + timeline |
470
- | Returns | Verification flows for recent or specified execution(s) |
471
-
472
- Helpers `buildReceiptVerificationFlow()`, `inferProofTier()`, and `validateExecutionReceipt()` are exported. See `pnpm example:receipt-verification`.
473
-
474
- ### `runPortfolioWatchDemo(input?)`
475
-
476
- ```ts
477
- async runPortfolioWatchDemo(input?: {
478
- brief?: string;
479
- host?: "cursor" | "claude" | "mcp";
480
- }): Promise<PortfolioWatchFlow>
481
- ```
482
-
483
- | | |
484
- |--|--|
485
- | Auth | Required |
486
- | HTTP | Composite — `applyFinancialIntent` + market event (`autoRestore: true`) + timeline |
487
- | Returns | Portfolio watch flow — register → while away → return briefing |
488
- | Use | agent-in-host demo |
489
-
490
- ### `getPortfolioWatchFlow(input?)`
491
-
492
- ```ts
493
- async getPortfolioWatchFlow(input?: {
494
- objectiveId?: string;
495
- brief?: string;
496
- host?: "cursor" | "claude" | "mcp";
497
- }): Promise<PortfolioWatchFlow[]>
498
- ```
499
-
500
- | | |
501
- |--|--|
502
- | Auth | Required |
503
- | HTTP | Composite — Automatic objectives + health + allocation + timeline |
504
- | Returns | Read-only briefing for active Automatic objectives |
505
-
506
- Helpers `buildPortfolioWatchFlow()`, `DEFAULT_PORTFOLIO_WATCH_BRIEF`, and `inferPortfolioWatchPhase()` are exported. See `pnpm example:portfolio-watch`.
507
-
508
- ### `runFullAureonLoopDemo(input?)`
509
-
510
- ```ts
511
- async runFullAureonLoopDemo(input?: {
512
- brief?: string;
513
- }): Promise<FullAureonLoopFlow>
514
- ```
515
-
516
- | | |
517
- |--|--|
518
- | Auth | Required |
519
- | HTTP | Composite — intent + allocation paradox + restore (`autoRestore: false`) + receipt verification |
520
- | Returns | Full loop — intent → plan check → restore → verify |
521
- | Use | Content Arc — full AUREON loop positioning demo |
522
-
523
- ### `getFullAureonLoopFlow(input?)`
524
-
525
- ```ts
526
- async getFullAureonLoopFlow(input?: {
527
- objectiveId?: string;
528
- brief?: string;
529
- }): Promise<FullAureonLoopFlow[]>
530
- ```
531
-
532
- | | |
533
- |--|--|
534
- | Auth | Required |
535
- | HTTP | Composite — objectives + allocation + latest receipt + validation |
536
- | Returns | Read-only full-loop flows for active objectives with receipts |
537
-
538
- Helpers `buildFullAureonLoopFlow()`, `DEFAULT_FULL_LOOP_BRIEF`, and `inferFullAureonLoopPhase()` are exported. See `pnpm example:full-aureon-loop`.
539
-
540
- ---
541
-
542
- ## 6. Vault
543
-
544
- Vault reads and prepare endpoints. The API returns calldata **steps**; the host wallet signs and broadcasts, meaning the API never holds user keys.
545
-
546
- ### `getVault()`
547
-
548
- ```ts
549
- async getVault(): Promise<VaultOverview>
550
- ```
551
-
552
- | | |
553
- |--|--|
554
- | Auth | Required |
555
- | HTTP | `GET /vault` |
556
- | Returns | `address`, `chainId`, `tokens`, `balances`, `poolAddress`, `explorerBase`, `keeperAddress` |
557
-
558
- ### `getVaultStatus()`
559
-
560
- ```ts
561
- async getVaultStatus(): Promise<VaultStatus>
562
- // { empty, totalNotionalUsd, canRestore }
563
- ```
564
-
565
- | | |
566
- |--|--|
567
- | Auth | Required |
568
- | HTTP | `GET /vault/status` |
569
- | Use | Compact funding signal before restore |
570
-
571
- ### `prepareVaultDeposit({ symbol, amount })`
572
-
573
- ```ts
574
- async prepareVaultDeposit(input: {
575
- symbol: string; // "ETH" or any allowlisted ERC-20 (WETH, stables, …)
576
- amount: string;
577
- }): Promise<VaultPrepareResult>
578
- ```
579
-
580
- | | |
581
- |--|--|
582
- | Auth | Required |
583
- | HTTP | `POST /vault/prepare-deposit` body `{ symbol, amount }` |
584
- | ETH | Steps include `depositETH` (native value on step → vault WETH) |
585
- | ERC-20 | Steps include `approve` then `deposit` for any allowlisted symbol |
586
- | Host duty | Sign `steps` in order on `chainId`; broadcast each tx |
587
-
588
- ### `prepareVaultWithdraw({ symbol?, amount })`
589
-
590
- ```ts
591
- async prepareVaultWithdraw(input: {
592
- symbol?: string; // default "WETH"; any vault ERC-20 held by the user
593
- amount: string;
594
- }): Promise<VaultPrepareResult>
595
- ```
596
-
597
- | | |
598
- |--|--|
599
- | Auth | Required |
600
- | HTTP | `POST /vault/prepare-withdraw` body `{ symbol, amount }` |
601
- | Symbol | Any allowlisted vault ERC-20 (not native ETH, use WETH) |
602
- | Host duty | Sign and broadcast returned `steps` |
603
-
604
- ---
605
-
606
- ## 7. Market and execution
607
-
608
- ### Launch / rehearsal flow
609
-
610
- ```mermaid
611
- sequenceDiagram
612
- participant App
613
- participant SDK
614
- participant API
615
-
616
- App->>SDK: listMarketPresets
617
- API-->>App: presets
618
- App->>SDK: applyMarketEvent autoRestore true
619
- API-->>App: event + portfolio + health + executions
620
- Note over API: may run vault or staged restore
621
- App->>SDK: getTimeline
622
- API-->>App: violation_detected execution_completed
623
- ```
624
-
625
- ### `listMarketPresets()`
626
-
627
- ```ts
628
- async listMarketPresets(): Promise<MarketPreset[]>
629
- ```
630
-
631
- | | |
632
- |--|--|
633
- | Auth | Required |
634
- | HTTP | `GET /market/presets` |
635
- | Unwrap | `{ presets }` |
636
- | Fields | `name`, `description`, `symbol`, `priceChangeRatio` |
637
-
638
- ### `applyMarketEvent(input)`
639
-
640
- ```ts
641
- async applyMarketEvent(input: ApplyMarketEventInput): Promise<{
642
- event: MarketEvent;
643
- portfolio: PortfolioSnapshot;
644
- health: ObjectiveHealth[];
645
- executions: ExecutionReceipt[];
646
- }>
647
- ```
648
-
649
- | | |
650
- |--|--|
651
- | Auth | Required |
652
- | HTTP | `POST /market/events` |
653
- | Normalization | Uppercases symbol; `autoRestore` defaults **false** (must opt in to restore) |
654
- | Validation | Symbol required; finite `priceChangeRatio`; rejects extreme ≤ -0.95 |
655
-
656
- ### `getRestorePlan(objectiveId)`
657
-
658
- ```ts
659
- async getRestorePlan(objectiveId: string): Promise<RestorePlan>
660
- // { kind, amountHuman, approxUsd, message, sellSymbol?, buySymbol? }
661
- ```
662
-
663
- | | |
664
- |--|--|
665
- | Auth | Required |
666
- | HTTP | `GET /objectives/:id/restore-plan` |
667
- | Kinds | `wrap_eth` · `unwrap_weth` · `vault_swap` |
668
- | Use | Inspect plan before acting, noting that wrap/unwrap is client-side |
669
-
670
- ### `runExecution(objectiveId)`
671
-
672
- ```ts
673
- async runExecution(objectiveId: string): Promise<ExecutionReceipt>
674
- ```
675
-
676
- | | |
677
- |--|--|
678
- | Auth | Required |
679
- | HTTP | `POST /executions/run` body `{ objectiveId }` |
680
- | Settlement | Receipt may include `settlement: "vault"` or `"staged"` |
681
- | Use | Restore when plan kind is `vault_swap` (rejects wrap/unwrap with action details) |
682
-
683
- ### `restoreObjective(objectiveId)`
684
-
685
- ```ts
686
- async restoreObjective(objectiveId: string): Promise<ExecutionReceipt>
687
- ```
688
-
689
- | | |
690
- |--|--|
691
- | Auth | Required |
692
- | HTTP | `POST /objectives/:id/restore` |
693
- | Settlement | Vault-backed restore when configured; same honesty labels as `runExecution` |
694
- | Use | Preferred vault restore entry for Automatic objectives after breach |
695
-
696
- ### `listExecutions(objectiveId?)`
697
-
698
- ```ts
699
- async listExecutions(objectiveId?: string): Promise<ExecutionReceipt[]>
700
- ```
701
-
702
- | | |
703
- |--|--|
704
- | Auth | Required |
705
- | HTTP | `GET /executions` optional `?objectiveId=` |
706
- | Unwrap | `{ executions }` |
707
-
708
- ---
709
-
710
- ## 8. Session helper
711
-
712
- ```ts
713
- import { createSessionTokenProvider } from "@buildaureon/sdk";
714
-
715
- const session = createSessionTokenProvider(initialToken?: string | null);
716
- session.getAccessToken(); // () => string | null
717
- session.setToken(token);
718
- session.clear();
719
- ```
720
-
721
- | Method | Purpose |
722
- |--------|---------|
723
- | `getAccessToken` | Pass directly into `createAureonClient({ getAccessToken })` |
724
- | `setToken` | After `verifyWallet` / `devLogin` |
725
- | `clear` | After `logout` or local sign-out |
726
-
727
- ---
728
-
729
- ## 9. Method → HTTP cheat sheet
730
-
731
- | Method | Verb | Path | Auth |
732
- |--------|------|------|------|
733
- | `ping` | GET | `/healthz` | no |
734
- | `getAuthNonce` | GET | `/auth/nonce` | no |
735
- | `verifyWallet` | POST | `/auth/verify` | no |
736
- | `devLogin` | POST | `/auth/dev-login` | no |
737
- | `logout` | POST | `/auth/logout` | recommended |
738
- | `me` | GET | `/auth/me` | **yes** |
739
- | `createObjective` | POST | `/objectives` | **yes** |
740
- | `listObjectives` | GET | `/objectives` | **yes** |
741
- | `getObjective` | GET | `/objectives/:id` | **yes** |
742
- | `updateObjective` | PATCH | `/objectives/:id` | **yes** |
743
- | `pauseObjective` | POST | `/objectives/:id/pause` | **yes** |
744
- | `resumeObjective` | POST | `/objectives/:id/resume` | **yes** |
745
- | `getHealth` | GET | `/health` | **yes** |
746
- | `getTimeline` | GET | `/timeline` | **yes** |
747
- | `getPortfolio` | GET | `/portfolio` | **yes** |
748
- | `setPortfolio` | PUT | `/portfolio` | **yes** |
749
- | `clearPortfolio` | POST | `/portfolio/clear` | **yes** |
750
- | `syncPortfolio` | POST | `/portfolio/sync` | **yes** |
751
- | `refreshWatchdog` | POST | `/watchdog/refresh` | **yes** |
752
- | `getOverview` | GET | `/overview` | **yes** |
753
- | `getAllocationVsTarget` | composite | overview + objectives + health | **yes** |
754
- | `applyFinancialIntent` | composite | create objective + health + portfolio | **yes** |
755
- | `getObjectivePortfolioFlow` | composite | objectives + health + portfolio | **yes** |
756
- | `runDriftRestoreDemo` | composite | seed + drift + manual restore | **yes** |
757
- | `getDriftRestoreFlow` | composite | objectives + health + allocation + executions | **yes** |
758
- | `runReceiptVerificationDemo` | composite | drift-restore + validate + settlement | **yes** |
759
- | `getReceiptVerificationFlow` | composite | executions + validation + settlement | **yes** |
760
- | `runPortfolioWatchDemo` | composite | intent + auto-restore market event + briefing | **yes** |
761
- | `getPortfolioWatchFlow` | composite | Automatic objectives + health + timeline | **yes** |
762
- | `runFullAureonLoopDemo` | composite | intent + plan paradox + restore + verify | **yes** |
763
- | `getFullAureonLoopFlow` | composite | objectives + allocation + receipt validation | **yes** |
764
- | `listMarketPresets` | GET | `/market/presets` | **yes** |
765
- | `applyMarketEvent` | POST | `/market/events` | **yes** |
766
- | `getRestorePlan` | GET | `/objectives/:id/restore-plan` | **yes** |
767
- | `restoreObjective` | POST | `/objectives/:id/restore` | **yes** |
768
- | `runExecution` | POST | `/executions/run` | **yes** |
769
- | `listExecutions` | GET | `/executions` | **yes** |
770
- | `getVault` | GET | `/vault` | **yes** |
771
- | `getVaultStatus` | GET | `/vault/status` | **yes** |
772
- | `prepareVaultDeposit` | POST | `/vault/prepare-deposit` | **yes** |
773
- | `prepareVaultWithdraw` | POST | `/vault/prepare-withdraw` | **yes** |
774
-
775
- ---
776
-
777
- ## 10. Common error patterns
778
-
779
- | Situation | Typical `code` | Integrator action |
780
- |-----------|----------------|-------------------|
781
- | Forgot Bearer on protected route | `UNAUTHORIZED` | Re-login / fix `getAccessToken` |
782
- | Name too short on create | `VALIDATION_ERROR` | Fix form |
783
- | Unknown objective id | `NOT_FOUND` | Refresh list |
784
- | Backend restart mid-session | `UNAUTHORIZED` | Clear token, connect again |
785
- | Transient 503 | `SERVER_ERROR` | Retries if `maxRetries > 0` |
786
- | Offline | `NETWORK_ERROR` | Show connectivity banner |
787
-
788
- Full matrix: [error-model.md](./error-model.md).
1
+ # Client API Reference
2
+
3
+ Complete reference for every public method on `AureonClient` as implemented in
4
+ `src/client/aureon-client.ts`, plus factories and the session helper.
5
+
6
+ Cross-links: [auth](./auth.md) | [architecture](./architecture.md) | [error-model](./error-model.md) |
7
+ [data-contracts](./data-contracts.md) | [transport](./transport.md)
8
+
9
+ ---
10
+
11
+ ## Table of contents
12
+
13
+ 1. [Construction](#1-construction)
14
+ 2. [Connectivity](#2-connectivity)
15
+ 3. [Authentication](#3-authentication)
16
+ 4. [Objectives](#4-objectives)
17
+ 5. [Health, timeline, portfolio, overview](#5-health-timeline-portfolio-overview)
18
+ 6. [Vault](#6-vault)
19
+ 7. [Market and execution](#7-market-and-execution)
20
+ 8. [Session helper](#8-session-helper)
21
+ 9. [Method → HTTP cheat sheet](#9-method--http-cheat-sheet)
22
+ 10. [Common error patterns](#10-common-error-patterns)
23
+
24
+ ---
25
+
26
+ ## 1. Construction
27
+
28
+ ```ts
29
+ import {
30
+ createAureonClient,
31
+ AureonClient,
32
+ } from "@buildaureon/sdk";
33
+
34
+ const aureon = createAureonClient({
35
+ // network defaults to official API / mainnet
36
+ // network: "testnet" → stay on testnet on the same official host
37
+ apiKey: process.env.AUREON_API_KEY,
38
+ getAccessToken: () => sessionToken,
39
+ timeoutMs: 30_000,
40
+ maxRetries: 2,
41
+ });
42
+ ```
43
+
44
+ ### Options reference
45
+
46
+ | Option | Required | Default | Description |
47
+ |--------|----------|---------|-------------|
48
+ | `network` | no | `mainnet` | Omit for official API / mainnet. Pass `"testnet"` to stay on testnet. |
49
+ | `baseUrl` | no | `https://api.aureonlabs.network` | Leave unset. Override only if you must point at another host. |
50
+ | `apiKey` | SDK / CLI | N/A | Sent as `X-Aureon-Api-Key`. Issued developer keys also identify the bound wallet (no Bearer required). Env bootstrap keys are product-gate only. Utility uses wallet Bearer only. |
51
+ | `getAccessToken` | no | N/A | Optional Bearer getter. Wins over API-key identity when present. |
52
+ | `authToken` | no | N/A | Static Bearer string when `getAccessToken` is omitted. |
53
+ | `timeoutMs` | no | `30000` | Per-attempt abort timeout. |
54
+ | `maxRetries` | no | `0` | Extra attempts after first failure for retryable errors. |
55
+ | `retryDelayMs` | no | `250` | Fixed delay between retries. |
56
+ | `logger` | no | N/A | `AureonLogger`. |
57
+ | `headers` | no | `{}` | Merged into every request. |
58
+ | `fetch` | no | `globalThis.fetch` | Custom fetch for unusual runtimes. |
59
+
60
+ ### Construction rules
61
+
62
+ | Rule | Behavior |
63
+ |------|----------|
64
+ | Omitted `network` and `baseUrl` | Official API `https://api.aureonlabs.network`, chain 4663 |
65
+ | `network: "testnet"` | Same official host, chain 46630 |
66
+ | Explicit `baseUrl` | Override; official host is allowed with either network |
67
+ | `network` + disagreeing non-official host | Throws |
68
+ | Invalid `baseUrl` scheme | Throws via `assertBaseUrl` |
69
+ | `aureon.network` / `aureon.chainId` | Resolved bundle |
70
+ | Both `authToken` and `getAccessToken` | Transport uses `getAccessToken` only |
71
+ | `aureon.baseUrl` getter | Returns resolved base (no trailing slash) |
72
+
73
+ ```mermaid
74
+ flowchart LR
75
+ Opts[AureonClientOptions] --> Ctor[constructor]
76
+ Ctor --> ResolveToken{getAccessToken_provided}
77
+ ResolveToken -->|yes| UseGetter[use_getter]
78
+ ResolveToken -->|no_but_authToken| Wrap[wrap_authToken]
79
+ ResolveToken -->|neither| NoAuth[no_Bearer]
80
+ Ctor --> Transport[TransportOptions]
81
+ ```
82
+
83
+ ---
84
+
85
+ ## 2. Connectivity
86
+
87
+ ### `ping()`
88
+
89
+ ```ts
90
+ async ping(): Promise<{ ok: true; service: string; version: string }>
91
+ ```
92
+
93
+ | | |
94
+ |--|--|
95
+ | Auth | No |
96
+ | HTTP | `GET /healthz` |
97
+ | Use | Boot checks, CLI smoke, CI health gate |
98
+ | Errors | `NETWORK_ERROR`, `TIMEOUT`, `SERVER_ERROR` |
99
+
100
+ ```ts
101
+ const { ok, service, version } = await aureon.ping();
102
+ // { ok: true, service: "aureon-backend", version: "0.2.0" }
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 3. Authentication
108
+
109
+ Deep narrative: [auth.md](./auth.md). Method cards below.
110
+
111
+ ### `getAuthNonce(address)`
112
+
113
+ ```ts
114
+ async getAuthNonce(address: string): Promise<AuthNonceResponse>
115
+ // AuthNonceResponse: { walletAddress, nonce, message, expiresAt }
116
+ ```
117
+
118
+ | | |
119
+ |--|--|
120
+ | Auth | No |
121
+ | HTTP | `GET /auth/nonce?address=<encoded>` |
122
+ | Client validation | Empty/whitespace address → `VALIDATION_ERROR` |
123
+ | Notes | Sign the returned `message` **exactly**. Do not build your own challenge. |
124
+
125
+ ### `verifyWallet({ address, message, signature })`
126
+
127
+ ```ts
128
+ async verifyWallet(input: {
129
+ address: string;
130
+ message: string;
131
+ signature: string;
132
+ }): Promise<AuthSessionResponse>
133
+ // { token, walletAddress, expiresAt, sessionId, mode? }
134
+ ```
135
+
136
+ | | |
137
+ |--|--|
138
+ | Auth | No (establishes auth) |
139
+ | HTTP | `POST /auth/verify` |
140
+ | Client validation | All three fields required after trim |
141
+ | Host duty | Store `token`; feed via `getAccessToken` |
142
+
143
+ ### `devLogin()`
144
+
145
+ ```ts
146
+ async devLogin(): Promise<AuthSessionResponse>
147
+ ```
148
+
149
+ | | |
150
+ |--|--|
151
+ | Auth | No |
152
+ | HTTP | `POST /auth/dev-login` |
153
+ | Backend gate | `AUREON_ALLOW_DEV_LOGIN=1` |
154
+ | Typical failure | Forbidden / unauthorized when flag off |
155
+ | Notes | May include `mode: "dev-bypass"`. Never ship as sole product login. |
156
+
157
+ ### `logout()`
158
+
159
+ ```ts
160
+ async logout(): Promise<{ ok: true }>
161
+ ```
162
+
163
+ | | |
164
+ |--|--|
165
+ | Auth | Bearer recommended |
166
+ | HTTP | `POST /auth/logout` |
167
+ | Host duty | Also `session.clear()` / stop returning token |
168
+
169
+ ### `me()`
170
+
171
+ ```ts
172
+ async me(): Promise<AuthMeResponse>
173
+ // { walletAddress: string }
174
+ ```
175
+
176
+ | | |
177
+ |--|--|
178
+ | Auth | **Required** |
179
+ | HTTP | `GET /auth/me` |
180
+ | Use | Session probe after hydrate |
181
+ | Errors | `UNAUTHORIZED` when token missing/invalid |
182
+
183
+ ---
184
+
185
+ ## 4. Objectives
186
+
187
+ ### Objective kinds and priorities
188
+
189
+ | `ObjectiveKind` | Intent |
190
+ |-----------------|--------|
191
+ | `stable_allocation` | Hold a target stable weight (e.g. 20% USDG) |
192
+ | `balanced_portfolio` | Hold balanced sleeve near a target weight |
193
+ | `risk_ceiling` | Keep risk at or below configured ceiling |
194
+ | `reward_reinvestment` | Reinvest rewards toward a target sleeve |
195
+
196
+ | `ObjectivePriority` | Notes |
197
+ |---------------------|-------|
198
+ | `low` / `medium` / `high` / `critical` | Influences evaluation ordering when multiple objectives compete. Create defaults to `high`. |
199
+
200
+ ### `createObjective(input)`
201
+
202
+ ```ts
203
+ async createObjective(input: CreateObjectiveInput): Promise<Objective>
204
+ ```
205
+
206
+ | | |
207
+ |--|--|
208
+ | Auth | Required |
209
+ | HTTP | `POST /objectives` |
210
+ | Client validation | Name ≥ 3 chars; kind; `targetWeight` ∈ [0,1]; `tolerance` ∈ [0,0.5]; priority if set |
211
+ | Automation | SDK supports **Automatic only**. Defaults **`automationMode: "auto"`**. Omit the field in agent integrations. |
212
+ | `targetSymbol` | Required when `kind === "balanced_portfolio"` (uppercased on normalize). |
213
+
214
+ **SDK policy:** Automatic mode only. Manual Approve belongs in the operator utility — do not build Manual agent loops with this package.
215
+
216
+ ```ts
217
+ const objective = await aureon.createObjective({
218
+ name: "Maintain 20% Stable Assets",
219
+ kind: "stable_allocation",
220
+ targetWeight: 0.2,
221
+ tolerance: 0.02,
222
+ priority: "high",
223
+ // automationMode omitted → Automatic
224
+ });
225
+
226
+ const balanced = await aureon.createObjective({
227
+ name: "Hold 30% NVDA sleeve",
228
+ kind: "balanced_portfolio",
229
+ targetSymbol: "NVDA",
230
+ targetWeight: 0.3,
231
+ tolerance: 0.05,
232
+ });
233
+ ```
234
+
235
+ ### `listObjectives()`
236
+
237
+ ```ts
238
+ async listObjectives(): Promise<Objective[]>
239
+ ```
240
+
241
+ | | |
242
+ |--|--|
243
+ | Auth | Required |
244
+ | HTTP | `GET /objectives` |
245
+ | Unwrap | `{ objectives: Objective[] }` → array |
246
+
247
+ ### `getObjective(id)`
248
+
249
+ ```ts
250
+ async getObjective(id: string): Promise<Objective>
251
+ ```
252
+
253
+ | | |
254
+ |--|--|
255
+ | Auth | Required |
256
+ | HTTP | `GET /objectives/:id` |
257
+ | Client validation | Id must be a non-trivial string (`assertId`) |
258
+ | Errors | `NOT_FOUND`, `VALIDATION_ERROR` |
259
+
260
+ ### `updateObjective(id, input)`
261
+
262
+ ```ts
263
+ async updateObjective(id: string, input: UpdateObjectiveInput): Promise<Objective>
264
+ ```
265
+
266
+ | | |
267
+ |--|--|
268
+ | Auth | Required |
269
+ | HTTP | `PATCH /objectives/:id` |
270
+ | Body | Partial: name, priority, targetWeight, tolerance, maxRiskScore, reinvestRatio |
271
+ | Locked at create | `targetSymbol`, `automationMode` — recreate the objective to change either |
272
+
273
+ ### `pauseObjective(id)` / `resumeObjective(id)`
274
+
275
+ ```ts
276
+ async pauseObjective(id: string): Promise<Objective>
277
+ async resumeObjective(id: string): Promise<Objective>
278
+ ```
279
+
280
+ | | |
281
+ |--|--|
282
+ | Auth | Required |
283
+ | HTTP | `POST /objectives/:id/pause` · `POST /objectives/:id/resume` |
284
+ | Effect | Pause stops continuous evaluation; health typically reports `paused` |
285
+
286
+ ```mermaid
287
+ stateDiagram-v2
288
+ [*] --> active: createObjective
289
+ active --> paused: pauseObjective
290
+ paused --> active: resumeObjective
291
+ active --> active: updateObjective
292
+ ```
293
+
294
+ ---
295
+
296
+ ## 5. Health, timeline, portfolio, overview
297
+
298
+ ### `getHealth(objectiveId?)`
299
+
300
+ ```ts
301
+ async getHealth(objectiveId?: string): Promise<ObjectiveHealth[]>
302
+ ```
303
+
304
+ | | |
305
+ |--|--|
306
+ | Auth | Required |
307
+ | HTTP | `GET /health` optional `?objectiveId=` |
308
+ | Unwrap | `{ health }` |
309
+ | States | `healthy` · `warning` · `violation` · `paused` |
310
+
311
+ ### `getTimeline(objectiveId?)`
312
+
313
+ ```ts
314
+ async getTimeline(objectiveId?: string): Promise<TimelineEvent[]>
315
+ ```
316
+
317
+ | | |
318
+ |--|--|
319
+ | Auth | Required |
320
+ | HTTP | `GET /timeline` optional `?objectiveId=` |
321
+ | Unwrap | `{ events }` |
322
+ | Use | Operator narrative for launch video / audit |
323
+
324
+ ### `getPortfolio()`
325
+
326
+ ```ts
327
+ async getPortfolio(): Promise<PortfolioSnapshot>
328
+ ```
329
+
330
+ | | |
331
+ |--|--|
332
+ | Auth | Required |
333
+ | HTTP | `GET /portfolio` |
334
+ | Empty book | Valid: `positions.length === 0`, notional may be `0` |
335
+
336
+ ### `clearPortfolio()`
337
+
338
+ ```ts
339
+ async clearPortfolio(): Promise<PortfolioSnapshot>
340
+ ```
341
+
342
+ | | |
343
+ |--|--|
344
+ | Auth | Required |
345
+ | HTTP | `POST /portfolio/clear` |
346
+ | Unwrap | `{ portfolio }` → snapshot |
347
+ | Notes | Clears wallet positions. Does **not** seed holdings. |
348
+
349
+ ### `syncPortfolio()`
350
+
351
+ ```ts
352
+ async syncPortfolio(): Promise<SyncPortfolioResult>
353
+ ```
354
+
355
+ | | |
356
+ |--|--|
357
+ | Auth | API key + Bearer |
358
+ | HTTP | `POST /portfolio/sync` |
359
+ | Returns | `{ portfolio, chainId, skippedZero }` |
360
+ | Notes | On-chain balances for the session wallet. Vault balances merge into the book. Does **not** invent holdings. |
361
+
362
+ ### `getOverview()`
363
+
364
+ ```ts
365
+ async getOverview(): Promise<DashboardOverview>
366
+ ```
367
+
368
+ | | |
369
+ |--|--|
370
+ | Auth | Required |
371
+ | HTTP | `GET /overview` |
372
+ | Contains | Health counts, global score, 24h portfolio change (daily snapshots), evaluation schedule, recent executions + events |
373
+
374
+ ### `getAllocationVsTarget()`
375
+
376
+ ```ts
377
+ async getAllocationVsTarget(): Promise<{
378
+ rows: AllocationComparisonRow[];
379
+ paradox: PlanParadoxResult;
380
+ overview: DashboardOverview;
381
+ }>
382
+ ```
383
+
384
+ | | |
385
+ |--|--|
386
+ | Auth | Required |
387
+ | HTTP | Composite — parallel `GET /overview`, `GET /objectives`, `GET /health` |
388
+ | Returns | Per-objective current vs target weights plus a green-book/off-plan paradox flag |
389
+ | Use | demo — objective vs actual portfolio without stitching JSON yourself |
390
+
391
+ Helpers `buildAllocationComparison()` and `detectPlanParadox()` are exported for custom integrators. See `pnpm example:green-vs-plan`.
392
+
393
+ ### `applyFinancialIntent(intent)`
394
+
395
+ ```ts
396
+ async applyFinancialIntent(intent: FinancialIntent): Promise<ObjectivePortfolioFlow>
397
+ ```
398
+
399
+ | | |
400
+ |--|--|
401
+ | Auth | Required |
402
+ | HTTP | Composite — `POST /objectives` + watchdog refresh + `GET /health` + `GET /portfolio` |
403
+ | Returns | Intent summary, created objective, health, portfolio snapshot, teaching message |
404
+ | Use | AI → objective → portfolio in one call |
405
+
406
+ ### `getObjectivePortfolioFlow(objectiveId?)`
407
+
408
+ ```ts
409
+ async getObjectivePortfolioFlow(objectiveId?: string): Promise<ObjectivePortfolioFlow[]>
410
+ ```
411
+
412
+ | | |
413
+ |--|--|
414
+ | Auth | Required |
415
+ | HTTP | Composite — objectives + health + portfolio |
416
+ | Returns | Flow snapshots for active objectives (or one id) |
417
+
418
+ Helpers `parseFinancialIntent()`, `resolveObjectiveFromIntent()`, and `buildObjectivePortfolioFlow()` are exported. See `pnpm example:ai-to-objective-to-portfolio`.
419
+
420
+ ### `runDriftRestoreDemo()`
421
+
422
+ ```ts
423
+ async runDriftRestoreDemo(): Promise<DriftRestoreFlow>
424
+ ```
425
+
426
+ | | |
427
+ |--|--|
428
+ | Auth | Required |
429
+ | HTTP | Composite — portfolio seed, objective create, market event (`autoRestore: false`), restore plan, manual restore |
430
+ | Returns | Three-beat `DriftRestoreFlow` — aligned → drift → restored |
431
+ | Use | drift → detection → restore teaching demo |
432
+
433
+ ### `getDriftRestoreFlow(objectiveId?)`
434
+
435
+ ```ts
436
+ async getDriftRestoreFlow(objectiveId?: string): Promise<DriftRestoreFlow[]>
437
+ ```
438
+
439
+ | | |
440
+ |--|--|
441
+ | Auth | Required |
442
+ | HTTP | Composite — objectives + health + allocation + executions (+ restore plan when off-plan) |
443
+ | Returns | Inferred drift-restore flows for active objectives |
444
+
445
+ Helpers `buildDriftRestoreFlow()`, `buildDriftRestoreFlowFromSnapshot()`, and `inferDriftPhase()` are exported. See `pnpm example:drift-detect-restore`.
446
+
447
+ ### `runReceiptVerificationDemo()`
448
+
449
+ ```ts
450
+ async runReceiptVerificationDemo(): Promise<ReceiptVerificationFlow>
451
+ ```
452
+
453
+ | | |
454
+ |--|--|
455
+ | Auth | Required |
456
+ | HTTP | Composite — `runDriftRestoreDemo()` + local validation + settlement lookup + timeline |
457
+ | Returns | Three-beat `ReceiptVerificationFlow` — claim → validate → verify |
458
+ | Use | receipt → verification teaching demo |
459
+
460
+ ### `getReceiptVerificationFlow(executionId?)`
461
+
462
+ ```ts
463
+ async getReceiptVerificationFlow(executionId?: string): Promise<ReceiptVerificationFlow[]>
464
+ ```
465
+
466
+ | | |
467
+ |--|--|
468
+ | Auth | Required |
469
+ | HTTP | Composite — executions + validation + settlement + timeline |
470
+ | Returns | Verification flows for recent or specified execution(s) |
471
+
472
+ Helpers `buildReceiptVerificationFlow()`, `inferProofTier()`, and `validateExecutionReceipt()` are exported. See `pnpm example:receipt-verification`.
473
+
474
+ ### `runPortfolioWatchDemo(input?)`
475
+
476
+ ```ts
477
+ async runPortfolioWatchDemo(input?: {
478
+ brief?: string;
479
+ host?: "cursor" | "claude" | "mcp";
480
+ }): Promise<PortfolioWatchFlow>
481
+ ```
482
+
483
+ | | |
484
+ |--|--|
485
+ | Auth | Required |
486
+ | HTTP | Composite — `applyFinancialIntent` + market event (`autoRestore: true`) + timeline |
487
+ | Returns | Portfolio watch flow — register → while away → return briefing |
488
+ | Use | agent-in-host demo |
489
+
490
+ ### `getPortfolioWatchFlow(input?)`
491
+
492
+ ```ts
493
+ async getPortfolioWatchFlow(input?: {
494
+ objectiveId?: string;
495
+ brief?: string;
496
+ host?: "cursor" | "claude" | "mcp";
497
+ }): Promise<PortfolioWatchFlow[]>
498
+ ```
499
+
500
+ | | |
501
+ |--|--|
502
+ | Auth | Required |
503
+ | HTTP | Composite — Automatic objectives + health + allocation + timeline |
504
+ | Returns | Read-only briefing for active Automatic objectives |
505
+
506
+ Helpers `buildPortfolioWatchFlow()`, `DEFAULT_PORTFOLIO_WATCH_BRIEF`, and `inferPortfolioWatchPhase()` are exported. See `pnpm example:portfolio-watch`.
507
+
508
+ ### `runFullAureonLoopDemo(input?)`
509
+
510
+ ```ts
511
+ async runFullAureonLoopDemo(input?: {
512
+ brief?: string;
513
+ }): Promise<FullAureonLoopFlow>
514
+ ```
515
+
516
+ | | |
517
+ |--|--|
518
+ | Auth | Required |
519
+ | HTTP | Composite — intent + allocation paradox + restore (`autoRestore: false`) + receipt verification |
520
+ | Returns | Full loop — intent → plan check → restore → verify |
521
+ | Use | Content Arc — full AUREON loop positioning demo |
522
+
523
+ ### `getFullAureonLoopFlow(input?)`
524
+
525
+ ```ts
526
+ async getFullAureonLoopFlow(input?: {
527
+ objectiveId?: string;
528
+ brief?: string;
529
+ }): Promise<FullAureonLoopFlow[]>
530
+ ```
531
+
532
+ | | |
533
+ |--|--|
534
+ | Auth | Required |
535
+ | HTTP | Composite — objectives + allocation + latest receipt + validation |
536
+ | Returns | Read-only full-loop flows for active objectives with receipts |
537
+
538
+ Helpers `buildFullAureonLoopFlow()`, `DEFAULT_FULL_LOOP_BRIEF`, and `inferFullAureonLoopPhase()` are exported. See `pnpm example:full-aureon-loop`.
539
+
540
+ ---
541
+
542
+ ## 6. Vault
543
+
544
+ Vault reads and prepare endpoints. The API returns calldata **steps**; the host wallet signs and broadcasts, meaning the API never holds user keys.
545
+
546
+ ### `getVault()`
547
+
548
+ ```ts
549
+ async getVault(): Promise<VaultOverview>
550
+ ```
551
+
552
+ | | |
553
+ |--|--|
554
+ | Auth | Required |
555
+ | HTTP | `GET /vault` |
556
+ | Returns | `address`, `chainId`, `tokens`, `balances`, `poolAddress`, `explorerBase`, `keeperAddress` |
557
+
558
+ ### `getVaultStatus()`
559
+
560
+ ```ts
561
+ async getVaultStatus(): Promise<VaultStatus>
562
+ // { empty, totalNotionalUsd, canRestore }
563
+ ```
564
+
565
+ | | |
566
+ |--|--|
567
+ | Auth | Required |
568
+ | HTTP | `GET /vault/status` |
569
+ | Use | Compact funding signal before restore |
570
+
571
+ ### `prepareVaultDeposit({ symbol, amount })`
572
+
573
+ ```ts
574
+ async prepareVaultDeposit(input: {
575
+ symbol: string; // "ETH" or any allowlisted ERC-20 (WETH, stables, …)
576
+ amount: string;
577
+ }): Promise<VaultPrepareResult>
578
+ ```
579
+
580
+ | | |
581
+ |--|--|
582
+ | Auth | Required |
583
+ | HTTP | `POST /vault/prepare-deposit` body `{ symbol, amount }` |
584
+ | ETH | Steps include `depositETH` (native value on step → vault WETH) |
585
+ | ERC-20 | Steps include `approve` then `deposit` for any allowlisted symbol |
586
+ | Host duty | Sign `steps` in order on `chainId`; broadcast each tx |
587
+
588
+ ### `prepareVaultWithdraw({ symbol?, amount })`
589
+
590
+ ```ts
591
+ async prepareVaultWithdraw(input: {
592
+ symbol?: string; // default "WETH"; any vault ERC-20 held by the user
593
+ amount: string;
594
+ }): Promise<VaultPrepareResult>
595
+ ```
596
+
597
+ | | |
598
+ |--|--|
599
+ | Auth | Required |
600
+ | HTTP | `POST /vault/prepare-withdraw` body `{ symbol, amount }` |
601
+ | Symbol | Any allowlisted vault ERC-20 (not native ETH, use WETH) |
602
+ | Host duty | Sign and broadcast returned `steps` |
603
+
604
+ ---
605
+
606
+ ## 7. Market and execution
607
+
608
+ ### Launch / rehearsal flow
609
+
610
+ ```mermaid
611
+ sequenceDiagram
612
+ participant App
613
+ participant SDK
614
+ participant API
615
+
616
+ App->>SDK: listMarketPresets
617
+ API-->>App: presets
618
+ App->>SDK: applyMarketEvent autoRestore true
619
+ API-->>App: event + portfolio + health + executions
620
+ Note over API: may run vault or staged restore
621
+ App->>SDK: getTimeline
622
+ API-->>App: violation_detected execution_completed
623
+ ```
624
+
625
+ ### `listMarketPresets()`
626
+
627
+ ```ts
628
+ async listMarketPresets(): Promise<MarketPreset[]>
629
+ ```
630
+
631
+ | | |
632
+ |--|--|
633
+ | Auth | Required |
634
+ | HTTP | `GET /market/presets` |
635
+ | Unwrap | `{ presets }` |
636
+ | Fields | `name`, `description`, `symbol`, `priceChangeRatio` |
637
+
638
+ ### `applyMarketEvent(input)`
639
+
640
+ ```ts
641
+ async applyMarketEvent(input: ApplyMarketEventInput): Promise<{
642
+ event: MarketEvent;
643
+ portfolio: PortfolioSnapshot;
644
+ health: ObjectiveHealth[];
645
+ executions: ExecutionReceipt[];
646
+ }>
647
+ ```
648
+
649
+ | | |
650
+ |--|--|
651
+ | Auth | Required |
652
+ | HTTP | `POST /market/events` |
653
+ | Normalization | Uppercases symbol; `autoRestore` defaults **false** (must opt in to restore) |
654
+ | Validation | Symbol required; finite `priceChangeRatio`; rejects extreme ≤ -0.95 |
655
+
656
+ ### `getRestorePlan(objectiveId)`
657
+
658
+ ```ts
659
+ async getRestorePlan(objectiveId: string): Promise<RestorePlan>
660
+ // { kind, amountHuman, approxUsd, message, sellSymbol?, buySymbol? }
661
+ ```
662
+
663
+ | | |
664
+ |--|--|
665
+ | Auth | Required |
666
+ | HTTP | `GET /objectives/:id/restore-plan` |
667
+ | Kinds | `wrap_eth` · `unwrap_weth` · `vault_swap` |
668
+ | Use | Inspect plan before acting, noting that wrap/unwrap is client-side |
669
+
670
+ ### `runExecution(objectiveId)`
671
+
672
+ ```ts
673
+ async runExecution(objectiveId: string): Promise<ExecutionReceipt>
674
+ ```
675
+
676
+ | | |
677
+ |--|--|
678
+ | Auth | Required |
679
+ | HTTP | `POST /executions/run` body `{ objectiveId }` |
680
+ | Settlement | Receipt may include `settlement: "vault"` or `"staged"` |
681
+ | Use | Restore when plan kind is `vault_swap` (rejects wrap/unwrap with action details) |
682
+
683
+ ### `restoreObjective(objectiveId)`
684
+
685
+ ```ts
686
+ async restoreObjective(objectiveId: string): Promise<ExecutionReceipt>
687
+ ```
688
+
689
+ | | |
690
+ |--|--|
691
+ | Auth | Required |
692
+ | HTTP | `POST /objectives/:id/restore` |
693
+ | Settlement | Vault-backed restore when configured; same honesty labels as `runExecution` |
694
+ | Use | Preferred vault restore entry for Automatic objectives after breach |
695
+
696
+ ### `listExecutions(objectiveId?)`
697
+
698
+ ```ts
699
+ async listExecutions(objectiveId?: string): Promise<ExecutionReceipt[]>
700
+ ```
701
+
702
+ | | |
703
+ |--|--|
704
+ | Auth | Required |
705
+ | HTTP | `GET /executions` optional `?objectiveId=` |
706
+ | Unwrap | `{ executions }` |
707
+
708
+ ---
709
+
710
+ ## 8. Session helper
711
+
712
+ ```ts
713
+ import { createSessionTokenProvider } from "@buildaureon/sdk";
714
+
715
+ const session = createSessionTokenProvider(initialToken?: string | null);
716
+ session.getAccessToken(); // () => string | null
717
+ session.setToken(token);
718
+ session.clear();
719
+ ```
720
+
721
+ | Method | Purpose |
722
+ |--------|---------|
723
+ | `getAccessToken` | Pass directly into `createAureonClient({ getAccessToken })` |
724
+ | `setToken` | After `verifyWallet` / `devLogin` |
725
+ | `clear` | After `logout` or local sign-out |
726
+
727
+ ---
728
+
729
+ ## 9. Method → HTTP cheat sheet
730
+
731
+ | Method | Verb | Path | Auth |
732
+ |--------|------|------|------|
733
+ | `ping` | GET | `/healthz` | no |
734
+ | `getAuthNonce` | GET | `/auth/nonce` | no |
735
+ | `verifyWallet` | POST | `/auth/verify` | no |
736
+ | `devLogin` | POST | `/auth/dev-login` | no |
737
+ | `logout` | POST | `/auth/logout` | recommended |
738
+ | `me` | GET | `/auth/me` | **yes** |
739
+ | `createObjective` | POST | `/objectives` | **yes** |
740
+ | `listObjectives` | GET | `/objectives` | **yes** |
741
+ | `getObjective` | GET | `/objectives/:id` | **yes** |
742
+ | `updateObjective` | PATCH | `/objectives/:id` | **yes** |
743
+ | `pauseObjective` | POST | `/objectives/:id/pause` | **yes** |
744
+ | `resumeObjective` | POST | `/objectives/:id/resume` | **yes** |
745
+ | `getHealth` | GET | `/health` | **yes** |
746
+ | `getTimeline` | GET | `/timeline` | **yes** |
747
+ | `getPortfolio` | GET | `/portfolio` | **yes** |
748
+ | `setPortfolio` | PUT | `/portfolio` | **yes** |
749
+ | `clearPortfolio` | POST | `/portfolio/clear` | **yes** |
750
+ | `syncPortfolio` | POST | `/portfolio/sync` | **yes** |
751
+ | `refreshWatchdog` | POST | `/watchdog/refresh` | **yes** |
752
+ | `getOverview` | GET | `/overview` | **yes** |
753
+ | `getAllocationVsTarget` | composite | overview + objectives + health | **yes** |
754
+ | `applyFinancialIntent` | composite | create objective + health + portfolio | **yes** |
755
+ | `getObjectivePortfolioFlow` | composite | objectives + health + portfolio | **yes** |
756
+ | `runDriftRestoreDemo` | composite | seed + drift + manual restore | **yes** |
757
+ | `getDriftRestoreFlow` | composite | objectives + health + allocation + executions | **yes** |
758
+ | `runReceiptVerificationDemo` | composite | drift-restore + validate + settlement | **yes** |
759
+ | `getReceiptVerificationFlow` | composite | executions + validation + settlement | **yes** |
760
+ | `runPortfolioWatchDemo` | composite | intent + auto-restore market event + briefing | **yes** |
761
+ | `getPortfolioWatchFlow` | composite | Automatic objectives + health + timeline | **yes** |
762
+ | `runFullAureonLoopDemo` | composite | intent + plan paradox + restore + verify | **yes** |
763
+ | `getFullAureonLoopFlow` | composite | objectives + allocation + receipt validation | **yes** |
764
+ | `listMarketPresets` | GET | `/market/presets` | **yes** |
765
+ | `applyMarketEvent` | POST | `/market/events` | **yes** |
766
+ | `getRestorePlan` | GET | `/objectives/:id/restore-plan` | **yes** |
767
+ | `restoreObjective` | POST | `/objectives/:id/restore` | **yes** |
768
+ | `runExecution` | POST | `/executions/run` | **yes** |
769
+ | `listExecutions` | GET | `/executions` | **yes** |
770
+ | `getVault` | GET | `/vault` | **yes** |
771
+ | `getVaultStatus` | GET | `/vault/status` | **yes** |
772
+ | `prepareVaultDeposit` | POST | `/vault/prepare-deposit` | **yes** |
773
+ | `prepareVaultWithdraw` | POST | `/vault/prepare-withdraw` | **yes** |
774
+
775
+ ---
776
+
777
+ ## 10. Common error patterns
778
+
779
+ | Situation | Typical `code` | Integrator action |
780
+ |-----------|----------------|-------------------|
781
+ | Forgot Bearer on protected route | `UNAUTHORIZED` | Re-login / fix `getAccessToken` |
782
+ | Name too short on create | `VALIDATION_ERROR` | Fix form |
783
+ | Unknown objective id | `NOT_FOUND` | Refresh list |
784
+ | Backend restart mid-session | `UNAUTHORIZED` | Clear token, connect again |
785
+ | Transient 503 | `SERVER_ERROR` | Retries if `maxRetries > 0` |
786
+ | Offline | `NETWORK_ERROR` | Show connectivity banner |
787
+
788
+ Full matrix: [error-model.md](./error-model.md).