@theoremjs/web 0.3.5-next.1005.geaafb0b → 0.3.5-next.1007.g0511d99

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/web",
3
- "version": "0.3.5-next.1005.geaafb0b",
3
+ "version": "0.3.5-next.1007.g0511d99",
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.1005.geaafb0b"
28
+ "@theoremjs/agents": "^0.3.5-next.1007.g0511d99"
29
29
  }
30
30
  }
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import { type GateReference, type NormalizedTurnRequest, type Profile, type ProfileDefinition, type ProviderHostOptions, TheoremError, type TurnHistoryMessage, type TurnInput, type TurnRequest } from '@theoremjs/agents';
9
9
  import { type ConversationInbox, type InboxItem, type InboxPolicy, type ReplyRun } from '@theoremjs/agents/conversation';
10
- import { type ClientTurnOptions } from '@theoremjs/agents/host';
10
+ import type { ClientTurnOptions } from '@theoremjs/agents/host';
11
11
  import { type TranscriptBlock } from '@theoremjs/agents/interface';
12
12
  import type { ConversationView, StatedTurn, TheoremInvokeRequest, TheoremRewound, TheoremSteerRequest, TheoremStopRequest, TheoremTurnInput } from '../client/transport.ts';
13
13
  import { type ReplyLine, type ReplyToSave, type ShapedReply } from './conversation.ts';
@@ -25,7 +25,8 @@ export type ChatContext = {
25
25
  conversations?: TheoremConversationStore;
26
26
  };
27
27
  /**
28
- * Where the chat saves a detached call's end: its conversation store, as `clientEvents` reads it.
28
+ * Where the chat saves a detached call's end: its conversation store, as `clientEvents` reads it,
29
+ * in the profile's wording.
29
30
  * None with `authorizeToolReplay`: every request reads a saved end, and that host checks each read.
30
31
  */
