@theoremjs/react 0.3.3 → 0.3.4-next.373.gab46e23
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 +21 -336
- package/client/host-call.d.ts +2 -2
- package/client/host-call.js +1 -2
- package/client/index.d.ts +1 -28
- package/client/index.js +1 -22
- package/client/live/apply-live-turn-tool-event.js +1 -1
- package/client/live/run-live-tool-call.d.ts +1 -3
- package/client/live/run-live-tool-call.js +1 -1
- package/client/transcript-groups.js +1 -1
- package/client/voice-recorder.js +1 -1
- package/components/live/use-live-runner-controls.d.ts +1 -2
- package/components/live/use-live-runner-model.d.ts +7 -8
- package/components/live/use-live-runner-model.js +1 -2
- package/components/live/use-live-runner-ui.d.ts +2 -4
- package/components/live/use-live-runner-ui.js +1 -1
- package/components/live/use-live-session-client.d.ts +2 -5
- package/components/live/use-live-session-client.js +1 -1
- package/hooks/use-described.d.ts +1 -1
- package/hooks/use-described.js +1 -1
- package/hooks/use-embedding-index.d.ts +1 -1
- package/hooks/use-embedding-index.js +1 -1
- package/hooks/use-one-call.d.ts +2 -2
- package/hooks/use-one-call.js +1 -2
- package/hooks/use-page-tool-warnings.d.ts +1 -1
- package/hooks/use-page-tool-warnings.js +1 -1
- package/hooks/use-theorem-chat-actions.d.ts +2 -4
- package/hooks/use-theorem-chat-actions.js +1 -3
- package/hooks/use-theorem-chat-state.d.ts +1 -2
- package/hooks/use-theorem-chat.d.ts +4 -5
- package/hooks/use-theorem-chat.js +1 -6
- package/hooks/use-theorem-decision.d.ts +1 -2
- package/hooks/use-theorem-embedding.d.ts +1 -2
- package/hooks/use-theorem-host.d.ts +2 -4
- package/hooks/use-theorem-host.js +1 -4
- package/hooks/use-theorem-interface.d.ts +1 -2
- package/hooks/use-trace-records.d.ts +1 -1
- package/index.d.ts +2 -3
- package/index.js +2 -3
- package/live.d.ts +1 -2
- package/package.json +3 -2
- package/server/mod.d.ts +1 -26
- package/server/mod.js +1 -24
- package/ui/ChatComposerBar.d.ts +1 -1
- package/ui/ChatTranscript.d.ts +1 -1
- package/ui/ChatTranscript.js +1 -1
- package/ui/ConsoleFrame.d.ts +1 -1
- package/ui/DecisionAnswers.d.ts +1 -1
- package/ui/EmbeddingDocuments.d.ts +2 -2
- package/ui/EmbeddingDocuments.js +1 -2
- package/ui/EmbeddingQuery.d.ts +1 -1
- package/ui/EmbeddingQuery.js +1 -2
- package/ui/EmbeddingResults.d.ts +1 -1
- package/ui/EmbeddingResults.js +1 -1
- package/ui/EmbeddingSpace.d.ts +1 -2
- package/ui/LiveRunner.d.ts +1 -2
- package/ui/SchemaFields.d.ts +1 -1
- package/ui/SchemaFields.js +1 -2
- package/ui/ShapedData.js +1 -1
- package/ui/StateFields.js +1 -1
- package/ui/TheoremChat.d.ts +2 -2
- package/ui/TheoremChat.js +1 -1
- package/ui/TheoremDecision.d.ts +1 -1
- package/ui/TheoremDecision.js +1 -1
- package/ui/TheoremEmbedding.d.ts +1 -1
- package/ui/TheoremEmbedding.js +1 -2
- package/ui/TheoremHost.d.ts +2 -3
- package/ui/TheoremHost.js +1 -3
- package/ui/ToolGateCard.d.ts +1 -1
- package/ui/ToolGateCard.js +1 -2
- package/ui/ToolResult.d.ts +1 -1
- package/ui/ToolResult.js +1 -2
- package/ui/ToolResultCharts.d.ts +1 -1
- package/ui/ToolResultCharts.js +1 -2
- package/ui/TraceInspector.d.ts +1 -1
- package/ui/TraceInspectorPanel.d.ts +1 -1
- package/ui/approval-heading.js +1 -1
- package/ui/embedding-space-gl.d.ts +2 -2
- package/ui/embedding-space-gl.js +1 -1
- package/ui/index.d.ts +1 -1
- package/ui/labels.d.ts +1 -1
- package/client/audio-level.d.ts +0 -5
- package/client/audio-level.js +0 -24
- package/client/decision-transport.d.ts +0 -70
- package/client/decision-transport.js +0 -175
- package/client/decode-composer-draft.d.ts +0 -11
- package/client/decode-composer-draft.js +0 -12
- package/client/embedding-input.d.ts +0 -84
- package/client/embedding-input.js +0 -194
- package/client/embedding-space.d.ts +0 -82
- package/client/embedding-space.js +0 -389
- package/client/embedding-transport.d.ts +0 -40
- package/client/embedding-transport.js +0 -71
- package/client/encode-composer-draft.d.ts +0 -9
- package/client/encode-composer-draft.js +0 -34
- package/client/encode-files.d.ts +0 -18
- package/client/encode-files.js +0 -54
- package/client/failure.d.ts +0 -29
- package/client/failure.js +0 -34
- package/client/generation-selection.d.ts +0 -15
- package/client/generation-selection.js +0 -24
- package/client/host-transport.d.ts +0 -70
- package/client/host-transport.js +0 -75
- package/client/live/live-mic-forward.d.ts +0 -30
- package/client/live/live-mic-forward.js +0 -46
- package/client/live/live-page-tool.d.ts +0 -34
- package/client/live/live-page-tool.js +0 -11
- package/client/live/live-state.d.ts +0 -13
- package/client/live/live-state.js +0 -22
- package/client/live/live-tool.d.ts +0 -11
- package/client/live/live-tool.js +0 -1
- package/client/live-client.d.ts +0 -189
- package/client/live-client.js +0 -829
- package/client/live-errors.d.ts +0 -2
- package/client/live-errors.js +0 -9
- package/client/live-messages.d.ts +0 -148
- package/client/live-messages.js +0 -100
- package/client/mic-capture.d.ts +0 -4
- package/client/mic-capture.js +0 -6
- package/client/oauth-popup.d.ts +0 -26
- package/client/oauth-popup.js +0 -30
- package/client/page-dispatch.d.ts +0 -15
- package/client/page-dispatch.js +0 -63
- package/client/pcm-downsample.d.ts +0 -4
- package/client/pcm-downsample.js +0 -45
- package/client/run-commit.d.ts +0 -34
- package/client/run-commit.js +0 -49
- package/client/run-session.d.ts +0 -79
- package/client/run-session.js +0 -207
- package/client/schema-fields.d.ts +0 -63
- package/client/schema-fields.js +0 -199
- package/client/shaped-data.d.ts +0 -118
- package/client/shaped-data.js +0 -343
- package/client/source-citations.d.ts +0 -13
- package/client/source-citations.js +0 -56
- package/client/space-geometry.d.ts +0 -39
- package/client/space-geometry.js +0 -183
- package/client/tool-result.d.ts +0 -78
- package/client/tool-result.js +0 -293
- package/client/tool-resume.d.ts +0 -50
- package/client/tool-resume.js +0 -14
- package/client/trace-feed.d.ts +0 -13
- package/client/trace-feed.js +0 -18
- package/client/transcript-schema.d.ts +0 -10
- package/client/transcript-schema.js +0 -120
- package/client/transport.d.ts +0 -264
- package/client/transport.js +0 -330
- package/client/turn-client.d.ts +0 -44
- package/client/turn-client.js +0 -88
- package/client/wire-line.d.ts +0 -56
- package/client/wire-line.js +0 -90
- package/client/worklets/mic-capture.js +0 -16
- package/server/checkpoint-ownership.d.ts +0 -6
- package/server/checkpoint-ownership.js +0 -42
- package/server/conversation-store.d.ts +0 -92
- package/server/conversation-store.js +0 -131
- package/server/conversation.d.ts +0 -193
- package/server/conversation.js +0 -552
- package/server/credential-store.d.ts +0 -24
- package/server/credential-store.js +0 -14
- package/server/decision-handler.d.ts +0 -42
- package/server/decision-handler.js +0 -46
- package/server/embedding-handler.d.ts +0 -33
- package/server/embedding-handler.js +0 -45
- package/server/handler.d.ts +0 -158
- package/server/handler.js +0 -775
- package/server/json-response.d.ts +0 -2
- package/server/json-response.js +0 -7
- package/server/mcp-handler.d.ts +0 -46
- package/server/mcp-handler.js +0 -312
- package/server/page-dispatch.d.ts +0 -22
- package/server/page-dispatch.js +0 -127
- package/server/request-body.d.ts +0 -2
- package/server/request-body.js +0 -42
- package/server/request-check.d.ts +0 -21
- package/server/request-check.js +0 -49
- package/server/session-authority.d.ts +0 -8
- package/server/session-authority.js +0 -78
- package/server/session-boundary.d.ts +0 -26
- package/server/session-boundary.js +0 -64
- package/server/session-identity.d.ts +0 -16
- package/server/session-identity.js +0 -41
- package/server/session-limits.d.ts +0 -12
- package/server/session-limits.js +0 -59
- package/server/session-store.d.ts +0 -123
- package/server/session-store.js +0 -264
- package/server/single-action.d.ts +0 -21
- package/server/single-action.js +0 -30
- package/server/steer-inbox.d.ts +0 -35
- package/server/steer-inbox.js +0 -52
- package/server/tool-operations.d.ts +0 -6
- package/server/tool-operations.js +0 -132
- package/server/turn-input.d.ts +0 -10
- package/server/turn-input.js +0 -29
package/README.md
CHANGED
|
@@ -49,12 +49,12 @@ The package has three parts:
|
|
|
49
49
|
|
|
50
50
|
- A ready-made chat, voice call, host console, and decision form. They are built on [Astryx](https://www.npmjs.com/package/@astryxdesign/core).
|
|
51
51
|
- Hooks and a transport, for your own UI.
|
|
52
|
-
-
|
|
52
|
+
- The server handler and the client of [`@theoremjs/web`](https://www.npmjs.com/package/@theoremjs/web), as `/server` and `/client`.
|
|
53
53
|
|
|
54
54
|
## Install
|
|
55
55
|
|
|
56
56
|
```bash
|
|
57
|
-
npm install @theoremjs/react @theoremjs/agents zod react react-dom
|
|
57
|
+
npm install @theoremjs/react @theoremjs/web @theoremjs/agents zod react react-dom
|
|
58
58
|
```
|
|
59
59
|
|
|
60
60
|
For the ready-made UI (`/ui` and `/live`), also install Astryx and StyleX:
|
|
@@ -65,7 +65,7 @@ npm install @astryxdesign/core @stylexjs/stylex
|
|
|
65
65
|
|
|
66
66
|
To build your own theme from the Theorem theme (`/ui/theme`), also install `@astryxdesign/theme-neutral`.
|
|
67
67
|
|
|
68
|
-
Use the versions that this package lists in `peerDependencies`. The Astryx and StyleX peers are optional. The hooks
|
|
68
|
+
Use the versions that this package lists in `peerDependencies`. Install `@theoremjs/react`, `@theoremjs/web`, and `@theoremjs/agents` at the same version. The Astryx and StyleX peers are optional. The hooks work without them.
|
|
69
69
|
|
|
70
70
|
When a chat turn, a call, a host request, or a decision fails, the ready-made UI shows the error in a banner that screen readers announce at once. The end of a live call is announced when the reader is next idle.
|
|
71
71
|
|
|
@@ -88,7 +88,7 @@ Replacing the registration affects later runs. An active run keeps the registrat
|
|
|
88
88
|
|
|
89
89
|
```ts
|
|
90
90
|
import { defineProfile, geminiProvider, registerProvider } from '@theoremjs/agents';
|
|
91
|
-
import { createMemoryConversationStore, createTheoremHandler } from '@theoremjs/
|
|
91
|
+
import { createMemoryConversationStore, createTheoremHandler } from '@theoremjs/web/server';
|
|
92
92
|
|
|
93
93
|
const gemini = registerProvider(geminiProvider, { keySlot: 'main' });
|
|
94
94
|
|
|
@@ -111,7 +111,7 @@ export const theorem = createTheoremHandler({
|
|
|
111
111
|
});
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
The memory store keeps each conversation in process memory. For other stores, see [Keep the conversation](#keep-the-conversation).
|
|
114
|
+
The memory store keeps each conversation in process memory. For other stores, see [Keep the conversation](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#keep-the-conversation).
|
|
115
115
|
|
|
116
116
|
### 2. Mount the handler
|
|
117
117
|
|
|
@@ -148,10 +148,10 @@ The profile, the keys, and the system prompt stay on the server. The browser rec
|
|
|
148
148
|
| `@theoremjs/react` | Hooks, transports, and client logic |
|
|
149
149
|
| `@theoremjs/react/ui` | `TheoremChat`, `TheoremHost`, `TheoremDecision`, `TheoremEmbedding`, and their parts |
|
|
150
150
|
| `@theoremjs/react/live` | `LiveRunner`, the voice and video call UI |
|
|
151
|
-
| `@theoremjs/react/server` |
|
|
151
|
+
| `@theoremjs/react/server` | `@theoremjs/web/server`: the handlers and the stores they use |
|
|
152
152
|
| `@theoremjs/react/ui/theme` | `theoremTheme`, the base for your own Astryx theme |
|
|
153
153
|
| `@theoremjs/react/ui/icons` | The icon set of the theme |
|
|
154
|
-
| `@theoremjs/react/client` |
|
|
154
|
+
| `@theoremjs/react/client` | `@theoremjs/web/client`: the client logic, without the hooks |
|
|
155
155
|
|
|
156
156
|
## Chat
|
|
157
157
|
|
|
@@ -232,7 +232,7 @@ Each profile type has a handler and a component. Mount the handler. Point the co
|
|
|
232
232
|
A `host` profile does not run a model. The page calls the tools of the profile directly. Each call passes through the gates and the guardrails of the kernel.
|
|
233
233
|
|
|
234
234
|
```ts
|
|
235
|
-
import { createTheoremHostHandler } from '@theoremjs/
|
|
235
|
+
import { createTheoremHostHandler } from '@theoremjs/web/server';
|
|
236
236
|
|
|
237
237
|
export const host = createTheoremHostHandler({ profile: opsConsole }); // mount at /api/host
|
|
238
238
|
```
|
|
@@ -253,27 +253,14 @@ The console builds a form from the input schema. It shows the result as figures,
|
|
|
253
253
|
|
|
254
254
|
#### Serve a host profile over MCP
|
|
255
255
|
|
|
256
|
-
`createTheoremMcpHandler` serves the same profile to MCP clients, such as coding agents and chat apps
|
|
257
|
-
|
|
258
|
-
```ts
|
|
259
|
-
import { createTheoremMcpHandler } from '@theoremjs/react/server';
|
|
260
|
-
|
|
261
|
-
export const mcp = createTheoremMcpHandler({ profile: docsTools, version: '1.0.0' }); // mount at /mcp
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
- `tools/list` gives each allowed tool with its input schema. A tool's `access` becomes the read-only and destructive hints of MCP.
|
|
265
|
-
- Clients of the current revision may cache the tool list for 5 minutes and the discovery result for an hour. Neither holds anything about the caller, so a shared cache may keep them.
|
|
266
|
-
- `tools/call` runs the tool through the gates, the guardrails, and the trace of the kernel. The client receives the text a model would read, not the raw output.
|
|
267
|
-
- A tool that fails returns a result marked `isError`, so the model can read it and try again.
|
|
268
|
-
- No one can approve a call over MCP. The handler refuses a profile when an allowed tool has a permission other than `auto`.
|
|
269
|
-
- A browser page on another origin is refused unless `origins` lists it.
|
|
256
|
+
`createTheoremMcpHandler` from `@theoremjs/web/server` serves the same profile to MCP clients, such as coding agents and chat apps. See [Serve a host profile over MCP](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#serve-a-host-profile-over-mcp).
|
|
270
257
|
|
|
271
258
|
### Decision
|
|
272
259
|
|
|
273
260
|
A `decision` profile has no conversation. You give it a JSON state and questions. It answers the questions about the state.
|
|
274
261
|
|
|
275
262
|
```ts
|
|
276
|
-
import { createTheoremDecisionHandler } from '@theoremjs/
|
|
263
|
+
import { createTheoremDecisionHandler } from '@theoremjs/web/server';
|
|
277
264
|
|
|
278
265
|
export const decide = createTheoremDecisionHandler({ profile, questions, vault }); // mount at /api/decision
|
|
279
266
|
```
|
|
@@ -308,7 +295,7 @@ For your own UI, use `useTheoremDecision`. Its `decide(state, assets)` takes the
|
|
|
308
295
|
An `embedding` profile turns inputs into vectors. Each input is text, or an object with `parts`: text and files.
|
|
309
296
|
|
|
310
297
|
```ts
|
|
311
|
-
import { createTheoremEmbeddingHandler } from '@theoremjs/
|
|
298
|
+
import { createTheoremEmbeddingHandler } from '@theoremjs/web/server';
|
|
312
299
|
|
|
313
300
|
export const embed = createTheoremEmbeddingHandler({ profile, vault }); // mount at /api/embedding
|
|
314
301
|
```
|
|
@@ -323,9 +310,9 @@ import { TheoremEmbedding } from '@theoremjs/react/ui';
|
|
|
323
310
|
|
|
324
311
|
Each request is held to the `inputs` of the profile before it is sent, and each shows as JSON and in the trace.
|
|
325
312
|
|
|
326
|
-
For your own UI, use `useTheoremEmbedding` for one request, and `embed(inputs, { task })` to set the task. Use `useEmbeddingIndex` to embed many documents in batches. `splitText`, `embeddingBatches`, and `rankMatches` from `@theoremjs/
|
|
313
|
+
For your own UI, use `useTheoremEmbedding` for one request, and `embed(inputs, { task })` to set the task. Use `useEmbeddingIndex` to embed many documents in batches. `splitText`, `embeddingBatches`, and `rankMatches` from `@theoremjs/web/client` split, batch, and rank as the bench does.
|
|
327
314
|
|
|
328
|
-
**Index** also draws the documents as a space: each a dot in a ball, placed by the three directions their vectors differ most along, and joined to its nearest neighbour when that pair is far more alike than the typical pair. A query is a white dot joined to its matches. Drag to turn it; point at a dot to name its document. For your own UI, `EmbeddingSpaceView` from `@theoremjs/react/ui` draws a space from `layoutSpace(vectors)`, or from `layoutSpaceSoon(vectors, signal)`, which lays it out in slices so the page stays responsive, and places a query with `placeQuery(space, vector)`, all from `@theoremjs/
|
|
315
|
+
**Index** also draws the documents as a space: each a dot in a ball, placed by the three directions their vectors differ most along, and joined to its nearest neighbour when that pair is far more alike than the typical pair. A query is a white dot joined to its matches. Drag to turn it; point at a dot to name its document. For your own UI, `EmbeddingSpaceView` from `@theoremjs/react/ui` draws a space from `layoutSpace(vectors)`, or from `layoutSpaceSoon(vectors, signal)`, which lays it out in slices so the page stays responsive, and places a query with `placeQuery(space, vector)`, all from `@theoremjs/web/client`. Where the browser cannot draw it, the view calls `onUnavailable`, and the bench lists the vectors instead.
|
|
329
316
|
|
|
330
317
|
### Live
|
|
331
318
|
|
|
@@ -398,324 +385,22 @@ A failed call does not reconnect. Without `live.sessionResumption`, a provider-e
|
|
|
398
385
|
|
|
399
386
|
### Your relay
|
|
400
387
|
|
|
401
|
-
|
|
402
|
-
Use the same authenticated session resolver and atomic session store for chat and live requests.
|
|
403
|
-
The boundary rejects native state that this conversation did not save.
|
|
404
|
-
Saved ownership also covers the operation state. An older live checkpoint cannot revive a completed action.
|
|
405
|
-
|
|
406
|
-
```ts
|
|
407
|
-
import { runSession } from '@theoremjs/agents';
|
|
408
|
-
import {
|
|
409
|
-
createTheoremSessionBoundary,
|
|
410
|
-
parseLiveOpenMessage,
|
|
411
|
-
} from '@theoremjs/react/server';
|
|
412
|
-
|
|
413
|
-
const boundary = await createTheoremSessionBoundary({
|
|
414
|
-
request,
|
|
415
|
-
session: authenticatedConversation,
|
|
416
|
-
sessionStore: sharedSessionStore,
|
|
417
|
-
});
|
|
418
|
-
const open = parseLiveOpenMessage(firstFrame);
|
|
419
|
-
const session = await runSession(
|
|
420
|
-
{ profile, ...await boundary.prepareLiveOpen(open, hostContext) },
|
|
421
|
-
{ vault: hostKeyVault, execution: boundary.toolExecution, pageExecution: boundary.pageExecution },
|
|
422
|
-
);
|
|
423
|
-
for await (const event of session.events()) {
|
|
424
|
-
if ((event.type === 'done' || event.type === 'provider_checkpoint') && event.providerState) {
|
|
425
|
-
await boundary.recordCheckpoint(event.providerState);
|
|
426
|
-
}
|
|
427
|
-
sendToBrowser(event);
|
|
428
|
-
}
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
- `prepareLiveOpen` returns validated history, slots, context, native state, and absence duration. It removes system-role history.
|
|
432
|
-
- Its second argument supplies server context. Browser context stays under `client`.
|
|
433
|
-
- Save checkpoint ownership before you send the event. If storage fails, close the session without advertising that checkpoint.
|
|
434
|
-
- The boundary refuses native resumption while a saved operation is ready, running, or uncertain. It does not repeat the operation.
|
|
435
|
-
- Without a session resolver, the boundary uses an anonymous cookie. Forward its `setCookie` value in the upgrade response.
|
|
436
|
-
- `open.host` is the `openMessage` that your `connection` returned.
|
|
437
|
-
- Read later messages with `parseLiveClientMessage`. Give context messages to `session.sendContext({ client: message.context })`.
|
|
388
|
+
The relay is server code. To authenticate the conversation and resume a call in your relay, see [Your relay](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#your-relay).
|
|
438
389
|
|
|
439
390
|
To build your own call view, use `useLiveRunnerModel(iface, connection, { slots, context, pageTools })` from `@theoremjs/react/ui`. It returns the state of the call, its captions, and its controls. `LiveCaptionsPanel` draws the captions.
|
|
440
391
|
|
|
441
392
|
### A custom browser transport
|
|
442
393
|
|
|
443
|
-
Use `withPageToolDispatch` when your screen
|
|
444
|
-
The helper runs callbacks only for dispatch grants received on the active stream.
|
|
445
|
-
It never reads a saved transcript to authorize callback execution.
|
|
446
|
-
Implement the transport's `pageResult` method to return the result to your authenticated server.
|
|
447
|
-
`createHttpTransport` and `createHostTransport` post that result to `/page-result`.
|
|
448
|
-
The built-in chat and host console apply this helper for their `pageTools`.
|
|
449
|
-
For a custom host view, pass callbacks as the second argument to `useTheoremHost`.
|
|
450
|
-
|
|
451
|
-
```ts
|
|
452
|
-
import { createHttpTransport, withPageToolDispatch } from '@theoremjs/react';
|
|
453
|
-
|
|
454
|
-
const transport = withPageToolDispatch(
|
|
455
|
-
createHttpTransport({ endpoint: '/api/theorem' }),
|
|
456
|
-
{ highlight: async argumentsFromServer => ({ output: { shown: argumentsFromServer.id } }) },
|
|
457
|
-
);
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
## Server options
|
|
461
|
-
|
|
462
|
-
`createTheoremHandler` requires `profile` and `provider`. All other options are optional.
|
|
463
|
-
|
|
464
|
-
| Option | Use |
|
|
465
|
-
| --- | --- |
|
|
466
|
-
| `profile` | The profile to serve. The kernel registers it when you create the handler. |
|
|
467
|
-
| `provider` | Host options, including the credential vault. A function can return these options per request, for example for tenant-specific credentials. |
|
|
468
|
-
| `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. |
|
|
469
|
-
| `host` | App data for the tool handlers (`ctx.host`), such as the signed-in user. |
|
|
470
|
-
| `pageToolBroker` | Delivers results to active page dispatches. Default: bounded process memory. |
|
|
471
|
-
| `conversationStore` | Where the conversation is kept. Required, except for a stateless profile, which must not have one. See [Keep the conversation](#keep-the-conversation). |
|
|
472
|
-
| `sessionStore`, `steerInbox` | Where open gates and queued steers are kept. Default: process memory. |
|
|
473
|
-
| `credentialStore` | Where tool credentials are kept, by session. Default: process memory. |
|
|
474
|
-
| `authorizationUrl` | Returns the sign-in URL for an OAuth gate. Without it, an OAuth gate has no URL. |
|
|
475
|
-
| `gateTtlMs` | How long a gate waits for an answer. Default: 30 minutes. A later answer fails with `session.gate_expired`. |
|
|
476
|
-
| `clientEvents` | Options for `forClient` and `clientError`, which prepare each event and each caught failure for the browser. `reader: 'builder'` sends the raw reason in place of the wording of the profile. Use it only in a development tool on your own machine. |
|
|
477
|
-
| `onError` | Receives each error that the handler catches. A visitor sees the wording of the profile for that kind of error, never the error. |
|
|
478
|
-
|
|
479
|
-
### Start a conversation with content
|
|
480
|
-
|
|
481
|
-
`startConversation` stores a conversation that opens on blocks you wrote, and returns its ref and its view. The model reads the blocks as history, so the user's next message is a follow-up.
|
|
482
|
-
|
|
483
|
-
```ts
|
|
484
|
-
import { startConversation, theoremSession } from '@theoremjs/react/server';
|
|
485
|
-
|
|
486
|
-
const session = theoremSession(request);
|
|
487
|
-
const { ref } = await startConversation({ sessionId: session.id, store: conversationStore }, profile, [
|
|
488
|
-
{ id: 'ask', kind: 'user-text', text: 'Two days in Lisbon. Where should I stay?' },
|
|
489
|
-
{ id: 'reply', kind: 'text', text: 'Stay in Chiado.' },
|
|
490
|
-
{ id: 'done', kind: 'turn-done' },
|
|
491
|
-
]);
|
|
492
|
-
// Send session.setCookie as Set-Cookie when it is set, and give the page the ref and view.
|
|
493
|
-
```
|
|
494
|
-
|
|
495
|
-
Pass the ref as `conversation` and the view as `conversationView`. The chat draws the view at once, and does not read the conversation from the server again.
|
|
394
|
+
Use `withPageToolDispatch` when your screen reads turn events through a custom transport. See [A custom browser transport](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#a-custom-browser-transport).
|
|
496
395
|
|
|
497
|
-
|
|
498
|
-
<TheoremChat endpoint="/api/theorem" conversation={ref} conversationView={view} />
|
|
499
|
-
```
|
|
500
|
-
|
|
501
|
-
- The store is the one you pass to the handler as `conversationStore`, and the session is the one the chat's requests carry. `theoremSession(request)` is the handler's cookie session: its `id`, and a `setCookie` header when the request had none. With your own `session` resolver, pass the id it returns.
|
|
502
|
-
- The profile's guardrails read the history first, at the `history` boundary, as they read every turn's history. A detector set to `redact` changes what the model reads; the transcript keeps your text. A detector set to `block` throws `detect.blocked`, and nothing is stored.
|
|
503
|
-
- The result's `events` are the guardrail events for what matched.
|
|
504
|
-
|
|
505
|
-
### Keep the conversation
|
|
506
|
-
|
|
507
|
-
The conversation store keeps the transcript, the history that the model reads, the provider's native state, and a reply that waits for a gate.
|
|
508
|
-
The session store keeps gates, permissions, and operations. The two stores are separate.
|
|
509
|
-
|
|
510
|
-
| Store | Where the conversation is kept |
|
|
511
|
-
| --- | --- |
|
|
512
|
-
| `createMemoryConversationStore()` | Process memory, for one server instance. A conversation that is not saved for 24 hours expires. At most 10,000 conversations are kept; the one saved longest ago goes first. Set `ttlMs` and `maxSessions` to change these limits. |
|
|
513
|
-
| `createSealedConversationStore({ keys, keyVersion })` | Nowhere on the server. The ref is the conversation itself, encrypted and signed with your key, and bound to the session. The browser cannot read it or change it. |
|
|
514
|
-
| Your own `TheoremConversationStore` | Your database. |
|
|
396
|
+
## Server
|
|
515
397
|
|
|
516
|
-
|
|
398
|
+
The handlers, the stores, and the client come from [`@theoremjs/web`](https://www.npmjs.com/package/@theoremjs/web). This package re-exports them as `@theoremjs/react/server` and `@theoremjs/react/client`. In the `@theoremjs/web` README:
|
|
517
399
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
-
|
|
521
|
-
-
|
|
522
|
-
- Each save issues a new ref. An older ref of the same conversation still opens, as a rewind does.
|
|
523
|
-
- If the user stops a reply, or the browser leaves while a reply runs, the server saves the result under a new ref that the browser never receives. The browser keeps the ref from when its message reached the server. The reply, and any tool call it settled, is lost to the browser. With the memory store or your own store, the ref does not change, and the chat shows what the server saved.
|
|
524
|
-
- The ref holds the whole conversation, including the bytes of each attachment. Every request sends it, so the conversation must stay under `maxRequestBytes`.
|
|
525
|
-
|
|
526
|
-
To keep conversations in your own database, implement these two methods:
|
|
527
|
-
|
|
528
|
-
```ts
|
|
529
|
-
import type {
|
|
530
|
-
ConversationSnapshot,
|
|
531
|
-
ConversationWriteResult,
|
|
532
|
-
StoredConversation,
|
|
533
|
-
} from '@theoremjs/react/server';
|
|
534
|
-
|
|
535
|
-
interface ConversationDatabase {
|
|
536
|
-
read(sessionId: string, ref: string): Promise<ConversationSnapshot | undefined>;
|
|
537
|
-
write(
|
|
538
|
-
sessionId: string,
|
|
539
|
-
ref: string | null,
|
|
540
|
-
expectedRevision: string | null,
|
|
541
|
-
next: StoredConversation,
|
|
542
|
-
): Promise<ConversationWriteResult>;
|
|
543
|
-
}
|
|
544
|
-
```
|
|
545
|
-
|
|
546
|
-
- Every read and write names the session. For a ref that this session did not write, `read` returns `undefined` and `write` returns `{ written: false }`.
|
|
547
|
-
- A null `ref` creates a conversation. Return a new opaque `ref` and `revision`.
|
|
548
|
-
- Otherwise, write only while the stored revision is still `expectedRevision`, as one atomic operation. Return `{ written: false }` on a conflict.
|
|
549
|
-
- Check what you read back with `storedConversationSchema`.
|
|
550
|
-
|
|
551
|
-
### Share session authority
|
|
552
|
-
|
|
553
|
-
Use one shared `TheoremSessionStore` when requests can reach several server instances.
|
|
554
|
-
New execution claims retain accepted request data and final prepared input under `operation.invocation`.
|
|
555
|
-
Use this data in `authorizeToolReplay` to check current access to the affected resource.
|
|
556
|
-
Older records can lack this evidence. Refuse disclosure if your access check needs it.
|
|
557
|
-
It holds approvals and provider checkpoint ownership. Tool credentials use the separate `credentialStore`.
|
|
558
|
-
|
|
559
|
-
```ts
|
|
560
|
-
import type {
|
|
561
|
-
SessionSnapshot,
|
|
562
|
-
SessionWriteResult,
|
|
563
|
-
TheoremSessionState,
|
|
564
|
-
} from '@theoremjs/react/server';
|
|
565
|
-
|
|
566
|
-
interface SharedSessionStore {
|
|
567
|
-
load(sessionId: string): Promise<SessionSnapshot | undefined>;
|
|
568
|
-
compareAndSwap(
|
|
569
|
-
sessionId: string,
|
|
570
|
-
expectedRevision: string | null,
|
|
571
|
-
next: TheoremSessionState,
|
|
572
|
-
): Promise<SessionWriteResult>;
|
|
573
|
-
}
|
|
574
|
-
```
|
|
575
|
-
|
|
576
|
-
Implement `compareAndSwap` as one atomic database operation. A separate read followed by a write is unsafe.
|
|
577
|
-
A null revision creates an absent session. A matching revision replaces the current state.
|
|
578
|
-
Return `{ written: false }` on a conflict. On success, return `{ written: true, revision }` with a new opaque revision.
|
|
579
|
-
Never reuse a revision, including after expiration. Return detached state from `load`.
|
|
580
|
-
Return write success only after the store meets its promised durability.
|
|
581
|
-
|
|
582
|
-
Each tool action has a kernel-issued `operationId`. The provider's `callId` identifies the upstream call.
|
|
583
|
-
An approval must carry both values. A new action receives a new operation ID even if its provider reuses a call ID.
|
|
584
|
-
A settled replay can omit input. If it supplies input, that input must match the accepted invocation.
|
|
585
|
-
The built-in clients copy this reference from the gate event. Custom clients must preserve it.
|
|
586
|
-
Historical events can omit operation IDs for display. They cannot authorize a new action.
|
|
587
|
-
|
|
588
|
-
The handler validates versioned state and retries a conflicting transition at most eight times.
|
|
589
|
-
It does not run tools inside this retry loop. Invalid state fails; it does not become an empty session.
|
|
590
|
-
The previous session `load`/`save` contract is not supported. Existing unversioned state and versions 1 or 2 require an explicit host migration.
|
|
591
|
-
An older pending gate does not prove that its body never ran. Verify the destination before restoring execution authority.
|
|
592
|
-
The current session state uses version 3. Gates and operation records use operation IDs as keys.
|
|
593
|
-
Each operation record contains its retained outcome. There is no separate outcome cache.
|
|
594
|
-
A gate belongs to the profile that issued it. Another profile cannot consume it through shared session storage.
|
|
595
|
-
The handler saves an accepted answer as ready before it invokes the kernel.
|
|
596
|
-
A retry before dispatch must repeat that accepted answer. It cannot change the input or decision.
|
|
597
|
-
Immediately before the tool body, an atomic claim changes ready to running.
|
|
598
|
-
The kernel saves the terminal outcome before it sends completion to the client.
|
|
599
|
-
A later answer receives that outcome without executing the tool or preparation hooks again.
|
|
600
|
-
The handler checks current tool registration and profile allowlisting before disclosing the outcome.
|
|
601
|
-
The handler checks current output rules before replay. Required redaction or refusal withholds the saved result.
|
|
602
|
-
Supply `authorizeToolReplay` for current role or resource access checks. This read-only callback can withhold a result without reopening the action.
|
|
603
|
-
If execution ends without a saved outcome, the claim remains running or becomes uncertain.
|
|
604
|
-
The handler never restores that operation as an approval. The host must check the destination before any new action.
|
|
605
|
-
Saved outcomes include guarded model read-back, media, provenance, and suspicious content signals.
|
|
606
|
-
The handler retains settled operations for 24 hours from settlement by default. Set `operationRetentionMs` to change this window.
|
|
607
|
-
Each saved outcome records its absolute retention deadline. Changing a handler's policy does not shorten that deadline.
|
|
608
|
-
Each issued gate records its absolute expiry. Changing `gateTtlMs` does not extend an issued gate.
|
|
609
|
-
Ready, running, and uncertain operations do not expire.
|
|
610
|
-
|
|
611
|
-
Use `sessionLimits` when your storage budget requires different finite limits. The defaults are:
|
|
612
|
-
|
|
613
|
-
| Limit | Default |
|
|
614
|
-
| --- | --- |
|
|
615
|
-
| `maxGates` | 32 |
|
|
616
|
-
| `maxOperations` | 128 |
|
|
617
|
-
| `maxCheckpoints` | 256 |
|
|
618
|
-
| `maxPermissions` | 2,048 |
|
|
619
|
-
| `maxStateBytes` | 32 MiB |
|
|
620
|
-
| `maxInvocationBytes` | 256 KiB |
|
|
621
|
-
| `maxOutcomeBytes` | 256 KiB |
|
|
622
|
-
|
|
623
|
-
Set `maxRequestBytes` to bound browser JSON before parsing. Its default is 16 MiB.
|
|
624
|
-
The handler rejects oversized requests before provider access or tool preparation.
|
|
625
|
-
Provider host options also accept `limits` for deadlines and upstream output.
|
|
626
|
-
Byte limits measure UTF-8 JSON. The handler reserves one maximum outcome for each gate and unresolved operation.
|
|
627
|
-
A new claim fails before dispatch when it cannot reserve that space.
|
|
628
|
-
An oversized result after dispatch leaves an uncertain claim. It does not restore an approval.
|
|
629
|
-
Limits never remove unresolved authority or shorten retained settlements. The host must reconcile and archive unresolved actions.
|
|
630
|
-
The memory store accepts the same `sessionLimits` options. Shared stores receive checked states through the handler.
|
|
631
|
-
|
|
632
|
-
The default memory store coordinates handlers that share the same store object.
|
|
633
|
-
It retains unexpired gates, unresolved operations, and unexpired outcomes during idle and capacity eviction.
|
|
634
|
-
It refuses a new session when every stored session has protected authority.
|
|
635
|
-
Separate memory stores and process restarts do not retain shared authority.
|
|
636
|
-
Atomic updates prevent two workers from dispatching the same operation. A process crash leaves its running claim protected.
|
|
637
|
-
These claims do not provide exactly-once effects at the destination. Use the operation ID with destination idempotency when available.
|
|
638
|
-
Concurrent pending attempts can reach preparation before one claims the body.
|
|
639
|
-
Permission checks and pre-body hooks must be read-only or independently idempotent. The kernel cannot prove hook purity.
|
|
640
|
-
A live session does not restore a dispatched call after an unexpected failure. It retains an uncertain call on that connection.
|
|
641
|
-
To retain execution claims across connections, supply a durable coordinator through `RunSessionOptions.execution`.
|
|
642
|
-
Browser dispatch uses a host-owned `PageToolExecution` service beside the execution coordinator.
|
|
643
|
-
`createTheoremHandler` supplies both services. Live relays pass the session boundary's `pageExecution` and `toolExecution` to `runSession`.
|
|
644
|
-
Forward live page results to `answerPageResult`. Preserve checkpoint ownership through `beforeEvent` when using the Studio bridge.
|
|
645
|
-
The default `PageToolBroker` keeps active result waiters in process memory. Several workers need a shared broker or request affinity.
|
|
646
|
-
Use `pageToolBroker` to supply that broker. It carries results; the atomic session store retains execution authority.
|
|
647
|
-
Lost result delivery does not permit another dispatch. The operation retains its claim or an uncertain outcome.
|
|
648
|
-
The default result deadline is 20 seconds. An expired or interrupted result cannot reopen approval.
|
|
649
|
-
|
|
650
|
-
## Build your own server
|
|
651
|
-
|
|
652
|
-
`createTheoremHandler` runs each chat reply through a small loop that `@theoremjs/react/server` exports. Use the loop when your server is not a `fetch` handler, or when your routes differ from the handler's. The conversation store, the guardrails, and the wire stay the same, so `TheoremChat` and the hooks work with your server unchanged.
|
|
653
|
-
|
|
654
|
-
| Function | Use |
|
|
655
|
-
| --- | --- |
|
|
656
|
-
| `readerConversationHost({ sessionId, store, profile, clientEvents })` | The conversation of one session, and how its events reach the browser (`forClient`). |
|
|
657
|
-
| `openConversation(host, ref, use)` | Reads the conversation under `ref`, or starts one when `ref` is `undefined`. It refuses a request that `use` does not allow, before anything runs. |
|
|
658
|
-
| `postedMessage(iface, input, context?)` | Checks the person's message against the profile's inputs. `iface` is `interfaceFromProfile(profile, defaultKernelScope.tools)` from `@theoremjs/agents/interface`. |
|
|
659
|
-
| `messageReply({ host, opened, message, walkAway?, runner })` | Posts the message, runs the reply and writes it back. Returns the lines to stream. |
|
|
660
|
-
| `answerReply({ host, opened, call, settling, runner })` | Continues a reply after one of its calls was answered. `settling` is the call's events from the kernel's `invokeTool`. |
|
|
661
|
-
| `rewindConversation({ host, opened, at, walkAway? })` | Cuts the conversation after transcript block `at`. `-1` empties it. |
|
|
662
|
-
| `conversationView(host, conversation)` | The conversation as the chat draws it. |
|
|
663
|
-
| `waitingCalls(conversation)` | The calls a paused reply waits on. A message or a rewind walks away from exactly these. |
|
|
664
|
-
|
|
665
|
-
`use` says what the request opens the conversation for: `{ kind: 'read' }`, `{ kind: 'message', abandon? }`, `{ kind: 'answer', call }`, or `{ kind: 'rewind', at }`.
|
|
666
|
-
|
|
667
|
-
The runner is how your server runs the model for a reply. This server answers a message for `support`, the profile from the [Quick start](#quick-start):
|
|
668
|
-
|
|
669
|
-
```ts
|
|
670
|
-
import { compactHistory, defaultKernelScope, runTurn } from '@theoremjs/agents';
|
|
671
|
-
import { interfaceFromProfile } from '@theoremjs/agents/interface';
|
|
672
|
-
import {
|
|
673
|
-
createMemoryConversationStore,
|
|
674
|
-
messageReply,
|
|
675
|
-
openConversation,
|
|
676
|
-
postedMessage,
|
|
677
|
-
type ReplyRunner,
|
|
678
|
-
readerConversationHost,
|
|
679
|
-
theoremTurnRequestSchema,
|
|
680
|
-
} from '@theoremjs/react/server';
|
|
681
|
-
|
|
682
|
-
const provider = { vault: { main: process.env.GEMINI_API_KEY } };
|
|
683
|
-
const conversations = createMemoryConversationStore();
|
|
684
|
-
|
|
685
|
-
async function* send(sessionId: string, body: unknown, signal: AbortSignal) {
|
|
686
|
-
const request = theoremTurnRequestSchema.parse(body);
|
|
687
|
-
const host = readerConversationHost({ sessionId, store: conversations, profile: support, clientEvents: undefined });
|
|
688
|
-
const runner: ReplyRunner = {
|
|
689
|
-
run: (turn) => runTurn({ profile: support.id, ...turn, signal }, provider),
|
|
690
|
-
async compact(history, tokens, model) {
|
|
691
|
-
const compacted = await compactHistory({ profile: support.id, history, tokens, signal, ...(model ? { model } : {}) }, provider);
|
|
692
|
-
return compacted?.history;
|
|
693
|
-
},
|
|
694
|
-
signal,
|
|
695
|
-
};
|
|
696
|
-
const message = postedMessage(interfaceFromProfile(support, defaultKernelScope.tools), request.input);
|
|
697
|
-
const opened = await openConversation(host, request.conversation, { kind: 'message' });
|
|
698
|
-
yield* messageReply({ host, opened, message, runner });
|
|
699
|
-
}
|
|
700
|
-
```
|
|
701
|
-
|
|
702
|
-
Write each line as one JSON line of an `application/x-ndjson` response. The reply's events come first, then a `conversation` line with the ref the store issued. When the run fails, its error line comes last.
|
|
703
|
-
|
|
704
|
-
What the loop leaves to you:
|
|
705
|
-
|
|
706
|
-
- The session. Every read and write names it, and the store refuses a ref from another session.
|
|
707
|
-
- 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`.
|
|
708
|
-
- 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`.
|
|
709
|
-
|
|
710
|
-
On the browser side, `@theoremjs/react/client` reads what your server sends:
|
|
711
|
-
|
|
712
|
-
| Export | Use |
|
|
713
|
-
| --- | --- |
|
|
714
|
-
| `CHAT_LINES` | The schemas of a reply's lines: each turn event, and the `conversation` line. |
|
|
715
|
-
| `ChatLine`, `ChatLineSink` | A checked line, and the callback that receives each one. |
|
|
716
|
-
| `fetchConversation(url, body, options?)` | POSTs a conversation read, and checks the view your server answers. |
|
|
717
|
-
| `fetchRewound(url, body, options?)` | POSTs a rewind, and checks the rewound conversation. |
|
|
718
|
-
| `failedDecisionTraces(err)` | The trace records that a failed decision left, for the trace inspector. |
|
|
400
|
+
- [Server options](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#server-options): what `createTheoremHandler` takes.
|
|
401
|
+
- [Keep the conversation](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#keep-the-conversation): the conversation stores, and your own database.
|
|
402
|
+
- [Share session authority](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#share-session-authority): one session store for several server instances.
|
|
403
|
+
- [Build your own server](https://github.com/masudl-hub/theoremai/blob/main/web/README.md#build-your-own-server): the reply loop, for a server that is not a `fetch` handler.
|
|
719
404
|
|
|
720
405
|
## Build your own UI
|
|
721
406
|
|
package/client/host-call.d.ts
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
7
|
import type { TranscriptBlock } from '@theoremjs/agents/interface';
|
|
8
|
-
import type { ClientFailure } from '
|
|
9
|
-
import { type JsonSchema } from '
|
|
8
|
+
import type { ClientFailure } from '@theoremjs/web/client';
|
|
9
|
+
import { type JsonSchema } from '@theoremjs/web/client';
|
|
10
10
|
export type ToolCall = Extract<TranscriptBlock, {
|
|
11
11
|
kind: 'tool';
|
|
12
12
|
}>['tool'];
|
package/client/host-call.js
CHANGED
package/client/index.d.ts
CHANGED
|
@@ -1,28 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { createDecisionTransport, type DecisionInterface, type DecisionQuestionView, type DecisionReply, type DecisionTransport, decisionAssets, decisionInterface, failedDecisionTraces, failedTraces, postDecision, readDecisionReply, withFailedTraces, } from './decision-transport.ts';
|
|
3
|
-
export { type ComposerDraftFields, composerFieldsFromDraft } from './decode-composer-draft.ts';
|
|
4
|
-
export { addUsage, checkEmbeddingInputs, checkInputs, cosineSimilarity, type EmbeddingFields, type EmbeddingInputCheck, type EmbeddingMatch, type EmbeddingMediaPart, type EmbeddingSplit, embeddingBatches, fieldsInput, inputFields, MAX_BATCH_INPUTS, rankMatches, readEmbeddingInput, readEmbeddingInputs, readsAsText, splitText, } from './embedding-input.ts';
|
|
5
|
-
export { type EmbeddingSpace, layoutSpace, layoutSpaceSoon, placeQuery, type SpaceCluster, type SpaceDocument, type SpaceLink, type SpacePoint, } from './embedding-space.ts';
|
|
6
|
-
export { createEmbeddingTransport, type EmbeddingInterface, type EmbeddingReply, type EmbeddingTransport, type EmbedOptions, embeddingInterface, postEmbedding, readEmbeddingReply, } from './embedding-transport.ts';
|
|
7
|
-
export { encodeComposerDraft } from './encode-composer-draft.ts';
|
|
8
|
-
export { filesToPending, pendingAttachmentsToFiles } from './encode-files.ts';
|
|
9
|
-
export { type ClientFailure, clientFailure, type TurnFailure } from './failure.ts';
|
|
10
|
-
export { createHostTransport, HOST_TOOL_KINDS, type HostInterface, type HostToolKind, type HostToolSource, type HostToolView, type HostTransport, hostInterface, type TheoremHostCallRequest, } from './host-transport.ts';
|
|
11
|
-
export type { LiveCallOptions, PageTool, PageToolAnswer, PageTools, } from './live/live-page-tool.ts';
|
|
12
|
-
export { type LiveConnectPhase, type LiveSessionStatus, type LiveState, liveState, } from './live/live-state.ts';
|
|
13
|
-
export type { LiveToolGatePrompt } from './live/live-tool.ts';
|
|
14
|
-
export type { LiveConnection } from './live-client.ts';
|
|
15
|
-
export { LiveSessionClient } from './live-client.ts';
|
|
16
|
-
export type { LiveSocket } from './live-messages.ts';
|
|
17
|
-
export { isOAuthComplete, notifyOAuthComplete } from './oauth-popup.ts';
|
|
18
|
-
export { type PageDispatchResult, withPageToolDispatch } from './page-dispatch.ts';
|
|
19
|
-
export { keepsConversation, type RunOutcome, resumeInterfaceTool, type StreamView, streamInterfaceDraftTurn, streamInterfaceTurn, } from './run-session.ts';
|
|
20
|
-
export { type JsonSchema, type SchemaControl, type SchemaField, sampleFromSchema, schemaControl, schemaFields, } from './schema-fields.ts';
|
|
21
|
-
export { citationsFromBlock, type SourceCitation, type SourceCitationBlock, } from './source-citations.ts';
|
|
22
|
-
export type { QueryMatch } from './space-geometry.ts';
|
|
23
|
-
export { layoutResult, type ResultChart, type ResultFigure, type ResultImage, type ResultLayout, } from './tool-result.ts';
|
|
24
|
-
export type { AnsweringGate, ToolDecisionAction, ToolGateResolution, } from './tool-resume.ts';
|
|
25
|
-
export { continueGatedToolInvocation } from './tool-resume.ts';
|
|
26
|
-
export { createTraceFeed, type TraceFeed } from './trace-feed.ts';
|
|
27
|
-
export { CHAT_LINES, type ChatLine, type ChatLineSink, type ClientTurnEvent, type ConversationLine, type ConversationView, createHttpTransport, fetchConversation, fetchRewound, type HostErrorBody, type HttpOptions, type HttpTransportOptions, hostError, isTheoremStreamError, type MalformedEvent, postJson, postNdjson, readNdjsonStream, type TheoremConversationRequest, type TheoremInvokeRequest, type TheoremReplay, type TheoremRewindRequest, type TheoremRewound, type TheoremSteerRequest, TheoremStreamError, type TheoremTransport, type TheoremTurnInput, type TheoremTurnRequest, type TurnEventSink, type UnsupportedEvent, type WireLines, } from './transport.ts';
|
|
28
|
-
export { buildInvokeRequest, buildTurnRequest, issuedOperationId, type RunScope, type WalkAway, } from './turn-client.ts';
|
|
1
|
+
export * from '@theoremjs/web/client';
|
package/client/index.js
CHANGED
|
@@ -1,22 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export { createDecisionTransport, decisionAssets, decisionInterface, failedDecisionTraces, failedTraces, postDecision, readDecisionReply, withFailedTraces, } from "./decision-transport.js";
|
|
3
|
-
export { composerFieldsFromDraft } from "./decode-composer-draft.js";
|
|
4
|
-
export { addUsage, checkEmbeddingInputs, checkInputs, cosineSimilarity, embeddingBatches, fieldsInput, inputFields, MAX_BATCH_INPUTS, rankMatches, readEmbeddingInput, readEmbeddingInputs, readsAsText, splitText, } from "./embedding-input.js";
|
|
5
|
-
export { layoutSpace, layoutSpaceSoon, placeQuery, } from "./embedding-space.js";
|
|
6
|
-
export { createEmbeddingTransport, embeddingInterface, postEmbedding, readEmbeddingReply, } from "./embedding-transport.js";
|
|
7
|
-
export { encodeComposerDraft } from "./encode-composer-draft.js";
|
|
8
|
-
export { filesToPending, pendingAttachmentsToFiles } from "./encode-files.js";
|
|
9
|
-
export { clientFailure } from "./failure.js";
|
|
10
|
-
export { createHostTransport, HOST_TOOL_KINDS, hostInterface, } from "./host-transport.js";
|
|
11
|
-
export { liveState, } from "./live/live-state.js";
|
|
12
|
-
export { LiveSessionClient } from "./live-client.js";
|
|
13
|
-
export { isOAuthComplete, notifyOAuthComplete } from "./oauth-popup.js";
|
|
14
|
-
export { withPageToolDispatch } from "./page-dispatch.js";
|
|
15
|
-
export { keepsConversation, resumeInterfaceTool, streamInterfaceDraftTurn, streamInterfaceTurn, } from "./run-session.js";
|
|
16
|
-
export { sampleFromSchema, schemaControl, schemaFields, } from "./schema-fields.js";
|
|
17
|
-
export { citationsFromBlock, } from "./source-citations.js";
|
|
18
|
-
export { layoutResult, } from "./tool-result.js";
|
|
19
|
-
export { continueGatedToolInvocation } from "./tool-resume.js";
|
|
20
|
-
export { createTraceFeed } from "./trace-feed.js";
|
|
21
|
-
export { CHAT_LINES, createHttpTransport, fetchConversation, fetchRewound, hostError, isTheoremStreamError, postJson, postNdjson, readNdjsonStream, TheoremStreamError, } from "./transport.js";
|
|
22
|
-
export { buildInvokeRequest, buildTurnRequest, issuedOperationId, } from "./turn-client.js";
|
|
1
|
+
export * from '@theoremjs/web/client';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TheoremStreamError } from
|
|
1
|
+
import { TheoremStreamError } from '@theoremjs/web/client';
|
|
2
2
|
/**
|
|
3
3
|
* A failed tool step as the host reported it: the user reads its wording (else
|
|
4
4
|
* the labels' for its kind); the model's `message` stays builder detail.
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { ExecuteToolOnRelay } from '
|
|
2
|
-
import type { PageTools } from './live-page-tool.ts';
|
|
3
|
-
import type { LiveGateAnswer, LiveToolGatePrompt } from './live-tool.ts';
|
|
1
|
+
import type { ExecuteToolOnRelay, LiveGateAnswer, LiveToolGatePrompt, PageTools } from '@theoremjs/web/client';
|
|
4
2
|
/**
|
|
5
3
|
* Live provider tool-call handler: the page answers the call if it is the
|
|
6
4
|
* page's; else run the model's call on the relay; at a gate, ask the user and
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { continueGatedToolInvocation } from
|
|
1
|
+
import { continueGatedToolInvocation } from '@theoremjs/web/client';
|
|
2
2
|
/**
|
|
3
3
|
* Live provider tool-call handler: the page answers the call if it is the
|
|
4
4
|
* page's; else run the model's call on the relay; at a gate, ask the user and
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* (Seance-style), not as separate messages.
|
|
5
5
|
*/
|
|
6
6
|
import { WORDED_STOP_KINDS } from '@theoremjs/agents/interface';
|
|
7
|
-
import { humanize } from
|
|
7
|
+
import { humanize } from '@theoremjs/web/client';
|
|
8
8
|
/** `used` with `more` added. A cost only one side reported is partial. */
|
|
9
9
|
function addUsage(used, more) {
|
|
10
10
|
if (!used)
|
package/client/voice-recorder.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { describeError } from '@theoremjs/agents';
|
|
2
2
|
import { pickMediaRecorderMime } from '@theoremjs/agents/interface';
|
|
3
|
-
import { timeDomainBytesToLevel } from
|
|
3
|
+
import { timeDomainBytesToLevel } from '@theoremjs/web/client';
|
|
4
4
|
class VoiceRecorderFailure extends Error {
|
|
5
5
|
code;
|
|
6
6
|
/** `detail` is raw diagnostic text for the builder, never shown to the user. */
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import type { LiveConnection, LiveConnectPhase, LiveSessionClient, LiveSessionStatus } from '@theoremjs/web/client';
|
|
1
2
|
import { type Dispatch, type MutableRefObject, type SetStateAction } from 'react';
|
|
2
3
|
import { type LiveCaptionState } from '../../client/live/live-captions.ts';
|
|
3
|
-
import type { LiveConnectPhase, LiveSessionStatus } from '../../client/live/live-state.ts';
|
|
4
4
|
import { type LiveFacingMode, type LiveVideoCapture } from '../../client/live/live-video.ts';
|
|
5
|
-
import type { LiveConnection, LiveSessionClient } from '../../client/live-client.ts';
|
|
6
5
|
/** Media + session lifecycle handlers for LiveRunner. */
|
|
7
6
|
export declare function useLiveRunnerControls(args: {
|
|
8
7
|
clientRef: MutableRefObject<LiveSessionClient | null>;
|