@theoremjs/react 0.3.0 → 0.3.1

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 (258) hide show
  1. package/README.md +728 -202
  2. package/client/composer-hints.js +1 -1
  3. package/client/decision-images.d.ts +76 -0
  4. package/client/decision-images.js +139 -0
  5. package/client/decision-transport.d.ts +26 -4
  6. package/client/decision-transport.js +79 -6
  7. package/client/embedding-input.d.ts +84 -0
  8. package/client/embedding-input.js +194 -0
  9. package/client/embedding-space.d.ts +82 -0
  10. package/client/embedding-space.js +389 -0
  11. package/client/embedding-transport.d.ts +40 -0
  12. package/client/embedding-transport.js +71 -0
  13. package/client/failure.d.ts +7 -10
  14. package/client/failure.js +9 -9
  15. package/client/host-call.d.ts +1 -1
  16. package/client/host-call.js +7 -2
  17. package/client/host-transport.d.ts +2 -0
  18. package/client/host-transport.js +3 -2
  19. package/client/index.d.ts +19 -11
  20. package/client/index.js +14 -10
  21. package/client/ink-waveform.d.ts +1 -1
  22. package/client/ink-waveform.js +1 -2
  23. package/client/live/apply-live-turn-tool-event.js +1 -1
  24. package/client/live/live-captions.d.ts +30 -0
  25. package/client/live/live-captions.js +105 -1
  26. package/client/live/live-mic-forward.d.ts +1 -0
  27. package/client/live/live-mic-forward.js +11 -2
  28. package/client/live/live-page-tool.d.ts +34 -0
  29. package/client/live/live-page-tool.js +11 -0
  30. package/client/live/live-state.d.ts +4 -2
  31. package/client/live/live-state.js +2 -0
  32. package/client/live/live-video.js +1 -1
  33. package/client/live/run-live-tool-call.d.ts +7 -2
  34. package/client/live/run-live-tool-call.js +48 -10
  35. package/client/live/use-live-caption-log.d.ts +17 -0
  36. package/client/live/use-live-caption-log.js +51 -0
  37. package/client/live-client.d.ts +52 -4
  38. package/client/live-client.js +250 -59
  39. package/client/live-messages.d.ts +51 -13
  40. package/client/live-messages.js +42 -9
  41. package/client/page-dispatch.d.ts +15 -0
  42. package/client/page-dispatch.js +63 -0
  43. package/client/run-commit.d.ts +16 -43
  44. package/client/run-commit.js +26 -101
  45. package/client/run-session.d.ts +40 -41
  46. package/client/run-session.js +104 -112
  47. package/client/schema-fields.js +27 -6
  48. package/client/shaped-data.js +37 -8
  49. package/client/source-citations.js +1 -1
  50. package/client/space-geometry.d.ts +39 -0
  51. package/client/space-geometry.js +183 -0
  52. package/client/state-fields.js +1 -1
  53. package/client/tool-result.js +30 -12
  54. package/client/tool-resume.d.ts +18 -1
  55. package/client/tool-resume.js +4 -1
  56. package/client/trace-feed.d.ts +1 -1
  57. package/client/trace-story.d.ts +2 -2
  58. package/client/trace-story.js +43 -19
  59. package/client/trace-view.d.ts +2 -2
  60. package/client/trace-view.js +56 -16
  61. package/client/transcript-groups.d.ts +28 -2
  62. package/client/transcript-groups.js +63 -13
  63. package/client/transcript-schema.d.ts +10 -0
  64. package/client/transcript-schema.js +120 -0
  65. package/client/transport.d.ts +114 -26
  66. package/client/transport.js +106 -32
  67. package/client/turn-client.d.ts +17 -8
  68. package/client/turn-client.js +26 -31
  69. package/client/voice-recorder.d.ts +1 -1
  70. package/client/voice-recorder.js +2 -5
  71. package/client/wire-line.js +5 -5
  72. package/client/worklets/mic-capture.js +9 -9
  73. package/components/InkWaveform.d.ts +12 -1
  74. package/components/InkWaveform.js +65 -42
  75. package/components/live/use-live-runner-controls.d.ts +3 -4
  76. package/components/live/use-live-runner-controls.js +6 -10
  77. package/components/live/use-live-runner-model.d.ts +10 -6
  78. package/components/live/use-live-runner-model.js +29 -14
  79. package/components/live/use-live-runner-ui.d.ts +10 -8
  80. package/components/live/use-live-runner-ui.js +19 -11
  81. package/components/live/use-live-session-client.d.ts +4 -4
  82. package/components/live/use-live-session-client.js +11 -8
  83. package/components/use-composer-voice.d.ts +4 -4
  84. package/components/use-composer-voice.js +8 -8
  85. package/components/use-editor-selection.js +4 -1
  86. package/components/use-voice-playback.d.ts +2 -1
  87. package/components/use-voice-playback.js +4 -4
  88. package/hooks/use-described.d.ts +5 -1
  89. package/hooks/use-described.js +11 -9
  90. package/hooks/use-embedding-index.d.ts +27 -0
  91. package/hooks/use-embedding-index.js +43 -0
  92. package/hooks/use-one-call.d.ts +31 -0
  93. package/hooks/use-one-call.js +76 -0
  94. package/hooks/use-page-tool-warnings.d.ts +6 -0
  95. package/hooks/use-page-tool-warnings.js +25 -0
  96. package/hooks/use-second-ticker.d.ts +2 -0
  97. package/hooks/use-second-ticker.js +13 -0
  98. package/hooks/use-theorem-chat-actions.d.ts +25 -21
  99. package/hooks/use-theorem-chat-actions.js +67 -45
  100. package/hooks/use-theorem-chat-state.d.ts +6 -6
  101. package/hooks/use-theorem-chat-state.js +13 -9
  102. package/hooks/use-theorem-chat.d.ts +48 -14
  103. package/hooks/use-theorem-chat.js +329 -141
  104. package/hooks/use-theorem-decision.d.ts +5 -10
  105. package/hooks/use-theorem-decision.js +4 -67
  106. package/hooks/use-theorem-embedding.d.ts +18 -0
  107. package/hooks/use-theorem-embedding.js +12 -0
  108. package/hooks/use-theorem-host.d.ts +5 -4
  109. package/hooks/use-theorem-host.js +26 -8
  110. package/hooks/use-theorem-interface.d.ts +6 -3
  111. package/hooks/use-theorem-interface.js +12 -22
  112. package/index.d.ts +6 -3
  113. package/index.js +5 -2
  114. package/live.d.ts +1 -0
  115. package/live.js +1 -1
  116. package/package.json +6 -5
  117. package/server/checkpoint-ownership.d.ts +6 -0
  118. package/server/checkpoint-ownership.js +42 -0
  119. package/server/conversation-store.d.ts +92 -0
  120. package/server/conversation-store.js +131 -0
  121. package/server/conversation.d.ts +193 -0
  122. package/server/conversation.js +552 -0
  123. package/server/decision-handler.d.ts +12 -4
  124. package/server/decision-handler.js +29 -38
  125. package/server/embedding-handler.d.ts +33 -0
  126. package/server/embedding-handler.js +45 -0
  127. package/server/handler.d.ts +58 -20
  128. package/server/handler.js +441 -238
  129. package/server/mod.d.ts +15 -6
  130. package/server/mod.js +13 -5
  131. package/server/page-dispatch.d.ts +22 -0
  132. package/server/page-dispatch.js +127 -0
  133. package/server/request-body.d.ts +2 -0
  134. package/server/request-body.js +42 -0
  135. package/server/request-check.d.ts +6 -1
  136. package/server/request-check.js +27 -12
  137. package/server/session-authority.d.ts +8 -0
  138. package/server/session-authority.js +78 -0
  139. package/server/session-boundary.d.ts +26 -0
  140. package/server/session-boundary.js +64 -0
  141. package/server/session-identity.d.ts +16 -0
  142. package/server/session-identity.js +41 -0
  143. package/server/session-limits.d.ts +12 -0
  144. package/server/session-limits.js +59 -0
  145. package/server/session-store.d.ts +69 -20
  146. package/server/session-store.js +220 -5
  147. package/server/single-action.d.ts +21 -0
  148. package/server/single-action.js +30 -0
  149. package/server/steer-inbox.js +1 -1
  150. package/server/tool-operations.d.ts +6 -0
  151. package/server/tool-operations.js +132 -0
  152. package/server/turn-input.d.ts +10 -0
  153. package/server/turn-input.js +29 -0
  154. package/styles/ink-controls.css +78 -78
  155. package/ui/CardWall.d.ts +10 -0
  156. package/ui/CardWall.js +61 -0
  157. package/ui/ChatComposerBar.d.ts +28 -5
  158. package/ui/ChatComposerBar.js +85 -30
  159. package/ui/ChatTranscript.d.ts +14 -1
  160. package/ui/ChatTranscript.js +110 -57
  161. package/ui/ConsoleFrame.d.ts +61 -4
  162. package/ui/ConsoleFrame.js +109 -9
  163. package/ui/DecisionAnswers.d.ts +40 -2
  164. package/ui/DecisionAnswers.js +166 -35
  165. package/ui/DecisionImages.d.ts +16 -0
  166. package/ui/DecisionImages.js +46 -0
  167. package/ui/EmbeddingDocuments.d.ts +78 -0
  168. package/ui/EmbeddingDocuments.js +278 -0
  169. package/ui/EmbeddingQuery.d.ts +27 -0
  170. package/ui/EmbeddingQuery.js +95 -0
  171. package/ui/EmbeddingResults.d.ts +41 -0
  172. package/ui/EmbeddingResults.js +165 -0
  173. package/ui/EmbeddingSpace.d.ts +26 -0
  174. package/ui/EmbeddingSpace.js +106 -0
  175. package/ui/LiveCaptionsPanel.d.ts +22 -0
  176. package/ui/LiveCaptionsPanel.js +27 -0
  177. package/ui/LiveRunner.d.ts +6 -4
  178. package/ui/LiveRunner.js +42 -55
  179. package/ui/PaneState.d.ts +33 -0
  180. package/ui/PaneState.js +50 -0
  181. package/ui/SchemaFields.d.ts +1 -1
  182. package/ui/SchemaFields.js +54 -26
  183. package/ui/ShapedData.js +73 -28
  184. package/ui/SidePanel.d.ts +74 -5
  185. package/ui/SidePanel.js +82 -9
  186. package/ui/StateFields.d.ts +10 -2
  187. package/ui/StateFields.js +56 -13
  188. package/ui/TheoremChat.d.ts +65 -14
  189. package/ui/TheoremChat.js +66 -78
  190. package/ui/TheoremDecision.d.ts +12 -20
  191. package/ui/TheoremDecision.js +78 -35
  192. package/ui/TheoremEmbedding.d.ts +27 -0
  193. package/ui/TheoremEmbedding.js +122 -0
  194. package/ui/TheoremHost.d.ts +22 -5
  195. package/ui/TheoremHost.js +127 -37
  196. package/ui/ToolGateCard.d.ts +5 -1
  197. package/ui/ToolGateCard.js +30 -23
  198. package/ui/ToolResult.js +12 -10
  199. package/ui/ToolResultCharts.js +29 -12
  200. package/ui/TraceCharts.d.ts +2 -2
  201. package/ui/TraceCharts.js +48 -17
  202. package/ui/TraceGuardrails.d.ts +3 -2
  203. package/ui/TraceGuardrails.js +24 -6
  204. package/ui/TraceInspector.d.ts +11 -1
  205. package/ui/TraceInspector.js +45 -28
  206. package/ui/TraceInspectorPanel.d.ts +31 -9
  207. package/ui/TraceInspectorPanel.js +77 -39
  208. package/ui/TraceOverview.d.ts +7 -3
  209. package/ui/TraceOverview.js +44 -14
  210. package/ui/TraceSpanDetail.js +24 -22
  211. package/ui/TraceStory.js +9 -8
  212. package/ui/TraceValues.js +19 -9
  213. package/ui/TraceWaterfall.js +12 -9
  214. package/ui/VoiceNote.js +4 -4
  215. package/ui/approval-heading.d.ts +4 -0
  216. package/ui/approval-heading.js +9 -0
  217. package/ui/arrive.d.ts +18 -0
  218. package/ui/arrive.js +46 -0
  219. package/ui/built/theme.css +86 -68
  220. package/ui/built/theme.css.d.ts +9 -0
  221. package/ui/built/theorem.d.ts +3 -3
  222. package/ui/built/theorem.js +34 -5
  223. package/ui/built/theorem.variants.d.ts +8 -2
  224. package/ui/code-language.d.ts +12 -0
  225. package/ui/code-language.js +50 -0
  226. package/ui/disclosure-motion.js +53 -9
  227. package/ui/embedding-space-gl.d.ts +37 -0
  228. package/ui/embedding-space-gl.js +663 -0
  229. package/ui/embedding-space-view.d.ts +8 -0
  230. package/ui/embedding-space-view.js +8 -0
  231. package/ui/glide.d.ts +7 -0
  232. package/ui/glide.js +44 -0
  233. package/ui/icons.js +2 -1
  234. package/ui/index.d.ts +20 -9
  235. package/ui/index.js +20 -10
  236. package/ui/labels-provider.js +5 -2
  237. package/ui/labels.d.ts +374 -85
  238. package/ui/labels.js +1028 -188
  239. package/ui/markdown-plugins.d.ts +9 -0
  240. package/ui/markdown-plugins.js +13 -0
  241. package/ui/mcp-icon.d.ts +6 -0
  242. package/ui/mcp-icon.js +8 -0
  243. package/ui/row-keys.d.ts +19 -0
  244. package/ui/row-keys.js +33 -0
  245. package/ui/theme.d.ts +1 -1
  246. package/ui/theme.js +2 -2
  247. package/ui/theorem-theme.js +32 -10
  248. package/ui/trace-palette.d.ts +2 -16
  249. package/ui/trace-palette.js +2 -16
  250. package/ui/trace-patterns.d.ts +11 -3
  251. package/ui/trace-patterns.js +16 -3
  252. package/ui/transcript-copy-text.js +1 -0
  253. package/ui/wall-columns.d.ts +8 -0
  254. package/ui/wall-columns.js +19 -0
  255. package/client/walk-away.d.ts +0 -34
  256. package/client/walk-away.js +0 -48
  257. package/server/walk-away.d.ts +0 -22
  258. package/server/walk-away.js +0 -41