31
32
  export declare function endingsOf(chat: ChatContext | undefined, options: {
@@ -7,10 +7,9 @@
7
7
  */
8
8
  import { compactHistory, defaultKernelScope, defineProfile, labelText, runTurn, TheoremError, } from '@theoremjs/agents';
9
9
  import { runConversation, } from '@theoremjs/agents/conversation';
10
- import { forClient } from '@theoremjs/agents/host';
11
10
  import { interfaceFromProfile, refuseInterfacePick, } from '@theoremjs/agents/interface';
12
11
  import { answerReply, conversationView, messageReply, openConversation, postedMessage, readerConversationHost, rewindConversation, statelessRefusal, waitingCalls, wakeReply, } from "./conversation.js";
13
- import { detachedAt, detachedEnd, readerEnding, sessionConversationInbox, } from "./conversation-inbox.js";
12
+ import { detachedAt, detachedEnd, readerEnding, readerOf, sessionConversationInbox, } from "./conversation-inbox.js";
14
13
  import { endedBlock, unknownConversation, } from "./conversation-store.js";
15
14
  import { sessionPageDispatch } from "./page-dispatch.js";
16
15
  import { announced, backgroundWiring, pausedWaits, recorded, replayAllowed, saveEnded, sessionCredentials, settlingOf, takeLapsed, takeWalkedAway, withAuthorizationUrls, } from "./session-calls.js";
@@ -18,7 +17,8 @@ import { steerStage, steerUnitOf, stopOnRequest } from "./steer-inbox.js";
18
17
  import { sessionToolCoordinator } from "./tool-operations.js";
19
18
  import { isRefusal, preparedTurn, stagesInOrder } from "./turn-wiring.js";
20
19
  /**
21
- * Where the chat saves a detached call's end: its conversation store, as `clientEvents` reads it.
20
+ * Where the chat saves a detached call's end: its conversation store, as `clientEvents` reads it,
21
+ * in the profile's wording.
22
22
  * None with `authorizeToolReplay`: every request reads a saved end, and that host checks each read.
23
23
  */
24
24
  export function endingsOf(chat, options) {
@@ -26,7 +26,7 @@ export function endingsOf(chat, options) {
26
26
  if (!store || options.authorizeToolReplay)
27
27
  return {};
28
28
  const { clientEvents } = options;
29
- return { endings: { store, forReader: (event) => forClient(event, clientEvents) } };
29
+ return { endings: { store, forReader: readerOf({ clientEvents, labels: chat.profile.labels }) } };
30
30
  }
31
31
  /**
32
32
  * The chat `definition` serves, with the store that keeps its conversation. `name` is the function
@@ -5,8 +5,9 @@
5
5
  *
6
6
  * @module
7
7
  */
8
- import { type LateResultItem, type Profile, type ToolOperationOutcome, type TurnEvent } from '@theoremjs/agents';
8
+ import { type LabelOverrides, type LateResultItem, type Profile, type ToolOperationOutcome, type TurnEvent } from '@theoremjs/agents';
9
9
  import type { ConversationInbox } from '@theoremjs/agents/conversation';
10
+ import { type ClientTurnOptions } from '@theoremjs/agents/host';
10
11
  import type { TranscriptBlock } from '@theoremjs/agents/interface';
11
12
  import type { DetachedEnding, StoredConversation } from './conversation-store.ts';
12
13
  import type { MutableStore } from './session-authority.ts';
@@ -36,6 +37,23 @@ export declare function detachedEnd(call: DetachedCall, operation: SessionToolOp
36
37
  export declare function detachedAt(tool: Extract<TranscriptBlock, {
37
38
  kind: 'tool';
38
39
  }>['tool']): number | undefined;
40
+ /** Who reads a chat's events: the host's `clientEvents`, in the profile's `labels`. */
41
+ export type ChatReader = {
42
+ clientEvents?: ClientTurnOptions;
43
+ labels?: LabelOverrides;
44
+ };
45
+ /**
46
+ * An event as `reader` reads it: a failure in the profile's wording, then `forClient`. The page,
47
+ * a late read and every end saved for it read the same.
48
+ */
49
+ export declare function readerOf(reader: ChatReader): (event: TurnEvent) => TurnEvent;
50
+ /**
51
+ * A detached call's end as `reader` reads it: what a conversation store's `end` takes, as the
52
+ * handler saves it when the call ends. For a host that saves an end it kept itself, such as one
53
+ * that ended before its store had `end`. Undefined when the reader reads the outcome as no call's
54
+ * end.
55
+ */
56
+ export declare function detachedEnding(operationId: string, outcome: ToolOperationOutcome, reader: ChatReader): DetachedEnding | undefined;
39
57
  /** A detached call's end as `forReader` lets its reader read it: the event its block takes. */
40
58
  export declare function readerEnding(outcome: ToolOperationOutcome, forReader: (event: TurnEvent) => TurnEvent): DetachedEnding['tool'] | undefined;
41
59
  /** Options for {@link sessionConversationInbox}. */
@@ -6,6 +6,8 @@
6
6
  * @module
7
7
  */
8
8
  import { labelText, } from '@theoremjs/agents';
9
+ import { withPublicLabels } from '@theoremjs/agents/guardrails';
10
+ import { forClient } from '@theoremjs/agents/host';
9
11
  /**
10
12
  * What became of a detached call, as the model and the page read it: the end the session saved, or
11
13
  * that it is unresolved when the session holds no end (the call was cut off, or its saved end was
@@ -41,6 +43,23 @@ export function detachedEnd(call, operation, labels) {
41
43
  export function detachedAt(tool) {
42
44
  return tool.detached?.at ?? (tool.state?.phase === 'background' ? tool.state.at : undefined);
43
45
  }
46
+ /**
47
+ * An event as `reader` reads it: a failure in the profile's wording, then `forClient`. The page,
48
+ * a late read and every end saved for it read the same.
49
+ */
50
+ export function readerOf(reader) {
51
+ return (event) => forClient(withPublicLabels(event, reader.labels), reader.clientEvents);
52
+ }
53
+ /**
54
+ * A detached call's end as `reader` reads it: what a conversation store's `end` takes, as the
55
+ * handler saves it when the call ends. For a host that saves an end it kept itself, such as one
56
+ * that ended before its store had `end`. Undefined when the reader reads the outcome as no call's
57
+ * end.
58
+ */
59
+ export function detachedEnding(operationId, outcome, reader) {
60
+ const tool = readerEnding(outcome, readerOf(reader));
61
+ return tool && { operationId, tool };
62
+ }
44
63
  /** A detached call's end as `forReader` lets its reader read it: the event its block takes. */
45
64
  export function readerEnding(outcome, forReader) {
46
65
  const event = forReader(outcome.event);
@@ -21,6 +21,7 @@ import { appendAssistantEventsToHistory, appendUserDraftToHistory, applyTurnEven
21
21
  import { base64ToBytes } from '@theoremjs/agents/kernel';
22
22
  import { stampWorked, stoppedReply } from "../client/run-commit.js";
23
23
  import { withoutHost } from "../client/transcript-schema.js";
24
+ import { readerOf } from "./conversation-inbox.js";
24
25
  import { emptyConversation, unknownConversation, } from "./conversation-store.js";
25
26
  import { kernelTurnInput } from "./turn-input.js";
26
27
  /** The paused call a reference names, when its call id and its operation both match. */
@@ -37,7 +38,7 @@ export function readerConversationHost(args) {
37
38
  sessionId: args.sessionId,
38
39
  store: args.store,
39
40
  showThoughts: streamThoughtsEnabled(profile.outputs),
40
- forReader: (event) => forClient(event, clientEvents),
41
+ forReader: readerOf({ clientEvents, labels: profile.labels }),
41
42
  failureText(failure) {
42
43
  const worded = forClient(withPublicLabels(failure, profile.labels), clientEvents);
43
44
  return worded.type === 'error' && worded.error
package/server/mod.d.ts CHANGED
@@ -12,6 +12,7 @@ export { type StatedTurn, theoremConversationRequestSchema, theoremInvokeRequest
12
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';
13
13
  export type { AppInbox, ContinueChoice, ConversationCore, FollowUpArgs, Generation, HoldStop, MessageArgs, Reply, ReplyPrepare, ReplyWiring, RunEnd, SaveHooks, WakeArgs, } from './conversation-core.ts';
14
14
  export { followedUp } from './conversation-core.ts';
15
+ export { type ChatReader, detachedEnding } from './conversation-inbox.ts';
15
16
  export { type ConversationSnapshot, type ConversationWriteResult, createMemoryConversationStore, createSealedConversationStore, type DetachedEnding, emptyConversation, endedBlock, type PausedReply, type ReplyEnd, type SealedConversationStoreOptions, type StoredConversation, storedConversationSchema, type TheoremConversationStore, type UncompactedBase, unknownConversation, type WriteContext, } from './conversation-store.ts';
16
17
  export { createTheoremConversationCore, type TheoremConversationCoreOptions, } from './create-conversation-core.ts';
17
18
  export { createMemoryCredentialStore, type TheoremCredentialStore, type TheoremCredentials, } from './credential-store.ts';
package/server/mod.js CHANGED
@@ -10,6 +10,7 @@ export { transcriptBlockSchema } from "../client/transcript-schema.js";
10
10
  export { theoremConversationRequestSchema, theoremInvokeRequestSchema, theoremNotifyRequestSchema, theoremReplaySchema, theoremRewindRequestSchema, theoremStartRequestSchema, theoremSteerRequestSchema, theoremStopRequestSchema, theoremTurnRequestSchema, theoremWakeRequestSchema, } from "../client/transport.js";
11
11
  export { answerReply, conversationView, messageReply, openConversation, postedMessage, readerConversationHost, rewindConversation, startConversation, statelessRefusal, waitingCalls, wakeReply, } from "./conversation.js";
12
12
  export { followedUp } from "./conversation-core.js";
13
+ export { detachedEnding } from "./conversation-inbox.js";
13
14
  export { createMemoryConversationStore, createSealedConversationStore, emptyConversation, endedBlock, storedConversationSchema, unknownConversation, } from "./conversation-store.js";
14
15
  export { createTheoremConversationCore, } from "./create-conversation-core.js";
15
16
  export { createMemoryCredentialStore, } from "./credential-store.js";