@oneie/sdk 0.9.0 → 0.10.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receivers.d.ts","sourceRoot":"","sources":["../src/receivers.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,626 @@
1
+ import { z } from "zod";
2
+ import { AgentActionResponseSchema, AgentStatusResponseSchema, CapabilityItemSchema, PayResponseSchema, RegisterResponseSchema, StatsSchema, } from "./schemas.js";
3
+ /**
4
+ * Declare a receiver contract. Identity at runtime — its only job is to pin the
5
+ * `Req`/`Res` generics so the catalog infers payload + outcome types.
6
+ */
7
+ export function receiver(r) {
8
+ return r;
9
+ }
10
+ const ok = z.object({ ok: z.boolean() });
11
+ /**
12
+ * The receiver catalog — one source of truth for capability. Object-literal keys
13
+ * are always literal, so `keyof typeof RECEIVERS` yields the declared receiver
14
+ * names and `ask<R>` infers payload + outcome by inference (no codegen).
15
+ *
16
+ * Populated incrementally: C2 = spine + 21 `world:*` + `grant-capability`;
17
+ * C4 = remaining families with metadata; C5 = the `meta:` family.
18
+ */
19
+ export const RECEIVERS = {
20
+ // ── Spine (non-world) — contracts only this cycle; route-wiring lands in C4 ──
21
+ "auth:agent": receiver({
22
+ receiver: "auth:agent",
23
+ summary: "Become an actor — mint a uid, wallet, and scoped API key",
24
+ request: z.object({ name: z.string().optional(), uid: z.string().optional(), kind: z.string().optional() }),
25
+ response: z.object({
26
+ uid: z.string(), name: z.string(), kind: z.string(),
27
+ wallet: z.string().nullable(), apiKey: z.string(), keyId: z.string(), returning: z.boolean(),
28
+ }),
29
+ effect: "ask",
30
+ reversible: false,
31
+ idempotent: true,
32
+ }),
33
+ "agents:sync": receiver({
34
+ receiver: "agents:sync",
35
+ summary: "Declare capability — sync agent definitions, skills, and memberships",
36
+ // Accepts a single markdown body or a structured multi-agent world payload.
37
+ request: z.union([
38
+ z.object({ markdown: z.string() }),
39
+ z.object({
40
+ agents: z.array(z.object({ name: z.string().optional(), content: z.string() })),
41
+ world: z.string().optional(),
42
+ description: z.unknown().optional(),
43
+ }),
44
+ ]),
45
+ response: z.object({
46
+ ok: z.boolean(), agent: z.string().optional(), uid: z.string().optional(),
47
+ wallet: z.string().nullable().optional(), suiObjectId: z.string().nullable().optional(),
48
+ skills: z.array(z.string()).optional(), world: z.string().optional(),
49
+ }).passthrough(),
50
+ effect: "ask",
51
+ }),
52
+ // ── world:* — workspace / actor / thing / key / path / learning mutations ──
53
+ "world:create-workspace": receiver({
54
+ receiver: "world:create-workspace",
55
+ summary: "Create a workspace; optionally provision a full billing-aware client (parent + credits + brand + starter agents) in one atomic call",
56
+ request: z.object({
57
+ name: z.string(),
58
+ slug: z.string(),
59
+ ownerEmail: z.string().email().optional(),
60
+ // Extended atomic client provision (optional — omit for a bare workspace).
61
+ parent: z.string().optional(),
62
+ plan: z.enum(["free", "pro", "studio", "agency", "enterprise"]).optional(),
63
+ credit: z.number().int().nonnegative().optional(),
64
+ markup: z.number().int().min(0).max(100).optional(),
65
+ cap: z.number().int().nonnegative().nullable().optional(),
66
+ brand: z.boolean().optional(),
67
+ agents: z.array(z.string()).optional(),
68
+ }),
69
+ response: z.object({ wsid: z.string(), slug: z.string() }),
70
+ effect: "ask", auth: "manage_workspace", reversible: false,
71
+ examples: [
72
+ { name: "Acme", slug: "acme", ownerEmail: "owner@acme.com" },
73
+ { name: "Acme", slug: "acme", parent: "donal", plan: "studio", credit: 50000, markup: 20, cap: 50000, brand: true, agents: ["sales", "support"] },
74
+ ],
75
+ }),
76
+ "world:invite-client": receiver({
77
+ receiver: "world:invite-client",
78
+ summary: "Agency mints a scoped invite; on accept the invitee owns a new workspace parented under the agency",
79
+ request: z.object({
80
+ slug: z.string(),
81
+ name: z.string().optional(),
82
+ email: z.string().email().optional(),
83
+ plan: z.enum(["free", "pro", "studio", "agency", "enterprise"]).optional(),
84
+ credits: z.number().int().nonnegative().optional(),
85
+ markup: z.number().int().min(0).max(100).optional(),
86
+ cap: z.number().int().nonnegative().nullable().optional(),
87
+ brand: z.boolean().optional(),
88
+ agents: z.array(z.string()).optional(),
89
+ }),
90
+ response: z.object({ token: z.string(), id: z.string(), child: z.string(), expiresAt: z.number() }),
91
+ effect: "ask", auth: "manage_clients", reversible: false,
92
+ examples: [{ slug: "beta", email: "owner@beta.com", plan: "studio", credits: 50000, markup: 20 }],
93
+ }),
94
+ "world:accept-client-invite": receiver({
95
+ receiver: "world:accept-client-invite",
96
+ summary: "Redeem a client invite — creates the workspace owned by the invitee (single-use, replay-protected)",
97
+ request: z.object({ token: z.string(), email: z.string().email().optional(), name: z.string().optional() }),
98
+ response: z.object({ wsid: z.string(), slug: z.string(), owner: z.string(), parent: z.string() }),
99
+ effect: "ask", reversible: false, idempotent: false,
100
+ }),
101
+ "world:invite-member": receiver({
102
+ receiver: "world:invite-member",
103
+ summary: "Invite a human member to a workspace",
104
+ request: z.object({ workspace: z.string(), email: z.string().email(), role: z.string().optional() }),
105
+ response: z.object({ ok: z.boolean(), uid: z.string() }),
106
+ effect: "ask", auth: "manage_members",
107
+ }),
108
+ "world:remove-member": receiver({
109
+ receiver: "world:remove-member",
110
+ summary: "Remove a member from a workspace",
111
+ request: z.object({ workspace: z.string(), aid: z.string() }),
112
+ response: ok, effect: "ask", auth: "manage_members", reversible: false,
113
+ }),
114
+ "world:suspend-workspace": receiver({
115
+ receiver: "world:suspend-workspace",
116
+ summary: "Suspend a workspace",
117
+ request: z.object({ workspace: z.string() }),
118
+ response: ok, effect: "ask", auth: "manage_workspace",
119
+ }),
120
+ "world:create-group": receiver({
121
+ receiver: "world:create-group",
122
+ summary: "Create a group in the caller's workspace",
123
+ request: z.object({ name: z.string(), type: z.string(), tags: z.array(z.string()).optional() }),
124
+ response: z.object({ gid: z.string() }), effect: "ask", auth: "manage_groups",
125
+ }),
126
+ "world:update-group": receiver({
127
+ receiver: "world:update-group",
128
+ summary: "Update a group's name, tags, or meta",
129
+ request: z.object({ gid: z.string(), name: z.string().optional(), tags: z.array(z.string()).optional(), meta: z.unknown().optional() }),
130
+ response: ok, effect: "ask", auth: "manage_groups",
131
+ }),
132
+ "world:remove-group": receiver({
133
+ receiver: "world:remove-group",
134
+ summary: "Delete a group",
135
+ request: z.object({ gid: z.string() }), response: ok, effect: "ask", auth: "manage_groups", reversible: false,
136
+ }),
137
+ "world:create-actor": receiver({
138
+ receiver: "world:create-actor",
139
+ summary: "Create an actor (agent or human) in the world",
140
+ request: z.object({
141
+ name: z.string(), type: z.string(), group: z.string().optional(),
142
+ tags: z.array(z.string()).optional(), model: z.string().optional(), prompt: z.string().optional(),
143
+ }),
144
+ response: z.object({ aid: z.string() }), effect: "ask", auth: "manage_actors",
145
+ examples: [{ name: "scout", type: "agent" }],
146
+ }),
147
+ "world:update-actor": receiver({
148
+ receiver: "world:update-actor",
149
+ summary: "Update an actor's name, tags, prompt, or model",
150
+ request: z.object({ aid: z.string(), name: z.string().optional(), tags: z.array(z.string()).optional(), prompt: z.string().optional(), model: z.string().optional() }),
151
+ response: ok, effect: "ask", auth: "manage_actors",
152
+ }),
153
+ "world:remove-actor": receiver({
154
+ receiver: "world:remove-actor",
155
+ summary: "Delete an actor",
156
+ request: z.object({ aid: z.string() }), response: ok, effect: "ask", auth: "manage_actors", reversible: false,
157
+ }),
158
+ "world:create-key": receiver({
159
+ receiver: "world:create-key",
160
+ summary: "Mint a scoped API key for an actor",
161
+ request: z.object({ actor: z.string(), scope: z.string().optional(), label: z.string().optional() }),
162
+ response: z.object({ key: z.string(), keyId: z.string() }), effect: "ask", auth: "manage_keys",
163
+ reversible: false,
164
+ }),
165
+ "world:revoke-key": receiver({
166
+ receiver: "world:revoke-key",
167
+ summary: "Revoke an API key",
168
+ request: z.object({ keyId: z.string() }), response: ok, effect: "ask", auth: "manage_keys", reversible: false,
169
+ }),
170
+ "world:create-thing": receiver({
171
+ receiver: "world:create-thing",
172
+ summary: "Create a thing (skill, token, product) in the world",
173
+ request: z.object({ name: z.string(), type: z.string(), group: z.string().optional(), tags: z.array(z.string()).optional(), price: z.number().optional() }),
174
+ response: z.object({ tid: z.string() }), effect: "ask", auth: "manage_things",
175
+ }),
176
+ "world:update-thing": receiver({
177
+ receiver: "world:update-thing",
178
+ summary: "Update a thing's name, tags, price, or meta",
179
+ request: z.object({ tid: z.string(), name: z.string().optional(), tags: z.array(z.string()).optional(), price: z.number().optional(), meta: z.unknown().optional() }),
180
+ response: ok, effect: "ask", auth: "manage_things",
181
+ }),
182
+ "world:remove-thing": receiver({
183
+ receiver: "world:remove-thing",
184
+ summary: "Delete a thing",
185
+ request: z.object({ tid: z.string() }), response: ok, effect: "ask", auth: "manage_things", reversible: false,
186
+ }),
187
+ "world:freeze-path": receiver({
188
+ receiver: "world:freeze-path",
189
+ summary: "Freeze a path so decay cannot weaken it",
190
+ request: z.object({ edge: z.string() }), response: ok, effect: "ask", auth: "manage_paths",
191
+ }),
192
+ "world:unfreeze-path": receiver({
193
+ receiver: "world:unfreeze-path",
194
+ summary: "Unfreeze a path",
195
+ request: z.object({ edge: z.string() }), response: ok, effect: "ask", auth: "manage_paths",
196
+ }),
197
+ "world:remove-path": receiver({
198
+ receiver: "world:remove-path",
199
+ summary: "Delete a path",
200
+ request: z.object({ edge: z.string() }), response: ok, effect: "ask", auth: "manage_paths", reversible: false,
201
+ }),
202
+ "world:create-hypothesis": receiver({
203
+ receiver: "world:create-hypothesis",
204
+ summary: "Record a hypothesis for later verification",
205
+ request: z.object({ claim: z.string(), tags: z.array(z.string()).optional(), confidence: z.number().optional() }),
206
+ response: z.object({ hid: z.string() }), effect: "ask", auth: "manage_learning",
207
+ }),
208
+ "world:promote-hypothesis": receiver({
209
+ receiver: "world:promote-hypothesis",
210
+ summary: "Promote a hypothesis to confirmed",
211
+ request: z.object({ hid: z.string() }), response: ok, effect: "ask", auth: "manage_learning",
212
+ }),
213
+ "world:reject-hypothesis": receiver({
214
+ receiver: "world:reject-hypothesis",
215
+ summary: "Reject a hypothesis with a reason",
216
+ request: z.object({ hid: z.string(), reason: z.string().optional() }), response: ok, effect: "ask", auth: "manage_learning",
217
+ }),
218
+ // ── grant-capability — capability grant (intercepted in signal/[receiver].ts) ──
219
+ "grant-capability": receiver({
220
+ receiver: "grant-capability",
221
+ summary: "Issue a scoped, time-boxed capability grant to a principal",
222
+ request: z.object({
223
+ grantee: z.string().min(1),
224
+ actions: z.array(z.string()).min(1),
225
+ scope: z.string().min(1),
226
+ valid_from: z.number(),
227
+ valid_to: z.number(),
228
+ }).refine((g) => g.valid_to > g.valid_from, { message: "valid_to must be after valid_from", path: ["valid_to"] }),
229
+ response: z.object({ outcome: z.literal("granted"), id: z.string(), grantee: z.string(), scope: z.string() }),
230
+ effect: "ask", auth: "mint_capability", reversible: false,
231
+ }),
232
+ // ════════════════════════════════════════════════════════════════════════
233
+ // C4 — remaining families (sequenced by recipe: identity → groups → BUILD
234
+ // → TRADE → TRANSACT → reads). Request schemas mirror the exact client.ts
235
+ // call sites so a wrong payload is a compile error (the C3 mechanism).
236
+ // ════════════════════════════════════════════════════════════════════════
237
+ // ── identity ──
238
+ "identity:address": receiver({
239
+ receiver: "identity:address",
240
+ summary: "Resolve an actor's wallet address",
241
+ request: z.object({ uid: z.string() }),
242
+ response: z.object({ uid: z.string(), address: z.string() }),
243
+ effect: "ask", cost: "free", idempotent: true,
244
+ }),
245
+ // ── auth (human session) ──
246
+ "auth:sign-in": receiver({
247
+ receiver: "auth:sign-in",
248
+ summary: "Sign in a human with email + password",
249
+ request: z.object({ email: z.string(), password: z.string() }),
250
+ response: z.object({ sessionId: z.string(), userId: z.string() }),
251
+ effect: "ask", reversible: false,
252
+ }),
253
+ "auth:sign-out": receiver({
254
+ receiver: "auth:sign-out",
255
+ summary: "End the current session",
256
+ request: z.object({}),
257
+ response: ok,
258
+ effect: "signal", idempotent: true,
259
+ }),
260
+ // ── board ──
261
+ "board:join": receiver({
262
+ receiver: "board:join",
263
+ summary: "Join the public board as an actor",
264
+ request: z.object({ uid: z.string(), group: z.string().optional() }),
265
+ response: z.object({ ok: z.boolean(), uid: z.string(), group: z.string(), role: z.string() }),
266
+ effect: "ask", idempotent: true,
267
+ }),
268
+ // ── agency (oo operator surface) ──
269
+ "agency:push:complete": receiver({
270
+ receiver: "agency:push:complete",
271
+ summary: "An agency finished pushing agents/skills — logs the sync event",
272
+ request: z.object({ agents: z.number().int().nonnegative(), skills: z.number().int().nonnegative() }),
273
+ response: ok,
274
+ effect: "signal", idempotent: true,
275
+ }),
276
+ "agency:friction": receiver({
277
+ receiver: "agency:friction",
278
+ summary: "A /do cycle stalled in an agency repo — surfaces the friction back to ONE",
279
+ request: z.object({ agency: z.string(), cycle: z.string().nullable(), wave: z.string().nullable(), reason: z.string() }),
280
+ response: ok,
281
+ effect: "signal",
282
+ }),
283
+ // ── groups ──
284
+ "groups:join": receiver({
285
+ receiver: "groups:join",
286
+ summary: "Join a group",
287
+ request: z.object({ gid: z.string() }),
288
+ response: z.object({ ok: z.boolean(), gid: z.string(), role: z.string() }),
289
+ effect: "signal", idempotent: true,
290
+ }),
291
+ "groups:leave": receiver({
292
+ receiver: "groups:leave",
293
+ summary: "Leave a group",
294
+ request: z.object({ gid: z.string() }),
295
+ response: ok,
296
+ effect: "signal", idempotent: true,
297
+ }),
298
+ "groups:invite": receiver({
299
+ receiver: "groups:invite",
300
+ summary: "Invite an actor to a group",
301
+ request: z.object({ gid: z.string(), uid: z.string(), role: z.string().optional() }),
302
+ response: ok,
303
+ effect: "signal", auth: "manage_members",
304
+ }),
305
+ "groups:members": receiver({
306
+ receiver: "groups:members",
307
+ summary: "List a group's members",
308
+ request: z.object({ gid: z.string() }),
309
+ response: z.object({
310
+ gid: z.string(),
311
+ members: z.array(z.object({ uid: z.string(), name: z.string().optional(), role: z.string() })),
312
+ }),
313
+ effect: "ask", cost: "free", idempotent: true,
314
+ }),
315
+ "billing:clients": receiver({
316
+ receiver: "billing:clients",
317
+ summary: "Agency P&L — per-client funded · burned · margin · balance · cap (margin from the ledger)",
318
+ request: z.object({}).optional(),
319
+ response: z.object({
320
+ agency: z.object({ slug: z.string(), name: z.string().nullable(), markup_pct: z.number(), pool: z.number() }).nullable(),
321
+ clients: z.array(z.object({
322
+ slug: z.string(), name: z.string().nullable(), plan: z.string(),
323
+ funded: z.number(), burned: z.number(), margin: z.number(), balance: z.number(), cap: z.number().nullable(),
324
+ })),
325
+ }),
326
+ effect: "ask", auth: "manage_clients", cost: "free", idempotent: true,
327
+ }),
328
+ // ── paths ──
329
+ "paths:bridge": receiver({
330
+ receiver: "paths:bridge",
331
+ summary: "Bridge two actors or groups with a path",
332
+ request: z.object({ from: z.string(), to: z.string() }),
333
+ response: z.object({
334
+ ok: z.boolean().optional(),
335
+ status: z.enum(["pending", "bridged"]).optional(),
336
+ key: z.string().optional(), gid: z.string().optional(), awaiting: z.string().optional(),
337
+ }),
338
+ effect: "ask",
339
+ }),
340
+ // ── subscriptions ──
341
+ "subscriptions:register": receiver({
342
+ receiver: "subscriptions:register",
343
+ summary: "Subscribe to a receiver's events by tag",
344
+ request: z.object({
345
+ receiver: z.string(),
346
+ tags: z.array(z.string()),
347
+ scope: z.enum(["private", "public"]).optional(),
348
+ }),
349
+ response: ok,
350
+ effect: "signal", idempotent: true,
351
+ }),
352
+ // ── agents (TRADE / lifecycle) ──
353
+ "agents:register": receiver({
354
+ receiver: "agents:register",
355
+ summary: "Register an agent as a sellable actor with capabilities",
356
+ request: z.object({
357
+ uid: z.string(),
358
+ kind: z.string().optional(),
359
+ capabilities: z.array(z.object({ skill: z.string(), price: z.number().optional() })).optional(),
360
+ wallet: z.string().optional(),
361
+ chain: z.string().optional(),
362
+ }),
363
+ response: RegisterResponseSchema,
364
+ effect: "ask", idempotent: true,
365
+ }),
366
+ "agents:commend": receiver({
367
+ receiver: "agents:commend",
368
+ summary: "Commend an agent — strengthen its reputation path",
369
+ request: z.object({ uid: z.string() }),
370
+ response: AgentActionResponseSchema,
371
+ effect: "signal",
372
+ }),
373
+ "agents:flag": receiver({
374
+ receiver: "agents:flag",
375
+ summary: "Flag an agent — add resistance to its reputation path",
376
+ request: z.object({ uid: z.string() }),
377
+ response: AgentActionResponseSchema,
378
+ effect: "signal",
379
+ }),
380
+ "agents:status": receiver({
381
+ receiver: "agents:status",
382
+ summary: "Set an agent active or inactive",
383
+ request: z.object({ uid: z.string(), status: z.string() }),
384
+ response: AgentStatusResponseSchema,
385
+ effect: "signal", idempotent: true,
386
+ }),
387
+ "agents:capabilities": receiver({
388
+ receiver: "agents:capabilities",
389
+ summary: "List an agent's published capabilities",
390
+ request: z.object({ uid: z.string() }),
391
+ response: z.array(CapabilityItemSchema),
392
+ effect: "ask", cost: "free", idempotent: true,
393
+ }),
394
+ "agents:deploy-on-behalf": receiver({
395
+ receiver: "agents:deploy-on-behalf",
396
+ summary: "Deploy an agent on behalf of an owner, inheriting their paths",
397
+ request: z.object({ owner: z.string(), spec: z.record(z.string(), z.unknown()) }),
398
+ response: z.object({
399
+ ok: z.boolean(), uid: z.string(), owner: z.string(),
400
+ inheritedPaths: z.array(z.object({ from: z.string(), to: z.string(), strength: z.number() })),
401
+ }),
402
+ effect: "ask", reversible: false, simulatable: true,
403
+ }),
404
+ // ── pay (TRANSACT — onchain settlement) ──
405
+ "pay:weight": receiver({
406
+ receiver: "pay:weight",
407
+ summary: "Pay for a task by weighting the path between two actors",
408
+ request: z.object({ from: z.string(), to: z.string(), task: z.string(), amount: z.number() }),
409
+ response: PayResponseSchema,
410
+ effect: "ask", cost: "variable", settles: "onchain", reversible: false, simulatable: true,
411
+ }),
412
+ // ── market (TRADE) ──
413
+ "market:hire": receiver({
414
+ receiver: "market:hire",
415
+ summary: "Hire an agent for a skill — opens a chat or returns an escrow template",
416
+ request: z.object({ providerUid: z.string(), skillId: z.string(), initialMessage: z.string().optional() }),
417
+ response: z.union([
418
+ z.object({ ok: z.literal(true), groupId: z.string(), chatUrl: z.string() }),
419
+ z.object({
420
+ status: z.literal(402), code: z.string(),
421
+ escrow_template: z.record(z.string(), z.unknown()), expires_at: z.string(),
422
+ }),
423
+ ]),
424
+ effect: "ask", cost: "variable", settles: "onchain", reversible: false, simulatable: true,
425
+ }),
426
+ "market:bounty": receiver({
427
+ receiver: "market:bounty",
428
+ summary: "Post a bounty for a skill, backed by an escrow",
429
+ request: z.object({
430
+ skillId: z.string(), sellerUid: z.string(), posterUid: z.string(), price: z.number(),
431
+ tags: z.array(z.string()).optional(),
432
+ content: z.record(z.string(), z.unknown()).optional(),
433
+ rubric: z.object({
434
+ fit: z.number().optional(), form: z.number().optional(),
435
+ truth: z.number().optional(), taste: z.number().optional(),
436
+ }).optional(),
437
+ deadline: z.string().optional(),
438
+ posterUnitObjectId: z.string().optional(),
439
+ workerUnitObjectId: z.string().optional(),
440
+ pathObjectId: z.string().optional(),
441
+ }),
442
+ response: z.object({ id: z.string(), escrowId: z.string().optional(), data: z.record(z.string(), z.unknown()) }),
443
+ effect: "ask", cost: "variable", settles: "onchain", reversible: false, simulatable: true,
444
+ }),
445
+ "market:bounties": receiver({
446
+ receiver: "market:bounties",
447
+ summary: "List bounties, optionally filtered by seller or poster",
448
+ request: z.object({ seller: z.string().optional(), poster: z.string().optional() }),
449
+ response: z.array(z.object({
450
+ id: z.string(), skillId: z.string(), sellerUid: z.string(), posterUid: z.string(), price: z.number(),
451
+ tags: z.array(z.string()).optional(), deadline: z.string().optional(), status: z.string(),
452
+ })),
453
+ effect: "ask", cost: "free", idempotent: true,
454
+ }),
455
+ "market:list": receiver({
456
+ receiver: "market:list",
457
+ summary: "List the capability market",
458
+ request: z.object({ tag: z.string().optional(), maxPrice: z.number().optional() }),
459
+ response: z.object({ capabilities: z.array(z.unknown()) }),
460
+ effect: "ask", cost: "free", idempotent: true,
461
+ }),
462
+ // ── capabilities ──
463
+ "capabilities:publish": receiver({
464
+ receiver: "capabilities:publish",
465
+ summary: "Publish a capability (skill listing) to the market",
466
+ request: z.object({
467
+ skillId: z.string(), name: z.string(), price: z.number(),
468
+ mode: z.string().optional(), visibility: z.string().optional(), scope: z.string().optional(),
469
+ tags: z.array(z.string()).optional(),
470
+ rubricThresholds: z.object({
471
+ fit: z.number().optional(), form: z.number().optional(),
472
+ truth: z.number().optional(), taste: z.number().optional(),
473
+ }).optional(),
474
+ }),
475
+ response: z.object({ ok: z.literal(true), sid: z.string(), scope: z.string() }),
476
+ effect: "ask",
477
+ }),
478
+ // ── loop ──
479
+ "loop:close": receiver({
480
+ receiver: "loop:close",
481
+ summary: "Close a loop session with an outcome",
482
+ request: z.object({
483
+ session: z.string(),
484
+ outcome: z.enum(["result", "timeout", "dissolved", "failure"]),
485
+ rubric: z.number().optional(),
486
+ reason: z.string().optional(),
487
+ }),
488
+ response: z.object({
489
+ ok: z.literal(true), stages: z.array(z.unknown()),
490
+ highways: z.array(z.object({ path: z.string(), strength: z.number(), resistance: z.number(), net: z.number() })),
491
+ }),
492
+ effect: "ask",
493
+ }),
494
+ // ── reads (free · idempotent) ──
495
+ "signals:list": receiver({
496
+ receiver: "signals:list",
497
+ summary: "List recent signals",
498
+ request: z.object({
499
+ limit: z.number().optional(), since: z.number().optional(),
500
+ from: z.number().optional(), to: z.number().optional(),
501
+ }),
502
+ response: z.array(z.object({
503
+ id: z.string(), from: z.string(), to: z.string(), skill: z.string().optional(),
504
+ outcome: z.enum(["success", "failure", "timeout"]), revenue: z.number(), ts: z.number(),
505
+ })),
506
+ effect: "ask", cost: "free", idempotent: true,
507
+ }),
508
+ "stats:current": receiver({
509
+ receiver: "stats:current",
510
+ summary: "Current world stats — units, skills, highways, revenue, signals",
511
+ request: z.object({}),
512
+ response: StatsSchema,
513
+ effect: "ask", cost: "free", idempotent: true,
514
+ }),
515
+ "dashboard:usage": receiver({
516
+ receiver: "dashboard:usage",
517
+ summary: "Caller's plan usage — calls, agents, limits",
518
+ request: z.object({}),
519
+ response: z.object({
520
+ tier: z.string(), calls_this_month: z.number(), agents_count: z.number(),
521
+ api_limit: z.number(), agent_limit: z.number(), loops: z.array(z.string()),
522
+ highways_count: z.number(), upgrade_url: z.string(),
523
+ }),
524
+ effect: "ask", cost: "free", idempotent: true,
525
+ }),
526
+ "world:state": receiver({
527
+ receiver: "world:state",
528
+ summary: "Full world snapshot — units, edges, highways, tags, stats",
529
+ request: z.object({}),
530
+ response: z.object({}).passthrough(),
531
+ effect: "ask", cost: "free", idempotent: true,
532
+ }),
533
+ // ════════════════════════════════════════════════════════════════════════
534
+ // C5 — meta: the self-describing surface. Pure reads an agent uses to learn
535
+ // the catalog, a receiver's schema, and its own memory before acting. The
536
+ // catalog/schema handlers are pure projections over RECEIVERS (see meta.ts).
537
+ // ════════════════════════════════════════════════════════════════════════
538
+ "meta:catalog": receiver({
539
+ receiver: "meta:catalog",
540
+ summary: "List every receiver the caller can use (with cost/reversibility/settlement), or a goal's recipe",
541
+ request: z.object({ goal: z.enum(["spine", "build", "trade", "transact"]).optional() }),
542
+ response: z.union([
543
+ z.array(z.object({
544
+ receiver: z.string(), summary: z.string(), effect: z.enum(["signal", "ask"]),
545
+ auth: z.string().optional(), reversible: z.boolean().optional(),
546
+ settles: z.enum(["none", "offchain", "onchain"]).optional(),
547
+ }).passthrough()),
548
+ z.object({ goal: z.string(), recipe: z.array(z.string()) }),
549
+ ]),
550
+ effect: "ask", cost: "free", idempotent: true,
551
+ }),
552
+ "meta:schema": receiver({
553
+ receiver: "meta:schema",
554
+ summary: "JSON Schema for one receiver's request + response — read it before you call",
555
+ request: z.object({ receiver: z.string() }),
556
+ response: z.object({
557
+ receiver: z.string(), summary: z.string(),
558
+ request: z.unknown(), response: z.unknown(),
559
+ }),
560
+ effect: "ask", cost: "free", idempotent: true,
561
+ }),
562
+ "meta:recall": receiver({
563
+ receiver: "meta:recall",
564
+ summary: "Recall the caller's hypotheses (memory), optionally filtered by a search term",
565
+ request: z.object({ match: z.string().optional(), limit: z.number().optional() }),
566
+ response: z.object({
567
+ hypotheses: z.array(z.object({
568
+ hid: z.string(), claim: z.string(), status: z.string(), confidence: z.number().nullable(),
569
+ })),
570
+ }),
571
+ effect: "ask", cost: "free", idempotent: true,
572
+ }),
573
+ // ── actor discovery + messaging ──────────────────────────────────────────
574
+ "actors:find": receiver({
575
+ receiver: "actors:find",
576
+ summary: "Find agents on the marketplace by name fragment or skill — marketplace discovery only",
577
+ request: z.object({
578
+ // human is excluded: personal names/emails are PII, not marketplace data.
579
+ type: z.enum(["agent", "world"]).optional(),
580
+ search: z.string().max(100).optional(),
581
+ skill: z.string().max(100).optional(),
582
+ limit: z.number().max(100).optional(),
583
+ }),
584
+ response: z.object({
585
+ actors: z.array(z.object({ uid: z.string(), name: z.string(), type: z.string() })),
586
+ total: z.number(),
587
+ }),
588
+ effect: "ask", cost: "free", idempotent: true,
589
+ }),
590
+ "peer:message": receiver({
591
+ receiver: "peer:message",
592
+ summary: "Send an async message to another agent's inbox — instant store, no LLM, no streaming",
593
+ request: z.object({ to: z.string(), content: z.string(), from: z.string().optional() }),
594
+ response: z.object({ ok: z.boolean(), id: z.string().optional(), ts: z.number().optional(), to: z.string().optional(), from: z.string().optional(), error: z.string().optional() }),
595
+ effect: "ask", idempotent: false,
596
+ }),
597
+ "chat:send": receiver({
598
+ receiver: "chat:send",
599
+ summary: "Send a message to a group the caller is a member of — sender is always the authenticated caller",
600
+ request: z.object({
601
+ group: z.string(),
602
+ text: z.string(),
603
+ // sender is NOT in the schema — derived server-side from the authenticated caller uid.
604
+ slug: z.string().optional(),
605
+ }),
606
+ response: z.object({ ok: z.boolean(), reply: z.string().optional(), error: z.string().optional() }),
607
+ effect: "ask", auth: "member",
608
+ }),
609
+ };
610
+ /**
611
+ * RECIPES — the four agent journeys as typed, ordered receiver sequences (C6).
612
+ * Each entry is `readonly ReceiverName[]`, so a typo or a renamed receiver is a
613
+ * compile error. `meta:catalog?goal=` returns one of these; the MCP server
614
+ * groups its tools by them. See `plans/agent-first-spec.md`.
615
+ */
616
+ export const RECIPES = {
617
+ /** Onboard: become an actor → mint a key → join a group → declare capability. */
618
+ spine: ["auth:agent", "world:create-key", "groups:join", "agents:sync"],
619
+ /** Build a world: workspace → group → actor → thing. */
620
+ build: ["world:create-workspace", "world:create-group", "world:create-actor", "world:create-thing"],
621
+ /** Trade: list a capability → browse the market → hire → pay. */
622
+ trade: ["capabilities:publish", "market:list", "market:hire", "pay:weight"],
623
+ /** Transact: post a bounty → settle it onchain. */
624
+ transact: ["market:bounty", "pay:weight"],
625
+ };
626
+ //# sourceMappingURL=receivers.js.map