@theoremjs/web 0.3.5-next.975.g3529c32 → 0.3.5-next.977.g42c51f5

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 CHANGED
@@ -133,7 +133,7 @@ const open = parseLiveOpenMessage(firstFrame);
133
133
  const session = await runSession(
134
134
  {
135
135
  profile,
136
- ...await boundary.prepareLiveOpen(open, hostContext),
136
+ ...await boundary.prepareLiveOpen(open, profile, hostContext),
137
137
  execution: boundary.toolExecution,
138
138
  pageExecution: boundary.pageExecution,
139
139
  },
@@ -148,7 +148,8 @@ for await (const event of session.events()) {
148
148
  ```
149
149
 
150
150
  - `prepareLiveOpen` returns validated history, options, context, native state, and absence duration. It removes system-role history.
151
- - Its second argument supplies server context. Browser context stays under `client`.
151
+ - Its second argument is the profile the call opens on. A model or effort the page picks is refused unless that profile sets `allowModelSelect` (or the binding's `allowEffortSelect`).
152
+ - Its third argument supplies server context. Browser context stays under `client`.
152
153
  - Save checkpoint ownership before you send the event. If storage fails, close the session without advertising that checkpoint.
153
154
  - The boundary refuses native resumption while a saved operation is ready, running, or uncertain. It does not repeat the operation.
154
155
  - Without a session resolver, the boundary uses an anonymous cookie. Forward its `setCookie` value in the upgrade response.
@@ -234,7 +235,7 @@ The controller writes no English text. The helpers below give the composer's con
234
235
  | `composerActionState(args)` | The primary button (`send`, `queue`, `stop`, or `none`), the send menu, and whether the button is off. |
235
236
  | `composerDrawerSummary(args)` | The count of waiting messages by kind, for a collapsed drawer. |
236
237
  | `resolveComposerHint(args)` | The stash hint, when the whole draft is selected. |
237
- | `isStashShortcut(event)` | Whether a key press is the stash shortcut, `STASH_SHORTCUT`. |
238
+ | `composerShortcut(event)` | The send-menu action a key press asks for: ⌘↵ steers, ⌘⇧↵ sends now, ⌘⇧S stashes; `null` otherwise. `COMPOSER_SHORTCUTS` has each action's key for `Kbd`. |
238
239
 
239
240
  ## A custom browser transport
240
241
 
@@ -1,22 +1,30 @@
1
+ import type { ComposerMenuAction } from '@theoremjs/agents/interface';
1
2
  /**
2
3
  * Composer hints — ephemeral guidance about the current composer interaction
3
4
  * (not pending-message state). Mirrors seance's `stash-selected-draft` hint.
4
5
  */
5
- /** Stash shortcut in Astryx `Kbd` notation (`mod` is ⌘ on macOS, Ctrl elsewhere). */
6
- export declare const STASH_SHORTCUT = "mod+shift+s";
7
- /** Which hint applies, and its shortcut; the UI words it. */
8
- export type ComposerHint = {
9
- id: 'stash-selected-draft';
10
- shortcut: string;
11
- };
12
- /** Whether a keydown is the stash shortcut (⌘⇧S / Ctrl+Shift+S). */
13
- export declare function isStashShortcut(event: {
6
+ /**
7
+ * Each send-menu action's key, in Astryx `Kbd` notation (`mod` is ⌘ on macOS, Ctrl elsewhere).
8
+ * `queue` is Enter: the composer's primary action while a reply runs.
9
+ */
10
+ export declare const COMPOSER_SHORTCUTS: Readonly<Record<ComposerMenuAction, string>>;
11
+ /**
12
+ * The send-menu action a keydown asks for: ⌘↵ steers, ⌘⇧↵ sends now, ⌘⇧S stashes (Ctrl
13
+ * elsewhere). `null` for any other key, plain Enter included: the field sends or queues that.
14
+ */
15
+ export declare function composerShortcut(event: {
14
16
  code: string;
17
+ key: string;
15
18
  metaKey: boolean;
16
19
  ctrlKey: boolean;
17
20
  shiftKey: boolean;
18
21
  altKey: boolean;
19
- }): boolean;
22
+ }): Exclude<ComposerMenuAction, 'queue'> | null;
23
+ /** Which hint applies, and its shortcut; the UI words it. */
24
+ export type ComposerHint = {
25
+ id: 'stash-selected-draft';
26
+ shortcut: string;
27
+ };
20
28
  /** The stash hint — shown while the whole draft is selected in the focused input and it can be stashed. */
21
29
  export declare function resolveComposerHint(args: {
22
30
  draftText: string;
@@ -2,11 +2,28 @@
2
2
  * Composer hints — ephemeral guidance about the current composer interaction
3
3
  * (not pending-message state). Mirrors seance's `stash-selected-draft` hint.
4
4
  */
5
- /** Stash shortcut in Astryx `Kbd` notation (`mod` is ⌘ on macOS, Ctrl elsewhere). */
6
- export const STASH_SHORTCUT = 'mod+shift+s';
7
- /** Whether a keydown is the stash shortcut (⌘⇧S / Ctrl+Shift+S). */
8
- export function isStashShortcut(event) {
9
- return (event.code === 'KeyS' && event.shiftKey && !event.altKey && (event.metaKey || event.ctrlKey));
5
+ /**
6
+ * Each send-menu action's key, in Astryx `Kbd` notation (`mod` is ⌘ on macOS, Ctrl elsewhere).
7
+ * `queue` is Enter: the composer's primary action while a reply runs.
8
+ */
9
+ export const COMPOSER_SHORTCUTS = {
10
+ queue: 'enter',
11
+ steer: 'mod+enter',
12
+ send_now: 'mod+shift+enter',
13
+ stash: 'mod+shift+s',
14
+ };
15
+ /**
16
+ * The send-menu action a keydown asks for: ⌘↵ steers, ⌘⇧↵ sends now, ⌘⇧S stashes (Ctrl
17
+ * elsewhere). `null` for any other key, plain Enter included: the field sends or queues that.
18
+ */
19
+ export function composerShortcut(event) {
20
+ if (event.altKey || !(event.metaKey || event.ctrlKey))
21
+ return null;
22
+ if (event.key === 'Enter')
23
+ return event.shiftKey ? 'send_now' : 'steer';
24
+ if (event.code === 'KeyS' && event.shiftKey)
25
+ return 'stash';
26
+ return null;
10
27
  }
11
28
  /** The stash hint — shown while the whole draft is selected in the focused input and it can be stashed. */
12
29
  export function resolveComposerHint(args) {
@@ -15,6 +32,6 @@ export function resolveComposerHint(args) {
15
32
  return null;
16
33
  return {
17
34
  id: 'stash-selected-draft',
18
- shortcut: STASH_SHORTCUT,
35
+ shortcut: COMPOSER_SHORTCUTS.stash,
19
36
  };
20
37
  }
package/client/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { float32Rms, float32RmsToLevel, INPUT_LEVEL_GAIN, timeDomainBytesToLevel, } from './audio-level.ts';
2
2
  export { type ChatController, type ChatOptionPicks, type ChatOptions, type ChatState, type ChatUpdate, createChatController, type MessageDelivery, type SendTextOptions, type SentTurn, } from './chat.ts';
3
3
  export { type ComposerDrawerKind, type ComposerDrawerSummary, composerDrawerSummary, } from './composer-drawer.ts';
4
- export { type ComposerHint, isStashShortcut, resolveComposerHint, STASH_SHORTCUT, } from './composer-hints.ts';
4
+ export { COMPOSER_SHORTCUTS, type ComposerHint, composerShortcut, resolveComposerHint, } from './composer-hints.ts';
5
5
  export { type ComposerActionState, composerActionState, composerHasPayload, } from './composer-primary.ts';
6
6
  export { createDecisionTransport, type DecisionInterface, type DecisionQuestionView, type DecisionReply, type DecisionReplyResult, type DecisionTransport, decisionAssets, decisionInterface, failedTraces, postDecision, questionViews, readDecisionReply, withFailedTraces, } from './decision-transport.ts';
7
7
  export { type ComposerDraftFields, composerFieldsFromDraft } from './decode-composer-draft.ts';
package/client/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  export { float32Rms, float32RmsToLevel, INPUT_LEVEL_GAIN, timeDomainBytesToLevel, } from "./audio-level.js";
2
2
  export { createChatController, } from "./chat.js";
3
3
  export { composerDrawerSummary, } from "./composer-drawer.js";
4
- export { isStashShortcut, resolveComposerHint, STASH_SHORTCUT, } from "./composer-hints.js";
4
+ export { COMPOSER_SHORTCUTS, composerShortcut, resolveComposerHint, } from "./composer-hints.js";
5
5
  export { composerActionState, composerHasPayload, } from "./composer-primary.js";
6
6
  export { createDecisionTransport, decisionAssets, decisionInterface, failedTraces, postDecision, questionViews, readDecisionReply, withFailedTraces, } from "./decision-transport.js";
7
7
  export { composerFieldsFromDraft } from "./decode-composer-draft.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@theoremjs/web",
3
- "version": "0.3.5-next.975.g3529c32",
3
+ "version": "0.3.5-next.977.g42c51f5",
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.975.g3529c32"
28
+ "@theoremjs/agents": "^0.3.5-next.977.g42c51f5"
29
29
  }
30
30
  }
@@ -1,4 +1,5 @@
1
1
  import { defineProfile, registerProfile, runEmbedding, z, } from '@theoremjs/agents';
2
+ import { refuseInterfacePick } from '@theoremjs/agents/interface';
2
3
  import { embeddingInterface } from "../client/embedding-transport.js";
3
4
  import { readBody } from "./handler.js";
4
5
  import { singleActionHandler } from "./single-action.js";
@@ -30,6 +31,7 @@ export function createTheoremEmbeddingHandler(options) {
30
31
  onError: options.onError,
31
32
  }, async (request) => {
32
33
  const body = await readBody(request, embedBodySchema);
34
+ refuseInterfacePick(profile, { model: body.model });
33
35
  const provider = typeof options.provider === 'function'
34
36
  ? await options.provider({ request, model: body.model })
35
37
  : options.provider;
package/server/handler.js CHANGED
@@ -42,7 +42,7 @@ import { checkPageToolTimeout, createMemoryPageToolBroker, pageToolResultSchema,
42
42
  import { authorizeToolReplay, compactHistory, defaultKernelScope, defineProfile, invokeTool, jsonObjectSchema, labelText, registerProfile, runTurn, TheoremError, toolInvocationHash, } from '@theoremjs/agents';
43
43
  import { runConversation } from '@theoremjs/agents/conversation';
44
44
  import { caughtStatus, clientError, forClient, HTTP_NOT_FOUND, } from '@theoremjs/agents/host';
45
- import { clientProfileInterface, gatedToolsFromEvents, interfaceFromProfile, promotedToolIdsFromEvents, toolSnapshotFromEvents, } from '@theoremjs/agents/interface';
45
+ import { clientProfileInterface, gatedToolsFromEvents, interfaceFromProfile, promotedToolIdsFromEvents, refuseInterfacePick, toolSnapshotFromEvents, } from '@theoremjs/agents/interface';
46
46
  import { answerGatedCall, isSealedSource, resolveGateTtlMs, } from '@theoremjs/agents/kernel';
47
47
  import { hostInterface, theoremHostCallRequestSchema, } from "../client/host-transport.js";
48
48
  import { theoremConversationRequestSchema, theoremInvokeRequestSchema, theoremNotifyRequestSchema, theoremRewindRequestSchema, theoremSteerRequestSchema, theoremStopRequestSchema, theoremTurnRequestSchema, theoremWakeRequestSchema, } from "../client/transport.js";
@@ -695,6 +695,8 @@ async function* chatTurn(ctx, request, session, turn, key, signal, stop, late) {
695
695
  * or its hold losing the chat), and the chat's hold it saves under.
696
696
  */
697
697
  function chatRunner(ctx, request, session, generation, held) {
698
+ // invariant: The page's pick is checked here, before prepare; a model prepare sets is the host's own.
699
+ refuseInterfacePick(ctx.profile, generation);
698
700
  const key = generation.turnId ? inboxKey(session.id, generation.turnId) : undefined;
699
701
  const stop = new AbortController();
700
702
  const signal = AbortSignal.any([request.signal, stop.signal, ...(held ? [held.run.signal] : [])]);
@@ -1,7 +1,8 @@
1
- import { type PageToolExecution, type ProviderCheckpoint, type SessionRequest, type ToolExecutionCoordinator, type TurnHistoryMessage } from '@theoremjs/agents';
1
+ import { type PageToolExecution, type ProviderCheckpoint, type ToolExecutionCoordinator, type TurnHistoryMessage } from '@theoremjs/agents';
2
2
  import { type LiveOpenMessage } from '../client/live-messages.ts';
3
3
  import { type PageToolBroker, type PageToolResult } from './page-dispatch.ts';
4
4
  import { type TheoremSessionStore } from './session-store.ts';
5
+ import { liveSessionOpen } from './turn-input.ts';
5
6
  export interface SessionBoundaryOptions {
6
7
  request: Request;
7
8
  session?: (request: Request) => string | undefined | Promise<string | undefined>;
@@ -14,11 +15,12 @@ export interface SessionBoundaryOptions {
14
15
  /** How long the page has to answer a tool call it runs, in milliseconds. Unset, it waits. */
15
16
  pageToolTimeoutMs?: number;
16
17
  }
17
- export type PreparedLiveOpen = Pick<SessionRequest, 'history' | 'inputOptions' | 'context' | 'providerState' | 'awayMs' | 'path' | 'options'>;
18
+ export type PreparedLiveOpen = ReturnType<typeof liveSessionOpen>;
18
19
  export interface TheoremSessionBoundary {
19
20
  sessionId: string;
20
21
  setCookie?: string;
21
- prepareLiveOpen(open: LiveOpenMessage, serverContext?: unknown): Promise<PreparedLiveOpen>;
22
+ /** Checks the page's open message against the profile the call opens on. */
23
+ prepareLiveOpen(open: LiveOpenMessage, profile: Parameters<typeof liveSessionOpen>[1], serverContext?: unknown): Promise<PreparedLiveOpen>;
22
24
  prepareProviderState(checkpoint: ProviderCheckpoint | undefined, history?: readonly TurnHistoryMessage[]): Promise<ProviderCheckpoint | undefined>;
23
25
  recordCheckpoint(checkpoint: ProviderCheckpoint): Promise<void>;
24
26
  toolExecution: ToolExecutionCoordinator;
@@ -29,12 +29,12 @@ export async function createTheoremSessionBoundary(options) {
29
29
  sessionId: id,
30
30
  ...(cookie?.setCookie ? { setCookie: cookie.setCookie } : {}),
31
31
  toolExecution: sessionToolCoordinator(store, id),
32
- async prepareLiveOpen(raw, server) {
32
+ async prepareLiveOpen(raw, profile, server) {
33
33
  const open = checkRequest(liveOpenMessageSchema, raw, 'live open');
34
34
  if (open.stated && !options.pageStatesTurn) {
35
35
  throw new TheoremError('request', labelText('error.request'));
36
36
  }
37
- const prepared = liveSessionOpen(open, server);
37
+ const prepared = liveSessionOpen(open, profile, server);
38
38
  const state = await store.read(id);
39
39
  const providerState = await requireOwnedCheckpoint(state.providerCheckpoints, prepared.providerState, state.operations);
40
40
  if (providerState &&
@@ -1,10 +1,12 @@
1
1
  import type { SessionRequest, TurnInput } from '@theoremjs/agents';
2
+ import { refuseInterfacePick } from '@theoremjs/agents/interface';
2
3
  import type { LiveOpenMessage } from '../client/live-messages.ts';
3
4
  import type { TheoremTurnInput } from '../client/transport.ts';
4
5
  /** A turn input off the wire as the kernel takes it: the page's context is the client's. */
5
6
  export declare function kernelTurnInput(input: TheoremTurnInput, server?: unknown): TurnInput;
6
7
  /**
7
8
  * What a live call's first message asks of the session, as `runSession` takes
8
- * it: the page's context is the client's, and `server` is the host's own.
9
+ * it: the page's context is the client's, and `server` is the host's own. A model
10
+ * or effort the page picks is refused unless `profile` lets the interface pick it.
9
11
  */
10
- export declare function liveSessionOpen(open: LiveOpenMessage, server?: unknown): Pick<SessionRequest, 'inputOptions' | 'context' | 'providerState' | 'awayMs' | 'history' | 'path' | 'options' | 'model' | 'effort'>;
12
+ export declare function liveSessionOpen(open: LiveOpenMessage, profile: Parameters<typeof refuseInterfacePick>[0], server?: unknown): Pick<SessionRequest, 'inputOptions' | 'context' | 'providerState' | 'awayMs' | 'history' | 'path' | 'options' | 'model' | 'effort'>;
@@ -1,3 +1,4 @@
1
+ import { refuseInterfacePick } from '@theoremjs/agents/interface';
1
2
  /** The page's context as the client's and the host's as the server's; nothing when neither gave any. */
2
3
  function turnContext(client, server) {
3
4
  const context = {
@@ -14,9 +15,11 @@ export function kernelTurnInput(input, server) {
14
15
  }
15
16
  /**
16
17
  * What a live call's first message asks of the session, as `runSession` takes
17
- * it: the page's context is the client's, and `server` is the host's own.
18
+ * it: the page's context is the client's, and `server` is the host's own. A model
19
+ * or effort the page picks is refused unless `profile` lets the interface pick it.
18
20
  */
19
- export function liveSessionOpen(open, server) {
21
+ export function liveSessionOpen(open, profile, server) {
22
+ refuseInterfacePick(profile, open);
20
23
  const context = turnContext(open.context, server);
21
24
  return {
22
25
  ...(open.history ? { history: open.history } : {}),