@@ -1,3 +1,5 @@
1
+ import { type GateReference, type ToolGate } from '@theoremjs/agents';
2
+ import type { PageDispatchResult } from './page-dispatch.ts';
1
3
  /**
2
4
  * Transport contract between a Theorem chat UI and the host that runs turns.
3
5
  *
@@ -9,7 +11,9 @@
9
11
  * @module
10
12
  */
11
13
  import { type ErrorKind, type TurnEvent, type TurnHistoryMessage, type TurnToolSnapshot, z } from '@theoremjs/agents';
12
- import { type ProfileInterface } from '@theoremjs/agents/interface';
14
+ import { type ErrorCopies } from '@theoremjs/agents/guardrails';
15
+ import { type ProfileInterface, type TranscriptBlock } from '@theoremjs/agents/interface';
16
+ import type { PagePart } from './tool-resume.ts';
13
17
  import type { TraceFeed } from './trace-feed.ts';
14
18
  import { type MalformedEvent, type UnsupportedEvent, type WireLines } from './wire-line.ts';
15
19
  export type { MalformedEvent, UnsupportedEvent, WireLines } from './wire-line.ts';
@@ -23,49 +27,55 @@ export type TheoremTurnInput = {
23
27
  text?: string;
24
28
  attachments?: EncodedBlob[];
25
29
  voice?: EncodedBlob[];
26
- history?: TurnHistoryMessage[];
27
- historyTokens?: number;
28
- inputTokens?: number;
30
+ /** The value chosen for each of the profile's `inputs.slots`. */
31
+ slots?: Record<string, string>;
32
+ /** What the page wants the agent to know: any JSON. The host reads it as untrusted. */
33
+ context?: unknown;
29
34
  };
