@theoremjs/web 0.3.5-next.982.g16b31de → 0.3.5-next.984.g892c959
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 -1
- package/client/chat.js +25 -3
- package/package.json +2 -2
- package/server/conversation-core.d.ts +8 -5
- package/server/conversation-core.js +5 -2
- package/server/handler.js +2 -2
- package/server/mod.d.ts +1 -0
- package/server/mod.js +1 -0
package/README.md
CHANGED
|
@@ -384,6 +384,7 @@ interface ConversationDatabase {
|
|
|
384
384
|
- A null `ref` creates a conversation. Return a new opaque `ref` and `revision`.
|
|
385
385
|
- Otherwise, write only while the stored revision is still `expectedRevision`, as one atomic operation. Return `{ written: false }` on a conflict.
|
|
386
386
|
- Check what you read back with `storedConversationSchema`.
|
|
387
|
+
- A store that keeps each block in its own place (a row, a column) checks one block with `transcriptBlockSchema`.
|
|
387
388
|
- Keep `id` as the handler gives it. It names the conversation in each turn's trace as `gen_ai.conversation.id`, and stays the same through every save and rewind.
|
|
388
389
|
|
|
389
390
|
### Share session authority
|
|
@@ -551,7 +552,7 @@ async function received(sessionId: string, text: string, ref: string | undefined
|
|
|
551
552
|
| `release(at, { ref, hold })` | Lets the conversation go under that hold, with no follow-up. |
|
|
552
553
|
| `read(at, { ref })` | Returns the conversation as a page draws it. |
|
|
553
554
|
| `rewind(at, { ref, at })` | Cuts the conversation after transcript block `at`. |
|
|
554
|
-
| `steer(at, { turnId,
|
|
555
|
+
| `steer(at, { turnId, id, input })` | Puts `input` into a running turn. Returns `false` when the turn is not running. Throws what `message` throws for an `input` the profile does not take, such as text over `inputs.maxTextChars`. |
|
|
555
556
|
| `stop(at, { turnId })` | Stops a running turn. Returns `false` when the turn is not running. When your `inbox` has a `stop`, it stops the reply that holds the conversation, and `turnId` is not read. |
|
|
556
557
|
|
|
557
558
|
The core takes these options from [Server options](#server-options), with the same meaning: `profile`, `onStage`, `sessionStore`, `conversationStore`, `credentialStore`, `gateTtlMs`, `operationRetentionMs`, `pageToolBroker`, `pageToolTimeoutMs`, `notifier`, `notifyRetryMs`, `lateResultsDecider`, `conversationLeaseMs`, `steerInbox`, and `clientEvents`. These options take the run context in place of the `Request`:
|
package/client/chat.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TheoremError, } from '@theoremjs/agents';
|
|
2
|
-
import { branchInterfaceTurnSession, consumeNextComposerQueue, convertSteersToFrontQueued, createComposerPendingMessage, defaultInterfaceEffort, emptyInterfaceTurnSession, moveComposerPendingWithinKind, orderComposerPendingMessages, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, saveComposerPendingMessage, takeSavedComposerPending, userDraftHasPayload, userDraftToSteerInject, } from '@theoremjs/agents/interface';
|
|
1
|
+
import { attachmentsRefused, TheoremError, } from '@theoremjs/agents';
|
|
2
|
+
import { branchInterfaceTurnSession, consumeNextComposerQueue, convertSteersToFrontQueued, createComposerPendingMessage, defaultInterfaceEffort, emptyInterfaceTurnSession, moveComposerPendingWithinKind, orderComposerPendingMessages, prepareUserTurn, promoteComposerPendingKind, removeComposerPendingMessage, removeLandedSteers, saveComposerPendingMessage, takeSavedComposerPending, userDraftHasPayload, userDraftToSteerInject, } from '@theoremjs/agents/interface';
|
|
3
3
|
import { composerHasPayload } from "./composer-primary.js";
|
|
4
4
|
import { composerFieldsFromDraft } from "./decode-composer-draft.js";
|
|
5
5
|
import { encodeComposerDraft } from "./encode-composer-draft.js";
|
|
@@ -277,7 +277,19 @@ class Chat {
|
|
|
277
277
|
if (Object.keys(patch).length > 0)
|
|
278
278
|
this.#set(patch);
|
|
279
279
|
};
|
|
280
|
-
setDraftText = (value) =>
|
|
280
|
+
setDraftText = (value) => {
|
|
281
|
+
const next = typeof value === 'function' ? value(this.#state.draftText) : value;
|
|
282
|
+
if (next === this.#state.draftText)
|
|
283
|
+
return;
|
|
284
|
+
const { failure } = this.#state;
|
|
285
|
+
const issues = this.#state.issues.filter((issue) => issue.code !== 'text_too_long');
|
|
286
|
+
// why: Editing the text answers a refusal for its length; a refusal for the files stays until they change.
|
|
287
|
+
this.#set({
|
|
288
|
+
draftText: next,
|
|
289
|
+
issues,
|
|
290
|
+
...(failure?.errorKind === 'input' && issues.length === 0 ? { failure: null } : {}),
|
|
291
|
+
});
|
|
292
|
+
};
|
|
281
293
|
setPendingFiles = (value) => this.#apply('pendingFiles', value);
|
|
282
294
|
setPendingVoice = (value) => this.#apply('pendingVoice', value);
|
|
283
295
|
setPendingMessages = (value) => this.#apply('pendingMessages', value);
|
|
@@ -322,6 +334,16 @@ class Chat {
|
|
|
322
334
|
try {
|
|
323
335
|
const draft = await encodeComposerDraft({ text: draftText, pendingFiles, pendingVoice });
|
|
324
336
|
message = createComposerPendingMessage({ kind, draft });
|
|
337
|
+
const { iface } = this.#options;
|
|
338
|
+
const checked = kind !== 'stash' && iface ? prepareUserTurn(iface.inputs, draft, iface.guardrails) : null;
|
|
339
|
+
if (checked && !checked.ok) {
|
|
340
|
+
// why: A message the profile refuses is never queued or steered; it stays in the composer as typed.
|
|
341
|
+
this.#set({
|
|
342
|
+
issues: checked.issues,
|
|
343
|
+
failure: clientFailure(attachmentsRefused(checked.issues), iface?.labels),
|
|
344
|
+
});
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
325
347
|
}
|
|
326
348
|
catch (err) {
|
|
327
349
|
this.#set({ failure: clientFailure(err, this.#options.iface?.labels) });
|
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.984.g892c959",
|
|
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.984.g892c959"
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -9,11 +9,11 @@ import { type GateReference, type NormalizedTurnRequest, type Profile, type Prof
|
|
|
9
9
|
import { type ConversationInbox, type InboxItem, type InboxPolicy, type ReplyRun } from '@theoremjs/agents/conversation';
|
|
10
10
|
import type { ClientTurnOptions } from '@theoremjs/agents/host';
|
|
11
11
|
import { type TranscriptBlock } from '@theoremjs/agents/interface';
|
|
12
|
-
import type { ConversationView, StatedTurn, TheoremInvokeRequest, TheoremRewound, TheoremTurnInput } from '../client/transport.ts';
|
|
12
|
+
import type { ConversationView, StatedTurn, TheoremInvokeRequest, TheoremRewound, TheoremSteerRequest, TheoremTurnInput } from '../client/transport.ts';
|
|
13
13
|
import { type ReplyLine, type ReplyToSave, type ShapedReply } from './conversation.ts';
|
|
14
14
|
import { type ReplyEnd, type TheoremConversationStore } from './conversation-store.ts';
|
|
15
15
|
import { type CallsContext, type CoreContext } from './session-calls.ts';
|
|
16
|
-
import { type SteerInbox
|
|
16
|
+
import { type SteerInbox } from './steer-inbox.ts';
|
|
17
17
|
import { type ReplyRefusal } from './turn-wiring.ts';
|
|
18
18
|
export type ChatProfile = Exclude<Profile, {
|
|
19
19
|
type: 'live' | 'decision' | 'host' | 'embedding';
|
|
@@ -247,11 +247,14 @@ export type ConversationCore = {
|
|
|
247
247
|
ref: string;
|
|
248
248
|
at: number;
|
|
249
249
|
}): Promise<TheoremRewound>;
|
|
250
|
-
/**
|
|
250
|
+
/**
|
|
251
|
+
* Puts a steer into a running turn, as the one user message the model reads. Throws what
|
|
252
|
+
* `message` throws for an input the profile does not take, such as text over its limit, and
|
|
253
|
+
* puts nothing in. False when the turn is not running.
|
|
254
|
+
*/
|
|
251
255
|
steer(at: CoreContext, args: {
|
|
252
256
|
turnId: string;
|
|
253
|
-
|
|
254
|
-
}): Promise<boolean>;
|
|
257
|
+
} & Pick<TheoremSteerRequest, 'id' | 'input'>): Promise<boolean>;
|
|
255
258
|
/**
|
|
256
259
|
* Stops a running turn where it stands. False when the turn is not running. Where the app's
|
|
257
260
|
* `inbox` has a `stop`, it stops the reply that holds the conversation, and reads no `turnId`.
|
|
@@ -13,7 +13,7 @@ import { detachedEnd, sessionConversationInbox } from "./conversation-inbox.js";
|
|
|
13
13
|
import { unknownConversation, } from "./conversation-store.js";
|
|
14
14
|
import { sessionPageDispatch } from "./page-dispatch.js";
|
|
15
15
|
import { announced, backgroundWiring, pausedWaits, recorded, replayAllowed, sessionCredentials, settlingOf, takeLapsed, takeWalkedAway, withAuthorizationUrls, } from "./session-calls.js";
|
|
16
|
-
import { steerStage, stopOnRequest } from "./steer-inbox.js";
|
|
16
|
+
import { steerStage, steerUnitOf, stopOnRequest } from "./steer-inbox.js";
|
|
17
17
|
import { sessionToolCoordinator } from "./tool-operations.js";
|
|
18
18
|
import { isRefusal, preparedTurn, stagesInOrder } from "./turn-wiring.js";
|
|
19
19
|
/**
|
|
@@ -769,7 +769,10 @@ export function createConversationCore(state) {
|
|
|
769
769
|
release: (at, args) => release(state, at, args),
|
|
770
770
|
read: (at, args) => read(state, at, args),
|
|
771
771
|
rewind: (at, args) => rewind(state, at, args),
|
|
772
|
-
steer: (at, { turnId,
|
|
772
|
+
steer: async (at, { turnId, ...steer }) => {
|
|
773
|
+
postedMessage(chatInterface(state.chat), steer.input);
|
|
774
|
+
return await state.steer.enqueue(inboxKey(at.sessionId, turnId), steerUnitOf(steer));
|
|
775
|
+
},
|
|
773
776
|
stop: (at, { turnId }) => {
|
|
774
777
|
const app = state.options.inbox?.(at);
|
|
775
778
|
if (app?.stop)
|
package/server/handler.js
CHANGED
|
@@ -53,7 +53,7 @@ export { theoremSession, theoremSessionId } from "./session-identity.js";
|
|
|
53
53
|
import { jsonResponse } from "./json-response.js";
|
|
54
54
|
import { boundedRequestJson, requestByteLimit } from "./request-body.js";
|
|
55
55
|
import { checkRequest } from "./request-check.js";
|
|
56
|
-
import { createMemorySteerInbox
|
|
56
|
+
import { createMemorySteerInbox } from "./steer-inbox.js";
|
|
57
57
|
const NDJSON_HEADERS = {
|
|
58
58
|
'content-type': 'application/x-ndjson; charset=utf-8',
|
|
59
59
|
'cache-control': 'no-store',
|
|
@@ -414,7 +414,7 @@ async function steer(ctx, chat, request, session) {
|
|
|
414
414
|
const saved = { conversation: taken.ref, landsAs: [...taken.landsAs] };
|
|
415
415
|
return jsonResponse(200, { ok: true, saved });
|
|
416
416
|
}
|
|
417
|
-
if (!(await core.steer(at, { turnId: body.turnId,
|
|
417
|
+
if (!(await core.steer(at, { turnId: body.turnId, id: body.id, input: body.input }))) {
|
|
418
418
|
// labels-exempt: internal diagnostic; the user reads the error kind's (or copy key's) wording
|
|
419
419
|
throw new TheoremError('request', `turn ${body.turnId} is not running`, {
|
|
420
420
|
copy: { key: 'session.turn_ended' },
|
package/server/mod.d.ts
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export { theoremHostCallRequestSchema } from '../client/host-transport.ts';
|
|
9
9
|
export type { LiveClientMessage, LiveOpenMessage } from '../client/live-messages.ts';
|
|
10
|
+
export { transcriptBlockSchema } from '../client/transcript-schema.ts';
|
|
10
11
|
export { type StatedTurn, theoremConversationRequestSchema, theoremInvokeRequestSchema, theoremNotifyRequestSchema, theoremReplaySchema, theoremRewindRequestSchema, theoremStartRequestSchema, theoremSteerRequestSchema, theoremStopRequestSchema, theoremTurnRequestSchema, theoremWakeRequestSchema, } from '../client/transport.ts';
|
|
11
12
|
export { answerReply, type ConversationHost, type ConversationUse, conversationView, type IssuedWalkAway, messageReply, type OpenedConversation, openConversation, type PostedMessage, postedMessage, type ReplyLine, type ReplyRunner, type ReplySaving, type ReplyToSave, type ReplyTurn, readerConversationHost, rewindConversation, type ShapedReply, startConversation, statelessRefusal, type WalkedAwayCall, waitingCalls, wakeReply, } from './conversation.ts';
|
|
12
13
|
export type { AppInbox, ContinueChoice, ConversationCore, FollowUpArgs, Generation, HoldStop, MessageArgs, Reply, ReplyPrepare, ReplyWiring, RunEnd, SaveHooks, WakeArgs, } from './conversation-core.ts';
|
package/server/mod.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @module
|
|
7
7
|
*/
|
|
8
8
|
export { theoremHostCallRequestSchema } from "../client/host-transport.js";
|
|
9
|
+
export { transcriptBlockSchema } from "../client/transcript-schema.js";
|
|
9
10
|
export { theoremConversationRequestSchema, theoremInvokeRequestSchema, theoremNotifyRequestSchema, theoremReplaySchema, theoremRewindRequestSchema, theoremStartRequestSchema, theoremSteerRequestSchema, theoremStopRequestSchema, theoremTurnRequestSchema, theoremWakeRequestSchema, } from "../client/transport.js";
|
|
10
11
|
export { answerReply, conversationView, messageReply, openConversation, postedMessage, readerConversationHost, rewindConversation, startConversation, statelessRefusal, waitingCalls, wakeReply, } from "./conversation.js";
|
|
11
12
|
export { followedUp } from "./conversation-core.js";
|