@autonoma-ai/sdk 0.2.2 → 0.2.4-canary.2dc39bb

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 (2) hide show
  1. package/README.md +30 -15
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @autonoma-ai/sdk
2
2
 
3
- Core protocol layer for the Autonoma Environment Factory. Handles HMAC verification, JWT-signed teardown tokens, FK graph ordering, and the `discover`/`up`/`down` request lifecycle.
3
+ Core protocol layer for the Autonoma Environment Factory. Handles HMAC verification, JWT-signed teardown tokens, dependency ordering from `_alias`/`_ref` graphs, and the `discover`/`up`/`down` request lifecycle.
4
4
 
5
- This package is the shared dependency of all ORM and server adapters — you don't need to install it directly unless you're building a custom adapter.
5
+ This package is the shared dependency of all server adapters — you don't need to install it directly unless you're building a custom adapter.
6
6
 
7
7
  ## Install
8
8
 
@@ -14,7 +14,7 @@ pnpm add @autonoma-ai/sdk
14
14
 
15
15
  ### `handleRequest(config, request)`
16
16
 
17
- Main entry point. Routes `discover`, `up`, and `down` actions, verifies HMAC, and delegates to the ORM adapter.
17
+ Main entry point. Routes `discover`, `up`, and `down` actions, verifies HMAC, and delegates to registered factories.
18
18
 
19
19
  ```typescript
20
20
  import { handleRequest } from '@autonoma-ai/sdk'
@@ -23,6 +23,26 @@ const response = await handleRequest(config, { body, headers })
23
23
  // { status: 200, body: { ... } }
24
24
  ```
25
25
 
26
+ ### `defineFactory({ inputSchema, create, teardown?, refSchema? })`
27
+
28
+ Defines a factory for a model. `inputSchema` is a Zod schema that the SDK uses to derive the discover response — no database introspection needed.
29
+
30
+ ```typescript
31
+ import { defineFactory } from '@autonoma-ai/sdk'
32
+ import { z } from 'zod'
33
+
34
+ const Organization = defineFactory({
35
+ inputSchema: z.object({ name: z.string(), slug: z.string() }),
36
+ create: async (data, ctx) => {
37
+ const org = await db.organization.create({ data })
38
+ return { id: org.id, ...data }
39
+ },
40
+ teardown: async (record, ctx) => {
41
+ await db.organization.delete({ where: { id: record.id } })
42
+ },
43
+ })
44
+ ```
45
+
26
46
  ### `checkScenario(adapter, scenario)`
27
47
 
28
48
  Dry-run a scenario against a real database — full create-then-teardown cycle. Use this in integration tests to validate scenario data before deploying.
@@ -35,30 +55,26 @@ const result = await checkScenario(adapter, {
35
55
  Organization: [{
36
56
  name: 'Test Org',
37
57
  slug: 'test-org',
38
- users: [{ email: 'admin@test.com', name: 'Admin' }],
58
+ _alias: 'org1',
39
59
  }],
40
60
  },
41
61
  })
42
62
 
43
- // result.valid true/false
44
- // result.phase 'ok' | 'up' | 'down'
45
- // result.errors [{ message, fix }]
46
- // result.timing { upMs, downMs }
63
+ // result.valid -> true/false
64
+ // result.phase -> 'ok' | 'up' | 'down'
65
+ // result.errors -> [{ message, fix }]
66
+ // result.timing -> { upMs, downMs }
47
67
  ```
48
68
 
49
- ### `checkAllScenarios(adapter, scenarios)`
50
-
51
- Runs `checkScenario` for each scenario definition and returns all results.
52
-
53
69
  ### Graph utilities (`@autonoma-ai/sdk/graph`)
54
70
 
55
- Exported from the `/graph` subpath for use in ORM adapters:
71
+ Exported from the `/graph` subpath:
56
72
 
57
73
  ```typescript
58
74
  import { topoSort, findDeferrableEdge } from '@autonoma-ai/sdk/graph'
59
75
  ```
60
76
 
61
- - `topoSort(edges)` — Kahn's algorithm + Tarjan's SCC for FK-ordered entity creation
77
+ - `topoSort(edges)` — Kahn's algorithm + Tarjan's SCC for dependency ordering
62
78
  - `findDeferrableEdge(scc, edges)` — finds a nullable FK in a cycle to break it
63
79
 
64
80
  ### Other exports
@@ -67,7 +83,6 @@ import { topoSort, findDeferrableEdge } from '@autonoma-ai/sdk/graph'
67
83
  |--------|-----|
68
84
  | `signBody` / `verifySignature` | HMAC-SHA256 signing for request auth |
69
85
  | `signRefs` / `verifyRefs` | JWT-like token for signing teardown refs |
70
- | `resolveTree` | Nested scenario tree → flat entity list with auto-wired FKs |
71
86
  | `fingerprint` | Deterministic hash of scenario definitions |
72
87
 
73
88
  ## Documentation
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autonoma-ai/sdk",
3
- "version": "0.2.2",
3
+ "version": "0.2.4-canary.2dc39bb",
4
4
  "description": "Autonoma Environment Factory SDK — protocol layer",
5
5
  "type": "module",
6
6
  "exports": {