30
35
  /**
31
36
  * State only the client holds, for hosts whose profile also lives in the browser
32
- * (the playground). `createHttpTransport` never sends it: `createTheoremHandler`
37
+ * (the studio). `createHttpTransport` never sends it: `createTheoremHandler`
33
38
  * keeps permissions, paused calls, and tool snapshots in its own session.
34
39
  */
35
40
  export type TheoremReplay = {
41
+ gateKind?: ToolGate['kind'];
36
42
  sessionPermissions?: string[];
37
43
  name?: string;
38
44
  input?: unknown;
39
- turnInput?: TheoremTurnInput;
40
45
  snapshot?: TurnToolSnapshot;
41
46
  promoted?: string[];
42
47
  model?: string;
43
48
  effort?: string;
44
- path?: string;
45
49
  };
46
- /** For a host that reads the playground's client-held state. */
50
+ /** For a host that reads the studio's client-held state. */
47
51
  export declare const theoremReplaySchema: z.ZodType<TheoremReplay>;
48
52
  /**
49
- * One text turn. The host resolves the profile; the client sends the conversation.
53
+ * One message. The host resolves the profile and owns the conversation: the
54
+ * client sends only the message and the ref of the conversation it continues.
50
55
  *
51
56
  * A message sent while the reply waits on gates walks away from them: `abandon`
52
- * names the waiting calls, and `input.history` ends on their step with those
53
- * calls open. The host settles each one cancelled, streams those events first,
54
- * and gives the model each call's answer before the message.
57
+ * names the waiting calls. The host settles each one cancelled, streams those
58
+ * events first, and gives the model each call's answer before the message.
55
59
  */
56
60
  export type TheoremTurnRequest = {
57
61
  input: TheoremTurnInput;
58
- previousInteractionId?: string;
62
+ /** The ref of the conversation this message continues; none starts one. */
63
+ conversation?: string;
59
64
  model?: string;
60
65
  effort?: string;
61
66
  /** Client-generated id so mid-turn steers can find this turn's inbox. */
62
67
  turnId?: string;
63
- /** Call ids of the paused calls this message walks away from. */
64
- abandon?: string[];
65
- replay?: Pick<TheoremReplay, 'sessionPermissions'> & {
66
- /** Each walked-away call as the client holds it, by call id, for a host without a session. */
67
- abandon?: Record<string, TheoremReplay>;
68
- };
68
+ /** invariant: Both issued IDs identify each paused action that this message abandons. */
69
+ abandon?: GateReference[];
70
+ /** The tools the person allowed for the page, for a host without a session (the studio). */
71
+ replay?: Pick<TheoremReplay, 'sessionPermissions'>;
72
+ /**
73
+ * The page's transcript before this message, sent only after the host answered that it can no
74
+ * longer open `conversation` (`session.conversation_unknown`). A host that restores from it (the
75
+ * studio) goes on from it under a new ref; `createTheoremHandler` keeps the conversation its own
76
+ * and does not.
77
+ */
78
+ transcript?: TranscriptBlock[];
69
79
  };
70
80
  /** A `/turn` body as `createTheoremHandler` reads it. */
71
81
  export declare const theoremTurnRequestSchema: z.ZodType<TheoremTurnRequest>;
