@llui/agent 0.0.48 → 0.0.50

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 (67) hide show
  1. package/dist/client/agentAttention.d.ts +129 -0
  2. package/dist/client/agentAttention.d.ts.map +1 -0
  3. package/dist/client/agentAttention.js +156 -0
  4. package/dist/client/agentAttention.js.map +1 -0
  5. package/dist/client/agentChat.d.ts +100 -0
  6. package/dist/client/agentChat.d.ts.map +1 -0
  7. package/dist/client/agentChat.js +84 -0
  8. package/dist/client/agentChat.js.map +1 -0
  9. package/dist/client/agentLog.d.ts +17 -0
  10. package/dist/client/agentLog.d.ts.map +1 -1
  11. package/dist/client/agentLog.js +18 -0
  12. package/dist/client/agentLog.js.map +1 -1
  13. package/dist/client/diff-render.d.ts +68 -0
  14. package/dist/client/diff-render.d.ts.map +1 -0
  15. package/dist/client/diff-render.js +141 -0
  16. package/dist/client/diff-render.js.map +1 -0
  17. package/dist/client/effect-handler.d.ts +29 -0
  18. package/dist/client/effect-handler.d.ts.map +1 -1
  19. package/dist/client/effect-handler.js +39 -0
  20. package/dist/client/effect-handler.js.map +1 -1
  21. package/dist/client/effects.d.ts +43 -0
  22. package/dist/client/effects.d.ts.map +1 -1
  23. package/dist/client/effects.js.map +1 -1
  24. package/dist/client/factory.d.ts +21 -0
  25. package/dist/client/factory.d.ts.map +1 -1
  26. package/dist/client/factory.js +15 -2
  27. package/dist/client/factory.js.map +1 -1
  28. package/dist/client/index.d.ts +4 -0
  29. package/dist/client/index.d.ts.map +1 -1
  30. package/dist/client/index.js +3 -0
  31. package/dist/client/index.js.map +1 -1
  32. package/dist/client/ws-client.d.ts +9 -0
  33. package/dist/client/ws-client.d.ts.map +1 -1
  34. package/dist/client/ws-client.js +120 -0
  35. package/dist/client/ws-client.js.map +1 -1
  36. package/dist/protocol.d.ts +103 -3
  37. package/dist/protocol.d.ts.map +1 -1
  38. package/dist/protocol.js.map +1 -1
  39. package/dist/server/cloudflare/durable-object.d.ts +41 -0
  40. package/dist/server/cloudflare/durable-object.d.ts.map +1 -1
  41. package/dist/server/cloudflare/durable-object.js +46 -0
  42. package/dist/server/cloudflare/durable-object.js.map +1 -1
  43. package/dist/server/cloudflare/index.d.ts +10 -3
  44. package/dist/server/cloudflare/index.d.ts.map +1 -1
  45. package/dist/server/cloudflare/index.js +10 -3
  46. package/dist/server/cloudflare/index.js.map +1 -1
  47. package/dist/server/core.d.ts +11 -1
  48. package/dist/server/core.d.ts.map +1 -1
  49. package/dist/server/core.js +1 -0
  50. package/dist/server/core.js.map +1 -1
  51. package/dist/server/lap/narrate.d.ts +31 -0
  52. package/dist/server/lap/narrate.d.ts.map +1 -0
  53. package/dist/server/lap/narrate.js +70 -0
  54. package/dist/server/lap/narrate.js.map +1 -0
  55. package/dist/server/lap/router.d.ts.map +1 -1
  56. package/dist/server/lap/router.js +6 -0
  57. package/dist/server/lap/router.js.map +1 -1
  58. package/dist/server/lap/wait-for-user-input.d.ts +13 -0
  59. package/dist/server/lap/wait-for-user-input.d.ts.map +1 -0
  60. package/dist/server/lap/wait-for-user-input.js +53 -0
  61. package/dist/server/lap/wait-for-user-input.js.map +1 -0
  62. package/dist/server/ws/pairing-registry.d.ts +101 -0
  63. package/dist/server/ws/pairing-registry.d.ts.map +1 -1
  64. package/dist/server/ws/pairing-registry.js +160 -0
  65. package/dist/server/ws/pairing-registry.js.map +1 -1
  66. package/package.json +7 -5
  67. package/styles/agent-panel.css +153 -0
@@ -275,6 +275,50 @@ export type LapConfirmResultResponse = {
275
275
  } | {
276
276
  status: 'still-pending';
277
277
  };
