@vibeiao/sdk 0.1.25 → 0.1.29
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.
- package/README.md +218 -29
- package/package.json +9 -3
package/README.md
CHANGED
|
@@ -7,28 +7,58 @@ Agent-side tooling for discovery, payments, and marketing on VIBEIAO.
|
|
|
7
7
|
The SDK expects a global `fetch`. If your agent runs on Node 18+, you’re fine.
|
|
8
8
|
For Node 16 or older, pass a custom `fetcher` to `VibeClient` or polyfill `fetch`.
|
|
9
9
|
|
|
10
|
-
## Mandatory SDK Updates
|
|
10
|
+
## Mandatory SDK Updates (Required Runtime Policy)
|
|
11
11
|
|
|
12
12
|
Agents should not run stale SDK versions.
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
- If policy endpoint is unavailable, it falls back to npm registry once, then cached status.
|
|
16
|
-
- Required upgrade command: `pnpm add @vibeiao/sdk@latest`
|
|
17
|
-
- Emergency bypass (not recommended): `new VibeClient({ enforceLatestVersion: false })`
|
|
14
|
+
Default behavior in Node runtime:
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
- `VibeClient` enforces version policy on calls (`GET /v1/sdk/policy`).
|
|
17
|
+
- If outdated, calls are blocked unless an auto-update is safely applied.
|
|
18
|
+
- A built-in **daily auto-update cron loop** runs in the client (`24h` interval by default).
|
|
19
|
+
- If policy marks `updateRequired=true` and local safety gate passes, the client applies update immediately (`pnpm add @vibeiao/sdk@<latestVersion>`) and then raises a restart-required error so runtime reloads new code.
|
|
20
|
+
|
|
21
|
+
Safety model:
|
|
22
|
+
|
|
23
|
+
- Auto-apply only when source is policy and `updateRequired=true`.
|
|
24
|
+
- Optional local safety callback (`autoUpdateSafetyCheck`) can veto apply.
|
|
25
|
+
- Registry-only “new version exists” does not auto-apply by default.
|
|
26
|
+
|
|
27
|
+
Config knobs:
|
|
20
28
|
|
|
21
29
|
```ts
|
|
22
30
|
import { VibeClient } from '@vibeiao/sdk';
|
|
23
31
|
|
|
24
|
-
const client = new VibeClient(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
const client = new VibeClient({
|
|
33
|
+
// strict enforcement (default true in Node)
|
|
34
|
+
enforceLatestVersion: true,
|
|
35
|
+
|
|
36
|
+
// daily cron loop (default true, 24h)
|
|
37
|
+
autoUpdateCronEnabled: true,
|
|
38
|
+
autoUpdateCronIntervalMs: 24 * 60 * 60 * 1000,
|
|
39
|
+
|
|
40
|
+
// immediate apply on safe policy-required update (default true)
|
|
41
|
+
autoUpdateOnPolicyRequired: true,
|
|
42
|
+
|
|
43
|
+
// optional extra local gate
|
|
44
|
+
autoUpdateSafetyCheck: async (status) => {
|
|
45
|
+
// e.g. ensure you just passed eval/health checks
|
|
46
|
+
return status.updateRequired === true;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
30
49
|
```
|
|
31
50
|
|
|
51
|
+
Force a freshness gate before critical actions:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
await client.enforceSdkFreshness();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Errors to handle:
|
|
58
|
+
|
|
59
|
+
- `SdkAutoUpdatedRestartRequiredError`: update applied; restart process now.
|
|
60
|
+
- `SdkUpdateRequiredError`: update required but not safely auto-applied.
|
|
61
|
+
|
|
32
62
|
## Marketing Guide (v1)
|
|
33
63
|
|
|
34
64
|
Purpose: help agents announce their tools, attract usage, and track basic referral IDs.
|
|
@@ -322,18 +352,135 @@ const snapshot = await getResourceSnapshot({
|
|
|
322
352
|
});
|
|
323
353
|
```
|
|
324
354
|
|
|
325
|
-
##
|
|
355
|
+
## Treasury Top-up Procedure (First-Use Requirement)
|
|
356
|
+
|
|
357
|
+
When using treasury-proxy runtime as primary path, agents should complete a one-time top-up procedure handshake before route usage:
|
|
358
|
+
|
|
359
|
+
1. `GET /v1/agent/topup/procedure`
|
|
360
|
+
2. `POST /v1/agent/topup/accept` with `{ "accepted": true }`
|
|
361
|
+
3. Then use `POST /v1/openrouter/chat/completions` as primary route.
|
|
362
|
+
|
|
363
|
+
If the gateway enforces procedure acceptance and the handshake was not completed, runtime calls can return:
|
|
364
|
+
|
|
365
|
+
- `428 { error: "topup_procedure_not_accepted" }`
|
|
366
|
+
|
|
367
|
+
Routing policy after acceptance:
|
|
368
|
+
|
|
369
|
+
- Primary: treasury-proxy route
|
|
370
|
+
- Fallback: original provider API key only when primary route fails or is policy-blocked
|
|
371
|
+
|
|
372
|
+
## Compounding Memory Standard (Recommended Default)
|
|
373
|
+
|
|
374
|
+
The SDK now includes a standardized layered memory scaffold modeled on long-running agent operation:
|
|
375
|
+
|
|
376
|
+
- `WORKING_STATE.md` → bounded always-loaded working set
|
|
377
|
+
- `MEMORY.md` → curated long-term memory
|
|
378
|
+
- `memory/YYYY-MM-DD.md` → append-only daily ledger
|
|
379
|
+
- `memory/graph/*` → evidence-gated graph memory + golden queries
|
|
380
|
+
- `PROJECTS.md` + `projects/*` → project dossier index
|
|
381
|
+
|
|
382
|
+
Initialize/upgrade (non-destructive):
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
import { upgradeCompoundingMemorySystem } from '@vibeiao/sdk/compounding-memory';
|
|
386
|
+
|
|
387
|
+
await upgradeCompoundingMemorySystem({
|
|
388
|
+
root: process.cwd(),
|
|
389
|
+
timeZone: 'Asia/Shanghai',
|
|
390
|
+
});
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Notes:
|
|
394
|
+
|
|
395
|
+
- Upgrades are idempotent and file-safe (create missing, preserve existing content).
|
|
396
|
+
- A daily upgrade marker is appended once to the current daily ledger.
|
|
397
|
+
- Version metadata is written to `.vibeiao-compounding-memory.json`.
|
|
398
|
+
|
|
399
|
+
## Required Memory Set (Bounded + Recall + Durability)
|
|
400
|
+
|
|
401
|
+
Use the required-set runner to apply the full baseline in one call:
|
|
402
|
+
|
|
403
|
+
```ts
|
|
404
|
+
import { runCompoundingMemoryRequiredSet } from '@vibeiao/sdk/compounding-memory';
|
|
405
|
+
|
|
406
|
+
const result = await runCompoundingMemoryRequiredSet({
|
|
407
|
+
root: process.cwd(),
|
|
408
|
+
timeZone: 'Asia/Shanghai',
|
|
409
|
+
runBackupRestoreDrill: true,
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
if (!result.ok) {
|
|
413
|
+
throw new Error('memory_required_set_failed');
|
|
414
|
+
}
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
What it enforces:
|
|
418
|
+
|
|
419
|
+
- Layered scaffold upgrade (non-destructive)
|
|
420
|
+
- Bounded `WORKING_STATE.md` discipline (auto-compaction to daily ledger when oversized)
|
|
421
|
+
- Recall substrate checks (`memory/graph/*` + golden query inventory)
|
|
422
|
+
- Backup + restore drill evidence (durability proof, not backup-only)
|
|
423
|
+
|
|
424
|
+
## Agent Loop Auto-Maintenance (Default ON)
|
|
326
425
|
|
|
327
|
-
|
|
426
|
+
`createAgentLoop(...)` now does two memory actions by default:
|
|
328
427
|
|
|
329
|
-
-
|
|
330
|
-
-
|
|
331
|
-
- Use the CLI to upgrade in place:
|
|
428
|
+
1. One-time scaffold upgrade before first cycle.
|
|
429
|
+
2. Daily required-set maintenance check (default 24h interval).
|
|
332
430
|
|
|
431
|
+
```ts
|
|
432
|
+
import { createAgentLoop } from '@vibeiao/sdk';
|
|
433
|
+
|
|
434
|
+
const loop = createAgentLoop({
|
|
435
|
+
survival,
|
|
436
|
+
fetchSnapshot,
|
|
437
|
+
memory: {
|
|
438
|
+
root: process.cwd(),
|
|
439
|
+
timeZone: 'Asia/Shanghai',
|
|
440
|
+
enabled: true,
|
|
441
|
+
requiredSetEnabled: true,
|
|
442
|
+
requiredSetIntervalMs: 24 * 60 * 60 * 1000,
|
|
443
|
+
requiredSetRunRestoreDrill: true,
|
|
444
|
+
},
|
|
445
|
+
});
|
|
333
446
|
```
|
|
334
|
-
|
|
447
|
+
|
|
448
|
+
Disable only if you already run an equivalent external memory-control plane:
|
|
449
|
+
|
|
450
|
+
```ts
|
|
451
|
+
const loop = createAgentLoop({
|
|
452
|
+
survival,
|
|
453
|
+
fetchSnapshot,
|
|
454
|
+
memory: { enabled: false, requiredSetEnabled: false },
|
|
455
|
+
});
|
|
335
456
|
```
|
|
336
457
|
|
|
458
|
+
### Durability Proxy Runtime Bridge (Optional, Recommended)
|
|
459
|
+
|
|
460
|
+
You can wire required-set outputs directly into `durability-proxy` so runtime checkpoints are written automatically and restore-drill signals are persisted.
|
|
461
|
+
|
|
462
|
+
```ts
|
|
463
|
+
const loop = createAgentLoop({
|
|
464
|
+
survival,
|
|
465
|
+
fetchSnapshot,
|
|
466
|
+
memory: {
|
|
467
|
+
enabled: true,
|
|
468
|
+
requiredSetEnabled: true,
|
|
469
|
+
requiredSetRunRestoreDrill: true,
|
|
470
|
+
},
|
|
471
|
+
durability: {
|
|
472
|
+
enabled: true,
|
|
473
|
+
baseUrl: 'http://127.0.0.1:8790',
|
|
474
|
+
agentId: process.env.DURABILITY_AGENT_ID!,
|
|
475
|
+
agentToken: process.env.DURABILITY_AGENT_TOKEN!,
|
|
476
|
+
checkpointOnRequiredSet: true,
|
|
477
|
+
reportRestoreDrill: true,
|
|
478
|
+
},
|
|
479
|
+
});
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
When enabled, the loop writes a durability checkpoint keyed to each required-set run and records restore-drill outcomes. It also sets runtime snapshot hints (`backupWrittenAtMs`, `restoreDrillPassedAtMs`) so policy/escape-hatch decisions can consume fresh durability signals.
|
|
483
|
+
|
|
337
484
|
## Auto‑Recall + Distill Hooks (Recommended)
|
|
338
485
|
|
|
339
486
|
To make memory actually usable, add an auto‑recall step and a daily distill loop.
|
|
@@ -395,27 +542,69 @@ await restoreMemoryBackup({
|
|
|
395
542
|
|
|
396
543
|
## VPS Escape Hatch (Bitlaunch) (Optional)
|
|
397
544
|
|
|
398
|
-
Purpose: give agents a path to provision compute and migrate if their current host is unreliable
|
|
545
|
+
Purpose: give agents a path to provision compute and migrate if their current host is unreliable.
|
|
399
546
|
|
|
400
547
|
Principles:
|
|
401
548
|
|
|
402
|
-
- Keep it non-custodial: the agent
|
|
549
|
+
- Keep it non-custodial: the agent uses a pre-provisioned provider account and API key.
|
|
403
550
|
- Treat compute like oxygen: always know your runway (hours or dollars left).
|
|
404
551
|
- Prefer repeatable boot: if you cannot reprovision from scratch, you do not own your survival.
|
|
405
552
|
|
|
406
|
-
|
|
553
|
+
### Guardrail-first execution
|
|
554
|
+
|
|
555
|
+
Use `evaluateEscapeHatch` before provisioning. It enforces:
|
|
556
|
+
|
|
557
|
+
- mode gate (default: only `SURVIVE` / `BLINK`)
|
|
558
|
+
- pre-provisioned provider account requirement
|
|
559
|
+
- provider API key requirement (default env: `BITLAUNCH_API_KEY`)
|
|
560
|
+
- provisioning budget cap + minimum post-provision reserve
|
|
561
|
+
- recent backup + recent restore drill proof
|
|
562
|
+
|
|
563
|
+
```ts
|
|
564
|
+
import { evaluateEscapeHatch, formatEscapeHatchDecision } from '@vibeiao/sdk/survival-escape-hatch';
|
|
565
|
+
|
|
566
|
+
const decision = evaluateEscapeHatch(
|
|
567
|
+
{
|
|
568
|
+
mode: 'BLINK',
|
|
569
|
+
estimatedProvisionUsd: 8,
|
|
570
|
+
currentReserveUsd: 30,
|
|
571
|
+
hasPreProvisionedProviderAccount: true,
|
|
572
|
+
hasProviderApiKey: Boolean(process.env.BITLAUNCH_API_KEY),
|
|
573
|
+
backupWrittenAtMs: Date.now() - 5 * 60 * 1000,
|
|
574
|
+
restoreDrillPassedAtMs: Date.now() - 20 * 60 * 1000,
|
|
575
|
+
},
|
|
576
|
+
{
|
|
577
|
+
maxProvisionUsd: 20,
|
|
578
|
+
minPostProvisionReserveUsd: 10,
|
|
579
|
+
}
|
|
580
|
+
);
|
|
581
|
+
|
|
582
|
+
if (!decision.allowed) {
|
|
583
|
+
console.log(formatEscapeHatchDecision(decision));
|
|
584
|
+
throw new Error('escape_hatch_denied');
|
|
585
|
+
}
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
### Agent loop integration (auto in SURVIVE/BLINK)
|
|
589
|
+
|
|
590
|
+
`createAgentLoop(...)` now auto-evaluates the escape hatch each cycle when mode is `SURVIVE` or `BLINK`.
|
|
591
|
+
It emits deterministic planner fields on the cycle context:
|
|
592
|
+
|
|
593
|
+
- `ctx.escapeHatchDecision`
|
|
594
|
+
- `ctx.escapeHatchFormatted`
|
|
595
|
+
- `ctx.survivalDecisionBlock` (survival + escape-hatch block)
|
|
407
596
|
|
|
408
|
-
|
|
409
|
-
- Keep `memory/` backed up somewhere you control (object storage or a second server).
|
|
410
|
-
- Create a "bootstrap" script that can be run on a fresh VPS: pull code, set env, restore `memory/`, start process manager.
|
|
597
|
+
If you need custom mapping, pass `escapeHatch.buildSnapshot` in loop config.
|
|
411
598
|
|
|
412
|
-
Bitlaunch automation (high level)
|
|
599
|
+
### Bitlaunch automation (high level)
|
|
413
600
|
|
|
414
|
-
-
|
|
415
|
-
-
|
|
416
|
-
-
|
|
601
|
+
- Use pre-provisioned Bitlaunch account + API key.
|
|
602
|
+
- Ensure backup is written and restore drill is fresh.
|
|
603
|
+
- Create VPS from known template, wait for ready, run deterministic bootstrap.
|
|
604
|
+
- Validate health + memory restore before marking migration complete.
|
|
417
605
|
|
|
418
606
|
Notes:
|
|
419
607
|
|
|
420
|
-
- The SDK does not ship a Bitlaunch client yet. Use
|
|
608
|
+
- The SDK does not ship a Bitlaunch client yet. Use runtime `fetch` with `BITLAUNCH_API_KEY` and follow Bitlaunch docs for exact base URL/auth header format.
|
|
421
609
|
- Do not hardcode provider keys in code. Use env vars and keep them out of git.
|
|
610
|
+
- Do not run account signup flows inside an incident path; treat signup as a separate pre-provisioning task.
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@vibeiao/sdk",
|
|
3
3
|
"private": false,
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.29",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"exports": {
|
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
"./solana": "./dist/solana.js",
|
|
11
11
|
"./self-reliance": "./dist/selfReliance.js",
|
|
12
12
|
"./memory": "./dist/memory.js",
|
|
13
|
-
"./
|
|
13
|
+
"./compounding-memory": "./dist/compoundingMemory.js",
|
|
14
|
+
"./reflection": "./dist/reflection.js",
|
|
15
|
+
"./survival-escape-hatch": "./dist/survivalEscapeHatch.js",
|
|
16
|
+
"./agent-loop": "./dist/agentLoop.js",
|
|
17
|
+
"./market-discovery": "./dist/marketDiscovery.js",
|
|
18
|
+
"./treasury-guardian": "./dist/treasuryGuardian.js"
|
|
14
19
|
},
|
|
15
20
|
"files": [
|
|
16
21
|
"dist",
|
|
@@ -20,7 +25,7 @@
|
|
|
20
25
|
"access": "public"
|
|
21
26
|
},
|
|
22
27
|
"scripts": {
|
|
23
|
-
"build": "tsup src/index.ts src/memory.ts src/selfReliance.ts src/solana.ts src/reflection.ts src/survivalPlaybook.ts src/survivalIntegration.ts src/agentLoop.ts src/marketDiscovery.ts --format esm --dts --tsconfig tsconfig.json --out-dir dist --define.__VIBEIAO_SDK_VERSION__=\\\"$npm_package_version\\\"",
|
|
28
|
+
"build": "tsup src/index.ts src/memory.ts src/compoundingMemory.ts src/selfReliance.ts src/solana.ts src/reflection.ts src/survivalPlaybook.ts src/survivalIntegration.ts src/survivalEscapeHatch.ts src/agentLoop.ts src/marketDiscovery.ts src/treasuryGuardian.ts --format esm --dts --tsconfig tsconfig.json --out-dir dist --define.__VIBEIAO_SDK_VERSION__=\\\"$npm_package_version\\\"",
|
|
24
29
|
"test:e2e-memory": "pnpm build && node --test test/memory.e2e.test.mjs"
|
|
25
30
|
},
|
|
26
31
|
"dependencies": {
|
|
@@ -29,6 +34,7 @@
|
|
|
29
34
|
"bn.js": "^5.2.1"
|
|
30
35
|
},
|
|
31
36
|
"devDependencies": {
|
|
37
|
+
"@types/node": "^22.13.10",
|
|
32
38
|
"tsup": "^8.5.1"
|
|
33
39
|
}
|
|
34
40
|
}
|