@@ -80,6 +90,7 @@ declare const INVOKE_DECISIONS: readonly ["approve", "deny"];
80
90
  export type TheoremInvokeRequest = {
81
91
  /** Call id of the paused tool call (`tool.callId` on its gate event). */
82
92
  gateId: string;
93
+ operationId: string;
83
94
  decision: (typeof INVOKE_DECISIONS)[number];
84
95
  /** The user's edit of the model's input; only with `approve`. */
85
96
  input?: unknown;
@@ -90,6 +101,12 @@ export type TheoremInvokeRequest = {
90
101
  * callback saved the token.
91
102
  */
92
103
  secret?: string;
104
+ /** The page's answer to a `page` gate, only with `approve`: the tool's output schema checks it. */
105
+ page?: PagePart;
106
+ /** The ref of the conversation whose reply waits on the gate. */
107
+ conversation?: string;
108
+ /** Client-generated id so steers sent while the reply goes on find its inbox. */
109
+ turnId?: string;
93
110
  replay?: TheoremReplay;
94
111
  };
95
112
  /** An `/invoke` body as `createTheoremHandler` reads it. */
@@ -103,40 +120,97 @@ export type TheoremSteerRequest = {
103
120
  };
104
121
  /** A `/steer` body as `createTheoremHandler` reads it. */
105
122
  export declare const theoremSteerRequestSchema: z.ZodType<TheoremSteerRequest>;
123
+ /**
124
+ * The ref the store issued for the conversation a run wrote: the client sends
125
+ * it with its next request. It comes before the run's error, which ends the stream.
126
+ * `posted` marks the write that holds the person's new message: a run that
127
+ * fails before it leaves the message unsent.
128
+ */
129
+ export type ConversationLine = {
130
+ type: 'conversation';
131
+ ref: string;
132
+ posted?: true;
133
+ };
134
+ /** The lines a chat's reply streams: turn events, and the conversation's ref. */
135
+ export declare const CHAT_LINES: WireLines<TurnEvent | ConversationLine>;
136
+ /** What the browser draws: the transcript, and the reply that waits on gates. */
137
+ export type ConversationView = {
138
+ transcript: TranscriptBlock[];
139
+ /** The reply that waits on gates: its events, and its blocks as the transcript will keep them. */
140
+ paused?: {
141
+ events: TurnEvent[];
142
+ blocks: TranscriptBlock[];
143
+ };
144
+ };
145
+ /** Read a conversation: a `/conversation` body. */
146
+ export type TheoremConversationRequest = {
147
+ conversation: string;
148
+ };
149
+ /** A `/conversation` body as `createTheoremHandler` reads it. */
150
+ export declare const theoremConversationRequestSchema: z.ZodType<TheoremConversationRequest>;
151
+ /**
152
+ * Cut the conversation after transcript block `at` (-1 empties it): a
153
+ * `/rewind` body. A reply waiting on gates is walked away from first.
154
+ */
155
+ export type TheoremRewindRequest = {
156
+ conversation: string;
157
+ at: number;
158
+ };
159
+ /** A `/rewind` body as `createTheoremHandler` reads it. */
160
+ export declare const theoremRewindRequestSchema: z.ZodType<TheoremRewindRequest>;
161
+ /** A rewound conversation: its new ref, and what the browser draws. */
162
+ export type TheoremRewound = {
163
+ conversation: string;
164
+ view: ConversationView;
165
+ };
106
166
  /** A turn event, one of a kind this client does not know (`unsupported`), or one that failed its check (`malformed`). */
107
167
  export type ClientTurnEvent = TurnEvent | UnsupportedEvent | MalformedEvent;
108
168
  export type TurnEventSink = (event: ClientTurnEvent) => void;
169
+ /** A line of a chat's reply: a turn event, or the ref of the conversation it wrote. */
170
+ export type ChatLine = ClientTurnEvent | ConversationLine;
171
+ export type ChatLineSink = (line: ChatLine) => void;
109
172
  export interface TheoremTransport {
110
173
  /** Client-safe interface for the host's profile (inputs, models, guardrail view). */
111
174
  describe(signal?: AbortSignal): Promise<ProfileInterface>;
112
- turn(request: TheoremTurnRequest, onEvent: TurnEventSink, signal?: AbortSignal): Promise<void>;
113
- invoke(request: TheoremInvokeRequest, onEvent: TurnEventSink, signal?: AbortSignal): Promise<void>;
175
+ turn(request: TheoremTurnRequest, onLine: ChatLineSink, signal?: AbortSignal): Promise<void>;
176
+ invoke(request: TheoremInvokeRequest, onLine: ChatLineSink, signal?: AbortSignal): Promise<void>;
114
177
  steer(request: TheoremSteerRequest): Promise<void>;
115
- /** Trace records the host sends back, when it delivers them (the playground does). */
178
+ /** The conversation under `ref`, as the host shows it. */
179
+ conversation(request: TheoremConversationRequest, signal?: AbortSignal): Promise<ConversationView>;
180
+ /** The conversation cut after a transcript block, under the ref the host issued for it. */
181
+ rewind(request: TheoremRewindRequest, signal?: AbortSignal): Promise<TheoremRewound>;
182
+ pageResult?(result: PageDispatchResult, signal?: AbortSignal): Promise<void>;
183
+ /** Trace records the host sends back, when it delivers them (the studio does). */
116
184
  traces?: TraceFeed;
117
185
  }
118
186
  /**
119
187
  * A failure the host reported: its kind, the host's wording when it sent one
120
- * (the profile's lexicon, applied on the host), and raw detail when the host
188
+ * (the profile's labels, applied on the host), and raw detail when the host
121
189
  * exposes it. `clientFailure` words it for the user.
122
190
  */
123
191
  export declare class TheoremStreamError extends Error {
124
192
  readonly kind: ErrorKind;
125
193
  readonly publicMessage?: string;
126
194
  readonly internalMessage?: string;
127
- constructor(kind: ErrorKind, publicMessage?: string, internalMessage?: string);
195
+ /** The labels key behind `publicMessage`, when the host gave one: what failed, more exactly than `kind`. */
196
+ readonly copy?: ErrorCopies;
197
+ constructor(kind: ErrorKind, publicMessage?: string, internalMessage?: string, copy?: ErrorCopies);
128
198
  }
129
199
  export declare function isTheoremStreamError(err: unknown): err is TheoremStreamError;
130
200
  /** A host error reply's body (JSON reply or `{ type: 'error' }` stream line). */
131
201
  export type HostErrorBody = {
132
202
  error?: string;
133
203
  errorKind?: ErrorKind;
204
+ /** The labels key behind `error`, when more specific than the kind's. */
205
+ errorCopy?: ErrorCopies;
134
206
  errorInternal?: string;
135
207
  };
136
208
  /** A host's error body, as the transport and the live client read it. */
137
209
  export declare const hostErrorBodySchema: z.ZodType<HostErrorBody>;
138
210
  /** A host's error body as a failure: its kind (else `fallbackKind`), wording, and detail. */
139
211
  export declare function hostError(body: HostErrorBody, fallbackKind: ErrorKind): TheoremStreamError;
212
+ /** The host could not open the message's conversation (`session.conversation_unknown`). */
213
+ export declare function isUnknownConversation(err: unknown): boolean;
140
214
  /**
141
215
  * Read an NDJSON reply, checking each line against `lines`: a kind it doesn't
142
216
  * list reaches `onLine` as `unsupported`, and a line that fails its check as
@@ -162,12 +236,26 @@ export declare function postNdjson<Line extends {
162
236
  signal?: AbortSignal;
163
237
  }): Promise<void>;
164
238
  /** POST JSON; a non-OK reply throws its failure. The OK reply's body is not read. */
165
- export declare function postJson(url: string, body: unknown, options?: HttpOptions): Promise<void>;
166
- /** GET, or POST `body` as JSON, and read the JSON reply; a non-OK reply throws its failure. */
239
+ export declare function postJson(url: string, body: unknown, options?: HttpOptions & {
240
+ signal?: AbortSignal;
241
+ }): Promise<void>;
242
+ /**
243
+ * GET, or POST `body` as JSON, and read the JSON reply; a non-OK reply throws its failure, after
244
+ * `failed` has read whatever else its JSON body carries.
245
+ */
167
246
  export declare function fetchJson(url: string, init: {
168
247
  body?: unknown;
169
248
  signal?: AbortSignal;
249
+ failed?: (body: unknown) => void;
170
250
  }, options?: HttpOptions): Promise<unknown>;
251
+ /** POST a conversation's read to `url`, and check the view the host answers. */
252
+ export declare function fetchConversation(url: string, body: unknown, options?: HttpOptions & {
253
+ signal?: AbortSignal;
254
+ }): Promise<ConversationView>;
255
+ /** POST a rewind to `url`, and check the rewound conversation the host answers. */
256
+ export declare function fetchRewound(url: string, body: unknown, options?: HttpOptions & {
257
+ signal?: AbortSignal;
258
+ }): Promise<TheoremRewound>;
171
259
  export type HttpTransportOptions = HttpOptions & {
172
260
  /** Base URL where `createTheoremHandler` is mounted. Default `/api/theorem`. */
173
261
  endpoint?: string;
@@ -1,3 +1,4 @@
1
+ import { gateReferenceSchema, TOOL_GATE_KINDS, } from '@theoremjs/agents';
1
2
  /**
2
3
  * Transport contract between a Theorem chat UI and the host that runs turns.
3
4
  *
@@ -8,59 +9,67 @@
8
9
  *
9
10
  * @module
10
11
  */
11
- import { describeError, errorKindSchema, isAbortError, TheoremError, TURN_EVENT_SCHEMAS, throwIfAborted, turnHistoryMessageSchema, turnToolSnapshotSchema, z, } from '@theoremjs/agents';
12
- import { kindOfHttpStatus } from '@theoremjs/agents/guardrails';
13
- import { profileInterfaceSchema } from '@theoremjs/agents/interface';
12
+ import { describeError, errorKindSchema, isAbortError, TheoremError, TURN_EVENT_SCHEMAS, throwIfAborted, turnEventSchema, turnHistoryMessageSchema, turnToolSnapshotSchema, z, } from '@theoremjs/agents';
13
+ import { errorCopiesSchema, kindOfHttpStatus, } from '@theoremjs/agents/guardrails';
14
+ import { profileInterfaceSchema, } from '@theoremjs/agents/interface';
15
+ import { transcriptBlockSchema } from "./transcript-schema.js";
14
16
  import { checkWire, parseWireJson, readWireLine, } from "./wire-line.js";
15
17
  const encodedBlob = z.object({ name: z.string(), mimeType: z.string(), data: z.string() });
16
18
  true;
17
19
  const theoremTurnInput = z.object({
20
+ slots: z.record(z.string(), z.string()).optional(),
21
+ context: z.unknown().optional(),
18
22
  text: z.string().optional(),
19
23
  attachments: z.array(encodedBlob).optional(),
20
24
  voice: z.array(encodedBlob).optional(),
21
- history: z.array(turnHistoryMessageSchema).optional(),
22
- historyTokens: z.number().optional(),
23
- inputTokens: z.number().optional(),
24
25
  });
25
26
  true;
26
27
  const theoremReplay = z.object({
28
+ gateKind: z.enum(TOOL_GATE_KINDS).optional(),
27
29
  sessionPermissions: z.array(z.string()).optional(),
28
30
  name: z.string().optional(),
29
31
  input: z.unknown().optional(),
30
- turnInput: theoremTurnInput.optional(),
31
32
  snapshot: turnToolSnapshotSchema.optional(),
32
33
  promoted: z.array(z.string()).optional(),
33
34
  model: z.string().optional(),
34
35
  effort: z.string().optional(),
35
- path: z.string().optional(),
36
36
  });
37
37
  true;
38
- /** For a host that reads the playground's client-held state. */
38
+ /** For a host that reads the studio's client-held state. */
39
39
  export const theoremReplaySchema = theoremReplay;
40
40
  /** An id the client made: trimmed, never blank. */
41
41
  const clientId = z.string().trim().min(1);
42
42
  const theoremTurnRequest = z.object({
43
43
  input: theoremTurnInput,
44
- previousInteractionId: z.string().optional(),
44
+ conversation: z.string().min(1).optional(),
45
45
  model: z.string().optional(),
46
46
  effort: z.string().optional(),
47
47
  turnId: clientId.optional(),
48
- abandon: z.array(z.string().min(1)).min(1).optional(),
49
- replay: theoremReplay
50
- .pick({ sessionPermissions: true })
51
- .extend({ abandon: z.record(z.string(), theoremReplay).optional() })
52
- .optional(),
48
+ abandon: z.array(gateReferenceSchema).min(1).optional(),
49
+ replay: theoremReplay.pick({ sessionPermissions: true }).optional(),
50
+ transcript: z.array(transcriptBlockSchema).optional(),
53
51
  });
54
52
  true;
55
53
  /** A `/turn` body as `createTheoremHandler` reads it. */
56
54
  export const theoremTurnRequestSchema = theoremTurnRequest;
57
55
  /** What the user answers a gate with; walking away rides on the next message (`TheoremTurnRequest.abandon`). */
58
56
  const INVOKE_DECISIONS = ['approve', 'deny'];
57
+ const pagePart = z.union([
58
+ z.strictObject({ unanswered: z.literal(true) }),
59
+ z
60
+ .strictObject({ output: z.unknown() })
61
+ .refine((part) => 'output' in part)
62
+ .transform((part) => ({ output: part.output })),
63
+ ]);
59
64
  const theoremInvokeRequest = z.object({
60
65
  gateId: z.string().min(1),
66
+ operationId: z.string().min(1).max(256),
61
67
  decision: z.enum(INVOKE_DECISIONS),
62
68
  input: z.unknown().optional(),
63
69
  secret: z.string().optional(),
70
+ page: pagePart.optional(),
71
+ conversation: z.string().min(1).optional(),
72
+ turnId: clientId.optional(),
64
73
  replay: theoremReplay.optional(),
65
74
  });
66
75
  true;
@@ -74,16 +83,49 @@ const theoremSteerRequest = z.object({
74
83
  true;
75
84
  /** A `/steer` body as `createTheoremHandler` reads it. */
76
85
  export const theoremSteerRequestSchema = theoremSteerRequest;
86
+ const conversationLine = z.object({
87
+ type: z.literal('conversation'),
88
+ ref: z.string().min(1),
89
+ posted: z.literal(true).optional(),
90
+ });
91
+ true;
92
+ /** The lines a chat's reply streams: turn events, and the conversation's ref. */
93
+ export const CHAT_LINES = {
94
+ ...TURN_EVENT_SCHEMAS,
95
+ conversation: conversationLine,
96
+ };
97
+ const conversationView = z.object({
98
+ transcript: z.array(transcriptBlockSchema),
99
+ paused: z
100
+ .object({ events: z.array(turnEventSchema), blocks: z.array(transcriptBlockSchema) })
101
+ .optional(),
102
+ });
103
+ true;
104
+ const theoremConversationRequest = z.object({ conversation: z.string().min(1) });
105
+ true;
106
+ /** A `/conversation` body as `createTheoremHandler` reads it. */
107
+ export const theoremConversationRequestSchema = theoremConversationRequest;
108
+ const theoremRewindRequest = z.object({
109
+ conversation: z.string().min(1),
110
+ at: z.number().int().min(-1),
111
+ });
112
+ true;
113
+ /** A `/rewind` body as `createTheoremHandler` reads it. */
114
+ export const theoremRewindRequestSchema = theoremRewindRequest;
115
+ const theoremRewound = z.object({ conversation: z.string().min(1), view: conversationView });
116
+ true;
77
117
  /**
78
118
  * A failure the host reported: its kind, the host's wording when it sent one
79
- * (the profile's lexicon, applied on the host), and raw detail when the host
119
+ * (the profile's labels, applied on the host), and raw detail when the host
80
120
  * exposes it. `clientFailure` words it for the user.
81
121
  */
82
122
  export class TheoremStreamError extends Error {
83
123
  kind;
84
124
  publicMessage;
85
125
  internalMessage;
86
- constructor(kind, publicMessage, internalMessage) {
126
+ /** The labels key behind `publicMessage`, when the host gave one: what failed, more exactly than `kind`. */
127
+ copy;
128
+ constructor(kind, publicMessage, internalMessage, copy) {
87
129
  super(internalMessage ?? publicMessage ?? kind);
88
130
  this.name = 'TheoremStreamError';
89
131
  this.kind = kind;
@@ -91,6 +133,8 @@ export class TheoremStreamError extends Error {
91
133
  this.publicMessage = publicMessage;
92
134
  if (internalMessage)
93
135
  this.internalMessage = internalMessage;
136
+ if (copy)
137
+ this.copy = copy;
94
138
  }
95
139
  }
96
140
  export function isTheoremStreamError(err) {
@@ -103,6 +147,7 @@ function textOf(value) {
103
147
  const hostErrorBody = z.object({
104
148
  error: z.string().optional(),
105
149
  errorKind: errorKindSchema.optional(),
150
+ errorCopy: errorCopiesSchema.optional(),
106
151
  errorInternal: z.string().optional(),
107
152
  });
108
153
  true;
@@ -112,12 +157,19 @@ export const hostErrorBodySchema = hostErrorBody;
112
157
  export function hostError(body, fallbackKind) {
113
158
  const publicMessage = textOf(body.error);
114
159
  const internal = textOf(body.errorInternal);
115
- return new TheoremStreamError(body.errorKind ?? fallbackKind, publicMessage, internal && internal !== publicMessage ? internal : undefined);
160
+ return new TheoremStreamError(body.errorKind ?? fallbackKind, publicMessage, internal && internal !== publicMessage ? internal : undefined, body.errorCopy);
161
+ }
162
+ /** The host could not open the message's conversation (`session.conversation_unknown`). */
163
+ export function isUnknownConversation(err) {
164
+ if (!isTheoremStreamError(err) || err.copy === undefined)
165
+ return false;
166
+ const copies = Array.isArray(err.copy) ? err.copy : [err.copy];
167
+ return copies.some((copy) => copy.key === 'session.conversation_unknown');
116
168
  }
117
169
  /** One NDJSON line checked against `lines`; an `error` line ends the stream as a {@link TheoremStreamError}. */
118
170
  function parseStreamLine(lines, text) {
119
171
  const line = readWireLine(lines, text);
120
- // An `error` line passed the error event's schema, whose fields include the body's.
172
+ // why: An `error` line passed the error event's schema, whose fields include the body's.
121
173
  if (line.type === 'error')
122
174
  throw hostError(hostErrorBody.parse(line), 'internal');
123
175
  return line;
@@ -139,7 +191,7 @@ function flushNdjsonChunk(buffer, lines, onLine) {
139
191
  */
140
192
  export async function readNdjsonStream(response, lines, onLine, signal) {
141
193
  if (!response.body)
142
- throw new TheoremError('bad_response', 'stream reply has no body'); // lexicon-exempt: internal diagnostic
194
+ throw new TheoremError('bad_response', 'stream reply has no body'); // labels-exempt: internal diagnostic
143
195
  const reader = response.body.getReader();
144
196
  const decoder = new TextDecoder();
145
197
  let buffer = '';
@@ -174,18 +226,19 @@ async function resolveHeaders(options) {
174
226
  * kind. A body that is not JSON (a proxy's page) leaves the status to speak; a
175
227
  * JSON body that fails the error body's schema is `bad_response`.
176
228
  */
177
- async function failureFromResponse(response) {
229
+ async function failureFromResponse(response, failed) {
178
230
  const text = await response.text();
179
231
  let raw;
180
232
  try {
181
233
  raw = JSON.parse(text);
234
+ failed?.(raw);
182
235
  }
183
236
  catch {
184
237
  return hostError({ errorInternal: `HTTP ${String(response.status)}` }, kindOfHttpStatus(response.status));
185
238
  }
186
239
  const body = hostErrorBody.safeParse(raw);
187
240
  if (!body.success) {
188
- // lexicon-exempt: internal diagnostic; the user reads error.bad_response
241
+ // labels-exempt: internal diagnostic; the user reads error.bad_response
189
242
  return new TheoremError('bad_response', `HTTP ${String(response.status)} error body failed its wire check`);
190
243
  }
191
244
  return hostError({ ...body.data, errorInternal: body.data.errorInternal ?? `HTTP ${String(response.status)}` }, kindOfHttpStatus(response.status));
@@ -210,25 +263,43 @@ async function request(url, init, options) {
210
263
  * events ({@link TURN_EVENT_SCHEMAS}), or a host's own schema beside them.
211
264
  */
212
265
  export async function postNdjson(url, body, lines, onLine, options = {}) {
266
+ const response = await jsonPostResponse(url, body, options);
267
+ await readNdjsonStream(response, lines, onLine, options.signal);
268
+ }
269
+ async function jsonPostResponse(url, body, options) {
213
270
  const response = await request(url, { method: 'POST', body: JSON.stringify(body), signal: options.signal }, options);
214
271
  if (!response.ok)
215
272
  throw await failureFromResponse(response);
216
- await readNdjsonStream(response, lines, onLine, options.signal);
273
+ return response;
217
274
  }
218
275
  /** POST JSON; a non-OK reply throws its failure. The OK reply's body is not read. */
219
276
  export async function postJson(url, body, options = {}) {
220
- const response = await request(url, { method: 'POST', body: JSON.stringify(body) }, options);
221
- if (!response.ok)
222
- throw await failureFromResponse(response);
277
+ await jsonPostResponse(url, body, options);
223
278
  }
224
- /** GET, or POST `body` as JSON, and read the JSON reply; a non-OK reply throws its failure. */
279
+ /**
280
+ * GET, or POST `body` as JSON, and read the JSON reply; a non-OK reply throws its failure, after
281
+ * `failed` has read whatever else its JSON body carries.
282
+ */
225
283
  export async function fetchJson(url, init, options = {}) {
226
- const method = init.body === undefined ? { method: 'GET' } : { method: 'POST', body: JSON.stringify(init.body) };
284
+ const method = init.body === undefined
285
+ ? { method: 'GET' }
286
+ : { method: 'POST', body: JSON.stringify(init.body) };
227
287
  const response = await request(url, { ...method, signal: init.signal }, options);
228
288
  if (!response.ok)
229
- throw await failureFromResponse(response);
289
+ throw await failureFromResponse(response, init.failed);
230
290
  return parseWireJson(await response.text());
231
291
  }
292
+ /** POST a conversation's read to `url`, and check the view the host answers. */
293
+ export async function fetchConversation(url, body, options = {}) {
294
+ const { signal, ...http } = options;
295
+ // labels-exempt: internal diagnostic; the user reads error.bad_response
296
+ return checkWire(conversationView, await fetchJson(url, { body, signal }, http), 'the conversation');
297
+ }
298
+ /** POST a rewind to `url`, and check the rewound conversation the host answers. */
299
+ export async function fetchRewound(url, body, options = {}) {
300
+ const { signal, ...http } = options;
301
+ return checkWire(theoremRewound, await fetchJson(url, { body, signal }, http), 'the rewound conversation');
302
+ }
232
303
  /** Drops trailing '/'s by scanning back, not with a regex (a `/\/+$/` scan is quadratic on long runs of '/'). */
233
304
  function withoutTrailingSlashes(url) {
234
305
  let end = url.length;
@@ -246,11 +317,14 @@ export function createHttpTransport(options = {}) {
246
317
  const response = await request(base, { method: 'GET', signal }, options);
247
318
  if (!response.ok)
248
319
  throw await failureFromResponse(response);
249
- // lexicon-exempt: internal diagnostic; the user reads error.bad_response
320
+ // labels-exempt: internal diagnostic; the user reads error.bad_response
250
321
  return checkWire(describedSchema, parseWireJson(await response.text()), 'the profile description').interface;
251
322
  },
252
- turn: ({ replay: _replay, ...body }, onEvent, signal) => postNdjson(`${base}/turn`, body, TURN_EVENT_SCHEMAS, onEvent, { ...options, signal }),
253
- invoke: ({ replay: _replay, ...body }, onEvent, signal) => postNdjson(`${base}/invoke`, body, TURN_EVENT_SCHEMAS, onEvent, { ...options, signal }),
323
+ turn: ({ replay: _replay, ...body }, onEvent, signal) => postNdjson(`${base}/turn`, body, CHAT_LINES, onEvent, { ...options, signal }),
324
+ invoke: ({ replay: _replay, ...body }, onEvent, signal) => postNdjson(`${base}/invoke`, body, CHAT_LINES, onEvent, { ...options, signal }),
325
+ conversation: (body, signal) => fetchConversation(`${base}/conversation`, body, { ...options, signal }),
326
+ rewind: (body, signal) => fetchRewound(`${base}/rewind`, body, { ...options, signal }),
327
+ pageResult: (body, signal) => postJson(`${base}/page-result`, body, { ...options, signal }),
254
328
  steer: (body) => postJson(`${base}/steer`, body, options),
255
329
  };
256
330
  }
@@ -1,28 +1,37 @@
1
- import type { TurnEvent } from '@theoremjs/agents';
1
+ import { type TurnEvent } from '@theoremjs/agents';
2
2
  import { type AttachmentValidationIssue, type ComposerProfileInterface, type GatedToolContext, type InterfaceTurnSession, type TranscriptBlock, type UserTurnDraft } from '@theoremjs/agents/interface';
3
- import type { TheoremInvokeRequest, TheoremTurnInput, TheoremTurnRequest } from './transport.ts';
4
- export declare function turnInputFromSession(session: InterfaceTurnSession, overrides?: TheoremTurnInput): TheoremTurnInput;
5
- /** A gated call as the client holds it, for a host without a session (the playground). */
3
+ import type { PagePart } from './tool-resume.ts';
4
+ import type { TheoremInvokeRequest, TheoremReplay, TheoremTurnInput, TheoremTurnRequest } from './transport.ts';
5
+ export declare function issuedOperationId(call: {
6
+ operationId?: string;
7
+ }): string;
8
+ /** A gated call as the client holds it, for a host without a session (the studio). */
6
9
  export type HeldCall = {
7
10
  name: string;
8
11
  /** The model's input to the call. */
9
12
  input: unknown;
13
+ gateKind?: TheoremReplay['gateKind'];
10
14
  sessionPermissions?: string[];
11
15
  };
12
- /** A paused session, and the calls it waits on that a message walks away from. */
16
+ /** The calls a paused reply waits on that a message walks away from. */
13
17
  export type WalkAway = {
14
- paused: InterfaceTurnSession;
15
18
  calls: readonly GatedToolContext[];
16
19
  };
17
- export declare function buildTurnRequest(iface: ComposerProfileInterface, session: InterfaceTurnSession, input: TheoremTurnInput, options?: {
20
+ /** Where a request goes on from: the ref of the conversation the host keeps, and the run's id for steers. */
21
+ export type RunScope = {
22
+ conversation?: string;
18
23
  turnId?: string;
24
+ };
25
+ export declare function buildTurnRequest(iface: ComposerProfileInterface, session: InterfaceTurnSession, input: TheoremTurnInput, options?: RunScope & {
19
26
  walkAway?: WalkAway;
20
27
  }): TheoremTurnRequest;
21
28
  export declare function buildInvokeRequest(iface: ComposerProfileInterface, session: InterfaceTurnSession, args: HeldCall & {
22
29
  gateId: string;
30
+ operationId: string;
23
31
  decision: TheoremInvokeRequest['decision'];
24
32
  secret?: string;
25
- }): TheoremInvokeRequest;
33
+ page?: PagePart;
34
+ }, scope?: RunScope): TheoremInvokeRequest;
26
35
  export declare function projectUserTurn(iface: ComposerProfileInterface, draft: UserTurnDraft): {
27
36
  ok: true;
28
37
  blocks: TranscriptBlock[];
@@ -1,13 +1,11 @@
1
+ import { labelText, TheoremError } from '@theoremjs/agents';
1
2
  import { foldTurnEvents, prepareUserTurn, streamThoughtsEnabled, } from '@theoremjs/agents/interface';
2
3
  import { filesToPending } from "./encode-files.js";
3
4
  import { defaultModel } from "./generation-selection.js";
4
- export function turnInputFromSession(session, overrides = {}) {
5
- return {
6
- ...overrides,
7
- history: session.history,
8
- ...(session.inputTokens !== undefined ? { inputTokens: session.inputTokens } : {}),
9
- ...(session.historyTokens !== undefined ? { historyTokens: session.historyTokens } : {}),
10
- };
5
+ export function issuedOperationId(call) {
6
+ if (!call.operationId)
7
+ throw new TheoremError('request', labelText('session.gate_expired'));
8
+ return call.operationId;
11
9
  }
12
10
  function resolveModelId(iface, session) {
13
11
  return session.selectedModel ?? defaultModel(iface);
@@ -31,48 +29,45 @@ function gateReplay(iface, session, call) {
31
29
  return {
32
30
  name: call.name,
33
31
  input: call.input,
32
+ ...(call.gateKind ? { gateKind: call.gateKind } : {}),
34
33
  sessionPermissions: call.sessionPermissions ?? session.sessionPermissions,
35
- turnInput: turnInputFromSession(session),
36
34
  ...(session.toolSnapshot ? { snapshot: session.toolSnapshot } : {}),
37
35
  ...(session.promotedToolIds.length ? { promoted: [...session.promotedToolIds] } : {}),
38
36
  ...generationFields(iface, session),
39
37
  };
40
38
  }
41
- /**
42
- * The paused calls a message walks away from: their ids, and each call as a
43
- * host without a session replays it, from the session as it paused.
44
- */
45
- function abandonFields(iface, walkAway) {
46
- if (!walkAway.calls.length)
47
- return undefined;
39
+ function scopeFields(scope) {
48
40
  return {
49
- abandon: walkAway.calls.map((call) => call.callId),
50
- replays: Object.fromEntries(walkAway.calls.map((call) => [
51
- call.callId,
52
- gateReplay(iface, walkAway.paused, { name: call.name, input: call.arguments }),
53
- ])),
41
+ ...(scope.conversation ? { conversation: scope.conversation } : {}),
42
+ ...(scope.turnId ? { turnId: scope.turnId } : {}),
54
43
  };
55
44
  }
56
45
  export function buildTurnRequest(iface, session, input, options = {}) {
57
- const walked = options.walkAway ? abandonFields(iface, options.walkAway) : undefined;
46
+ const abandon = (options.walkAway?.calls ?? []).map((call) => ({
47
+ callId: call.callId,
48
+ operationId: issuedOperationId(call),
49
+ }));
58
50
  return {
59
- previousInteractionId: session.previousInteractionId,
60
- ...(options.turnId ? { turnId: options.turnId } : {}),
51
+ ...scopeFields(options),
61
52
  ...generationFields(iface, session),
62
53
  input,
63
- ...(walked ? { abandon: walked.abandon } : {}),
64
- replay: {
65
- sessionPermissions: session.sessionPermissions,
66
- ...(walked ? { abandon: walked.replays } : {}),
67
- },
54
+ ...(abandon.length ? { abandon } : {}),
55
+ replay: { sessionPermissions: session.sessionPermissions },
68
56
  };
69
57
  }
70
- export function buildInvokeRequest(iface, session, args) {
58
+ export function buildInvokeRequest(iface, session, args, scope = {}) {
71
59
  return {
60
+ ...scopeFields(scope),
72
61
  gateId: args.gateId,
62
+ operationId: args.operationId,
73
63
  decision: args.decision,
74
64
  ...(args.secret === undefined ? {} : { secret: args.secret }),
75
- replay: gateReplay(iface, session, args),
65
+ ...(args.page === undefined ? {} : { page: args.page }),
66
+ replay: gateReplay(iface, session, {
67
+ ...args,
68
+ gateKind: args.gateKind ??
69
+ (session.gatedTool?.callId === args.gateId ? session.gatedTool.gateKind : undefined),
70
+ }),
76
71
  };
77
72
  }
78
73
  export function projectUserTurn(iface, draft) {
@@ -86,7 +81,7 @@ export function prepareComposerTurn(iface, text, pendingFiles, pendingVoice = []
86
81
  });
87
82
  }
88
83
  export function foldAssistantTurn(iface, events) {
89
- // Its `turn-done` blocks stay: hidden in the view, they carry the reply's worked time.
84
+ // why: Its `turn-done` blocks stay: hidden in the view, they carry the reply's worked time.
90
85
  return foldTurnEvents(events, {
91
86
  showThoughts: streamThoughtsEnabled(iface.outputs),
92
87
  });