@theoremjs/web 0.3.5-next.986.g09d7a13 → 0.3.5-next.988.gb2d8ffd
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.js +33 -5
package/README.md
CHANGED
|
@@ -815,6 +815,7 @@ What the loop leaves to you:
|
|
|
815
815
|
- The session. Every read and write names it, and the store refuses a ref from another session.
|
|
816
816
|
- Gates. A profile whose tools wait for approval needs a session store that issues each gate and checks its answer. `createTheoremHandler` keeps one. With your own server, check the answer, run the call with `invokeTool`, and pass its events to `answerReply`.
|
|
817
817
|
- Walking away. A message to a reply that waits on gates must name exactly `waitingCalls(conversation)` as `abandon`, and pass each call's cancelled run as `walkAway`.
|
|
818
|
+
- Tool data. When `profileShowsToolData(profile)` is `false`, give the page each line through `eventWithoutToolData` and each block of a view through `blockWithoutToolData`. All three come from `@theoremjs/agents/interface`. Drop a line or a block that either one returns as `undefined`. Do not apply them to what you save: the model's history is rebuilt from the saved transcript.
|
|
818
819
|
|
|
819
820
|
On the browser side, `@theoremjs/web/client` reads what your server sends:
|
|
820
821
|
|
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.988.gb2d8ffd",
|
|
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.988.gb2d8ffd"
|
|
29
29
|
}
|
|
30
30
|
}
|
package/server/handler.js
CHANGED
|
@@ -41,7 +41,7 @@ import { pageToolResultSchema, sessionPageDispatch } from "./page-dispatch.js";
|
|
|
41
41
|
*/
|
|
42
42
|
import { defaultKernelScope, defineProfile, labelText, TheoremError, } from '@theoremjs/agents';
|
|
43
43
|
import { caughtStatus, clientError, forClient, HTTP_NOT_FOUND, } from '@theoremjs/agents/host';
|
|
44
|
-
import { clientProfileInterface } from '@theoremjs/agents/interface';
|
|
44
|
+
import { blockWithoutToolData, clientProfileInterface, eventWithoutToolData, profileShowsToolData, } from '@theoremjs/agents/interface';
|
|
45
45
|
import { hostInterface, theoremHostCallRequestSchema } from "../client/host-transport.js";
|
|
46
46
|
import { theoremConversationRequestSchema, theoremInvokeRequestSchema, theoremNotifyRequestSchema, theoremRewindRequestSchema, theoremSteerRequestSchema, theoremStopRequestSchema, theoremTurnRequestSchema, theoremWakeRequestSchema, } from "../client/transport.js";
|
|
47
47
|
import { statelessRefusal } from "./conversation.js";
|
|
@@ -119,6 +119,32 @@ function caughtError(ctx, err, request) {
|
|
|
119
119
|
ctx.options.onError?.(err, { request });
|
|
120
120
|
return clientError(err, ctx.profile.labels, ctx.options.clientEvents);
|
|
121
121
|
}
|
|
122
|
+
/** A line as the page may have it: under `tools.showData: false`, none of a tool call's data. */
|
|
123
|
+
function shownLine(ctx, line) {
|
|
124
|
+
if (line.type === 'conversation')
|
|
125
|
+
return line;
|
|
126
|
+
const event = forClient(line, ctx.options.clientEvents);
|
|
127
|
+
return profileShowsToolData(ctx.profile) ? event : eventWithoutToolData(event);
|
|
128
|
+
}
|
|
129
|
+
/** The conversation as the page may have it, by `shownLine`'s rule. */
|
|
130
|
+
function shownView(ctx, view) {
|
|
131
|
+
if (profileShowsToolData(ctx.profile))
|
|
132
|
+
return view;
|
|
133
|
+
const blocks = (list) => list.flatMap((block) => blockWithoutToolData(block) ?? []);
|
|
134
|
+
const { paused, ...rest } = view;
|
|
135
|
+
return {
|
|
136
|
+
...rest,
|
|
137
|
+
transcript: blocks(view.transcript),
|
|
138
|
+
...(paused
|
|
139
|
+
? {
|
|
140
|
+
paused: {
|
|
141
|
+
events: paused.events.flatMap((event) => eventWithoutToolData(event) ?? []),
|
|
142
|
+
blocks: blocks(paused.blocks),
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
: {}),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
122
148
|
function eventStream(ctx, request, source) {
|
|
123
149
|
const encoder = new TextEncoder();
|
|
124
150
|
const line = (value) => encoder.encode(`${JSON.stringify(value)}\n`);
|
|
@@ -131,8 +157,10 @@ function eventStream(ctx, request, source) {
|
|
|
131
157
|
controller.enqueue(line(value));
|
|
132
158
|
};
|
|
133
159
|
try {
|
|
134
|
-
for await (const
|
|
135
|
-
|
|
160
|
+
for await (const line of source()) {
|
|
161
|
+
const shown = shownLine(ctx, line);
|
|
162
|
+
if (shown)
|
|
163
|
+
send(shown);
|
|
136
164
|
}
|
|
137
165
|
}
|
|
138
166
|
catch (err) {
|
|
@@ -328,7 +356,7 @@ async function conversation(ctx, chat, request, session) {
|
|
|
328
356
|
const view = await coreOf(ctx, chat, request).read(contextOf(ctx, request, session.id), {
|
|
329
357
|
ref: body.conversation,
|
|
330
358
|
});
|
|
331
|
-
return jsonResponse(200, view);
|
|
359
|
+
return jsonResponse(200, shownView(ctx, view));
|
|
332
360
|
}
|
|
333
361
|
/**
|
|
334
362
|
* A reply to no message, for results that ended since the model last ran. It runs under a hold of
|
|
@@ -389,7 +417,7 @@ async function rewind(ctx, chat, request, session) {
|
|
|
389
417
|
ref: body.conversation,
|
|
390
418
|
at: body.at,
|
|
391
419
|
});
|
|
392
|
-
return jsonResponse(200, rewound);
|
|
420
|
+
return jsonResponse(200, { ...rewound, view: shownView(ctx, rewound.view) });
|
|
393
421
|
}
|
|
394
422
|
async function steer(ctx, chat, request, session) {
|
|
395
423
|
const body = await readBody(request, theoremSteerRequestSchema, ctx.options.maxRequestBytes);
|