@theoremjs/web 0.3.5-next.981.gf4729de → 0.3.5-next.982.g16b31de
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 +1 -1
- package/client/transport.d.ts +1 -1
- package/package.json +2 -2
- package/server/conversation-core.js +10 -9
- package/server/handler.d.ts +5 -3
- package/server/handler.js +3 -2
- package/server/notifier.d.ts +3 -2
- package/server/notifier.js +3 -2
package/README.md
CHANGED
|
@@ -478,7 +478,7 @@ Browser dispatch uses a host-owned `PageToolExecution` service beside the execut
|
|
|
478
478
|
`createTheoremHandler` supplies both services. Live relays put the session boundary's `pageExecution` and `toolExecution` on `SessionRequest`.
|
|
479
479
|
|
|
480
480
|
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`.
|
|
481
|
-
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.
|
|
481
|
+
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. With `inbox`, the read always tells the page to listen, because your app saves replies the page did not start: call `notifier.publish(sessionId)` after each one. The model reads the result only as your decider says.
|
|
482
482
|
|
|
483
483
|
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 ended and no saved reply told it. When the session holds no end for the call (it dropped the settled operation, or marked the call `uncertain`), the result waits as an error with the code `outcome_not_retained` or the uncertainty's reason, and the model reads that the action is unresolved. `ended` hears that end too. A call `authorizeToolReplay` withholds from the request does not wait.
|
|
484
484
|
|
package/client/transport.d.ts
CHANGED
|
@@ -213,7 +213,7 @@ export type TheoremWakeRequest = {
|
|
|
213
213
|
};
|
|
214
214
|
/** A `/wake` body as `createTheoremHandler` reads it. */
|
|
215
215
|
export declare const theoremWakeRequestSchema: z.ZodType<TheoremWakeRequest>;
|
|
216
|
-
/** Listen for
|
|
216
|
+
/** Listen for changes to this session: a background call ended, or the app saved a reply. A `/notify` body. */
|
|
217
217
|
export type TheoremNotifyRequest = Record<string, never>;
|
|
218
218
|
/** A `/notify` body as `createTheoremHandler` reads it. */
|
|
219
219
|
export declare const theoremNotifyRequestSchema: z.ZodType<TheoremNotifyRequest>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/web",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.982.g16b31de",
|
|
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.
|
|
28
|
+
"@theoremjs/agents": "^0.3.5-next.982.g16b31de"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -516,18 +516,19 @@ async function currentView(ctx, at, host, ref, conversation) {
|
|
|
516
516
|
return view;
|
|
517
517
|
const wake = (await wakeDue(ctx, at, host, ref, conversation)) ? { wake: true } : {};
|
|
518
518
|
if (!detached)
|
|
519
|
-
return { ...view, ...wake };
|
|
519
|
+
return { ...view, ...notifyOffer(ctx), ...wake };
|
|
520
520
|
const { operations } = await ctx.sessions.read(at.sessionId);
|
|
521
521
|
const transcript = await Promise.all(view.transcript.map((block) => isDetachedBlock(block) ? lateBlock(ctx, at, block, operations, host) : block));
|
|
522
|
+
// why: an app's inbox saves replies the page did not ask for, so its page always listens
|
|
523
|
+
const listens = ctx.options.inbox !== undefined || transcript.some(isDetachedBlock);
|
|
524
|
+
return { ...view, transcript, ...(listens ? notifyOffer(ctx) : {}), ...wake };
|
|
525
|
+
}
|
|
526
|
+
/** The view's offer to listen on `/notify`: none without a notifier. */
|
|
527
|
+
function notifyOffer(ctx) {
|
|
522
528
|
const { notifier, notifyRetryMs } = ctx.options;
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
...(notifier && transcript.some(isDetachedBlock)
|
|
527
|
-
? { notify: notifyRetryMs === undefined ? {} : { retryMs: notifyRetryMs } }
|
|
528
|
-
: {}),
|
|
529
|
-
...wake,
|
|
530
|
-
};
|
|
529
|
+
if (!notifier)
|
|
530
|
+
return {};
|
|
531
|
+
return { notify: notifyRetryMs === undefined ? {} : { retryMs: notifyRetryMs } };
|
|
531
532
|
}
|
|
532
533
|
/**
|
|
533
534
|
* Whether the page wakes the chat now: the decider's policy tells a waiting result to a reply to no
|
package/server/handler.d.ts
CHANGED
|
@@ -13,8 +13,9 @@ import { type PageToolBroker } from './page-dispatch.ts';
|
|
|
13
13
|
* - `POST <base>/stop` → stop a running turn where it stands
|
|
14
14
|
* - `POST <base>/page-result` → the page's result for a tool the turn ran in the page
|
|
15
15
|
* - `POST <base>/conversation` → the transcript and the paused reply, to draw
|
|
16
|
-
* - `POST <base>/notify` → NDJSON that stays open: one line now, and one each
|
|
17
|
-
*
|
|
16
|
+
* - `POST <base>/notify` → NDJSON that stays open: one line now, and one for each `publish` under
|
|
17
|
+
* this session: a background call ended, or the app saved a reply.
|
|
18
|
+
* Set `notifier` to serve it
|
|
18
19
|
* - `POST <base>/rewind` → `{ conversation, view }` the conversation cut after one block, and its new ref
|
|
19
20
|
* - `POST <base>/wake` → NDJSON for a reply to no message: the model takes up the results of
|
|
20
21
|
* background calls that ended since it last ran. Empty when none waits
|
|
@@ -138,7 +139,8 @@ export type TheoremHandlerOptions<Item extends InboxItem = InboxItem> = ReplyWir
|
|
|
138
139
|
/**
|
|
139
140
|
* Tells an open page that a background call ended, so it redraws with no turn or reload. Unset,
|
|
140
141
|
* the page reads the end on its next turn or reload. A sweep that marks a call itself calls
|
|
141
|
-
* `publish` too. `
|
|
142
|
+
* `publish` too. With `inbox`, the page always listens, and the app calls `publish` for each
|
|
143
|
+
* reply it saves away from the page. `createMemoryNotifier` for one instance.
|
|
142
144
|
*/
|
|
143
145
|
notifier?: TheoremNotifier;
|
|
144
146
|
/**
|
package/server/handler.js
CHANGED
|
@@ -13,8 +13,9 @@ import { pageToolResultSchema, sessionPageDispatch } from "./page-dispatch.js";
|
|
|
13
13
|
* - `POST <base>/stop` → stop a running turn where it stands
|
|
14
14
|
* - `POST <base>/page-result` → the page's result for a tool the turn ran in the page
|
|
15
15
|
* - `POST <base>/conversation` → the transcript and the paused reply, to draw
|
|
16
|
-
* - `POST <base>/notify` → NDJSON that stays open: one line now, and one each
|
|
17
|
-
*
|
|
16
|
+
* - `POST <base>/notify` → NDJSON that stays open: one line now, and one for each `publish` under
|
|
17
|
+
* this session: a background call ended, or the app saved a reply.
|
|
18
|
+
* Set `notifier` to serve it
|
|
18
19
|
* - `POST <base>/rewind` → `{ conversation, view }` the conversation cut after one block, and its new ref
|
|
19
20
|
* - `POST <base>/wake` → NDJSON for a reply to no message: the model takes up the results of
|
|
20
21
|
* background calls that ended since it last ran. Empty when none waits
|
package/server/notifier.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Where a session's open pages hear that a background call ended
|
|
3
|
-
* page that hears it reads the conversation, so one read decides what a
|
|
2
|
+
* Where a session's open pages hear that a background call ended or the app saved a reply. The line
|
|
3
|
+
* carries no content: a page that hears it reads the conversation, so one read decides what a
|
|
4
|
+
* reader sees.
|
|
4
5
|
*
|
|
5
6
|
* @module
|
|
6
7
|
*/
|
package/server/notifier.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Where a session's open pages hear that a background call ended
|
|
3
|
-
* page that hears it reads the conversation, so one read decides what a
|
|
2
|
+
* Where a session's open pages hear that a background call ended or the app saved a reply. The line
|
|
3
|
+
* carries no content: a page that hears it reads the conversation, so one read decides what a
|
|
4
|
+
* reader sees.
|
|
4
5
|
*
|
|
5
6
|
* @module
|
|
6
7
|
*/
|