@theoremjs/web 0.3.5-next.931.ge6a1c43 → 0.3.5-next.933.gfc0e83b

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -271,7 +271,7 @@ const transport = withPageToolDispatch(
271
271
  | `pageStatesTurn` | Let the page say which prompt lines a turn gets, through `stated` on a turn or a live call. Set it only for a page you trust as yourself, such as a builder's own tool. Without it, a request with `stated` is refused. |
272
272
  | `conversationStore` | Where the conversation is kept. Required, except for a stateless profile, which must not have one. See [Keep the conversation](#keep-the-conversation). |
273
273
  | `sessionStore`, `steerInbox` | Where open gates are kept, and where steers and stops reach a running turn. Default: process memory, which reaches only turns this process runs. On more than one instance, give a shared `SteerInbox`. |
274
- | `authorizeWake` | Whether a wake turn runs: `TurnWiring.authorizeWake`, called with `{ host, conversation }`, where `host` is what your `host` option makes of the request. Return `false` to skip it, for example to cap wakes. The results stay unread for the next message. Unset, every due wake runs. Set it on your `TurnWiring`, and the studio applies it too. See [the background section](#share-session-authority). |
274
+ | `lateResultsDecider` | Who tells the model that a background call ended: `TurnWiring.lateResultsDecider`. Set it on your `TurnWiring`, and the studio uses it too. Unset, no page wakes the chat and no reply reads a late result. `pageWakes` lets the open page wake it. See [the background section](#share-session-authority). |
275
275
  | `notifier`, `notifyRetryMs` | Tell an open page that a background call ended, and how long the page waits to reopen a cut stream. Unset, the page reads the end on its next turn or reload. See [the background section](#share-session-authority). |
276
276
  | `credentialStore` | Where tool credentials are kept, by session. Default: process memory. |
277
277
  | `authorizationUrl` | Returns the sign-in URL for an OAuth gate. Without it, an OAuth gate has no URL. |
@@ -458,11 +458,21 @@ Browser dispatch uses a host-owned `PageToolExecution` service beside the execut
458
458
  `createTheoremHandler` supplies both services. Live relays put the session boundary's `pageExecution` and `toolExecution` on `SessionRequest`.
459
459
 
460
460
  A tool with a `background` setting runs inline until you pass the `background` option to `createTheoremHandler`, or return `background` from `prepare`, with an `execution` of your own that has `detach`, when the same turns run elsewhere in your app too. The option takes `{ request, sessionId }` and returns a `ToolBackgroundService`, which receives each detached call and its late events. The session keeps the call as `background` until it settles, and a late settlement does not invalidate a checkpoint. A conversation read shows the call as it stands: running, then its result, or an error for a marked call. An open page reads it on its next turn or reload, unless you set `notifier`. When the session has dropped a settled operation, the block reads an error with the code `outcome_not_retained`. On a durable store, a worker that dies leaves the operation as `background`, so your sweep marks it `uncertain` with `worker_lost` through `compareAndSwap`. Keep the service's values valid after the request ends. A live relay passes its service to `runSession`.
461
- To show an open page that a background call ended, with no turn or reload, pass `notifier: createMemoryNotifier()` to `createTheoremHandler`. While a call runs, the conversation read tells the page to open `POST <base>/notify`. The handler sends one `changed` line when the stream opens, and one when each background call in the session ends. The line carries no content, so the page calls the same conversation read as before. The page closes the stream when no call runs. The model reads the result without a new message. When results are due, the conversation read says `wake: true`, and the page posts `<base>/wake` once it is idle. The handler runs a turn with no message: it passes the session's stored outcome in `input.lateResults`, and the model answers. The turn is the wake. A result is due when its call settled, the transcript does not end on a person's message, no `late-results` block names the call, and no wake took the result up before. The handler marks each result taken (`wokenAt` on the session's operation) before the model runs, so one result wakes the conversation once. Two pages that post at once run one turn, and a wake that fails is not tried again. The next message still reads any result that no `late-results` block names, while the session keeps the operation. A message the person sends during a wake wins: the wake writes nothing, and its stream ends with no error. `authorizeWake` on your `TurnWiring` decides whether a wake runs, for example to cap wakes for each person. It reads the turn's `host`, so the same function works in the studio, where `host` is the person the builder acts as. A refused wake still marks its results taken. A call `authorizeToolReplay` withholds from the request stays unread and does not wake.
461
+ To show an open page that a background call ended, with no turn or reload, pass `notifier: createMemoryNotifier()` to `createTheoremHandler`. While a call runs, the conversation read tells the page to open `POST <base>/notify`. The handler sends one `changed` line when the stream opens, and one when each background call in the session ends. The line carries no content, so the page calls the same conversation read as before. The page closes the stream when no call runs. The model reads the result only as your decider says.
462
462
 
463
- The late-results feed is the one way a result reaches the model. If your `background` service told the model a result some other way, such as with your own `onStage`, remove that, or the model reads it twice.
463
+ Set `lateResultsDecider` on your `TurnWiring` and pass it to `createTheoremHandler`. Unset, nothing tells the model a background call ended: the conversation read never says `wake: true`, `<base>/wake` runs nothing, and the next message reads no late result. A result waits for the model when its call settled and no `late-results` block names the call, while the session keeps the operation. A call `authorizeToolReplay` withholds from the request does not wait.
464
464
 
465
- To wake a conversation with no page open, post `<base>/wake` through the handler from your server, with your own `Request` and the conversation's current reference. Your `conversationStore` must give that reference: the reference of `createSealedConversationStore` is the sealed conversation itself, so each write gives a new one, which only the page holds.
465
+ - `give({ reason, host, conversation, results })` picks, by `operationId`, the results a reply reads. It is asked once for each reply, before the model runs: `reason: 'message'` for the person's message, `'wake'` for a reply to no message. The model reads each result it gives once. One it leaves out waits for a later reply. `host` is what your `host` option makes of the request.
466
+ - `due({ host, conversation, results })` says whether a page open on the chat wakes it now. It is asked on every conversation read, so it must change nothing. Say yes only when `give` would give something. Unset, no page wakes the chat.
467
+ - `ended({ host, result, wake, notify })` hears each background call end. `wake(conversation)` runs a reply to no message from the server, as a page's wake does, so a chat answers with no page open. `notify()` tells the session's open pages to read again.
468
+
469
+ `pageWakes` is the decider for an app with no server of its own: the page open on the chat wakes it, and every reply reads every result that waits. Write your own to keep a count, such as a cap or quiet hours, or to reply from the server.
470
+
471
+ When `due` says yes, the conversation read says `wake: true`, and the page posts `<base>/wake` once it is idle. The handler runs a turn with no message and passes what `give` gives in `input.lateResults`. A wake runs only when the transcript does not end on a person's message and no reply waits on a gate. The handler takes each result (`wokenAt` on the session's operation) before it asks `give`, so two pages that post at once run one turn. A result `give` leaves out loses that mark, and a later wake can take it. A wake that fails is not tried again; the next message's `give` is asked. A message the person sends during a wake wins: the wake writes nothing, and its stream ends with no error.
472
+
473
+ The decider is the one way a result reaches the model. If your `background` service told the model a result some other way, such as with your own `onStage`, remove that, or the model reads it twice.
474
+
475
+ To wake from the server, call `wake` with the conversation's current reference. Your `conversationStore` must keep that reference across writes: the reference of `createSealedConversationStore` is the sealed conversation itself, so each write gives a new one, which only the page holds. The reply runs with the headers of the request that started the call and no signal, because that request has ended.
466
476
 
467
477
  `createMemoryNotifier` reaches only pages connected to the process that ran the call. On more than one instance, give a shared `TheoremNotifier`. Your sweep calls `publish` with the session id after it marks a call `worker_lost`, because that write does not pass through the handler. Hosting platforms cut long responses. Set `notifyRetryMs` so that the page reopens the stream after that wait. Unset, the page does not reopen it, and reads the end on its next turn or reload.
468
478
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/web",
3
- "version": "0.3.5-next.931.ge6a1c43",
3
+ "version": "0.3.5-next.933.gfc0e83b",
4
4
  "description": "Theorem on the web platform, with no UI framework: Web-standard server handlers that serve a profile, and the browser client that talks to them.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -25,6 +25,6 @@
25
25
  },
26
26
  "peerDependencies": {
27
27
  "zod": "^4.6.5",
28
- "@theoremjs/agents": "^0.3.5-next.931.ge6a1c43"
28
+ "@theoremjs/agents": "^0.3.5-next.933.gfc0e83b"
29
29
  }
30
30
  }
@@ -153,8 +153,11 @@ export type TheoremHandlerOptions = {
153
153
  status: 'settled';
154
154
  }>;
155
155
  }) => boolean | Promise<boolean>;
156
- /** Whether a wake may run: `TurnWiring.authorizeWake`, given the `host` this request makes. */
157
- authorizeWake?: TurnWiring['authorizeWake'];
156
+ /**
157
+ * Who tells the model that a background call ended: `TurnWiring.lateResultsDecider`. Unset, no
158
+ * page wakes the chat and no reply reads a late result. `pageWakes` lets the open page wake it.
159
+ */
160
+ lateResultsDecider?: TurnWiring['lateResultsDecider'];
158
161
  /**
159
162
  * Tool credentials by session. Your OAuth callback route saves the token here
160
163
  * under the same session id; every turn reads from here. Default: in-process
package/server/handler.js CHANGED
@@ -419,36 +419,94 @@ function backgroundWiring(ctx, request, sessionId) {
419
419
  const service = ctx.options.background?.({ request, sessionId });
420
420
  return service ? { background: announced(ctx, request, sessionId, service) } : {};
421
421
  }
422
- /** `service`, telling the session's open page through the notifier when each of its calls ends. */
422
+ /**
423
+ * `service`, telling the session's open pages when each of its calls ends, and the decider's
424
+ * `ended`, with the wake and the notify it may use.
425
+ */
423
426
  function announced(ctx, request, sessionId, service) {
424
- const { notifier } = ctx.options;
425
- if (!notifier)
427
+ const { notifier, lateResultsDecider } = ctx.options;
428
+ const ended = lateResultsDecider?.ended?.bind(lateResultsDecider);
429
+ if (!notifier && !ended)
426
430
  return service;
431
+ const notify = async () => {
432
+ await notifier?.publish(sessionId);
433
+ };
427
434
  return {
428
435
  detached(call) {
429
436
  service.detached(call);
430
437
  void call.done
431
- .then(() => notifier.publish(sessionId))
438
+ .then(async () => {
439
+ await notify();
440
+ if (!ended)
441
+ return;
442
+ const { operations } = await ctx.sessions.read(sessionId);
443
+ const operation = Object.hasOwn(operations, call.operationId)
444
+ ? operations[call.operationId]
445
+ : undefined;
446
+ if (operation?.status !== 'settled')
447
+ return;
448
+ await ended({
449
+ host: await ctx.options.host?.(request),
450
+ result: { operationId: call.operationId, outcome: operation.outcome },
451
+ wake: (conversation) => serverWake(ctx, request, sessionId, conversation),
452
+ notify,
453
+ });
454
+ })
432
455
  .catch((err) => ctx.options.onError?.(err, { request }));
433
456
  },
434
457
  event: (event, call) => service.event(event, call),
435
458
  };
436
459
  }
460
+ /**
461
+ * The decider's wake, with no page: the reply runs on a request of its own, with the headers of
462
+ * the one that started the call and no signal, because that request has ended.
463
+ */
464
+ async function serverWake(ctx, started, sessionId, conversation) {
465
+ const request = new Request(started.url, { headers: started.headers });
466
+ const lines = await wakeLines(ctx, request, { id: sessionId }, conversation, {});
467
+ if (!lines)
468
+ return;
469
+ for await (const line of lines) {
470
+ if (line.type === 'error') {
471
+ // labels-exempt: internal diagnostic for the decider's wake; no page reads it
472
+ throw new TheoremError(line.errorKind, line.errorInternal ?? line.error ?? 'the wake failed');
473
+ }
474
+ }
475
+ }
437
476
  /** A settled call's answer, streamed again. */
438
477
  async function* once(event, labels) {
439
478
  yield withPublicLabels(event, labels);
440
479
  }
441
480
  /**
442
- * `turn.input`, with the settled ends of the conversation's detached calls the model has not read.
443
- * A call the host does not let this request replay stays unread, as its block stays withheld.
481
+ * `turn.input`, with the late results this reply gives the model: those the wake took, or those
482
+ * the decider gives a message. A reply that goes on after a pause has none, so it is asked once.
444
483
  */
445
- async function withLateResults(ctx, request, turn, operations) {
446
- const settled = await readableResults(ctx, request, turn.unread ?? [], operations);
447
- if (settled.length === 0)
484
+ async function withLateResults(ctx, request, host, turn, operations, late) {
485
+ if (!turn.unread)
486
+ return turn.input;
487
+ const given = late.given ??
488
+ (await givenResults(ctx, host, late.conversation, await readableResults(ctx, request, turn.unread, operations), 'message'));
489
+ if (given.length === 0)
448
490
  return turn.input;
449
- const outcomes = settled.map((operation) => operation.outcome);
491
+ const outcomes = given.map((operation) => operation.outcome);
450
492
  return { ...turn.input, lateResults: [...(turn.input.lateResults ?? []), ...outcomes] };
451
493
  }
494
+ /** Those of `results` the decider gives the reply; none without a decider. */
495
+ async function givenResults(ctx, host, conversation, results, reason) {
496
+ const decider = ctx.options.lateResultsDecider;
497
+ if (!decider || conversation === undefined || results.length === 0)
498
+ return [];
499
+ const ids = new Set(await decider.give({
500
+ reason,
501
+ host,
502
+ conversation,
503
+ results: results.map(lateResult),
504
+ }));
505
+ return results.filter((operation) => ids.has(operation.operationId));
506
+ }
507
+ function lateResult(operation) {
508
+ return { operationId: operation.operationId, outcome: operation.outcome };
509
+ }
452
510
  /** The calls among `unread` that ended, as this request may read them. */
453
511
  async function readableResults(ctx, request, unread, operations) {
454
512
  const readable = [];
@@ -469,7 +527,7 @@ async function wakeResults(ctx, request, conversation, operations) {
469
527
  return readable.filter((operation) => operation.wokenAt === undefined);
470
528
  }
471
529
  /** One model run of a chat's reply, its gates recorded in the session as they pause. */
472
- async function* chatTurn(ctx, request, session, turn, key, stop) {
530
+ async function* chatTurn(ctx, request, session, turn, key, stop, late) {
473
531
  const state = await ctx.sessions.read(session.id);
474
532
  const provider = await providerFor(ctx, request, turn.model);
475
533
  const host = await ctx.options.host?.(request);
@@ -484,7 +542,7 @@ async function* chatTurn(ctx, request, session, turn, key, stop) {
484
542
  execution: sessionToolCoordinator(ctx.sessions, session.id),
485
543
  ...backgroundWiring(ctx, request, session.id),
486
544
  pageExecution: sessionPageDispatch(ctx.sessions, session.id, ctx.pageToolBroker, ctx.options.pageToolTimeoutMs).execution,
487
- input: await withLateResults(ctx, request, turn, state.operations),
545
+ input: await withLateResults(ctx, request, host, turn, state.operations, late),
488
546
  ...(turn.conversationId ? { conversationId: turn.conversationId } : {}),
489
547
  ...(turn.providerState ? { providerState: turn.providerState } : {}),
490
548
  sessionPermissions: state.permissions,
@@ -512,12 +570,15 @@ async function* chatTurn(ctx, request, session, turn, key, stop) {
512
570
  }
513
571
  }
514
572
  /** How this request runs the model for a reply: its generation, and its abort (the request's, or a stop). */
515
- function chatRunner(ctx, request, session, generation) {
573
+ function chatRunner(ctx, request, session, generation, given) {
516
574
  const key = generation.turnId ? inboxKey(session.id, generation.turnId) : undefined;
517
575
  const stop = new AbortController();
518
576
  const signal = AbortSignal.any([request.signal, stop.signal]);
519
577
  return {
520
- run: (turn) => chatTurn(ctx, request, session, turn, key, stop),
578
+ run: (turn) => chatTurn(ctx, request, session, turn, key, stop, {
579
+ ...(generation.conversation === undefined ? {} : { conversation: generation.conversation }),
580
+ ...(given ? { given } : {}),
581
+ }),
521
582
  async compact(history, tokens, model) {
522
583
  const provider = await providerFor(ctx, request, model);
523
584
  const compacted = await compactHistory({
@@ -586,47 +647,70 @@ async function conversation(ctx, request, session) {
586
647
  if (!host)
587
648
  throw statelessRefusal('read');
588
649
  const opened = await openConversation(host, body.conversation, { kind: 'read' });
589
- return jsonResponse(200, await currentView(ctx, request, session, host, opened.conversation));
650
+ return jsonResponse(200, await currentView(ctx, request, session, host, body.conversation, opened.conversation));
590
651
  }
591
652
  /**
592
653
  * A reply to no message, for results that ended since the model last ran. Each result is taken by
593
- * one wake, before the model runs, so two pages that wake at once run it once, and a wake that
594
- * fails or is refused is not tried again; the next message reads what it left.
654
+ * one wake before the decider is asked, so two pages that wake at once run it once. The decider's
655
+ * `give` picks what the reply reads; what it leaves is let go, for a later reply.
595
656
  */
596
657
  async function wake(ctx, request, session) {
597
658
  const body = await readBody(request, theoremWakeRequestSchema, ctx.options.maxRequestBytes);
659
+ const input = kernelTurnInput(body.input ?? {}, await ctx.options.context?.(request));
660
+ const lines = await wakeLines(ctx, request, session, body.conversation, body, input);
661
+ return eventStream(ctx, request, lines ? () => lines : async function* () { });
662
+ }
663
+ /** The wake's reply, or undefined when the decider gives it nothing to read. */
664
+ async function wakeLines(ctx, request, session, conversation, generation, input) {
598
665
  const host = conversationHost(ctx, session);
599
666
  if (!host)
600
667
  throw statelessRefusal('wake');
601
- const opened = await openConversation(host, body.conversation, { kind: 'read' });
668
+ if (!ctx.options.lateResultsDecider)
669
+ return undefined;
670
+ const opened = await openConversation(host, conversation, { kind: 'read' });
602
671
  const { operations } = await ctx.sessions.read(session.id);
603
672
  const due = await wakeResults(ctx, request, opened.conversation, operations);
673
+ if (due.length === 0)
674
+ return undefined;
604
675
  const now = Date.now();
605
- const taken = due.length
606
- ? await ctx.sessions.mutate(session.id, (state) => due.filter(({ operationId }) => {
607
- const operation = state.operations[operationId];
608
- if (operation?.status !== 'settled' || operation.wokenAt !== undefined)
609
- return false;
610
- state.operations[operationId] = { ...operation, wokenAt: now };
611
- return true;
612
- }))
613
- : [];
614
- const { authorizeWake } = ctx.options;
615
- const allowed = taken.length > 0 &&
616
- (!authorizeWake ||
617
- (await authorizeWake({
618
- host: await ctx.options.host?.(request),
619
- conversation: body.conversation,
620
- })));
621
- if (!allowed)
622
- return eventStream(ctx, request, async function* () { });
623
- const runner = chatRunner(ctx, request, session, body);
624
- const input = kernelTurnInput(body.input ?? {}, await ctx.options.context?.(request));
676
+ const taken = await ctx.sessions.mutate(session.id, (state) => due.filter(({ operationId }) => {
677
+ const operation = state.operations[operationId];
678
+ if (operation?.status !== 'settled' || operation.wokenAt !== undefined)
679
+ return false;
680
+ state.operations[operationId] = { ...operation, wokenAt: now };
681
+ return true;
682
+ }));
683
+ let given = [];
684
+ try {
685
+ given = await givenResults(ctx, await ctx.options.host?.(request), conversation, taken, 'wake');
686
+ }
687
+ finally {
688
+ const kept = new Set(given.map((operation) => operation.operationId));
689
+ const left = taken.filter((operation) => !kept.has(operation.operationId));
690
+ // why: A result the decider did not give leaves no mark, so a later wake can still give it.
691
+ if (left.length)
692
+ await letGo(ctx, session, left, now);
693
+ }
694
+ if (given.length === 0)
695
+ return undefined;
696
+ const runner = chatRunner(ctx, request, session, { ...generation, conversation }, given);
625
697
  const { notifier } = ctx.options;
626
- return eventStream(ctx, request, async function* () {
627
- yield* wakeReply({ host, opened, runner, input });
698
+ return (async function* () {
699
+ yield* wakeReply({ host, opened, runner, ...(input ? { input } : {}) });
628
700
  // why: The page that woke draws its reply; any other page open on the session reads it now.
629
701
  notifier?.publish(session.id);
702
+ })();
703
+ }
704
+ /** Takes the wake's mark off results it did not read. */
705
+ async function letGo(ctx, session, left, wokenAt) {
706
+ await ctx.sessions.mutate(session.id, (state) => {
707
+ for (const { operationId } of left) {
708
+ const operation = state.operations[operationId];
709
+ if (operation?.status !== 'settled' || operation.wokenAt !== wokenAt)
710
+ continue;
711
+ const { wokenAt: _taken, ...rest } = operation;
712
+ state.operations[operationId] = rest;
713
+ }
630
714
  });
631
715
  }
632
716
  const CHANGED_LINE = new TextEncoder().encode('{"type":"changed"}\n');
@@ -673,23 +757,38 @@ async function notify(ctx, request, session, notifier) {
673
757
  * why: The transcript keeps a detached call as the turn left it. The session holds what became of
674
758
  * it, so a call that has ended does not read as running.
675
759
  */
676
- async function currentView(ctx, request, session, host, conversation) {
760
+ async function currentView(ctx, request, session, host, ref, conversation) {
677
761
  const view = conversationView(host, conversation);
678
762
  if (!view.transcript.some(isDetachedBlock))
679
763
  return view;
680
764
  const { operations } = await ctx.sessions.read(session.id);
681
765
  const transcript = await Promise.all(view.transcript.map((block) => isDetachedBlock(block) ? lateBlock(ctx, request, block, operations, host) : block));
682
766
  const { notifier, notifyRetryMs } = ctx.options;
683
- const due = await wakeResults(ctx, request, conversation, operations);
684
767
  return {
685
768
  ...view,
686
769
  transcript,
687
770
  ...(notifier && transcript.some(isDetachedBlock)
688
771
  ? { notify: notifyRetryMs === undefined ? {} : { retryMs: notifyRetryMs } }
689
772
  : {}),
690
- ...(due.length > 0 ? { wake: true } : {}),
773
+ ...((await wakeDue(ctx, request, ref, conversation, operations))
774
+ ? { wake: true }
775
+ : {}),
691
776
  };
692
777
  }
778
+ /** Whether the page wakes the chat now: results wait that no wake took, and the decider says so. */
779
+ async function wakeDue(ctx, request, ref, conversation, operations) {
780
+ const due = ctx.options.lateResultsDecider?.due;
781
+ if (!due)
782
+ return false;
783
+ const results = await wakeResults(ctx, request, conversation, operations);
784
+ if (results.length === 0)
785
+ return false;
786
+ return await due.call(ctx.options.lateResultsDecider, {
787
+ host: await ctx.options.host?.(request),
788
+ conversation: ref,
789
+ results: results.map(lateResult),
790
+ });
791
+ }
693
792
  function isDetachedBlock(block) {
694
793
  return block.kind === 'tool' && block.tool.state?.phase === 'background';
695
794
  }
@@ -764,7 +863,7 @@ async function rewind(ctx, request, session) {
764
863
  throw new TheoremError('internal', labelText('error.internal'));
765
864
  const rewound = {
766
865
  conversation: next.ref,
767
- view: await currentView(ctx, request, session, host, next.conversation),
866
+ view: await currentView(ctx, request, session, host, next.ref, next.conversation),
768
867
  };
769
868
  return jsonResponse(200, rewound);
770
869
  }
package/server/mod.d.ts CHANGED
@@ -17,6 +17,7 @@ export { createTheoremHandler, createTheoremHostHandler, readBody, type TheoremH
17
17
  export { createTheoremMcpHandler, type TheoremMcpHandlerOptions } from './mcp-handler.ts';
18
18
  export { createMemoryNotifier, type TheoremNotifier } from './notifier.ts';
19
19
  export { createMemoryPageToolBroker, type PageToolBroker, type PageToolResult, pageToolResultSchema, sessionPageDispatch, } from './page-dispatch.ts';
20
+ export { pageWakes } from './page-wakes.ts';
20
21
  export { checkRequest, parseLiveClientMessage, parseLiveOpenMessage } from './request-check.ts';
21
22
  export { sessionStateStore } from './session-authority.ts';
22
23
  export { createTheoremSessionBoundary, type PreparedLiveOpen, type SessionBoundaryOptions, type TheoremSessionBoundary, } from './session-boundary.ts';
package/server/mod.js CHANGED
@@ -16,6 +16,7 @@ export { createTheoremHandler, createTheoremHostHandler, readBody, theoremSessio
16
16
  export { createTheoremMcpHandler } from "./mcp-handler.js";
17
17
  export { createMemoryNotifier } from "./notifier.js";
18
18
  export { createMemoryPageToolBroker, pageToolResultSchema, sessionPageDispatch, } from "./page-dispatch.js";
19
+ export { pageWakes } from "./page-wakes.js";
19
20
  export { checkRequest, parseLiveClientMessage, parseLiveOpenMessage } from "./request-check.js";
20
21
  export { sessionStateStore } from "./session-authority.js";
21
22
  export { createTheoremSessionBoundary, } from "./session-boundary.js";
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @module
3
+ * The ready-made decider for an app with no server of its own: the page open on the chat wakes it.
4
+ */
5
+ import type { LateResultsDecider } from '@theoremjs/agents';
6
+ /**
7
+ * The page open on a chat wakes it when a background call ends, and a reply reads every result
8
+ * that waits. It keeps no count: each result is read once, by the first reply that runs.
9
+ */
10
+ export declare const pageWakes: LateResultsDecider;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The page open on a chat wakes it when a background call ends, and a reply reads every result
3
+ * that waits. It keeps no count: each result is read once, by the first reply that runs.
4
+ */
5
+ export const pageWakes = {
6
+ give: ({ results }) => results.map((result) => result.operationId),
7
+ due: ({ results }) => results.length > 0,
8
+ };