@theoremjs/web 0.3.5-next.930.gfb5cd40 → 0.3.5-next.932.g295cc67
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 +2 -2
- package/package.json +2 -2
- package/server/handler.d.ts +2 -9
- package/server/handler.js +5 -1
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` |
|
|
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). |
|
|
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,7 +458,7 @@ 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` decides whether a wake runs, for example to cap wakes for each person. 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 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.
|
|
462
462
|
|
|
463
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.
|
|
464
464
|
|
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.932.g295cc67",
|
|
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.932.g295cc67"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/server/handler.d.ts
CHANGED
|
@@ -153,15 +153,8 @@ export type TheoremHandlerOptions = {
|
|
|
153
153
|
status: 'settled';
|
|
154
154
|
}>;
|
|
155
155
|
}) => boolean | Promise<boolean>;
|
|
156
|
-
/**
|
|
157
|
-
|
|
158
|
-
* refuse is not tried again for the same results; the next message reads them. Unset, every wake
|
|
159
|
-
* runs.
|
|
160
|
-
*/
|
|
161
|
-
authorizeWake?: (context: {
|
|
162
|
-
request: Request;
|
|
163
|
-
conversation: string;
|
|
164
|
-
}) => boolean | Promise<boolean>;
|
|
156
|
+
/** Whether a wake may run: `TurnWiring.authorizeWake`, given the `host` this request makes. */
|
|
157
|
+
authorizeWake?: TurnWiring['authorizeWake'];
|
|
165
158
|
/**
|
|
166
159
|
* Tool credentials by session. Your OAuth callback route saves the token here
|
|
167
160
|
* under the same session id; every turn reads from here. Default: in-process
|
package/server/handler.js
CHANGED
|
@@ -613,7 +613,11 @@ async function wake(ctx, request, session) {
|
|
|
613
613
|
: [];
|
|
614
614
|
const { authorizeWake } = ctx.options;
|
|
615
615
|
const allowed = taken.length > 0 &&
|
|
616
|
-
(!authorizeWake ||
|
|
616
|
+
(!authorizeWake ||
|
|
617
|
+
(await authorizeWake({
|
|
618
|
+
host: await ctx.options.host?.(request),
|
|
619
|
+
conversation: body.conversation,
|
|
620
|
+
})));
|
|
617
621
|
if (!allowed)
|
|
618
622
|
return eventStream(ctx, request, async function* () { });
|
|
619
623
|
const runner = chatRunner(ctx, request, session, body);
|