@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.
Files changed (193) hide show
  1. package/README.md +21 -336
  2. package/client/host-call.d.ts +2 -2
  3. package/client/host-call.js +1 -2
  4. package/client/index.d.ts +1 -28
  5. package/client/index.js +1 -22
  6. package/client/live/apply-live-turn-tool-event.js +1 -1
  7. package/client/live/run-live-tool-call.d.ts +1 -3
  8. package/client/live/run-live-tool-call.js +1 -1
  9. package/client/transcript-groups.js +1 -1
  10. package/client/voice-recorder.js +1 -1
  11. package/components/live/use-live-runner-controls.d.ts +1 -2
  12. package/components/live/use-live-runner-model.d.ts +7 -8
  13. package/components/live/use-live-runner-model.js +1 -2
  14. package/components/live/use-live-runner-ui.d.ts +2 -4
  15. package/components/live/use-live-runner-ui.js +1 -1
  16. package/components/live/use-live-session-client.d.ts +2 -5
  17. package/components/live/use-live-session-client.js +1 -1
  18. package/hooks/use-described.d.ts +1 -1
  19. package/hooks/use-described.js +1 -1
  20. package/hooks/use-embedding-index.d.ts +1 -1
  21. package/hooks/use-embedding-index.js +1 -1
  22. package/hooks/use-one-call.d.ts +2 -2
  23. package/hooks/use-one-call.js +1 -2
  24. package/hooks/use-page-tool-warnings.d.ts +1 -1
  25. package/hooks/use-page-tool-warnings.js +1 -1
  26. package/hooks/use-theorem-chat-actions.d.ts +2 -4
  27. package/hooks/use-theorem-chat-actions.js +1 -3
  28. package/hooks/use-theorem-chat-state.d.ts +1 -2
  29. package/hooks/use-theorem-chat.d.ts +4 -5
  30. package/hooks/use-theorem-chat.js +1 -6
  31. package/hooks/use-theorem-decision.d.ts +1 -2
  32. package/hooks/use-theorem-embedding.d.ts +1 -2
  33. package/hooks/use-theorem-host.d.ts +2 -4
  34. package/hooks/use-theorem-host.js +1 -4
  35. package/hooks/use-theorem-interface.d.ts +1 -2
  36. package/hooks/use-trace-records.d.ts +1 -1
  37. package/index.d.ts +2 -3
  38. package/index.js +2 -3
  39. package/live.d.ts +1 -2
  40. package/package.json +3 -2
  41. package/server/mod.d.ts +1 -26
  42. package/server/mod.js +1 -24
  43. package/ui/ChatComposerBar.d.ts +1 -1
  44. package/ui/ChatTranscript.d.ts +1 -1
  45. package/ui/ChatTranscript.js +1 -1
  46. package/ui/ConsoleFrame.d.ts +1 -1
  47. package/ui/DecisionAnswers.d.ts +1 -1
  48. package/ui/EmbeddingDocuments.d.ts +2 -2
  49. package/ui/EmbeddingDocuments.js +1 -2
  50. package/ui/EmbeddingQuery.d.ts +1 -1
  51. package/ui/EmbeddingQuery.js +1 -2
  52. package/ui/EmbeddingResults.d.ts +1 -1
  53. package/ui/EmbeddingResults.js +1 -1
  54. package/ui/EmbeddingSpace.d.ts +1 -2
  55. package/ui/LiveRunner.d.ts +1 -2
  56. package/ui/SchemaFields.d.ts +1 -1
  57. package/ui/SchemaFields.js +1 -2
  58. package/ui/ShapedData.js +1 -1
  59. package/ui/StateFields.js +1 -1
  60. package/ui/TheoremChat.d.ts +2 -2
  61. package/ui/TheoremChat.js +1 -1
  62. package/ui/TheoremDecision.d.ts +1 -1
  63. package/ui/TheoremDecision.js +1 -1
  64. package/ui/TheoremEmbedding.d.ts +1 -1
  65. package/ui/TheoremEmbedding.js +1 -2
  66. package/ui/TheoremHost.d.ts +2 -3
  67. package/ui/TheoremHost.js +1 -3
  68. package/ui/ToolGateCard.d.ts +1 -1
  69. package/ui/ToolGateCard.js +1 -2
  70. package/ui/ToolResult.d.ts +1 -1
  71. package/ui/ToolResult.js +1 -2
  72. package/ui/ToolResultCharts.d.ts +1 -1
  73. package/ui/ToolResultCharts.js +1 -2
  74. package/ui/TraceInspector.d.ts +1 -1
  75. package/ui/TraceInspectorPanel.d.ts +1 -1
  76. package/ui/approval-heading.js +1 -1
  77. package/ui/embedding-space-gl.d.ts +2 -2
  78. package/ui/embedding-space-gl.js +1 -1
  79. package/ui/index.d.ts +1 -1
  80. package/ui/labels.d.ts +1 -1
  81. package/client/audio-level.d.ts +0 -5
  82. package/client/audio-level.js +0 -24
  83. package/client/decision-transport.d.ts +0 -70
  84. package/client/decision-transport.js +0 -175
  85. package/client/decode-composer-draft.d.ts +0 -11
  86. package/client/decode-composer-draft.js +0 -12
  87. package/client/embedding-input.d.ts +0 -84
  88. package/client/embedding-input.js +0 -194
  89. package/client/embedding-space.d.ts +0 -82
  90. package/client/embedding-space.js +0 -389
  91. package/client/embedding-transport.d.ts +0 -40
  92. package/client/embedding-transport.js +0 -71
  93. package/client/encode-composer-draft.d.ts +0 -9
  94. package/client/encode-composer-draft.js +0 -34
  95. package/client/encode-files.d.ts +0 -18
  96. package/client/encode-files.js +0 -54
  97. package/client/failure.d.ts +0 -29
  98. package/client/failure.js +0 -34
  99. package/client/generation-selection.d.ts +0 -15
  100. package/client/generation-selection.js +0 -24
  101. package/client/host-transport.d.ts +0 -70
  102. package/client/host-transport.js +0 -75
  103. package/client/live/live-mic-forward.d.ts +0 -30
  104. package/client/live/live-mic-forward.js +0 -46
  105. package/client/live/live-page-tool.d.ts +0 -34
  106. package/client/live/live-page-tool.js +0 -11
  107. package/client/live/live-state.d.ts +0 -13
  108. package/client/live/live-state.js +0 -22
  109. package/client/live/live-tool.d.ts +0 -11
  110. package/client/live/live-tool.js +0 -1
  111. package/client/live-client.d.ts +0 -189
  112. package/client/live-client.js +0 -829
  113. package/client/live-errors.d.ts +0 -2
  114. package/client/live-errors.js +0 -9
  115. package/client/live-messages.d.ts +0 -148
  116. package/client/live-messages.js +0 -100
  117. package/client/mic-capture.d.ts +0 -4
  118. package/client/mic-capture.js +0 -6
  119. package/client/oauth-popup.d.ts +0 -26
  120. package/client/oauth-popup.js +0 -30
  121. package/client/page-dispatch.d.ts +0 -15
  122. package/client/page-dispatch.js +0 -63
  123. package/client/pcm-downsample.d.ts +0 -4
  124. package/client/pcm-downsample.js +0 -45
  125. package/client/run-commit.d.ts +0 -34
  126. package/client/run-commit.js +0 -49
  127. package/client/run-session.d.ts +0 -79
  128. package/client/run-session.js +0 -207
  129. package/client/schema-fields.d.ts +0 -63
  130. package/client/schema-fields.js +0 -199
  131. package/client/shaped-data.d.ts +0 -118
  132. package/client/shaped-data.js +0 -343
  133. package/client/source-citations.d.ts +0 -13
  134. package/client/source-citations.js +0 -56
  135. package/client/space-geometry.d.ts +0 -39
  136. package/client/space-geometry.js +0 -183
  137. package/client/tool-result.d.ts +0 -78
  138. package/client/tool-result.js +0 -293
  139. package/client/tool-resume.d.ts +0 -50
  140. package/client/tool-resume.js +0 -14
  141. package/client/trace-feed.d.ts +0 -13
  142. package/client/trace-feed.js +0 -18
  143. package/client/transcript-schema.d.ts +0 -10
  144. package/client/transcript-schema.js +0 -120
  145. package/client/transport.d.ts +0 -264
  146. package/client/transport.js +0 -330
  147. package/client/turn-client.d.ts +0 -44
  148. package/client/turn-client.js +0 -88
  149. package/client/wire-line.d.ts +0 -56
  150. package/client/wire-line.js +0 -90
  151. package/client/worklets/mic-capture.js +0 -16
  152. package/server/checkpoint-ownership.d.ts +0 -6
  153. package/server/checkpoint-ownership.js +0 -42
  154. package/server/conversation-store.d.ts +0 -92
  155. package/server/conversation-store.js +0 -131
  156. package/server/conversation.d.ts +0 -193
  157. package/server/conversation.js +0 -552
  158. package/server/credential-store.d.ts +0 -24
  159. package/server/credential-store.js +0 -14
  160. package/server/decision-handler.d.ts +0 -42
  161. package/server/decision-handler.js +0 -46
  162. package/server/embedding-handler.d.ts +0 -33
  163. package/server/embedding-handler.js +0 -45
  164. package/server/handler.d.ts +0 -158
  165. package/server/handler.js +0 -775
  166. package/server/json-response.d.ts +0 -2
  167. package/server/json-response.js +0 -7
  168. package/server/mcp-handler.d.ts +0 -46
  169. package/server/mcp-handler.js +0 -312
  170. package/server/page-dispatch.d.ts +0 -22
  171. package/server/page-dispatch.js +0 -127
  172. package/server/request-body.d.ts +0 -2
  173. package/server/request-body.js +0 -42
  174. package/server/request-check.d.ts +0 -21
  175. package/server/request-check.js +0 -49
  176. package/server/session-authority.d.ts +0 -8
  177. package/server/session-authority.js +0 -78
  178. package/server/session-boundary.d.ts +0 -26
  179. package/server/session-boundary.js +0 -64
  180. package/server/session-identity.d.ts +0 -16
  181. package/server/session-identity.js +0 -41
  182. package/server/session-limits.d.ts +0 -12
  183. package/server/session-limits.js +0 -59
  184. package/server/session-store.d.ts +0 -123
  185. package/server/session-store.js +0 -264
  186. package/server/single-action.d.ts +0 -21
  187. package/server/single-action.js +0 -30
  188. package/server/steer-inbox.d.ts +0 -35
  189. package/server/steer-inbox.js +0 -52
  190. package/server/tool-operations.d.ts +0 -6
  191. package/server/tool-operations.js +0 -132
  192. package/server/turn-input.d.ts +0 -10
  193. package/server/turn-input.js +0 -29