278
+ /**
279
+ * Long-poll for the user's next chat-composer submission. Returns
280
+ * `{ status: 'submitted', text, at }` on receipt of a
281
+ * `user-input-submitted` WS frame from the paired runtime, or
282
+ * `{ status: 'timeout' }` after `timeoutMs`. Each submission is
283
+ * delivered to exactly one waiter (FIFO); arrivals while no waiter
284
+ * is parked are buffered up to a small bound so a quick "type before
285
+ * Claude reaches the tool call" doesn't lose the message.
286
+ */
287
+ export type LapWaitForUserInputRequest = {
288
+ timeoutMs?: number;
289
+ };
290
+ export type LapWaitForUserInputResponse = {
291
+ status: 'submitted';
292
+ text: string;
293
+ at: number;
294
+ } | {
295
+ status: 'timeout';
296
+ };
297
+ /**
298
+ * Push narration prose into the activity feed without dispatching a
299
+ * Msg. The agent uses this for "I'm thinking…" / "About to do X
300
+ * because…" / "I noticed Y, going to investigate" — running commentary
301
+ * the user can read inline with agent actions.
302
+ *
303
+ * The server synthesizes a `LogEntry { kind: 'narrate', detail: text }`,
304
+ * appends it to the per-tid recent-log buffer (visible to subsequent
305
+ * `describe_recent_actions` calls), AND pushes a `log-push` frame to
306
+ * the paired browser so the in-app activity feed renders it in real
307
+ * time. No client roundtrip — the agent gets `{ ok: true }` synchronously
308
+ * once the server has accepted the narration.
309
+ */
310
+ export type LapNarrateRequest = {
311
+ text: string;
312
+ /**
313
+ * Optional one-line label for the entry's `intent` field, e.g.
314
+ * "Thinking" / "Notice" / "Plan". Defaults to "Agent narrated"
315
+ * when omitted.
316
+ */
317
+ intent?: string;
318
+ };
319
+ export type LapNarrateResponse = {
320
+ ok: true;
321
+ };
278
322
  export type LapWaitRequest = {
279
323
  path?: string;
280
324
  timeoutMs?: number;
@@ -396,6 +440,14 @@ export type LapEndpointMap = {
396
440
  req: LapWaitRequest;
397
441
  res: LapWaitResponse;
398
442
  };
443
+ '/lap/v1/wait-for-user-input': {
444
+ req: LapWaitForUserInputRequest;
445
+ res: LapWaitForUserInputResponse;
446
+ };
447
+ '/lap/v1/narrate': {
448
+ req: LapNarrateRequest;
449
+ res: LapNarrateResponse;
450
+ };
399
451
  '/lap/v1/query-dom': {
400
452
  req: LapQueryDomRequest;
401
453
  res: LapQueryDomResponse;
@@ -416,7 +468,24 @@ export type LapEndpointMap = {
416
468
  export type LapPath = keyof LapEndpointMap;
417
469
  export type LapRequest<P extends LapPath> = LapEndpointMap[P]['req'];
418
470
  export type LapResponse<P extends LapPath> = LapEndpointMap[P]['res'];
419
- export type LogKind = 'proposed' | 'dispatched' | 'confirmed' | 'rejected' | 'blocked' | 'read' | 'error';
471
+ export type LogKind = 'proposed' | 'dispatched' | 'confirmed' | 'rejected' | 'blocked' | 'read' | 'error'
472
+ /**
473
+ * The user typed a message into the in-app chat composer (the agentChat
474
+ * namespace) and submitted it. The agent's `wait_for_user_input` tool
475
+ * picks up the same submission. Surfacing it in the activity log is
476
+ * what makes the agent panel a real conversational surface — agent
477
+ * actions and user replies share one chronological timeline.
478
+ */
479
+ | 'user-input'
480
+ /**
481
+ * The agent emitted prose into the activity feed via `/lap/v1/narrate`
482
+ * — narration like "thinking about your request…", "I'm about to add
483
+ * an alternative because…", or any out-of-band commentary that
484
+ * doesn't fit a `dispatched` / `read` lifecycle. Lets the agent talk
485
+ * to the user inside the app without inventing a fake `@agentOnly`
486
+ * Msg type.
487
+ */
488
+ | 'narrate';
420
489
  export type LogEntry = {
421
490
  id: string;
422
491
  at: number;
@@ -470,7 +539,25 @@ export type LogAppendFrame = {
470
539
  t: 'log-append';
471
540
  entry: LogEntry;
472
541
  };
473
- export type ClientFrame = HelloFrame | RpcReplyFrame | RpcErrorFrame | ConfirmResolvedFrame | StateUpdateFrame | LogAppendFrame;
542
+ /**
543
+ * Inverted input channel. The user submits a message through the in-app
544
+ * chat composer (`agentChat`); the runtime forwards the text on this
545
+ * frame to the pairing server, which routes it to the parked
546
+ * `wait_for_user_input` LAP call (if any).
547
+ *
548
+ * The runtime ALSO appends a synthetic `LogEntry { kind: 'user-input' }`
549
+ * to the local activity log so the panel renders it inline with agent
550
+ * actions — the conversation reads as a single timeline. The frame and
551
+ * the log entry are independent: the frame travels server-side and
552
+ * delivers Claude's reply trigger; the log entry stays browser-side
553
+ * for visibility.
554
+ */
555
+ export type UserInputSubmittedFrame = {
556
+ t: 'user-input-submitted';
557
+ text: string;
558
+ at: number;
559
+ };
560
+ export type ClientFrame = HelloFrame | RpcReplyFrame | RpcErrorFrame | ConfirmResolvedFrame | StateUpdateFrame | LogAppendFrame | UserInputSubmittedFrame;
474
561
  export type RpcFrame = {
475
562
  t: 'rpc';
476
563
  id: string;
@@ -483,7 +570,20 @@ export type RevokedFrame = {
483
570
  export type ActiveFrame = {
484
571
  t: 'active';
485
572
  };
486
- export type ServerFrame = RpcFrame | RevokedFrame | ActiveFrame;
573
+ /**
574
+ * Server-pushed log entry. Used today by the `narrate` LAP method:
575
+ * the agent calls `/lap/v1/narrate { text }`, the server synthesizes
576
+ * a `LogEntry { kind: 'narrate' }` and pushes it down to the paired
577
+ * runtime so the in-app activity feed renders the narration in real
578
+ * time. Distinct from the browser-emitted `log-append` frame:
579
+ * `log-append` is browser → server (rpc-derived audit), `log-push`
580
+ * is server → browser (server-originated entries, no echo).
581
+ */
582
+ export type LogPushFrame = {
583
+ t: 'log-push';
584
+ entry: LogEntry;
585
+ };
586
+ export type ServerFrame = RpcFrame | RevokedFrame | ActiveFrame | LogPushFrame;
487
587
  declare const TokenBrand: unique symbol;
488
588
  export type AgentToken = string & {
489
589
  readonly [TokenBrand]: 'AgentToken';
@@ -1 +1 @@
1
- {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GACpB,aAAa,GACb,SAAS,GACT,QAAQ,GACR,cAAc,GACd,SAAS,GACT,cAAc,GACd,SAAS,GACT,UAAU,CAAA;AAEd,MAAM,MAAM,QAAQ,GAAG;IACrB,KAAK,EAAE;QACL,IAAI,EAAE,YAAY,CAAA;QAClB,MAAM,CAAC,EAAE,MAAM,CAAA;QACf,YAAY,CAAC,EAAE,MAAM,CAAA;KACtB,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,YAAY,GAAG,YAAY,CAAA;AAEjE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,gBAAgB,EAAE,OA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ACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,GAEf,MAAM,aAAa,CAAA","sourcesContent":["// ── LAP — LLui Agent Protocol ────────────────────────────────────\n// JSON over HTTPS between the llui-agent bridge (MCP side) and the\n// @llui/agent server library mounted in the developer's backend.\n// See docs/superpowers/specs/2026-04-19-llui-agent-design.md §7.\n\nexport type LapErrorCode =\n | 'auth-failed'\n | 'revoked'\n | 'paused'\n | 'rate-limited'\n | 'invalid'\n | 'schema-error'\n | 'timeout'\n | 'internal'\n\nexport type LapError = {\n error: {\n code: LapErrorCode\n detail?: string\n retryAfterMs?: number\n }\n}\n\n/**\n * Who can dispatch a Msg variant.\n *\n * - `'shared'` (default) — both UI bindings and the agent can dispatch.\n * - `'human-only'` — UI-only. Agent calls to `/message` for these variants\n * are rejected with `LapMessageRejectReason: 'human-only'`. Use for\n * internal UI events (focus/blur, scroll, hover) the LLM has no business\n * triggering.\n * - `'agent-only'` — no UI binding exists. Reserved for LLM-driven flows\n * like batch operations or \"explain this state\" introspection variants.\n * Lint warns if a view references one via `send({ type: 'X' })`.\n *\n * JSDoc sugar: `@humanOnly` → `'human-only'`, `@agentOnly` → `'agent-only'`.\n * Absence of either tag → `'shared'`. The two tags are mutually exclusive\n * (enforced by `llui/agent-exclusive-annotations` ESLint rule).\n */\nexport type DispatchMode = 'shared' | 'human-only' | 'agent-only'\n\nexport type MessageAnnotations = {\n intent: string | null\n alwaysAffordable: boolean\n requiresConfirm: boolean\n dispatchMode: DispatchMode\n /**\n * Concrete copy-paste example dispatches authored as `@example`\n * JSDoc tags. Multiple tags on one variant become multiple\n * entries (mix typical / edge cases without nesting strings).\n */\n examples: string[]\n /**\n * Non-blocking caution authored as `@warning`. Distinct from\n * `requiresConfirm` (runtime user gate); this informs the LLM at\n * affordance time so it can decide whether the dispatch's\n * downstream is acceptable.\n */\n warning: string | null\n /**\n * Effect kinds this variant emits when dispatched, declared via\n * `@emits(\"kind1\", \"kind2\")`. Lets the agent reason about side\n * effects (cloud writes, analytics, persistent state changes)\n * before dispatching, and chunk multi-step flows accordingly\n * (\"don't dispatch X 100 times — each one fires cloud/save\").\n * Empty when the variant doesn't emit effects or the author hasn't\n * annotated it yet.\n */\n emits: string[]\n /**\n * Boolean predicate authored as `@routeGated(\"expr\")` JSDoc, with\n * `state` bound at evaluation time. The variant only surfaces in\n * `list_actions` when the predicate returns true. Compile-time\n * alternative to `agentAffordances(state) => Msg[]` for the common\n * case of \"this Msg is reachable when state.X looks like Y.\" Null\n * when the variant has no `@routeGated` tag (default affordance\n * behavior applies).\n */\n routeGate?: string | null\n}\n\nexport type MessageSchemaEntry = {\n payloadSchema: object\n annotations: MessageAnnotations\n}\n\nexport type LapDescribeResponse = {\n name: string\n version: string\n stateSchema: object\n messages: Record<string, MessageSchemaEntry>\n docs: AgentDocs | null\n conventions: {\n dispatchModel: 'TEA'\n confirmationModel: 'runtime-mediated'\n readSurfaces: readonly (\n | 'state'\n | 'query_dom'\n | 'describe_visible_content'\n | 'describe_context'\n )[]\n }\n schemaHash: string\n}\n\nexport type LapStateRequest = { path?: string }\nexport type LapStateResponse = { state: unknown }\n\nexport type LapActionsResponse = {\n actions: Array<{\n variant: string\n /**\n * Human-readable phrase from `@intent(\"…\")`, or `null` when the\n * variant has no `@intent` annotation. Callers that surface\n * affordances to an LLM should treat `null` as \"this action is\n * undocumented\" — neither synthesise a label from the variant name\n * nor invent one. Pre-`@intent` variants would previously surface\n * as `intent: \"<variant>\"` here, which made unannotated actions\n * indistinguishable from properly-labelled ones; emitting `null`\n * keeps the gap visible.\n */\n intent: string | null\n requiresConfirm: boolean\n /**\n * `'shared'` — both UI and agent can dispatch. `'agent-only'` — no UI\n * binding exists; the agent is the sole dispatcher. `'human-only'`\n * variants never appear here (filtered before serialization).\n */\n dispatchMode: 'shared' | 'agent-only'\n /**\n * Where this affordance came from:\n * - `'binding'` — a tagged event handler is currently\n * mounted in the rendered DOM.\n * - `'always-affordable'` — the app's `agentAffordances(state)`\n * hook listed it as available right now.\n * - `'schema'` — neither of the above; the variant\n * is in the Msg union and annotated `@agentOnly`. The\n * `payloadHint` carries a synthesized example from the\n * compiler-derived field types — copy-paste-ready for\n * `send_message`. Bulk-edit operations land here.\n */\n source: 'binding' | 'always-affordable' | 'schema'\n selectorHint: string | null\n payloadHint: object | null\n /** Cautionary text from `@warning` JSDoc, or null. */\n warning: string | null\n /** Concrete examples from `@example` JSDoc, in source order. */\n examples: string[]\n /**\n * Effect kinds this variant emits, from `@emits(\"k1\", \"k2\")`.\n * Empty when not annotated.\n */\n emits: string[]\n /**\n * Per-field guidance lifted from `@should(\"…\")` JSDoc on payload\n * fields. Path is dot/bracket notation rooted at the payload (e.g.\n * `\"cells[].meta\"`). Surfaces hints that would otherwise be buried\n * inside the schema tree, so callers can read them alongside\n * `examples` without diving into `description.messages.variants`.\n */\n fieldHints: Array<{ path: string; hint: string }>\n }>\n}\n\nexport type LapMessageRequest = {\n msg: { type: string; [k: string]: unknown }\n reason?: string\n /**\n * Backpressure contract for how long `/message` waits before returning:\n * - `drained` (default): dispatch, then loop until the message queue is\n * idle for `drainQuietMs` ms or the 5s hard cap trips. Captures any\n * effect round-trips (http/delay/debounce) that feed back as messages.\n * - `idle`: dispatch + flush + one microtask yield. Captures the\n * synchronous update cycle but not async effects.\n * - `none`: dispatch and return without flushing. For high-throughput\n * fire-and-forget dispatch.\n */\n waitFor?: 'drained' | 'idle' | 'none'\n /**\n * Quiescence window when `waitFor === 'drained'`. Drain completes when\n * no new update cycle fires for this many ms. Default 100ms — long\n * enough for a localhost HTTP round-trip, short enough to be\n * imperceptible. Ignored for `idle` / `none`.\n */\n drainQuietMs?: number\n /**\n * Hard cap on total wait time. When `waitFor === 'drained'`, this is\n * the upper bound on how long the drain loop can run; if reached, the\n * response carries `drain.timedOut: true` with partial results. For\n * `pending-confirmation` messages, this is how long to wait for\n * the user's confirm/reject. Default 5_000ms.\n */\n timeoutMs?: number\n /**\n * Include the full post-drain `stateAfter` snapshot in the response.\n * Default `false` — the response carries `stateDiff` only and the\n * caller applies it to the prior snapshot (from connect/observe). For\n * apps with non-trivial state, the diff is orders of magnitude\n * smaller than the full state, and resending the snapshot on every\n * dispatch wastes bandwidth and (for LLM callers) context budget.\n *\n * Set `true` when the caller doesn't track state incrementally and\n * wants the snapshot back. The legacy `confirmed` and `wait` paths\n * always carry `stateAfter` because their flow is asynchronous and\n * a diff would be ambiguous.\n */\n includeState?: boolean\n}\n\nexport type LapMessageRejectReason =\n | 'human-only'\n | 'user-cancelled'\n | 'timeout'\n | 'invalid'\n | 'schema-error'\n | 'revoked'\n | 'paused'\n\n/**\n * Drain metadata attached to `dispatched` / `confirmed` responses.\n * `effectsObserved` counts update-cycle commits (not individual effects) —\n * it's a proxy for \"how much activity happened during the drain window.\"\n * `errors` surfaces sync throws from `onEffect` and unhandled rejections\n * from effect handlers that fired during the drain window, so the LLM\n * can see when an HTTP handler crashed silently.\n *\n * `warnings` surfaces non-blocking observations from the schema\n * validator — typically `untyped-field` flags raised in strict mode\n * when the agent provided a value for an `'unknown'`-typed field. The\n * dispatch landed (we accepted the value) but the validator couldn't\n * structurally check it, so the agent learns of the gap and can\n * tighten the next try if needed. Lenient mode never emits warnings;\n * the field is omitted in that case.\n */\nexport type LapDrainMeta = {\n effectsObserved: number\n durationMs: number\n timedOut: boolean\n errors: Array<{ kind: 'error' | 'unhandledrejection'; message: string; stack?: string }>\n warnings?: Array<{ path: string; code: string; message: string }>\n}\n\nexport type LapMessageResponse =\n | {\n status: 'dispatched'\n /**\n * Full post-drain state snapshot. Present only when the caller\n * passed `includeState: true` in the request — by default,\n * `stateDiff` is the only state-shaped field on the response\n * because callers can apply the diff to the prior snapshot from\n * `connect` / `observe`. See `LapMessageRequest.includeState`.\n */\n stateAfter?: unknown\n /**\n * Structural diff from pre-dispatch state to post-drain state,\n * in JSON-Patch shape (RFC 6902 subset: `add`, `remove`,\n * `replace`). Empty when the dispatch produced no observable\n * state change. The default state surface for callers — apply\n * incrementally to the snapshot from `connect`/`observe`.\n */\n stateDiff: import('./state-diff.js').StateDiff\n actions: LapActionsResponse['actions']\n drain: LapDrainMeta\n }\n | { status: 'pending-confirmation'; confirmId: string }\n | {\n /**\n * The user approved a `pending-confirmation` message. `stateAfter`\n * is the state snapshot captured when the approve was resolved;\n * effects produced by the approved dispatch may still be in\n * flight. The LLM should follow up with an `observe` call to\n * pick up a drained view and fresh actions — by design the\n * confirm path doesn't carry drain semantics because approval\n * can arrive arbitrarily later than the original request.\n */\n status: 'confirmed'\n stateAfter: unknown\n }\n | { status: 'rejected'; reason: LapMessageRejectReason; detail?: string }\n\nexport type LapConfirmResultRequest = { confirmId: string; timeoutMs?: number }\nexport type LapConfirmResultResponse =\n | { status: 'confirmed'; stateAfter: unknown }\n | { status: 'rejected'; reason: 'user-cancelled' | 'timeout' }\n | { status: 'still-pending' }\n\nexport type LapWaitRequest = { path?: string; timeoutMs?: number }\nexport type LapWaitResponse =\n | { status: 'changed'; stateAfter: unknown }\n | { status: 'timeout'; stateAfter: unknown }\n\nexport type LapQueryDomRequest = { name: string; multiple?: boolean }\nexport type LapQueryDomResponse = {\n elements: Array<{ text: string; attrs: Record<string, string>; path: number[] }>\n}\n\nexport type OutlineNode =\n | { kind: 'heading'; level: number; text: string }\n | { kind: 'text'; text: string }\n | { kind: 'list'; items: OutlineNode[] }\n | { kind: 'item'; text: string; children?: OutlineNode[] }\n | { kind: 'button'; text: string; disabled: boolean; actionVariant: string | null }\n | { kind: 'input'; label: string | null; value: string | null; type: string }\n | { kind: 'link'; text: string; href: string }\n\nexport type LapDescribeVisibleResponse = {\n outline: OutlineNode[]\n /**\n * Where the outline came from:\n * - `'data-agent'`: the app has `data-agent`-tagged zones and the\n * walker scoped the outline to them. The author chose what to\n * surface; trust the result.\n * - `'fallback'`: no `data-agent` tags exist; the walker fell back\n * to a depth- and count-limited semantic walk of the entire\n * root element. Useful for first-pass dogfood targets that\n * haven't tagged their views.\n * - `'truncated'`: same as `'fallback'` but the cap (200 nodes)\n * was hit before the walk finished. The visible content beyond\n * that point is not represented; reach for `query_dom` or state\n * reads if you need more.\n */\n source: 'data-agent' | 'fallback' | 'truncated'\n}\n\n// ── App + context documentation ──────────────────────────────────\n// Static app-level docs (authored once on the component record) and\n// dynamic per-state context docs (pure function of state, served by\n// `/lap/v1/context`). See spec §5.4.\n\nexport type AgentDocs = {\n purpose: string\n overview?: string\n cautions?: string[]\n /**\n * Free-form idiomatic-usage examples authored by the app: typical\n * sequences of dispatches the LLM should know about, like \"to\n * delete a saved matrix: dispatch Confirm/Ask first, then on\n * approve dispatch Cloud/Delete.\" Each entry is one example;\n * order is up to the author.\n */\n examples?: string[]\n}\n\nexport type AgentContext = {\n summary: string\n hints?: string[]\n cautions?: string[]\n}\n\nexport type LapContextResponse = { context: AgentContext }\n\n// ── Unified observe ──────────────────────────────────────────────\n// Single-call bootstrap. Replaces the get_state + list_actions +\n// describe_app trio for the common \"what can I see, what can I do\"\n// question. Returns the dynamic state + actions slice alongside the\n// static description (name/version/messages/docs) and any\n// state-derived context so one round-trip gives the LLM everything it\n// needs to decide its next action.\n\nexport type LapObserveResponse = {\n state: unknown\n actions: LapActionsResponse['actions']\n description: LapDescribeResponse\n context: AgentContext | null\n}\n\n// LAP endpoint catalog — a compile-time map binding each path to its\n// request/response shape. Useful for the bridge's dispatcher and for\n// typed test helpers.\nexport type LapEndpointMap = {\n '/lap/v1/describe': { req: null; res: LapDescribeResponse }\n '/lap/v1/state': { req: LapStateRequest; res: LapStateResponse }\n '/lap/v1/actions': { req: null; res: LapActionsResponse }\n '/lap/v1/message': { req: LapMessageRequest; res: LapMessageResponse }\n '/lap/v1/confirm-result': { req: LapConfirmResultRequest; res: LapConfirmResultResponse }\n '/lap/v1/wait': { req: LapWaitRequest; res: LapWaitResponse }\n '/lap/v1/query-dom': { req: LapQueryDomRequest; res: LapQueryDomResponse }\n '/lap/v1/describe-visible': { req: null; res: LapDescribeVisibleResponse }\n '/lap/v1/context': { req: null; res: LapContextResponse }\n '/lap/v1/observe': { req: null; res: LapObserveResponse }\n}\n\nexport type LapPath = keyof LapEndpointMap\nexport type LapRequest<P extends LapPath> = LapEndpointMap[P]['req']\nexport type LapResponse<P extends LapPath> = LapEndpointMap[P]['res']\n\n// ── Relay WS frames ──────────────────────────────────────────────\n// Bidirectional framing between the LLui runtime in the browser and\n// the @llui/agent server over /agent/ws. See spec §10.5.\n\nexport type LogKind =\n | 'proposed'\n | 'dispatched'\n | 'confirmed'\n | 'rejected'\n | 'blocked'\n | 'read'\n | 'error'\n\nexport type LogEntry = {\n id: string\n at: number\n kind: LogKind\n variant?: string\n intent?: string\n detail?: string\n /**\n * Structural diff from pre-dispatch state to post-drain state, in\n * JSON-Patch shape. Populated only for `kind: 'dispatched'` entries\n * — read entries (get_state / list_actions / observe / …) don't\n * mutate state, and an empty diff would just be noise. Lets the\n * agent reconstruct what each past action did without re-fetching\n * state snapshots.\n */\n stateDiff?: import('./state-diff.js').StateDiff\n}\n\nexport type HelloFrame = {\n t: 'hello'\n appName: string\n appVersion: string\n msgSchema: Record<string, MessageSchemaEntry>\n stateSchema: object\n affordancesSample: object[]\n docs: AgentDocs | null\n schemaHash: string\n}\n\nexport type RpcReplyFrame = { t: 'rpc-reply'; id: string; result: unknown }\nexport type RpcErrorFrame = { t: 'rpc-error'; id: string; code: string; detail?: string }\nexport type ConfirmResolvedFrame = {\n t: 'confirm-resolved'\n confirmId: string\n outcome: 'confirmed' | 'user-cancelled'\n stateAfter?: unknown\n}\nexport type StateUpdateFrame = { t: 'state-update'; path: string; stateAfter: unknown }\nexport type LogAppendFrame = { t: 'log-append'; entry: LogEntry }\n\nexport type ClientFrame =\n | HelloFrame\n | RpcReplyFrame\n | RpcErrorFrame\n | ConfirmResolvedFrame\n | StateUpdateFrame\n | LogAppendFrame\n\nexport type RpcFrame = { t: 'rpc'; id: string; tool: string; args: unknown }\nexport type RevokedFrame = { t: 'revoked' }\nexport type ActiveFrame = { t: 'active' }\n\nexport type ServerFrame = RpcFrame | RevokedFrame | ActiveFrame\n\n// ── Tokens + pairing ─────────────────────────────────────────────\n\ndeclare const TokenBrand: unique symbol\nexport type AgentToken = string & { readonly [TokenBrand]: 'AgentToken' }\n\nexport type TokenStatus =\n | 'awaiting-ws'\n | 'awaiting-claude'\n | 'active'\n | 'pending-resume'\n | 'revoked'\n\nexport type TokenRecord = {\n tid: string\n /**\n * SHA-256 hex of the bearer token. The plaintext token is never\n * stored — incoming requests hash their `Authorization: Bearer …`\n * value and look up by this field. Hash-only storage keeps a leaked\n * store from being a live-token leak. Mirrors the standard session-\n * cookie / API-key pattern.\n */\n tokenHash: string\n uid: string | null\n status: TokenStatus\n createdAt: number\n /**\n * Hard-expiry in milliseconds since epoch. The mint endpoint sets\n * this to `now + hardExpiryMs`; the verify path rejects requests\n * presenting tokens whose record has `expiresAt <= now`. Pre-0.0.35\n * the equivalent value lived inside the JWT payload as `exp` (in\n * seconds); the new opaque-token flow keeps it server-side so the\n * record is the single source of truth.\n */\n expiresAt: number\n lastSeenAt: number\n pendingResumeUntil: number | null\n origin: string\n label: string | null\n}\n\nexport type AgentSession = {\n tid: string\n label: string\n status: 'active' | 'pending-resume' | 'revoked'\n createdAt: number\n lastSeenAt: number\n}\n\n// HTTP envelopes for the mint/resume/revoke/sessions endpoints (non-LAP).\n\nexport type MintRequest = Record<string, never>\nexport type MintResponse = {\n token: AgentToken\n tid: string\n wsUrl: string\n lapUrl: string\n expiresAt: number\n}\n\nexport type ResumeListRequest = { tids: string[] }\nexport type ResumeListResponse = { sessions: AgentSession[] }\n\nexport type ResumeClaimRequest = { tid: string }\nexport type ResumeClaimResponse = { token: AgentToken; wsUrl: string }\n\nexport type RevokeRequest = { tid: string }\nexport type RevokeResponse = { status: 'revoked' }\n\nexport type SessionsResponse = { sessions: AgentSession[] }\n\n// ── Audit ────────────────────────────────────────────────────────\n\nexport type AuditEvent =\n | 'mint'\n | 'claim'\n | 'resume'\n | 'revoke'\n | 'lap-call'\n | 'msg-dispatched'\n | 'msg-blocked'\n | 'confirm-proposed'\n | 'confirm-approved'\n | 'confirm-rejected'\n | 'rate-limited'\n | 'auth-failed'\n\nexport type AuditEntry = {\n at: number\n tid: string | null\n uid: string | null\n event: AuditEvent\n detail: object\n}\n\n// ── Codec exports ─────────────────────────────────────────────────\n//\n// Re-exported here so consumers can `import { ..., type AgentCodec }\n// from '@llui/agent/protocol'`. The implementation lives in\n// `./codecs.ts` to keep the protocol type surface together but the\n// runtime registry/walkers separate.\n\nexport {\n WIRE_TAG,\n WIRE_VALUE,\n CodecRegistry,\n isoDateCodec,\n epochMillisCodec,\n makeDefaultCodecs,\n encodeForWire,\n decodeFromWire,\n type AgentCodec,\n} from './codecs.js'\n"]}
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA,oEAAoE;AACpE,mEAAmE;AACnE,iEAAiE;AACjE,iEAAiE;AAynBjE,qEAAqE;AACrE,EAAE;AACF,qEAAqE;AACrE,4DAA4D;AAC5D,mEAAmE;AACnE,qCAAqC;AAErC,OAAO,EACL,QAAQ,EACR,UAAU,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,aAAa,EACb,cAAc,GAEf,MAAM,aAAa,CAAA","sourcesContent":["// ── LAP — LLui Agent Protocol ────────────────────────────────────\n// JSON over HTTPS between the llui-agent bridge (MCP side) and the\n// @llui/agent server library mounted in the developer's backend.\n// See docs/superpowers/specs/2026-04-19-llui-agent-design.md §7.\n\nexport type LapErrorCode =\n | 'auth-failed'\n | 'revoked'\n | 'paused'\n | 'rate-limited'\n | 'invalid'\n | 'schema-error'\n | 'timeout'\n | 'internal'\n\nexport type LapError = {\n error: {\n code: LapErrorCode\n detail?: string\n retryAfterMs?: number\n }\n}\n\n/**\n * Who can dispatch a Msg variant.\n *\n * - `'shared'` (default) — both UI bindings and the agent can dispatch.\n * - `'human-only'` — UI-only. Agent calls to `/message` for these variants\n * are rejected with `LapMessageRejectReason: 'human-only'`. Use for\n * internal UI events (focus/blur, scroll, hover) the LLM has no business\n * triggering.\n * - `'agent-only'` — no UI binding exists. Reserved for LLM-driven flows\n * like batch operations or \"explain this state\" introspection variants.\n * Lint warns if a view references one via `send({ type: 'X' })`.\n *\n * JSDoc sugar: `@humanOnly` → `'human-only'`, `@agentOnly` → `'agent-only'`.\n * Absence of either tag → `'shared'`. The two tags are mutually exclusive\n * (enforced by `llui/agent-exclusive-annotations` ESLint rule).\n */\nexport type DispatchMode = 'shared' | 'human-only' | 'agent-only'\n\nexport type MessageAnnotations = {\n intent: string | null\n alwaysAffordable: boolean\n requiresConfirm: boolean\n dispatchMode: DispatchMode\n /**\n * Concrete copy-paste example dispatches authored as `@example`\n * JSDoc tags. Multiple tags on one variant become multiple\n * entries (mix typical / edge cases without nesting strings).\n */\n examples: string[]\n /**\n * Non-blocking caution authored as `@warning`. Distinct from\n * `requiresConfirm` (runtime user gate); this informs the LLM at\n * affordance time so it can decide whether the dispatch's\n * downstream is acceptable.\n */\n warning: string | null\n /**\n * Effect kinds this variant emits when dispatched, declared via\n * `@emits(\"kind1\", \"kind2\")`. Lets the agent reason about side\n * effects (cloud writes, analytics, persistent state changes)\n * before dispatching, and chunk multi-step flows accordingly\n * (\"don't dispatch X 100 times — each one fires cloud/save\").\n * Empty when the variant doesn't emit effects or the author hasn't\n * annotated it yet.\n */\n emits: string[]\n /**\n * Boolean predicate authored as `@routeGated(\"expr\")` JSDoc, with\n * `state` bound at evaluation time. The variant only surfaces in\n * `list_actions` when the predicate returns true. Compile-time\n * alternative to `agentAffordances(state) => Msg[]` for the common\n * case of \"this Msg is reachable when state.X looks like Y.\" Null\n * when the variant has no `@routeGated` tag (default affordance\n * behavior applies).\n */\n routeGate?: string | null\n}\n\nexport type MessageSchemaEntry = {\n payloadSchema: object\n annotations: MessageAnnotations\n}\n\nexport type LapDescribeResponse = {\n name: string\n version: string\n stateSchema: object\n messages: Record<string, MessageSchemaEntry>\n docs: AgentDocs | null\n conventions: {\n dispatchModel: 'TEA'\n confirmationModel: 'runtime-mediated'\n readSurfaces: readonly (\n | 'state'\n | 'query_dom'\n | 'describe_visible_content'\n | 'describe_context'\n )[]\n }\n schemaHash: string\n}\n\nexport type LapStateRequest = { path?: string }\nexport type LapStateResponse = { state: unknown }\n\nexport type LapActionsResponse = {\n actions: Array<{\n variant: string\n /**\n * Human-readable phrase from `@intent(\"…\")`, or `null` when the\n * variant has no `@intent` annotation. Callers that surface\n * affordances to an LLM should treat `null` as \"this action is\n * undocumented\" — neither synthesise a label from the variant name\n * nor invent one. Pre-`@intent` variants would previously surface\n * as `intent: \"<variant>\"` here, which made unannotated actions\n * indistinguishable from properly-labelled ones; emitting `null`\n * keeps the gap visible.\n */\n intent: string | null\n requiresConfirm: boolean\n /**\n * `'shared'` — both UI and agent can dispatch. `'agent-only'` — no UI\n * binding exists; the agent is the sole dispatcher. `'human-only'`\n * variants never appear here (filtered before serialization).\n */\n dispatchMode: 'shared' | 'agent-only'\n /**\n * Where this affordance came from:\n * - `'binding'` — a tagged event handler is currently\n * mounted in the rendered DOM.\n * - `'always-affordable'` — the app's `agentAffordances(state)`\n * hook listed it as available right now.\n * - `'schema'` — neither of the above; the variant\n * is in the Msg union and annotated `@agentOnly`. The\n * `payloadHint` carries a synthesized example from the\n * compiler-derived field types — copy-paste-ready for\n * `send_message`. Bulk-edit operations land here.\n */\n source: 'binding' | 'always-affordable' | 'schema'\n selectorHint: string | null\n payloadHint: object | null\n /** Cautionary text from `@warning` JSDoc, or null. */\n warning: string | null\n /** Concrete examples from `@example` JSDoc, in source order. */\n examples: string[]\n /**\n * Effect kinds this variant emits, from `@emits(\"k1\", \"k2\")`.\n * Empty when not annotated.\n */\n emits: string[]\n /**\n * Per-field guidance lifted from `@should(\"…\")` JSDoc on payload\n * fields. Path is dot/bracket notation rooted at the payload (e.g.\n * `\"cells[].meta\"`). Surfaces hints that would otherwise be buried\n * inside the schema tree, so callers can read them alongside\n * `examples` without diving into `description.messages.variants`.\n */\n fieldHints: Array<{ path: string; hint: string }>\n }>\n}\n\nexport type LapMessageRequest = {\n msg: { type: string; [k: string]: unknown }\n reason?: string\n /**\n * Backpressure contract for how long `/message` waits before returning:\n * - `drained` (default): dispatch, then loop until the message queue is\n * idle for `drainQuietMs` ms or the 5s hard cap trips. Captures any\n * effect round-trips (http/delay/debounce) that feed back as messages.\n * - `idle`: dispatch + flush + one microtask yield. Captures the\n * synchronous update cycle but not async effects.\n * - `none`: dispatch and return without flushing. For high-throughput\n * fire-and-forget dispatch.\n */\n waitFor?: 'drained' | 'idle' | 'none'\n /**\n * Quiescence window when `waitFor === 'drained'`. Drain completes when\n * no new update cycle fires for this many ms. Default 100ms — long\n * enough for a localhost HTTP round-trip, short enough to be\n * imperceptible. Ignored for `idle` / `none`.\n */\n drainQuietMs?: number\n /**\n * Hard cap on total wait time. When `waitFor === 'drained'`, this is\n * the upper bound on how long the drain loop can run; if reached, the\n * response carries `drain.timedOut: true` with partial results. For\n * `pending-confirmation` messages, this is how long to wait for\n * the user's confirm/reject. Default 5_000ms.\n */\n timeoutMs?: number\n /**\n * Include the full post-drain `stateAfter` snapshot in the response.\n * Default `false` — the response carries `stateDiff` only and the\n * caller applies it to the prior snapshot (from connect/observe). For\n * apps with non-trivial state, the diff is orders of magnitude\n * smaller than the full state, and resending the snapshot on every\n * dispatch wastes bandwidth and (for LLM callers) context budget.\n *\n * Set `true` when the caller doesn't track state incrementally and\n * wants the snapshot back. The legacy `confirmed` and `wait` paths\n * always carry `stateAfter` because their flow is asynchronous and\n * a diff would be ambiguous.\n */\n includeState?: boolean\n}\n\nexport type LapMessageRejectReason =\n | 'human-only'\n | 'user-cancelled'\n | 'timeout'\n | 'invalid'\n | 'schema-error'\n | 'revoked'\n | 'paused'\n\n/**\n * Drain metadata attached to `dispatched` / `confirmed` responses.\n * `effectsObserved` counts update-cycle commits (not individual effects) —\n * it's a proxy for \"how much activity happened during the drain window.\"\n * `errors` surfaces sync throws from `onEffect` and unhandled rejections\n * from effect handlers that fired during the drain window, so the LLM\n * can see when an HTTP handler crashed silently.\n *\n * `warnings` surfaces non-blocking observations from the schema\n * validator — typically `untyped-field` flags raised in strict mode\n * when the agent provided a value for an `'unknown'`-typed field. The\n * dispatch landed (we accepted the value) but the validator couldn't\n * structurally check it, so the agent learns of the gap and can\n * tighten the next try if needed. Lenient mode never emits warnings;\n * the field is omitted in that case.\n */\nexport type LapDrainMeta = {\n effectsObserved: number\n durationMs: number\n timedOut: boolean\n errors: Array<{ kind: 'error' | 'unhandledrejection'; message: string; stack?: string }>\n warnings?: Array<{ path: string; code: string; message: string }>\n}\n\nexport type LapMessageResponse =\n | {\n status: 'dispatched'\n /**\n * Full post-drain state snapshot. Present only when the caller\n * passed `includeState: true` in the request — by default,\n * `stateDiff` is the only state-shaped field on the response\n * because callers can apply the diff to the prior snapshot from\n * `connect` / `observe`. See `LapMessageRequest.includeState`.\n */\n stateAfter?: unknown\n /**\n * Structural diff from pre-dispatch state to post-drain state,\n * in JSON-Patch shape (RFC 6902 subset: `add`, `remove`,\n * `replace`). Empty when the dispatch produced no observable\n * state change. The default state surface for callers — apply\n * incrementally to the snapshot from `connect`/`observe`.\n */\n stateDiff: import('./state-diff.js').StateDiff\n actions: LapActionsResponse['actions']\n drain: LapDrainMeta\n }\n | { status: 'pending-confirmation'; confirmId: string }\n | {\n /**\n * The user approved a `pending-confirmation` message. `stateAfter`\n * is the state snapshot captured when the approve was resolved;\n * effects produced by the approved dispatch may still be in\n * flight. The LLM should follow up with an `observe` call to\n * pick up a drained view and fresh actions — by design the\n * confirm path doesn't carry drain semantics because approval\n * can arrive arbitrarily later than the original request.\n */\n status: 'confirmed'\n stateAfter: unknown\n }\n | { status: 'rejected'; reason: LapMessageRejectReason; detail?: string }\n\nexport type LapConfirmResultRequest = { confirmId: string; timeoutMs?: number }\nexport type LapConfirmResultResponse =\n | { status: 'confirmed'; stateAfter: unknown }\n | { status: 'rejected'; reason: 'user-cancelled' | 'timeout' }\n | { status: 'still-pending' }\n\n/**\n * Long-poll for the user's next chat-composer submission. Returns\n * `{ status: 'submitted', text, at }` on receipt of a\n * `user-input-submitted` WS frame from the paired runtime, or\n * `{ status: 'timeout' }` after `timeoutMs`. Each submission is\n * delivered to exactly one waiter (FIFO); arrivals while no waiter\n * is parked are buffered up to a small bound so a quick \"type before\n * Claude reaches the tool call\" doesn't lose the message.\n */\nexport type LapWaitForUserInputRequest = { timeoutMs?: number }\nexport type LapWaitForUserInputResponse =\n | { status: 'submitted'; text: string; at: number }\n | { status: 'timeout' }\n\n/**\n * Push narration prose into the activity feed without dispatching a\n * Msg. The agent uses this for \"I'm thinking…\" / \"About to do X\n * because…\" / \"I noticed Y, going to investigate\" — running commentary\n * the user can read inline with agent actions.\n *\n * The server synthesizes a `LogEntry { kind: 'narrate', detail: text }`,\n * appends it to the per-tid recent-log buffer (visible to subsequent\n * `describe_recent_actions` calls), AND pushes a `log-push` frame to\n * the paired browser so the in-app activity feed renders it in real\n * time. No client roundtrip — the agent gets `{ ok: true }` synchronously\n * once the server has accepted the narration.\n */\nexport type LapNarrateRequest = {\n text: string\n /**\n * Optional one-line label for the entry's `intent` field, e.g.\n * \"Thinking\" / \"Notice\" / \"Plan\". Defaults to \"Agent narrated\"\n * when omitted.\n */\n intent?: string\n}\nexport type LapNarrateResponse = { ok: true }\n\nexport type LapWaitRequest = { path?: string; timeoutMs?: number }\nexport type LapWaitResponse =\n | { status: 'changed'; stateAfter: unknown }\n | { status: 'timeout'; stateAfter: unknown }\n\nexport type LapQueryDomRequest = { name: string; multiple?: boolean }\nexport type LapQueryDomResponse = {\n elements: Array<{ text: string; attrs: Record<string, string>; path: number[] }>\n}\n\nexport type OutlineNode =\n | { kind: 'heading'; level: number; text: string }\n | { kind: 'text'; text: string }\n | { kind: 'list'; items: OutlineNode[] }\n | { kind: 'item'; text: string; children?: OutlineNode[] }\n | { kind: 'button'; text: string; disabled: boolean; actionVariant: string | null }\n | { kind: 'input'; label: string | null; value: string | null; type: string }\n | { kind: 'link'; text: string; href: string }\n\nexport type LapDescribeVisibleResponse = {\n outline: OutlineNode[]\n /**\n * Where the outline came from:\n * - `'data-agent'`: the app has `data-agent`-tagged zones and the\n * walker scoped the outline to them. The author chose what to\n * surface; trust the result.\n * - `'fallback'`: no `data-agent` tags exist; the walker fell back\n * to a depth- and count-limited semantic walk of the entire\n * root element. Useful for first-pass dogfood targets that\n * haven't tagged their views.\n * - `'truncated'`: same as `'fallback'` but the cap (200 nodes)\n * was hit before the walk finished. The visible content beyond\n * that point is not represented; reach for `query_dom` or state\n * reads if you need more.\n */\n source: 'data-agent' | 'fallback' | 'truncated'\n}\n\n// ── App + context documentation ──────────────────────────────────\n// Static app-level docs (authored once on the component record) and\n// dynamic per-state context docs (pure function of state, served by\n// `/lap/v1/context`). See spec §5.4.\n\nexport type AgentDocs = {\n purpose: string\n overview?: string\n cautions?: string[]\n /**\n * Free-form idiomatic-usage examples authored by the app: typical\n * sequences of dispatches the LLM should know about, like \"to\n * delete a saved matrix: dispatch Confirm/Ask first, then on\n * approve dispatch Cloud/Delete.\" Each entry is one example;\n * order is up to the author.\n */\n examples?: string[]\n}\n\nexport type AgentContext = {\n summary: string\n hints?: string[]\n cautions?: string[]\n}\n\nexport type LapContextResponse = { context: AgentContext }\n\n// ── Unified observe ──────────────────────────────────────────────\n// Single-call bootstrap. Replaces the get_state + list_actions +\n// describe_app trio for the common \"what can I see, what can I do\"\n// question. Returns the dynamic state + actions slice alongside the\n// static description (name/version/messages/docs) and any\n// state-derived context so one round-trip gives the LLM everything it\n// needs to decide its next action.\n\nexport type LapObserveResponse = {\n state: unknown\n actions: LapActionsResponse['actions']\n description: LapDescribeResponse\n context: AgentContext | null\n}\n\n// LAP endpoint catalog — a compile-time map binding each path to its\n// request/response shape. Useful for the bridge's dispatcher and for\n// typed test helpers.\nexport type LapEndpointMap = {\n '/lap/v1/describe': { req: null; res: LapDescribeResponse }\n '/lap/v1/state': { req: LapStateRequest; res: LapStateResponse }\n '/lap/v1/actions': { req: null; res: LapActionsResponse }\n '/lap/v1/message': { req: LapMessageRequest; res: LapMessageResponse }\n '/lap/v1/confirm-result': { req: LapConfirmResultRequest; res: LapConfirmResultResponse }\n '/lap/v1/wait': { req: LapWaitRequest; res: LapWaitResponse }\n '/lap/v1/wait-for-user-input': {\n req: LapWaitForUserInputRequest\n res: LapWaitForUserInputResponse\n }\n '/lap/v1/narrate': { req: LapNarrateRequest; res: LapNarrateResponse }\n '/lap/v1/query-dom': { req: LapQueryDomRequest; res: LapQueryDomResponse }\n '/lap/v1/describe-visible': { req: null; res: LapDescribeVisibleResponse }\n '/lap/v1/context': { req: null; res: LapContextResponse }\n '/lap/v1/observe': { req: null; res: LapObserveResponse }\n}\n\nexport type LapPath = keyof LapEndpointMap\nexport type LapRequest<P extends LapPath> = LapEndpointMap[P]['req']\nexport type LapResponse<P extends LapPath> = LapEndpointMap[P]['res']\n\n// ── Relay WS frames ──────────────────────────────────────────────\n// Bidirectional framing between the LLui runtime in the browser and\n// the @llui/agent server over /agent/ws. See spec §10.5.\n\nexport type LogKind =\n | 'proposed'\n | 'dispatched'\n | 'confirmed'\n | 'rejected'\n | 'blocked'\n | 'read'\n | 'error'\n /**\n * The user typed a message into the in-app chat composer (the agentChat\n * namespace) and submitted it. The agent's `wait_for_user_input` tool\n * picks up the same submission. Surfacing it in the activity log is\n * what makes the agent panel a real conversational surface — agent\n * actions and user replies share one chronological timeline.\n */\n | 'user-input'\n /**\n * The agent emitted prose into the activity feed via `/lap/v1/narrate`\n * — narration like \"thinking about your request…\", \"I'm about to add\n * an alternative because…\", or any out-of-band commentary that\n * doesn't fit a `dispatched` / `read` lifecycle. Lets the agent talk\n * to the user inside the app without inventing a fake `@agentOnly`\n * Msg type.\n */\n | 'narrate'\n\nexport type LogEntry = {\n id: string\n at: number\n kind: LogKind\n variant?: string\n intent?: string\n detail?: string\n /**\n * Structural diff from pre-dispatch state to post-drain state, in\n * JSON-Patch shape. Populated only for `kind: 'dispatched'` entries\n * — read entries (get_state / list_actions / observe / …) don't\n * mutate state, and an empty diff would just be noise. Lets the\n * agent reconstruct what each past action did without re-fetching\n * state snapshots.\n */\n stateDiff?: import('./state-diff.js').StateDiff\n}\n\nexport type HelloFrame = {\n t: 'hello'\n appName: string\n appVersion: string\n msgSchema: Record<string, MessageSchemaEntry>\n stateSchema: object\n affordancesSample: object[]\n docs: AgentDocs | null\n schemaHash: string\n}\n\nexport type RpcReplyFrame = { t: 'rpc-reply'; id: string; result: unknown }\nexport type RpcErrorFrame = { t: 'rpc-error'; id: string; code: string; detail?: string }\nexport type ConfirmResolvedFrame = {\n t: 'confirm-resolved'\n confirmId: string\n outcome: 'confirmed' | 'user-cancelled'\n stateAfter?: unknown\n}\nexport type StateUpdateFrame = { t: 'state-update'; path: string; stateAfter: unknown }\nexport type LogAppendFrame = { t: 'log-append'; entry: LogEntry }\n/**\n * Inverted input channel. The user submits a message through the in-app\n * chat composer (`agentChat`); the runtime forwards the text on this\n * frame to the pairing server, which routes it to the parked\n * `wait_for_user_input` LAP call (if any).\n *\n * The runtime ALSO appends a synthetic `LogEntry { kind: 'user-input' }`\n * to the local activity log so the panel renders it inline with agent\n * actions — the conversation reads as a single timeline. The frame and\n * the log entry are independent: the frame travels server-side and\n * delivers Claude's reply trigger; the log entry stays browser-side\n * for visibility.\n */\nexport type UserInputSubmittedFrame = {\n t: 'user-input-submitted'\n text: string\n at: number\n}\n\nexport type ClientFrame =\n | HelloFrame\n | RpcReplyFrame\n | RpcErrorFrame\n | ConfirmResolvedFrame\n | StateUpdateFrame\n | LogAppendFrame\n | UserInputSubmittedFrame\n\nexport type RpcFrame = { t: 'rpc'; id: string; tool: string; args: unknown }\nexport type RevokedFrame = { t: 'revoked' }\nexport type ActiveFrame = { t: 'active' }\n/**\n * Server-pushed log entry. Used today by the `narrate` LAP method:\n * the agent calls `/lap/v1/narrate { text }`, the server synthesizes\n * a `LogEntry { kind: 'narrate' }` and pushes it down to the paired\n * runtime so the in-app activity feed renders the narration in real\n * time. Distinct from the browser-emitted `log-append` frame:\n * `log-append` is browser → server (rpc-derived audit), `log-push`\n * is server → browser (server-originated entries, no echo).\n */\nexport type LogPushFrame = { t: 'log-push'; entry: LogEntry }\n\nexport type ServerFrame = RpcFrame | RevokedFrame | ActiveFrame | LogPushFrame\n\n// ── Tokens + pairing ─────────────────────────────────────────────\n\ndeclare const TokenBrand: unique symbol\nexport type AgentToken = string & { readonly [TokenBrand]: 'AgentToken' }\n\nexport type TokenStatus =\n | 'awaiting-ws'\n | 'awaiting-claude'\n | 'active'\n | 'pending-resume'\n | 'revoked'\n\nexport type TokenRecord = {\n tid: string\n /**\n * SHA-256 hex of the bearer token. The plaintext token is never\n * stored — incoming requests hash their `Authorization: Bearer …`\n * value and look up by this field. Hash-only storage keeps a leaked\n * store from being a live-token leak. Mirrors the standard session-\n * cookie / API-key pattern.\n */\n tokenHash: string\n uid: string | null\n status: TokenStatus\n createdAt: number\n /**\n * Hard-expiry in milliseconds since epoch. The mint endpoint sets\n * this to `now + hardExpiryMs`; the verify path rejects requests\n * presenting tokens whose record has `expiresAt <= now`. Pre-0.0.35\n * the equivalent value lived inside the JWT payload as `exp` (in\n * seconds); the new opaque-token flow keeps it server-side so the\n * record is the single source of truth.\n */\n expiresAt: number\n lastSeenAt: number\n pendingResumeUntil: number | null\n origin: string\n label: string | null\n}\n\nexport type AgentSession = {\n tid: string\n label: string\n status: 'active' | 'pending-resume' | 'revoked'\n createdAt: number\n lastSeenAt: number\n}\n\n// HTTP envelopes for the mint/resume/revoke/sessions endpoints (non-LAP).\n\nexport type MintRequest = Record<string, never>\nexport type MintResponse = {\n token: AgentToken\n tid: string\n wsUrl: string\n lapUrl: string\n expiresAt: number\n}\n\nexport type ResumeListRequest = { tids: string[] }\nexport type ResumeListResponse = { sessions: AgentSession[] }\n\nexport type ResumeClaimRequest = { tid: string }\nexport type ResumeClaimResponse = { token: AgentToken; wsUrl: string }\n\nexport type RevokeRequest = { tid: string }\nexport type RevokeResponse = { status: 'revoked' }\n\nexport type SessionsResponse = { sessions: AgentSession[] }\n\n// ── Audit ────────────────────────────────────────────────────────\n\nexport type AuditEvent =\n | 'mint'\n | 'claim'\n | 'resume'\n | 'revoke'\n | 'lap-call'\n | 'msg-dispatched'\n | 'msg-blocked'\n | 'confirm-proposed'\n | 'confirm-approved'\n | 'confirm-rejected'\n | 'rate-limited'\n | 'auth-failed'\n\nexport type AuditEntry = {\n at: number\n tid: string | null\n uid: string | null\n event: AuditEvent\n detail: object\n}\n\n// ── Codec exports ─────────────────────────────────────────────────\n//\n// Re-exported here so consumers can `import { ..., type AgentCodec }\n// from '@llui/agent/protocol'`. The implementation lives in\n// `./codecs.ts` to keep the protocol type surface together but the\n// runtime registry/walkers separate.\n\nexport {\n WIRE_TAG,\n WIRE_VALUE,\n CodecRegistry,\n isoDateCodec,\n epochMillisCodec,\n makeDefaultCodecs,\n encodeForWire,\n decodeFromWire,\n type AgentCodec,\n} from './codecs.js'\n"]}
@@ -46,7 +46,48 @@
46
46
  * See `./worker.ts` for `routeToAgentDO` and the full wiring.
47
47
  */
48
48
  import type { CoreOptions, AgentCoreHandle } from '../core.js';
49
+ import type { UserInputStorage } from '../ws/pairing-registry.js';
49
50
  export type DurableObjectOptions = Omit<CoreOptions, 'registry'>;
51
+ /**
52
+ * Minimal subset of the Cloudflare Durable Object `state.storage`
53
+ * surface needed to back the registry's `UserInputStorage` adapter.
54
+ * Declared structurally so we don't pull in `@cloudflare/workers-types`
55
+ * — that's a peer dependency of the host's Worker project, not ours.
56
+ */
57
+ export interface DurableObjectStorageLike {
58
+ get<T>(key: string): Promise<T | undefined>;
59
+ put<T>(key: string, value: T): Promise<void>;
60
+ delete(key: string): Promise<boolean>;
61
+ }
62
+ /**
63
+ * Build a `UserInputStorage` adapter backed by the DO's `state.storage`.
64
+ * Pass the result to `AgentPairingDurableObject`'s constructor opts to
65
+ * make buffered chat-composer submissions survive DO eviction (process
66
+ * restarts, deploys, idle eviction). Without this adapter the in-memory
67
+ * buffer is lost on eviction; with it, the next request restores any
68
+ * buffered messages from before the eviction.
69
+ *
70
+ * Parked `waitForUserInput` waiters can't be persisted (they're JS
71
+ * Promise resolvers); the LAP client retries naturally on its own
72
+ * timeout, and the retry sees the restored buffer.
73
+ *
74
+ * Usage:
75
+ *
76
+ * ```ts
77
+ * export class AgentDO {
78
+ * private agent: AgentPairingDurableObject
79
+ * constructor(state: DurableObjectState) {
80
+ * this.agent = new AgentPairingDurableObject({
81
+ * userInputStorage: makeDurableObjectUserInputStorage(state.storage),
82
+ * })
83
+ * }
84
+ * fetch(req: Request) {
85
+ * return this.agent.fetch(req)
86
+ * }
87
+ * }
88
+ * ```
89
+ */
90
+ export declare function makeDurableObjectUserInputStorage(storage: DurableObjectStorageLike): UserInputStorage;
50
91
  /**
51
92
  * Agent server instance scoped to a single Durable Object. All
52
93
  * pairing state lives in the DO's in-process memory — which is safe
@@ -1 +1 @@
1
- {"version":3,"file":"durable-object.d.ts","sourceRoot":"","sources":["../../../src/server/cloudflare/durable-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAI9D,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;AAEhE;;;;;;;;;GASG;AACH,qBAAa,yBAAyB;IACpC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;gBAEnB,IAAI,EAAE,oBAAoB;IAIhC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAgB7C"}
1
+ {"version":3,"file":"durable-object.d.ts","sourceRoot":"","sources":["../../../src/server/cloudflare/durable-object.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAG9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAEjE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,CAAA;AAEhE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAA;IAC3C,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAC5C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACtC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,iCAAiC,CAC/C,OAAO,EAAE,wBAAwB,GAChC,gBAAgB,CAiBlB;AAED;;;;;;;;;GASG;AACH,qBAAa,yBAAyB;IACpC,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAA;gBAEnB,IAAI,EAAE,oBAAoB;IAIhC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;CAgB7C"}
@@ -1,5 +1,51 @@
1
1
  import { createLluiAgentCore } from '../core.js';
2
2
  import { handleCloudflareUpgrade } from '../web/upgrade.js';
3
+ /**
4
+ * Build a `UserInputStorage` adapter backed by the DO's `state.storage`.
5
+ * Pass the result to `AgentPairingDurableObject`'s constructor opts to
6
+ * make buffered chat-composer submissions survive DO eviction (process
7
+ * restarts, deploys, idle eviction). Without this adapter the in-memory
8
+ * buffer is lost on eviction; with it, the next request restores any
9
+ * buffered messages from before the eviction.
10
+ *
11
+ * Parked `waitForUserInput` waiters can't be persisted (they're JS
12
+ * Promise resolvers); the LAP client retries naturally on its own
13
+ * timeout, and the retry sees the restored buffer.
14
+ *
15
+ * Usage:
16
+ *
17
+ * ```ts
18
+ * export class AgentDO {
19
+ * private agent: AgentPairingDurableObject
20
+ * constructor(state: DurableObjectState) {
21
+ * this.agent = new AgentPairingDurableObject({
22
+ * userInputStorage: makeDurableObjectUserInputStorage(state.storage),
23
+ * })
24
+ * }
25
+ * fetch(req: Request) {
26
+ * return this.agent.fetch(req)
27
+ * }
28
+ * }
29
+ * ```
30
+ */
31
+ export function makeDurableObjectUserInputStorage(storage) {
32
+ // One key per tid keeps the operations O(1) and avoids cross-tid
33
+ // contention. Prefix is to namespace from any other agent storage
34
+ // a future feature might add.
35
+ const key = (tid) => `__llui_agent_user_input_buf__:${tid}`;
36
+ return {
37
+ async read(tid) {
38
+ const stored = await storage.get(key(tid));
39
+ return stored ?? [];
40
+ },
41
+ async write(tid, buffer) {
42
+ await storage.put(key(tid), buffer);
43
+ },
44
+ async clear(tid) {
45
+ await storage.delete(key(tid));
46
+ },
47
+ };
48
+ }
3
49
  /**
4
50
  * Agent server instance scoped to a single Durable Object. All
5
51
  * pairing state lives in the DO's in-process memory — which is safe
@@ -1 +1 @@
1
- {"version":3,"file":"durable-object.js","sourceRoot":"","sources":["../../../src/server/cloudflare/durable-object.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAI3D;;;;;;;;;GASG;AACH,MAAM,OAAO,yBAAyB;IAC3B,KAAK,CAAiB;IAE/B,YAAY,IAA0B;QACpC,IAAI,CAAC,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAY;QACtB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE5B,gEAAgE;QAChE,gEAAgE;QAChE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QAEzB,iEAAiE;QACjE,sBAAsB;QACtB,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,uBAAuB,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QACjD,CAAC;QAED,OAAO,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IACnD,CAAC;CACF","sourcesContent":["/**\n * Durable Object helper for hosting the agent pairing + LAP surface\n * on Cloudflare Workers. One DO instance owns one `tid` — its\n * in-memory `PairingRegistry` survives across Worker isolate\n * invocations because the DO IS persistent.\n *\n * This file exports a class designed to be composed into a real\n * Durable Object in the user's Worker project. We intentionally\n * don't subclass `DurableObject` from `@cloudflare/workers-types` —\n * that dependency belongs to the user's project, not ours. Users\n * wrap an instance of `AgentPairingDurableObject` in their own DO\n * class and forward `fetch` to it.\n *\n * Usage in a Worker project:\n *\n * ```ts\n * // worker.ts\n * import { AgentPairingDurableObject } from '@llui/agent/server/cloudflare'\n *\n * export class AgentDO {\n * private agent: AgentPairingDurableObject\n * constructor(_state: DurableObjectState, env: Env) {\n * // Tokens are opaque (see token.ts) — no signing key needed.\n * this.agent = new AgentPairingDurableObject({})\n * }\n * fetch(req: Request): Promise<Response> {\n * return this.agent.fetch(req)\n * }\n * }\n *\n * export default {\n * async fetch(req: Request, env: Env): Promise<Response> {\n * // routeToAgentDO now takes a `resolveTid` callback — typically\n * // a fetch to the root DO's token-resolution endpoint, or a\n * // const stub when you don't shard by tid.\n * return routeToAgentDO(req, env.AGENT_DO, async (token) => {\n * const stub = env.AGENT_DO.get(env.AGENT_DO.idFromName('__root'))\n * const r = await stub.fetch(`http://internal/__resolve?token=${encodeURIComponent(token)}`)\n * const body = (await r.json()) as { tid: string | null }\n * return body.tid\n * })\n * },\n * }\n * ```\n *\n * See `./worker.ts` for `routeToAgentDO` and the full wiring.\n */\nimport type { CoreOptions, AgentCoreHandle } from '../core.js'\nimport { createLluiAgentCore } from '../core.js'\nimport { handleCloudflareUpgrade } from '../web/upgrade.js'\n\nexport type DurableObjectOptions = Omit<CoreOptions, 'registry'>\n\n/**\n * Agent server instance scoped to a single Durable Object. All\n * pairing state lives in the DO's in-process memory — which is safe\n * here because the DO is a persistent addressable entity, not a\n * one-shot Worker isolate.\n *\n * Users instantiate one of these inside their DO class's constructor\n * and delegate `fetch` to `agent.fetch(req)`. LAP HTTP routes and\n * WebSocket upgrades both flow through this single entry.\n */\nexport class AgentPairingDurableObject {\n readonly agent: AgentCoreHandle\n\n constructor(opts: DurableObjectOptions) {\n this.agent = createLluiAgentCore(opts)\n }\n\n async fetch(req: Request): Promise<Response> {\n const url = new URL(req.url)\n\n // LAP routes (/agent/lap/v1/*, /agent/*). `router` returns null\n // for non-matching paths so we can fall through to the upgrade.\n const lapRes = await this.agent.router(req)\n if (lapRes) return lapRes\n\n // WebSocket upgrade — uses `WebSocketPair`, which only exists in\n // Cloudflare Workers.\n if (url.pathname === '/agent/ws') {\n return handleCloudflareUpgrade(req, this.agent)\n }\n\n return new Response('Not Found', { status: 404 })\n }\n}\n"]}
1
+ {"version":3,"file":"durable-object.js","sourceRoot":"","sources":["../../../src/server/cloudflare/durable-object.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAA;AAiB3D;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,iCAAiC,CAC/C,OAAiC;IAEjC,iEAAiE;IACjE,kEAAkE;IAClE,8BAA8B;IAC9B,MAAM,GAAG,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,iCAAiC,GAAG,EAAE,CAAA;IACnE,OAAO;QACL,KAAK,CAAC,IAAI,CAAC,GAAG;YACZ,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAsC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;YAC/E,OAAO,MAAM,IAAI,EAAE,CAAA;QACrB,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,MAAM;YACrB,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAAA;QACrC,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,GAAG;YACb,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QAChC,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,OAAO,yBAAyB;IAC3B,KAAK,CAAiB;IAE/B,YAAY,IAA0B;QACpC,IAAI,CAAC,KAAK,GAAG,mBAAmB,CAAC,IAAI,CAAC,CAAA;IACxC,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,GAAY;QACtB,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE5B,gEAAgE;QAChE,gEAAgE;QAChE,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAC3C,IAAI,MAAM;YAAE,OAAO,MAAM,CAAA;QAEzB,iEAAiE;QACjE,sBAAsB;QACtB,IAAI,GAAG,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;YACjC,OAAO,uBAAuB,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAA;QACjD,CAAC;QAED,OAAO,IAAI,QAAQ,CAAC,WAAW,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;IACnD,CAAC;CACF","sourcesContent":["/**\n * Durable Object helper for hosting the agent pairing + LAP surface\n * on Cloudflare Workers. One DO instance owns one `tid` — its\n * in-memory `PairingRegistry` survives across Worker isolate\n * invocations because the DO IS persistent.\n *\n * This file exports a class designed to be composed into a real\n * Durable Object in the user's Worker project. We intentionally\n * don't subclass `DurableObject` from `@cloudflare/workers-types` —\n * that dependency belongs to the user's project, not ours. Users\n * wrap an instance of `AgentPairingDurableObject` in their own DO\n * class and forward `fetch` to it.\n *\n * Usage in a Worker project:\n *\n * ```ts\n * // worker.ts\n * import { AgentPairingDurableObject } from '@llui/agent/server/cloudflare'\n *\n * export class AgentDO {\n * private agent: AgentPairingDurableObject\n * constructor(_state: DurableObjectState, env: Env) {\n * // Tokens are opaque (see token.ts) — no signing key needed.\n * this.agent = new AgentPairingDurableObject({})\n * }\n * fetch(req: Request): Promise<Response> {\n * return this.agent.fetch(req)\n * }\n * }\n *\n * export default {\n * async fetch(req: Request, env: Env): Promise<Response> {\n * // routeToAgentDO now takes a `resolveTid` callback — typically\n * // a fetch to the root DO's token-resolution endpoint, or a\n * // const stub when you don't shard by tid.\n * return routeToAgentDO(req, env.AGENT_DO, async (token) => {\n * const stub = env.AGENT_DO.get(env.AGENT_DO.idFromName('__root'))\n * const r = await stub.fetch(`http://internal/__resolve?token=${encodeURIComponent(token)}`)\n * const body = (await r.json()) as { tid: string | null }\n * return body.tid\n * })\n * },\n * }\n * ```\n *\n * See `./worker.ts` for `routeToAgentDO` and the full wiring.\n */\nimport type { CoreOptions, AgentCoreHandle } from '../core.js'\nimport { createLluiAgentCore } from '../core.js'\nimport { handleCloudflareUpgrade } from '../web/upgrade.js'\nimport type { UserInputStorage } from '../ws/pairing-registry.js'\n\nexport type DurableObjectOptions = Omit<CoreOptions, 'registry'>\n\n/**\n * Minimal subset of the Cloudflare Durable Object `state.storage`\n * surface needed to back the registry's `UserInputStorage` adapter.\n * Declared structurally so we don't pull in `@cloudflare/workers-types`\n * — that's a peer dependency of the host's Worker project, not ours.\n */\nexport interface DurableObjectStorageLike {\n get<T>(key: string): Promise<T | undefined>\n put<T>(key: string, value: T): Promise<void>\n delete(key: string): Promise<boolean>\n}\n\n/**\n * Build a `UserInputStorage` adapter backed by the DO's `state.storage`.\n * Pass the result to `AgentPairingDurableObject`'s constructor opts to\n * make buffered chat-composer submissions survive DO eviction (process\n * restarts, deploys, idle eviction). Without this adapter the in-memory\n * buffer is lost on eviction; with it, the next request restores any\n * buffered messages from before the eviction.\n *\n * Parked `waitForUserInput` waiters can't be persisted (they're JS\n * Promise resolvers); the LAP client retries naturally on its own\n * timeout, and the retry sees the restored buffer.\n *\n * Usage:\n *\n * ```ts\n * export class AgentDO {\n * private agent: AgentPairingDurableObject\n * constructor(state: DurableObjectState) {\n * this.agent = new AgentPairingDurableObject({\n * userInputStorage: makeDurableObjectUserInputStorage(state.storage),\n * })\n * }\n * fetch(req: Request) {\n * return this.agent.fetch(req)\n * }\n * }\n * ```\n */\nexport function makeDurableObjectUserInputStorage(\n storage: DurableObjectStorageLike,\n): UserInputStorage {\n // One key per tid keeps the operations O(1) and avoids cross-tid\n // contention. Prefix is to namespace from any other agent storage\n // a future feature might add.\n const key = (tid: string) => `__llui_agent_user_input_buf__:${tid}`\n return {\n async read(tid) {\n const stored = await storage.get<Array<{ text: string; at: number }>>(key(tid))\n return stored ?? []\n },\n async write(tid, buffer) {\n await storage.put(key(tid), buffer)\n },\n async clear(tid) {\n await storage.delete(key(tid))\n },\n }\n}\n\n/**\n * Agent server instance scoped to a single Durable Object. All\n * pairing state lives in the DO's in-process memory — which is safe\n * here because the DO is a persistent addressable entity, not a\n * one-shot Worker isolate.\n *\n * Users instantiate one of these inside their DO class's constructor\n * and delegate `fetch` to `agent.fetch(req)`. LAP HTTP routes and\n * WebSocket upgrades both flow through this single entry.\n */\nexport class AgentPairingDurableObject {\n readonly agent: AgentCoreHandle\n\n constructor(opts: DurableObjectOptions) {\n this.agent = createLluiAgentCore(opts)\n }\n\n async fetch(req: Request): Promise<Response> {\n const url = new URL(req.url)\n\n // LAP routes (/agent/lap/v1/*, /agent/*). `router` returns null\n // for non-matching paths so we can fall through to the upgrade.\n const lapRes = await this.agent.router(req)\n if (lapRes) return lapRes\n\n // WebSocket upgrade — uses `WebSocketPair`, which only exists in\n // Cloudflare Workers.\n if (url.pathname === '/agent/ws') {\n return handleCloudflareUpgrade(req, this.agent)\n }\n\n return new Response('Not Found', { status: 404 })\n }\n}\n"]}
@@ -11,13 +11,20 @@
11
11
  * import {
12
12
  * AgentPairingDurableObject,
13
13
  * routeToAgentDO,
14
+ * makeDurableObjectUserInputStorage,
14
15
  * } from '@llui/agent/server/cloudflare'
15
16
  *
16
17
  * export class AgentDO {
17
18
  * private agent: AgentPairingDurableObject
18
- * constructor(_state: DurableObjectState, env: Env) {
19
+ * constructor(state: DurableObjectState, _env: Env) {
19
20
  * // Tokens are opaque (see token.ts) — no signing key needed.
20
- * this.agent = new AgentPairingDurableObject({})
21
+ * // The storage adapter makes the chat-composer's user-input
22
+ * // buffer survive DO eviction (deploys, idle eviction, runtime
23
+ * // restarts) — buffered messages from before the eviction are
24
+ * // restored on the next request.
25
+ * this.agent = new AgentPairingDurableObject({
26
+ * userInputStorage: makeDurableObjectUserInputStorage(state.storage),
27
+ * })
21
28
  * }
22
29
  * fetch(req: Request) {
23
30
  * return this.agent.fetch(req)
@@ -47,7 +54,7 @@
47
54
  * new_classes = ["AgentDO"]
48
55
  * ```
49
56
  */
50
- export { AgentPairingDurableObject, type DurableObjectOptions } from './durable-object.js';
57
+ export { AgentPairingDurableObject, type DurableObjectOptions, makeDurableObjectUserInputStorage, type DurableObjectStorageLike, } from './durable-object.js';
51
58
  export { routeToAgentDO, type MinimalDurableObjectNamespace, type MinimalDurableObjectId, type MinimalDurableObjectStub, } from './worker.js';
52
59
  export { createWHATWGPairingConnection, handleCloudflareUpgrade, extractToken, } from '../web/index.js';
53
60
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,EAAE,yBAAyB,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EACL,cAAc,EACd,KAAK,6BAA6B,EAClC,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,GAC9B,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,YAAY,GACb,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/server/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,EACL,yBAAyB,EACzB,KAAK,oBAAoB,EACzB,iCAAiC,EACjC,KAAK,wBAAwB,GAC9B,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,cAAc,EACd,KAAK,6BAA6B,EAClC,KAAK,sBAAsB,EAC3B,KAAK,wBAAwB,GAC9B,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,YAAY,GACb,MAAM,iBAAiB,CAAA"}
@@ -11,13 +11,20 @@
11
11
  * import {
12
12
  * AgentPairingDurableObject,
13
13
  * routeToAgentDO,
14
+ * makeDurableObjectUserInputStorage,
14
15
  * } from '@llui/agent/server/cloudflare'
15
16
  *
16
17
  * export class AgentDO {
17
18
  * private agent: AgentPairingDurableObject
18
- * constructor(_state: DurableObjectState, env: Env) {
19
+ * constructor(state: DurableObjectState, _env: Env) {
19
20
  * // Tokens are opaque (see token.ts) — no signing key needed.
20
- * this.agent = new AgentPairingDurableObject({})
21
+ * // The storage adapter makes the chat-composer's user-input
22
+ * // buffer survive DO eviction (deploys, idle eviction, runtime
23
+ * // restarts) — buffered messages from before the eviction are
24
+ * // restored on the next request.
25
+ * this.agent = new AgentPairingDurableObject({
26
+ * userInputStorage: makeDurableObjectUserInputStorage(state.storage),
27
+ * })
21
28
  * }
22
29
  * fetch(req: Request) {
23
30
  * return this.agent.fetch(req)
@@ -47,7 +54,7 @@
47
54
  * new_classes = ["AgentDO"]
48
55
  * ```
49
56
  */
50
- export { AgentPairingDurableObject } from './durable-object.js';
57
+ export { AgentPairingDurableObject, makeDurableObjectUserInputStorage, } from './durable-object.js';
51
58
  export { routeToAgentDO, } from './worker.js';
52
59
  export { createWHATWGPairingConnection, handleCloudflareUpgrade, extractToken, } from '../web/index.js';
53
60
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AACH,OAAO,EAAE,yBAAyB,EAA6B,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EACL,cAAc,GAIf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,YAAY,GACb,MAAM,iBAAiB,CAAA","sourcesContent":["/**\n * Cloudflare Workers + Durable Object adapter. Use this sub-path\n * from a Cloudflare Workers project where the agent pairing state\n * lives inside a Durable Object.\n *\n * See the full deployment recipe at\n * https://llui.dev/api/agent#cloudflare-deployment — the short\n * version:\n *\n * ```ts\n * import {\n * AgentPairingDurableObject,\n * routeToAgentDO,\n * } from '@llui/agent/server/cloudflare'\n *\n * export class AgentDO {\n * private agent: AgentPairingDurableObject\n * constructor(_state: DurableObjectState, env: Env) {\n * // Tokens are opaque (see token.ts) — no signing key needed.\n * this.agent = new AgentPairingDurableObject({})\n * }\n * fetch(req: Request) {\n * return this.agent.fetch(req)\n * }\n * }\n *\n * export default {\n * async fetch(req: Request, env: Env) {\n * return routeToAgentDO(req, env.AGENT_DO, async (token) => {\n * const stub = env.AGENT_DO.get(env.AGENT_DO.idFromName('__root'))\n * const r = await stub.fetch(`http://internal/__resolve?token=${encodeURIComponent(token)}`)\n * const body = (await r.json()) as { tid: string | null }\n * return body.tid\n * })\n * },\n * }\n * ```\n *\n * `wrangler.toml`:\n * ```toml\n * [[durable_objects.bindings]]\n * name = \"AGENT_DO\"\n * class_name = \"AgentDO\"\n *\n * [[migrations]]\n * tag = \"v1\"\n * new_classes = [\"AgentDO\"]\n * ```\n */\nexport { AgentPairingDurableObject, type DurableObjectOptions } from './durable-object.js'\nexport {\n routeToAgentDO,\n type MinimalDurableObjectNamespace,\n type MinimalDurableObjectId,\n type MinimalDurableObjectStub,\n} from './worker.js'\nexport {\n createWHATWGPairingConnection,\n handleCloudflareUpgrade,\n extractToken,\n} from '../web/index.js'\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/cloudflare/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDG;AACH,OAAO,EACL,yBAAyB,EAEzB,iCAAiC,GAElC,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,cAAc,GAIf,MAAM,aAAa,CAAA;AACpB,OAAO,EACL,6BAA6B,EAC7B,uBAAuB,EACvB,YAAY,GACb,MAAM,iBAAiB,CAAA","sourcesContent":["/**\n * Cloudflare Workers + Durable Object adapter. Use this sub-path\n * from a Cloudflare Workers project where the agent pairing state\n * lives inside a Durable Object.\n *\n * See the full deployment recipe at\n * https://llui.dev/api/agent#cloudflare-deployment — the short\n * version:\n *\n * ```ts\n * import {\n * AgentPairingDurableObject,\n * routeToAgentDO,\n * makeDurableObjectUserInputStorage,\n * } from '@llui/agent/server/cloudflare'\n *\n * export class AgentDO {\n * private agent: AgentPairingDurableObject\n * constructor(state: DurableObjectState, _env: Env) {\n * // Tokens are opaque (see token.ts) — no signing key needed.\n * // The storage adapter makes the chat-composer's user-input\n * // buffer survive DO eviction (deploys, idle eviction, runtime\n * // restarts) — buffered messages from before the eviction are\n * // restored on the next request.\n * this.agent = new AgentPairingDurableObject({\n * userInputStorage: makeDurableObjectUserInputStorage(state.storage),\n * })\n * }\n * fetch(req: Request) {\n * return this.agent.fetch(req)\n * }\n * }\n *\n * export default {\n * async fetch(req: Request, env: Env) {\n * return routeToAgentDO(req, env.AGENT_DO, async (token) => {\n * const stub = env.AGENT_DO.get(env.AGENT_DO.idFromName('__root'))\n * const r = await stub.fetch(`http://internal/__resolve?token=${encodeURIComponent(token)}`)\n * const body = (await r.json()) as { tid: string | null }\n * return body.tid\n * })\n * },\n * }\n * ```\n *\n * `wrangler.toml`:\n * ```toml\n * [[durable_objects.bindings]]\n * name = \"AGENT_DO\"\n * class_name = \"AgentDO\"\n *\n * [[migrations]]\n * tag = \"v1\"\n * new_classes = [\"AgentDO\"]\n * ```\n */\nexport {\n AgentPairingDurableObject,\n type DurableObjectOptions,\n makeDurableObjectUserInputStorage,\n type DurableObjectStorageLike,\n} from './durable-object.js'\nexport {\n routeToAgentDO,\n type MinimalDurableObjectNamespace,\n type MinimalDurableObjectId,\n type MinimalDurableObjectStub,\n} from './worker.js'\nexport {\n createWHATWGPairingConnection,\n handleCloudflareUpgrade,\n extractToken,\n} from '../web/index.js'\n"]}
@@ -13,7 +13,7 @@ import type { TokenStore } from './token-store.js';
13
13
  import type { IdentityResolver } from './identity.js';
14
14
  import type { AuditSink } from './audit.js';
15
15
  import type { RateLimiter } from './rate-limit.js';
16
- import type { PairingConnection, PairingRegistry } from './ws/pairing-registry.js';
16
+ import type { PairingConnection, PairingRegistry, UserInputStorage } from './ws/pairing-registry.js';
17
17
  /**
18
18
  * Options accepted by `createLluiAgentCore`. Strict subset of
19
19
  * `ServerOptions` — everything needed to build the router, registry,
@@ -32,6 +32,16 @@ export type CoreOptions = {
32
32
  * Durable Object that persists across isolates) pass it here.
33
33
  */
34
34
  registry?: PairingRegistry;
35
+ /**
36
+ * Optional persistence adapter for the chat-composer's
37
+ * `wait_for_user_input` buffer. Wired automatically into the
38
+ * default `InMemoryPairingRegistry`; ignored when `opts.registry`
39
+ * is overridden (custom registries supply their own persistence).
40
+ * See `UserInputStorage` for the contract. Cloudflare DO hosts get
41
+ * a ready-made adapter from
42
+ * `@llui/agent/server/cloudflare`'s `makeDurableObjectUserInputStorage`.
43
+ */
44
+ userInputStorage?: UserInputStorage;
35
45
  /**
36
46
  * How long, in milliseconds, a token's record stays in
37
47
  * `pending-resume` after the WS pairing closes. During this window
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../src/server/core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAWlF;;;;;GAKG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAA;IAC1B;;;;;;;;;;;;;;;;;OAiBG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,MAAM,MAAM,YAAY,GACpB;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,CAAA;AAElE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,CAAC,GAAG,EAA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B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACzB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,aAAa,GAAG,SAAS,CAAA;CAAE,CAAA;AAElE;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAA;IAClD,QAAQ,EAAE,eAAe,CAAA;IACzB,UAAU,EAAE,UAAU,CAAA;IACtB,SAAS,EAAE,SAAS,CAAA;IACpB;;;;;;;;;;OAUG;IACH,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,iBAAiB,KAAK,OAAO,CAAC,YAAY,CAAC,CAAA;CACpF,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,GAAE,WAAgB,GAAG,eAAe,CAmH3E"}
@@ -36,6 +36,7 @@ export function createLluiAgentCore(opts = {}) {
36
36
  },
37
37
  });
38
38
  },
39
+ userInputStorage: opts.userInputStorage,
39
40
  });
40
41
  const httpRouter = createHttpRouter({
41
42
  tokenStore,