@theoremjs/web 0.3.5-next.1016.gc4ded01 → 0.3.5-next.1018.g6c48978
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 -0
- package/package.json +2 -2
- package/server/handler.d.ts +13 -1
- package/server/handler.js +29 -2
- package/server/turn-wiring.d.ts +4 -13
package/README.md
CHANGED
|
@@ -284,6 +284,7 @@ const transport = withPageToolDispatch(
|
|
|
284
284
|
| `session` | Returns the session id of the caller, for example `${userId}:${conversationId}`. Return `undefined` to refuse the request with a 401. Default: a random id in an HttpOnly, SameSite=Lax cookie that lasts 30 days. |
|
|
285
285
|
| `host` | App data for the tool handlers (`ctx.host`), such as the signed-in user. The handler asks it one time for each run, when the run first reads it. |
|
|
286
286
|
| `prepare` | Your app's own turn, from the one the handler builds (`TurnWiring.prepare` from `@theoremjs/agents`). Set what your app sets per turn, such as `system`, `credentials`, `onStage`, `onEvent` and `onAgentCall`; read your app data as `turn.host`. The handler keeps its profile and its abort. Your `onStage` runs before the handler's steering, and your `credentials` are read before the session's. An `execution` you return decides each call, and the session still records the same call; a `background` you return takes the place of the `background` option. A call held at a gate runs on, once answered, with the `host`, `onStage`, `credentials`, `execution` and `background` you give for that call's turn; that turn has `answersHeldCall`, and its `onEvent` is not called, because no new turn runs. |
|
|
287
|
+
| `core` | A `ConversationCore` your app built (`createTheoremConversationCore`). The handler runs each chat call on it, and takes no `prepare`, `inbox`, `onStage`, `beforeSave`, `afterSave`, `compact`, `lateResultsDecider`, `background`, `replyFeed`, `authorizeToolReplay` or `authorizationUrl` beside it: the core has them. It does take `intake` and `onContinue`. |
|
|
287
288
|
| `inbox`, `beforeSave`, `afterSave`, `compact` | Your app's own inbox and your steps around each save, as [the conversation core](#run-replies-with-no-page-request) takes them. Each is given the request's context: its `host` is what `host` returned for the request, so `await at.host`. With `inbox`, every reply the page starts runs under a hold of your conversation, and a wake tells the items that wait in it. A steer needs `intake`: it saves the message into your inbox. Without `intake`, the handler refuses the steer with a `config` error. Do not set `inbox` with `lateResultsDecider`. |
|
|
288
289
|
| `onStage` | The server's own stage handler, on every call the handler runs, a host profile's included: after your app's (`prepare`), before steering. For a rule the server adds to whatever the app says, such as a question before each tool that writes. |
|
|
289
290
|
| `pageToolBroker` | Delivers results to active page dispatches. Default: bounded process memory. |
|
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.1018.g6c48978",
|
|
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.1018.g6c48978"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/server/handler.d.ts
CHANGED
|
@@ -47,7 +47,7 @@ import { type ClientTurnOptions } from '@theoremjs/agents/host';
|
|
|
47
47
|
import { type TranscriptBlock } from '@theoremjs/agents/interface';
|
|
48
48
|
import type { ToolBackgroundService } from '@theoremjs/agents/kernel';
|
|
49
49
|
import { type TheoremTurnInput } from '../client/transport.ts';
|
|
50
|
-
import { type ReplyWiring } from './conversation-core.ts';
|
|
50
|
+
import { type ConversationCore, type ReplyWiring } from './conversation-core.ts';
|
|
51
51
|
import type { TheoremConversationStore } from './conversation-store.ts';
|
|
52
52
|
import type { TheoremCredentialStore } from './credential-store.ts';
|
|
53
53
|
import type { TheoremNotifier } from './notifier.ts';
|
|
@@ -179,6 +179,18 @@ export type TheoremHandlerOptions<Item extends InboxItem = InboxItem> = ReplyWir
|
|
|
179
179
|
* that stopped without letting go keeps the chat no longer. Default 60000.
|
|
180
180
|
*/
|
|
181
181
|
conversationLeaseMs?: number;
|
|
182
|
+
/**
|
|
183
|
+
* The app's own conversation core, which runs every reply, read, rewind, stop and steer the page
|
|
184
|
+
* asks for, in place of the core the handler builds. The page's request reaches it as a
|
|
185
|
+
* `CoreContext`: the session's id, the request's signal, and `host`. The core brings its own
|
|
186
|
+
* profile, provider, inbox, stores, notifier and save steps, so none of these is read here:
|
|
187
|
+
* `prepare`, `onStage`, `inbox`, `beforeSave`, `afterSave`, `compact`, `lateResultsDecider`,
|
|
188
|
+
* `background`, `replyFeed`, `authorizeToolReplay`, `authorizationUrl`. The handler refuses one
|
|
189
|
+
* set beside it. `intake` and `onContinue` still run here, and `intake` then needs no `inbox`:
|
|
190
|
+
* the core's own is the one it saves into. `conversationStore` is still required for a profile
|
|
191
|
+
* that keeps a conversation, and the handler reads no conversation from it.
|
|
192
|
+
*/
|
|
193
|
+
core?: ConversationCore;
|
|
182
194
|
/**
|
|
183
195
|
* Who runs the next reply when a reply ends with items that wait and may be told now. `here`:
|
|
184
196
|
* the handler runs it in the same response. `taken`: your app runs it, by its own call to the
|
package/server/handler.js
CHANGED
|
@@ -235,8 +235,34 @@ function callsOf(ctx, request) {
|
|
|
235
235
|
},
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
|
+
/** The options the app's own `core` brings itself, so the handler refuses them beside it. */
|
|
239
|
+
const CORE_OWNED = [
|
|
240
|
+
'prepare',
|
|
241
|
+
'onStage',
|
|
242
|
+
'inbox',
|
|
243
|
+
'beforeSave',
|
|
244
|
+
'afterSave',
|
|
245
|
+
'compact',
|
|
246
|
+
'lateResultsDecider',
|
|
247
|
+
'background',
|
|
248
|
+
'replyFeed',
|
|
249
|
+
'authorizeToolReplay',
|
|
250
|
+
'authorizationUrl',
|
|
251
|
+
];
|
|
252
|
+
/** Refuses an option the app's `core` already holds: the handler would never read it. */
|
|
253
|
+
function oneCore(options) {
|
|
254
|
+
if (options.core === undefined)
|
|
255
|
+
return;
|
|
256
|
+
const doubled = CORE_OWNED.filter((name) => options[name] !== undefined);
|
|
257
|
+
if (doubled.length === 0)
|
|
258
|
+
return;
|
|
259
|
+
// labels-exempt: builder config error at setup; no user sees it
|
|
260
|
+
throw new TheoremError('config', `createTheoremHandler runs on the app's \`core\`, which brings its own ${doubled.map((name) => `\`${name}\``).join(', ')}; do not set ${doubled.length === 1 ? 'it' : 'them'} here`);
|
|
261
|
+
}
|
|
238
262
|
/** The chat's conversation core as `request` runs it. */
|
|
239
263
|
function coreOf(ctx, chat, request) {
|
|
264
|
+
if (ctx.options.core)
|
|
265
|
+
return ctx.options.core;
|
|
240
266
|
const calls = callsOf(ctx, request);
|
|
241
267
|
return ctx.wire({
|
|
242
268
|
...calls,
|
|
@@ -576,9 +602,10 @@ async function route(ctx, request, session) {
|
|
|
576
602
|
export function createTheoremHandler(options) {
|
|
577
603
|
const chat = chatOf('createTheoremHandler', options.profile, options.conversationStore);
|
|
578
604
|
oneInbox(options);
|
|
579
|
-
|
|
605
|
+
oneCore(options);
|
|
606
|
+
if (options.intake && !options.inbox && !options.core) {
|
|
580
607
|
// labels-exempt: builder config error at setup; no user sees it
|
|
581
|
-
throw new TheoremError('config', 'createTheoremHandler needs `inbox` with `intake`');
|
|
608
|
+
throw new TheoremError('config', 'createTheoremHandler needs `inbox` or `core` with `intake`');
|
|
582
609
|
}
|
|
583
610
|
const { prepare, inbox, beforeSave, afterSave, compact } = options;
|
|
584
611
|
return serve('createTheoremHandler', chat.profile, options, {
|
package/server/turn-wiring.d.ts
CHANGED
|
@@ -6,20 +6,11 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @module
|
|
8
8
|
*/
|
|
9
|
-
import type { NormalizedTurnRequest, StageHandler, TurnRequest } from '@theoremjs/agents';
|
|
10
|
-
import { type
|
|
11
|
-
|
|
12
|
-
* The app's refusal of a reply, in place of a turn: its own line is the reply, with no model run.
|
|
13
|
-
* `host` is the app's own values for the line's block.
|
|
14
|
-
*/
|
|
15
|
-
export type ReplyRefusal = {
|
|
16
|
-
refuse: {
|
|
17
|
-
text: string;
|
|
18
|
-
host?: JsonObject;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
9
|
+
import type { NormalizedTurnRequest, ReplyRefusal, StageHandler, TurnRequest, TurnWiring } from '@theoremjs/agents';
|
|
10
|
+
import { type ToolBackgroundService, type ToolCredentialSource } from '@theoremjs/agents/kernel';
|
|
11
|
+
export type { ReplyRefusal };
|
|
21
12
|
/** The app's `prepare` for a turn the server runs: the turn, or its refusal of the reply. */
|
|
22
|
-
export type AppPrepare =
|
|
13
|
+
export type AppPrepare = NonNullable<TurnWiring['prepare']>;
|
|
23
14
|
/** Whether `prepare` refused the reply. */
|
|
24
15
|
export declare function isRefusal(prepared: TurnRequest | ReplyRefusal): prepared is ReplyRefusal;
|
|
25
16
|
/** The fields a handler sets on every turn, which `prepare` cannot replace. */
|