package/ui/ShapedData.js CHANGED
@@ -12,8 +12,8 @@ import { Table } from '@astryxdesign/core/Table';
12
12
  import { Text } from '@astryxdesign/core/Text';
13
13
  import { Token } from '@astryxdesign/core/Token';
14
14
  import { VStack } from '@astryxdesign/core/VStack';
15
+ import { fieldLabel, fieldReading, isPlain, isProse, isRow, json, MAX_ROWS, plainReading, rowHeading, shapeOf, splitFields, unpacked, withUnit, } from '@theoremjs/web/client';
15
16
  import { Component, useMemo, useState } from 'react';
16
- import { fieldLabel, fieldReading, isPlain, isProse, isRow, json, MAX_ROWS, plainReading, rowHeading, shapeOf, splitFields, unpacked, withUnit, } from "../client/shaped-data.js";
17
17
  import { Arrive, useArrive } from "./arrive.js";
18
18
  import { useLabels } from "./labels-provider.js";
19
19
  import { useMarkdownPlugins } from "./markdown-plugins.js";
package/ui/StateFields.js CHANGED
@@ -15,9 +15,9 @@ import { Thumbnail } from '@astryxdesign/core/Thumbnail';
15
15
  import { Tokenizer } from '@astryxdesign/core/Tokenizer';
16
16
  import { VStack } from '@astryxdesign/core/VStack';
17
17
  import { IconPlus, IconX } from '@tabler/icons-react';
18
+ import { humanize, isPlain } from '@theoremjs/web/client';
18
19
  import { createContext, useContext, useId, useState } from 'react';
19
20
  import { IMAGE_ACCEPT, imageSrc } from "../client/decision-images.js";
20
- import { humanize, isPlain } from "../client/shaped-data.js";
21
21
  import { blankLike, isWordList, tableColumns } from "../client/state-fields.js";
22
22
  import { useImageReader } from "./DecisionImages.js";
23
23
  import { useLabels } from "./labels-provider.js";
@@ -1,7 +1,7 @@
1
1
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
+ import type { PageTools } from '@theoremjs/web/client';
3
+ import { type ConversationView, type HttpTransportOptions, type TheoremTransport } from '@theoremjs/web/client';
2
4
  import { type ReactNode, type Ref } from 'react';
3
- import type { PageTools } from '../client/live/live-page-tool.ts';
4
- import { type ConversationView, type HttpTransportOptions, type TheoremTransport } from '../client/transport.ts';
5
5
  import { type SentTurn, type UseTheoremChatOptions } from '../hooks/use-theorem-chat.ts';
6
6
  import type { TheoremLabels } from './labels.ts';
7
7
  export type TheoremChatProps = {
package/ui/TheoremChat.js CHANGED
@@ -6,9 +6,9 @@ import { Layout, LayoutContent } from '@astryxdesign/core/Layout';
6
6
  import { Text } from '@astryxdesign/core/Text';
7
7
  import { VStack } from '@astryxdesign/core/VStack';
8
8
  import { moveComposerPendingWithinKind, removeComposerPendingMessage, } from '@theoremjs/agents/interface';
9
+ import { createHttpTransport, } from '@theoremjs/web/client';
9
10
  import { useImperativeHandle, useMemo, useRef, } from 'react';
10
11
  import { parseAspectRatio } from "../client/image-output.js";
11
- import { createHttpTransport, } from "../client/transport.js";
12
12
  import { useTheoremChat, } from "../hooks/use-theorem-chat.js";
13
13
  import { useTheoremInterface } from "../hooks/use-theorem-interface.js";
14
14
  import { ChatComposerBar } from "./ChatComposerBar.js";
@@ -1,5 +1,5 @@
1
+ import { type DecisionTransport } from '@theoremjs/web/client';
1
2
  import { type DecisionImages } from '../client/decision-images.ts';
2
- import { type DecisionTransport } from '../client/decision-transport.ts';
3
3
  import { type ConsolePageProps } from './ConsoleFrame.tsx';
4
4
  import { type TheoremDecisionAnswersProps } from './DecisionAnswers.tsx';
5
5
  export type TheoremDecisionProps = ConsolePageProps & {
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { Banner } from '@astryxdesign/core/Banner';
3
+ import { createDecisionTransport, } from '@theoremjs/web/client';
3
4
  import { useMemo, useRef, useState } from 'react';
4
5
  import { droppedImages, namedImages, stateFields, } from "../client/decision-images.js";
5
- import { createDecisionTransport, } from "../client/decision-transport.js";
6
6
  import { useTheoremDecision } from "../hooks/use-theorem-decision.js";
7
7
  import { ConsoleFrame, JsonRequest, RequestCard, ResponseColumn, RunBar, useBytes, } from "./ConsoleFrame.js";
8
8
  import { TheoremDecisionAnswers } from "./DecisionAnswers.js";
@@ -1,4 +1,4 @@
1
- import { type EmbeddingTransport } from '../client/embedding-transport.ts';
1
+ import { type EmbeddingTransport } from '@theoremjs/web/client';
2
2
  import { type ConsolePageProps } from './ConsoleFrame.tsx';
3
3
  import { type EmbeddingDocument } from './EmbeddingDocuments.tsx';
4
4
  export type TheoremEmbeddingProps = ConsolePageProps & {
@@ -1,8 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { VStack } from '@astryxdesign/core/VStack';
3
+ import { createEmbeddingTransport, rankMatches, } from '@theoremjs/web/client';
3
4
  import { useMemo, useRef, useState } from 'react';
4
- import { rankMatches } from "../client/embedding-input.js";
5
- import { createEmbeddingTransport, } from "../client/embedding-transport.js";
6
5
  import { useEmbeddingIndex } from "../hooks/use-embedding-index.js";
7
6
  import { useTheoremEmbedding } from "../hooks/use-theorem-embedding.js";
8
7
  import { ConsoleFrame, ConsoleSection, ResponseColumn, } from "./ConsoleFrame.js";
@@ -1,8 +1,7 @@
1
1
  import type { DefinedTheme } from '@astryxdesign/core/theme';
2
+ import type { HttpOptions, PageTools } from '@theoremjs/web/client';
3
+ import { type HostTransport } from '@theoremjs/web/client';
2
4
  import { type CSSProperties } from 'react';
3
- import { type HostTransport } from '../client/host-transport.ts';
4
- import type { PageTools } from '../client/live/live-page-tool.ts';
5
- import type { HttpOptions } from '../client/transport.ts';
6
5
  import { type TheoremLabels } from './labels.ts';
7
6
  export type TheoremHostProps = {
8
7
  /** Where `createTheoremHostHandler` is mounted. Default `/api/host`. Ignored when `transport` is set. */
package/ui/TheoremHost.js CHANGED
@@ -10,11 +10,9 @@ import { Text } from '@astryxdesign/core/Text';
10
10
  import { Token } from '@astryxdesign/core/Token';
11
11
  import { VStack } from '@astryxdesign/core/VStack';
12
12
  import { IconMathFunction, IconWorld } from '@tabler/icons-react';
13
+ import { createHostTransport, isRow, json, missingFields, } from '@theoremjs/web/client';
13
14
  import { useMemo, useRef, useState } from 'react';
14
15
  import { hostCallFailure, hostCallStatus, hostConsoleView, } from "../client/host-call.js";
15
- import { createHostTransport, } from "../client/host-transport.js";
16
- import { missingFields } from "../client/schema-fields.js";
17
- import { isRow, json } from "../client/shaped-data.js";
18
16
  import { toolCallLabel } from "../client/transcript-groups.js";
19
17
  import { useSecondTicker } from "../hooks/use-second-ticker.js";
20
18
  import { useTheoremHost } from "../hooks/use-theorem-host.js";
@@ -1,5 +1,5 @@
1
1
  import type { ToolGate } from '@theoremjs/agents/kernel';
2
- import type { ToolDecisionAction } from '../client/tool-resume.ts';
2
+ import type { ToolDecisionAction } from '@theoremjs/web/client';
3
3
  export type ToolDecision = ToolDecisionAction;
4
4
  /** The widest a gate card gets, in pixels. */
5
5
  export declare const GATE_CARD_WIDTH = 400;
@@ -11,9 +11,8 @@ import { TextInput } from '@astryxdesign/core/TextInput';
11
11
  import { Token } from '@astryxdesign/core/Token';
12
12
  import { VStack } from '@astryxdesign/core/VStack';
13
13
  import { IconEye, IconFlame, IconPencil } from '@tabler/icons-react';
14
+ import { humanize, isOAuthComplete } from '@theoremjs/web/client';
14
15
  import { useCallback, useEffect, useState } from 'react';
15
- import { isOAuthComplete } from "../client/oauth-popup.js";
16
- import { humanize } from "../client/shaped-data.js";
17
16
  import { approvalHeading } from "./approval-heading.js";
18
17
  import { TheoremLabelsProvider, useLabels } from "./labels-provider.js";
19
18
  /** The widest a gate card gets, in pixels. */
@@ -1,4 +1,4 @@
1
- import { type ResultMedia } from '../client/tool-result.ts';
1
+ import { type ResultMedia } from '@theoremjs/web/client';
2
2
  /**
3
3
  * A tool's output under one Response heading, led by what answers it (figures,
4
4
  * charts, the images and audio it returned), then the data itself drawn by its shape, with its JSON one
package/ui/ToolResult.js CHANGED
@@ -6,9 +6,8 @@ import { useLocale } from '@astryxdesign/core/i18n';
6
6
  import { Lightbox } from '@astryxdesign/core/Lightbox';
7
7
  import { Skeleton } from '@astryxdesign/core/Skeleton';
8
8
  import { VStack } from '@astryxdesign/core/VStack';
9
+ import { hasLead, layoutResult, returnedMedia, withUnit, } from '@theoremjs/web/client';
9
10
  import { lazy, Suspense, useMemo, useState } from 'react';
10
- import { withUnit } from "../client/shaped-data.js";
11
- import { hasLead, layoutResult, returnedMedia, } from "../client/tool-result.js";
12
11
  import { Arrive } from "./arrive.js";
13
12
  import { useLabels } from "./labels-provider.js";
14
13
  import { keyedByContent } from "./row-keys.js";
@@ -1,4 +1,4 @@
1
- import { type ResultChart } from '../client/tool-result.ts';
1
+ import { type ResultChart } from '@theoremjs/web/client';
2
2
  /** Each chart in its card, side by side where the column is wide enough. */
3
3
  export declare function ToolResultCharts({ charts }: {
4
4
  charts: readonly ResultChart[];
@@ -3,10 +3,9 @@ import { HStack } from '@astryxdesign/core/HStack';
3
3
  import { useLocale } from '@astryxdesign/core/i18n';
4
4
  import { Text } from '@astryxdesign/core/Text';
5
5
  import { VStack } from '@astryxdesign/core/VStack';
6
+ import { timeFormats, withUnit } from '@theoremjs/web/client';
6
7
  import { useMemo } from 'react';
7
8
  import { Bar, BarChart, Cell, Line, LineChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts';
8
- import { withUnit } from "../client/shaped-data.js";
9
- import { timeFormats } from "../client/tool-result.js";
10
9
  import { Arrive } from "./arrive.js";
11
10
  import { CardWall } from "./CardWall.js";
12
11
  import { ChartFrame, ChartTip, FIRST_WIDTH_PX } from "./TraceOverview.js";
@@ -1,6 +1,6 @@
1
1
  import type { TraceRecord } from '@theoremjs/agents';
2
+ import type { TraceFeed } from '@theoremjs/web/client';
2
3
  import { type ReactNode } from 'react';
3
- import type { TraceFeed } from '../client/trace-feed.ts';
4
4
  /** The inspector over the records a feed has delivered; the panel loads this module when it first opens. */
5
5
  export declare function TraceFeedBody({ traces, isWide, }: {
6
6
  traces: TraceFeed | undefined;
@@ -1,7 +1,7 @@
1
1
  import type { TraceRecord } from '@theoremjs/agents';
2
2
  import type { ProfileObservabilityView } from '@theoremjs/agents/interface';
3
+ import type { TraceFeed } from '@theoremjs/web/client';
3
4
  import { type ReactNode } from 'react';
4
- import type { TraceFeed } from '../client/trace-feed.ts';
5
5
  import { type SidePanelLabels } from './SidePanel.tsx';
6
6
  export type TraceInspector = {
7
7
  /** The header toggle; null when the host drives the trace or the profile records none. */
@@ -1,4 +1,4 @@
1
- import { humanize } from "../client/shaped-data.js";
1
+ import { humanize } from '@theoremjs/web/client';
2
2
  /** "@concierge wants to check the weather": the tool's `labels.request`, else its name in words. */
3
3
  export function approvalHeading(t, gate, toolName, agent) {
4
4
  const request = gate.request ??
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import type { EmbeddingSpace, SpacePoint } from '../client/embedding-space.ts';
12
- import { type QueryMatch } from '../client/space-geometry.ts';
11
+ import type { EmbeddingSpace, SpacePoint } from '@theoremjs/web/client';
12
+ import { type QueryMatch } from '@theoremjs/web/client';
13
13
  /** What the space highlights: a query's matches, and the document under the pointer. */
14
14
  export type SpaceFocus = {
15
15
  query: SpacePoint | null;
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @module
10
10
  */
11
- import { DOT_FLOATS, FRAME_SLOT, queryGeometry, SEGMENT_FLOATS, spaceGeometry, } from "../client/space-geometry.js";
11
+ import { DOT_FLOATS, FRAME_SLOT, queryGeometry, SEGMENT_FLOATS, spaceGeometry, } from '@theoremjs/web/client';
12
12
  /** Slot states per texture row. */
13
13
  const STATE_ROW = 1024;
14
14
  /** Field of view, in radians. */
package/ui/index.d.ts CHANGED
@@ -8,8 +8,8 @@
8
8
  *
9
9
  * @module
10
10
  */
11
+ export type { LiveCallOptions, PageTool, PageToolAnswer, PageTools, } from '@theoremjs/web/client';
11
12
  export type { InkWaveStatus } from '../client/ink-waveform.ts';
12
- export type { LiveCallOptions, PageTool, PageToolAnswer, PageTools, } from '../client/live/live-page-tool.ts';
13
13
  export { useLiveCaptionLog } from '../client/live/use-live-caption-log.ts';
14
14
  export { InkWaveform, type InkWaveformProps, type InkWaveLevels, } from '../components/InkWaveform.tsx';
15
15
  export { useLiveRunnerModel } from '../components/live/use-live-runner-model.ts';
package/ui/labels.d.ts CHANGED
@@ -7,8 +7,8 @@
7
7
  *
8
8
  * @module
9
9
  */
10
+ import type { LiveState } from '@theoremjs/web/client';
10
11
  import type { ComposerDrawerSummary } from '../client/composer-drawer.ts';
11
- import type { LiveState } from '../client/live/live-state.ts';
12
12
  import type { TurnUsage, WorkStatus } from '../client/transcript-groups.ts';
13
13
  export declare const THEOREM_UI_CATALOG: {
14
14
  readonly '@theorem.agent.handle': {
@@ -1,5 +0,0 @@
1
- /** Shared mic RMS → waveform level scaling for live and turn-composer paths. */
2
- export declare const INPUT_LEVEL_GAIN = 4;
3
- export declare function float32Rms(samples: Float32Array): number;
4
- export declare function float32RmsToLevel(samples: Float32Array): number;
5
- export declare function timeDomainBytesToLevel(samples: Uint8Array<ArrayBufferLike>): number;
@@ -1,24 +0,0 @@
1
- /** Shared mic RMS → waveform level scaling for live and turn-composer paths. */
2
- export const INPUT_LEVEL_GAIN = 4;
3
- export function float32Rms(samples) {
4
- let sum = 0;
5
- for (const sample of samples) {
6
- sum += sample * sample;
7
- }
8
- if (samples.length === 0)
9
- return 0;
10
- return Math.sqrt(sum / samples.length);
11
- }
12
- export function float32RmsToLevel(samples) {
13
- return Math.min(1, float32Rms(samples) * INPUT_LEVEL_GAIN);
14
- }
15
- export function timeDomainBytesToLevel(samples) {
16
- let sum = 0;
17
- for (const sample of samples) {
18
- const normalized = (sample - 128) / 128;
19
- sum += normalized * normalized;
20
- }
21
- if (samples.length === 0)
22
- return 0;
23
- return Math.min(1, Math.sqrt(sum / samples.length) * INPUT_LEVEL_GAIN);
24
- }
@@ -1,70 +0,0 @@
1
- /**
2
- * The browser side of a decision profile: what the host lets the page see of
3
- * it, and the one call that asks its questions about some state.
4
- *
5
- * @module
6
- */
7
- import { type DecisionAsset, type DecisionJson, type DecisionProfile, type DecisionQuestion, type DecisionResult, type TraceRecord } from '@theoremjs/agents';
8
- import type { TraceFeed } from './trace-feed.ts';
9
- import { type HttpOptions } from './transport.ts';
10
- /** One question as the page sees it: its answer type and the names of its options or levels. Instructions stay on the host. */
11
- export type DecisionQuestionView = {
12
- id: string;
13
- type: DecisionQuestion['type'];
14
- /** A choice's labels, a score's levels from 0 up; empty for a number. */
15
- labels: string[];
16
- /**
17
- * A box's image: the one its question gives, a reference or a state field, else the field its
18
- * instructions first name in backticks.
19
- */
20
- field?: string;
21
- };
22
- /** What a decision profile shows the page. */
23
- export type DecisionInterface = {
24
- type: 'decision';
25
- identity: {
26
- handle: string;
27
- };
28
- contract: string;
29
- maxStateBytes?: number;
30
- questions: DecisionQuestionView[];
31
- /** The host's own images, by the reference its questions write, sent with every decision. */
32
- images?: Record<string, DecisionAsset>;
33
- observability?: {
34
- record: boolean;
35
- };
36
- };
37
- /** The page's view of a decision profile, the questions its host asks, and the host's own images. */
38
- export declare function decisionInterface(profile: Pick<DecisionProfile, 'identity' | 'decision' | 'inputs' | 'observability'>, questions: Record<string, DecisionQuestion>, images?: Record<string, DecisionAsset>): DecisionInterface;
39
- /**
40
- * The images a decision sends: the host's own and the page's. A page image may not take a name
41
- * the host's use, so the questions always read the host's picture.
42
- */
43
- export declare function decisionAssets(host: Record<string, DecisionAsset> | undefined, page: Record<string, DecisionAsset> | undefined): Record<string, DecisionAsset> | undefined;
44
- /** A decision's reply: the answers, and the trace records a host that delivers them sent back. */
45
- export type DecisionReply = {
46
- result: DecisionResult;
47
- traces?: TraceRecord[];
48
- };
49
- export interface DecisionTransport {
50
- describe(signal?: AbortSignal): Promise<DecisionInterface>;
51
- /** `assets` are the images the state names, by reference. */
52
- decide(state: Exclude<DecisionJson, null>, signal?: AbortSignal, assets?: Record<string, DecisionAsset>): Promise<DecisionReply>;
53
- /** Where the host's trace records land, for the inspector. */
54
- traces?: TraceFeed;
55
- }
56
- /** Marks a decision's failure with the trace records it left, for the page's inspector. */
57
- export declare function withFailedTraces(err: unknown, traces: readonly TraceRecord[]): unknown;
58
- /** The trace records a failed decision left; none when its host sent none. */
59
- export declare function failedTraces(err: unknown): readonly TraceRecord[];
60
- export declare const failedDecisionTraces: typeof failedTraces;
61
- /** POSTs `body` and reads its reply with `read`; a failure keeps the trace records its body carried. */
62
- export declare function postWithTraces<Reply>(url: string, body: unknown, signal: AbortSignal | undefined, options: HttpOptions, read: (raw: unknown) => Reply): Promise<Reply>;
63
- /** POSTs a decision and reads its reply; a failure keeps the trace records its body carried. */
64
- export declare function postDecision(url: string, body: unknown, signal: AbortSignal | undefined, options?: HttpOptions): Promise<DecisionReply>;
65
- /** A host's decide reply, checked: the answers, and any trace records it delivers. */
66
- export declare function readDecisionReply(raw: unknown): DecisionReply;
67
- /** Transport for a host mounted with `createTheoremDecisionHandler`. Default endpoint `/api/decision`. */
68
- export declare function createDecisionTransport(options?: HttpOptions & {
69
- endpoint?: string;
70
- }): DecisionTransport;
@@ -1,175 +0,0 @@
1
- /**
2
- * The browser side of a decision profile: what the host lets the page see of
3
- * it, and the one call that asks its questions about some state.
4
- *
5
- * @module
6
- */
7
- import { resolveObservabilityPolicy, TheoremError, traceRecordSchema, z, } from '@theoremjs/agents';
8
- import { fetchJson } from "./transport.js";
9
- import { checkWire } from "./wire-line.js";
10
- /** A score level's name: its text, or the first text inside a structured entry. */
11
- function entryLabel(entry, fallback) {
12
- if (typeof entry === 'string')
13
- return entry;
14
- const entries = Array.isArray(entry) ? entry : Object.keys(entry);
15
- return entries.length ? entryLabel(entries[0], fallback) : fallback;
16
- }
17
- function withField(field) {
18
- return field === undefined ? {} : { field };
19
- }
20
- /** The first field an entry names in backticks, as in "the mug in `photo`". */
21
- function namedField(entry) {
22
- if (typeof entry === 'string')
23
- return /\x60([^\x60\s]+)\x60/.exec(entry)?.[1];
24
- const entries = Array.isArray(entry) ? entry : Object.values(entry);
25
- for (const each of entries) {
26
- const field = namedField(each);
27
- if (field !== undefined)
28
- return field;
29
- }
30
- return undefined;
31
- }
32
- /** The page's view of a decision profile, the questions its host asks, and the host's own images. */
33
- export function decisionInterface(profile, questions, images) {
34
- return {
35
- type: 'decision',
36
- identity: { handle: profile.identity.handle },
37
- contract: profile.decision.contract,
38
- ...(profile.inputs.maxStateBytes === undefined
39
- ? {}
40
- : { maxStateBytes: profile.inputs.maxStateBytes }),
41
- questions: Object.entries(questions).map(([id, question]) => ({
42
- id,
43
- type: question.type,
44
- labels: question.type === 'choice'
45
- ? Object.keys(question.criteria)
46
- : question.type === 'score'
47
- ? question.criteria.map((entry, level) => entryLabel(entry, String(level)))
48
- : [],
49
- ...(question.type === 'box'
50
- ? withField(question.image ?? namedField(question.instructions))
51
- : {}),
52
- })),
53
- ...(images && Object.keys(images).length > 0 ? { images } : {}),
54
- ...(profile.observability
55
- ? { observability: { record: resolveObservabilityPolicy(profile.observability).record } }
56
- : {}),
57
- };
58
- }
59
- /**
60
- * The images a decision sends: the host's own and the page's. A page image may not take a name
61
- * the host's use, so the questions always read the host's picture.
62
- */
63
- export function decisionAssets(host, page) {
64
- const clash = Object.keys(page ?? {}).find((name) => host && Object.hasOwn(host, name));
65
- if (clash !== undefined)
66
- // labels-exempt: internal diagnostic; the user reads error.request
67
- throw new TheoremError('request', `the image ${clash} is the host's, so the page's needs another name`);
68
- const all = { ...host, ...page };
69
- return Object.keys(all).length > 0 ? all : undefined;
70
- }
71
- const probability = z.number().min(0).max(1);
72
- const probabilities = z
73
- .record(z.string(), probability)
74
- .refine((record) => Math.abs(Object.values(record).reduce((sum, value) => sum + value, 0) - 1) <= 0.001);
75
- const answerSchema = z.discriminatedUnion('type', [
76
- z.object({
77
- type: z.literal('choice'),
78
- choice: z.string(),
79
- confidence: probability,
80
- probabilities,
81
- }),
82
- z.object({ type: z.literal('noul'), noul: probability }),
83
- z.object({
84
- type: z.literal('box'),
85
- box: z.object({ top: probability, bottom: probability, left: probability, right: probability }),
86
- confidence: probability,
87
- }),
88
- z.object({
89
- type: z.literal('score'),
90
- score: z.number().nonnegative(),
91
- confidence: probability,
92
- legend: z.record(z.string(), z.string().min(1)),
93
- probabilities,
94
- }),
95
- ]);
96
- const replySchema = z.object({
97
- result: z.object({
98
- model: z.string().min(1),
99
- answers: z.record(z.string(), answerSchema),
100
- usage: z
101
- .object({
102
- inputTokens: z.number().int().nonnegative(),
103
- outputTokens: z.number().int().nonnegative(),
104
- costUsd: z.number().nonnegative().optional(),
105
- })
106
- .optional(),
107
- }),
108
- traces: z.array(traceRecordSchema).optional(),
109
- });
110
- /** The trace records a failed decision left, by the failure thrown for it. */
111
- const traceFailures = new WeakMap();
112
- /** Marks a decision's failure with the trace records it left, for the page's inspector. */
113
- export function withFailedTraces(err, traces) {
114
- if (traces.length > 0 && typeof err === 'object' && err !== null)
115
- traceFailures.set(err, traces);
116
- return err;
117
- }
118
- /** The trace records a failed decision left; none when its host sent none. */
119
- export function failedTraces(err) {
120
- return (typeof err === 'object' && err !== null && traceFailures.get(err)) || [];
121
- }
122
- export const failedDecisionTraces = failedTraces;
123
- const failedBody = z.object({ traces: z.array(traceRecordSchema) });
124
- /** POSTs `body` and reads its reply with `read`; a failure keeps the trace records its body carried. */
125
- export async function postWithTraces(url, body, signal, options, read) {
126
- let traces = [];
127
- const failed = (raw) => {
128
- const parsed = failedBody.safeParse(raw);
129
- if (parsed.success)
130
- traces = parsed.data.traces;
131
- };
132
- try {
133
- return read(await fetchJson(url, { body, signal, failed }, options));
134
- }
135
- catch (err) {
136
- throw withFailedTraces(err, traces);
137
- }
138
- }
139
- /** POSTs a decision and reads its reply; a failure keeps the trace records its body carried. */
140
- export function postDecision(url, body, signal, options = {}) {
141
- return postWithTraces(url, body, signal, options, readDecisionReply);
142
- }
143
- /** A host's decide reply, checked: the answers, and any trace records it delivers. */
144
- export function readDecisionReply(raw) {
145
- // labels-exempt: internal diagnostic; the user reads error.bad_response
146
- return checkWire(replySchema, raw, 'the decision');
147
- }
148
- const describedSchema = z.object({
149
- interface: z.object({
150
- type: z.literal('decision'),
151
- identity: z.object({ handle: z.string() }),
152
- contract: z.string(),
153
- maxStateBytes: z.number().optional(),
154
- questions: z.array(z.object({
155
- id: z.string(),
156
- type: z.enum(['choice', 'noul', 'score', 'box']),
157
- labels: z.array(z.string()),
158
- field: z.string().optional(),
159
- })),
160
- images: z
161
- .record(z.string(), z.object({ mimeType: z.enum(['image/png', 'image/jpeg']), data: z.string() }))
162
- .optional(),
163
- observability: z.object({ record: z.boolean() }).optional(),
164
- }),
165
- });
166
- /** Transport for a host mounted with `createTheoremDecisionHandler`. Default endpoint `/api/decision`. */
167
- export function createDecisionTransport(options = {}) {
168
- const base = (options.endpoint ?? '/api/decision').replace(/\/$/, '');
169
- return {
170
- async describe(signal) {
171
- return checkWire(describedSchema, await fetchJson(base, { signal }, options), 'the decision description').interface;
172
- },
173
- decide: (state, signal, assets) => postDecision(`${base}/decide`, { state, ...(assets ? { assets } : {}) }, signal, options),
174
- };
175
- }
@@ -1,11 +0,0 @@
1
- /**
2
- * Restore composer fields from a serializable pending `UserTurnDraft`.
3
- */
4
- import type { UserTurnDraft } from '@theoremjs/agents/interface';
5
- export type ComposerDraftFields = {
6
- text: string;
7
- files: File[];
8
- voice: File[];
9
- };
10
- /** Map an encoded pending draft back into live composer file fields. */
11
- export declare function composerFieldsFromDraft(draft: UserTurnDraft): ComposerDraftFields;
@@ -1,12 +0,0 @@
1
- /**
2
- * Restore composer fields from a serializable pending `UserTurnDraft`.
3
- */
4
- import { pendingAttachmentsToFiles } from "./encode-files.js";
5
- /** Map an encoded pending draft back into live composer file fields. */
6
- export function composerFieldsFromDraft(draft) {
7
- return {
8
- text: draft.text ?? '',
9
- files: pendingAttachmentsToFiles(draft.attachments ?? []),
10
- voice: pendingAttachmentsToFiles(draft.voice ?? []),
11
- };
12
- }
@@ -1,84 +0,0 @@
1
- /**
2
- * The rules behind an embedding console: the inputs as the JSON a request
3
- * sends, text split into documents, documents packed into the requests the
4
- * profile allows, all checked the way the kernel checks them, and documents
5
- * ranked by how alike they point to a query.
6
- *
7
- * @module
8
- */
9
- import { type EmbeddingInput, type EmbeddingPart, type EmbeddingUsage } from '@theoremjs/agents';
10
- import type { AttachmentValidationIssue } from '@theoremjs/agents/interface';
11
- import type { EmbeddingInterface } from './embedding-transport.ts';
12
- /** A part that is not text: a file sent inline, or one the provider already holds. */
13
- export type EmbeddingMediaPart = Exclude<EmbeddingPart, {
14
- type: 'text';
15
- }>;
16
- export type EmbeddingInputCheck = {
17
- ok: true;
18
- inputs: EmbeddingInput[];
19
- } | {
20
- ok: false;
21
- reason: 'invalid_json' | 'no_inputs';
22
- } | {
23
- ok: false;
24
- reason: 'too_many_inputs';
25
- max: number;
26
- inputs: EmbeddingInput[];
27
- } | {
28
- ok: false;
29
- reason: 'empty_input' | 'text_off';
30
- index: number;
31
- inputs: EmbeddingInput[];
32
- } | {
33
- ok: false;
34
- reason: 'attachments';
35
- issues: AttachmentValidationIssue[];
36
- inputs: EmbeddingInput[];
37
- };
38
- /** The request's inputs, read from its JSON; `undefined` when it is not a list of inputs. */
39
- export declare function readEmbeddingInputs(text: string): EmbeddingInput[] | undefined;
40
- /** One input, read from its JSON; `undefined` when it is not one. */
41
- export declare function readEmbeddingInput(text: string): EmbeddingInput | undefined;
42
- /** One input as fields edit it: its words, and the files beside them. */
43
- export type EmbeddingFields = {
44
- text: string;
45
- media: EmbeddingMediaPart[];
46
- };
47
- /** The input as fields, or `null` when it holds more than one text part and fields would lose it. */
48
- export declare function inputFields(input: EmbeddingInput): EmbeddingFields | null;
49
- /** Fields as the input they send: plain text alone, else its parts with the text first. */
50
- export declare function fieldsInput(fields: EmbeddingFields): EmbeddingInput;
51
- /** The inputs, held to the profile's rules and its model's limits as the kernel holds them in one request. */
52
- export declare function checkInputs(inputs: readonly EmbeddingInput[], rules: EmbeddingInterface['inputs']): EmbeddingInputCheck;
53
- /** The request's JSON as the inputs it sends, held to the profile's rules. */
54
- export declare function checkEmbeddingInputs(text: string, rules: EmbeddingInterface['inputs']): EmbeddingInputCheck;
55
- /** Where text is cut into documents: not at all, at each line, at blank lines, at commas, or at a separator of your own. */
56
- export type EmbeddingSplit = 'whole' | 'lines' | 'paragraphs' | 'commas' | {
57
- separator: string;
58
- };
59
- /** The text as documents, each trimmed, none empty. */
60
- export declare function splitText(text: string, split: EmbeddingSplit): string[];
61
- /** A file read as words and split, not sent as media: plain text, Markdown, CSV, and JSON. */
62
- export declare function readsAsText(file: {
63
- name: string;
64
- type: string;
65
- }): boolean;
66
- /** The most inputs the console sends in one request when the model sets no cap. */
67
- export declare const MAX_BATCH_INPUTS = 100;
68
- /**
69
- * The inputs, in order, as the fewest requests the profile and its model
70
- * allow: each holds at most `most` inputs and passes {@linkcode checkInputs}.
71
- * An input refused on its own goes alone, for the kernel to refuse.
72
- */
73
- export declare function embeddingBatches(inputs: readonly EmbeddingInput[], rules: EmbeddingInterface['inputs'], most?: number): EmbeddingInput[][];
74
- /** Two calls' usage as one: token counts and costs added, estimated when either was. */
75
- export declare function addUsage(a: EmbeddingUsage | undefined, b: EmbeddingUsage | undefined): EmbeddingUsage | undefined;
76
- /** How alike two vectors point, from -1 to 1. */
77
- export declare function cosineSimilarity(a: readonly number[], b: readonly number[]): number;
78
- /** A document and how alike it points to the query, from -1 to 1. */
79
- export type EmbeddingMatch = {
80
- index: number;
81
- score: number;
82
- };
83
- /** The documents, most alike to the query first; a vector of another width is left out. */
84
- export declare function rankMatches(query: readonly number[], documents: readonly (readonly number[])[]): EmbeddingMatch[];