@tangle-network/agent-app 0.60.142 → 0.60.143

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.
@@ -45,6 +45,10 @@ export interface ChatStreamCallbacks {
45
45
  onIntent?: (intent: TurnIntentData) => void;
46
46
  onText?: (delta: string) => void;
47
47
  onReasoning?: (delta: string) => void;
48
+ /** The message's reasoning so far, when it started and when it ended, after every reasoning delta and once
49
+ * when thinking ends. Spread it onto `ReasoningRow`. `consumeChatStream` and `streamChatTurn` keep it;
50
+ * a consumer that calls `dispatchChatStreamLine` itself wraps its callbacks with `trackChatReasoning`. */
51
+ onReasoningState?: (state: ChatReasoningState) => void;
48
52
  onToolCall?: (call: ChatStreamToolCall) => void;
49
53
  onToolResult?: (result: ChatStreamToolResult) => void;
50
54
  onUsage?: (usage: {
@@ -79,6 +83,51 @@ export interface ChatStreamCallbacks {
79
83
  /** A durable-plan snapshot from any plan lifecycle event. */
80
84
  onPlan?: (plan: ChatPlan) => void;
81
85
  }
86
+ /**
87
+ * One message's reasoning as the stream delivers it: the text so far, when the
88
+ * model started reasoning and when it stopped. Its fields are `ReasoningRow`'s
89
+ * props. Live state comes from `onReasoningState`; a saved message's comes from
90
+ * `chatReasoningFromParts`.
91
+ */
92
+ export interface ChatReasoningState {
93
+ text: string;
94
+ /** Epoch ms of the first reasoning delta. Absent only on history saved without times. */
95
+ startedAt?: number;
96
+ /** Epoch ms the reasoning ended: the answer's first text, an error, or the end of the turn. */
97
+ endedAt?: number;
98
+ /** Reasoning deltas are still arriving and nothing has ended them yet. */
99
+ thinking: boolean;
100
+ }
101
+ /** Callbacks that keep the turn's reasoning state, plus the two moments only the transport knows. */
102
+ export type TrackedChatStreamCallbacks = ChatStreamCallbacks & {
103
+ /** The turn's stream is over, or failed for good: thinking that is still open ends now. */
104
+ end: () => void;
105
+ /** The stream will replay the turn from its first event (a resume from 0): the text is rebuilt from the
106
+ * replay, and the start time of the first delta is kept, so "Thought for N seconds" still counts from it. */
107
+ replay: () => void;
108
+ };
109
+ /**
110
+ * Keep one turn's reasoning state from its stream: the first reasoning delta
111
+ * starts the clock, the answer's first text, an error or `end()` stops it, and
112
+ * every change reaches `callbacks.onReasoningState`. Reasoning that resumes
113
+ * after a tool call or an answer continues the same state as a new paragraph,
114
+ * the way a reload joins the turn's saved reasoning parts.
115
+ *
116
+ * It takes callbacks, not a stream, so it is the entry point for any
117
+ * transport: `streamChatTurn` and `consumeChatStream` apply it themselves; an
118
+ * app that dispatches lines one at a time (`dispatchChatStreamLine`) or reads
119
+ * its own frames (a Durable Object's live parts, server-side events) wraps its
120
+ * handlers with it, feeds `onReasoning` / `onText` / `onToolCall`, and calls
121
+ * `end()` when its stream closes.
122
+ */
123
+ export declare function trackChatReasoning(callbacks: ChatStreamCallbacks, now?: () => number): TrackedChatStreamCallbacks;
124
+ /**
125
+ * A saved message's reasoning, settled, from its persisted parts: every
126
+ * `{ type: 'reasoning', text, time }` part joined in order, from the first
127
+ * part's start to the last part's end. A reload shows it collapsed with how
128
+ * long the model thought. Undefined when the message has no reasoning text.
129
+ */
130
+ export declare function chatReasoningFromParts(parts: ReadonlyArray<unknown> | null | undefined): ChatReasoningState | undefined;
82
131
  /** Represent the result of consuming a chat stream including turn ID and content reception status */
83
132
  export interface ConsumeChatStreamResult {
84
133
  turnId: string | null;
@@ -3,7 +3,7 @@
3
3
  * every agent app's web UI hand-rolls: a model picker over the runtime's
4
4
  * model catalogue, a reasoning-effort selector, and a message thread with
5
5
  * User/Agent identity, per-message model + cost + tokens/sec metrics,
6
- * canonical tool rows, and a collapsible thinking section.
6
+ * canonical tool rows, and the shared reasoning row (`ReasoningRow`).
7
7
  *
8
8
  * Works for BOTH chat shapes: router-backed copilots (LoopEvents from
9
9
  * `runtime/openai-stream`) and sandbox-backed chats — the thread renders
@@ -30,6 +30,7 @@ import type { WorkProductPersistedPart } from '../work-product/types';
30
30
  import type { TurnPhaseData } from '../chat-routes/turn-progress';
31
31
  export * from './chat-stream';
32
32
  export { TurnProgress, type TurnProgressProps } from './turn-progress';
33
+ export { ReasoningRow, type ReasoningRowProps } from './reasoning-row';
33
34
  export * from './chat-interactions';
34
35
  export * from './chat-composer';
35
36
  export * from './workspace-prewarm';
@@ -157,7 +158,12 @@ export interface ChatUiMessage extends ChatMessageMetrics {
157
158
  id: string;
158
159
  role: 'user' | 'assistant' | 'system';
159
160
  content: string;
161
+ /** The model's reasoning for this message, shown in a {@link ReasoningRow} above the answer. */
160
162
  reasoning?: string;
163
+ /** When the model started reasoning (epoch ms): `ChatReasoningState.startedAt` from the stream or the saved parts. */
164
+ reasoningStartedAt?: number;
165
+ /** When the reasoning ended (epoch ms). Set, the row reads "Thought for N seconds"; unset while streaming, it is still thinking. */
166
+ reasoningEndedAt?: number;
161
167
  toolCalls?: ChatToolCallInfo[];
162
168
  /** Ordered text/tool sequence for true chronological interleaving. When
163
169
  * present and non-empty it is rendered in place of `content` + `toolCalls`;
@@ -291,10 +297,10 @@ export type ToolDetailRenderers = Record<string, (call: ChatToolCallInfo, messag
291
297
  * so `state.time` stays unset and the row shows no duration.
292
298
  */
293
299
  export declare function chatToolCallPart(call: ChatToolCallInfo): ToolPart;
294
- /** Whole seconds elapsed while `active`, ticking once a second. Powers the live
295
- * "thinking" timers (the pre-first-token row and the reasoning box) so a long
296
- * thinking gap shows progress instead of a frozen label. Counts from when
297
- * `active` first turns true; freezes when it clears. */
300
+ /** Whole seconds elapsed while `active`, ticking once a second; counts from
301
+ * when `active` first turns true and freezes when it clears. Kept for
302
+ * existing consumers: `ReasoningRow` times reasoning from the stream's own
303
+ * start instead. */
298
304
  export declare function useThinkingSeconds(active: boolean): number;
299
305
  /**
300
306
  * The message thread: one centered column; user messages are right-aligned
@@ -37,6 +37,7 @@ import {
37
37
  ProvenanceLegend,
38
38
  ProvenanceValue,
39
39
  QuestionOptionList,
40
+ ReasoningRow,
40
41
  RecordGrid,
41
42
  RunDrillIn,
42
43
  SeatPaywall,
@@ -46,6 +47,7 @@ import {
46
47
  activityTone,
47
48
  buildAnswerData,
48
49
  cancelChatInteraction,
50
+ chatReasoningFromParts,
49
51
  chatToolCallPart,
50
52
  consumeChatStream,
51
53
  createDurableInteractionAnswerSubmitter,
@@ -119,6 +121,7 @@ import {
119
121
  streamChatTurn,
120
122
  sumRecordGridColumn,
121
123
  terminalizePendingChatInteractions,
124
+ trackChatReasoning,
122
125
  triggerAttachmentDownload,
123
126
  upsertChatInteraction,
124
127
  useChatInteractions,
@@ -138,7 +141,7 @@ import {
138
141
  withoutRecordGridCreated,
139
142
  withoutRecordGridRemoved,
140
143
  withoutRecordGridUpdate
141
- } from "../chunk-EGEULRT2.js";
144
+ } from "../chunk-T4JJXUJI.js";
142
145
  import {
143
146
  SessionHistoryPanel,
144
147
  formatSessionTimestamp,
@@ -369,6 +372,7 @@ export {
369
372
  ProviderLogo,
370
373
  QualityCheckList,
371
374
  QuestionOptionList,
375
+ ReasoningRow,
372
376
  RecordGrid,
373
377
  ReviewQueuePanel,
374
378
  RouteChunkBoundary,
@@ -402,6 +406,7 @@ export {
402
406
  canTransitionInteractionStatus,
403
407
  cancelChatInteraction,
404
408
  cancelStatusFor,
409
+ chatReasoningFromParts,
405
410
  chatToolCallPart,
406
411
  chatTurnRequestInit,
407
412
  composerAnswerData,
@@ -521,6 +526,7 @@ export {
521
526
  sumRecordGridColumn,
522
527
  tabTerminalConnectionId,
523
528
  terminalizePendingChatInteractions,
529
+ trackChatReasoning,
524
530
  triggerAttachmentDownload,
525
531
  upsertChatInteraction,
526
532
  useChatInteractions,
@@ -0,0 +1,34 @@
1
+ /**
2
+ * The reasoning row every agent app shows above an answer. While the model
3
+ * reasons, its reasoning streams in live under "Thinking · 12s"; when the
4
+ * answer starts the row collapses to "Thought for 12 seconds", and a click
5
+ * opens it again. It renders nothing when the turn has no reasoning.
6
+ *
7
+ * The props are a `ChatReasoningState` (`./chat-stream`): spread the state the
8
+ * stream keeps (`onReasoningState`), or a saved message's
9
+ * (`chatReasoningFromParts`), onto the row. `ChatMessages` renders it for
10
+ * every assistant message that carries `reasoning`.
11
+ *
12
+ * It is built on the shared run-row shell (`RunRowShell` from
13
+ * `@tangle-network/ui/run`), so it reads as one family with the tool rows, and
14
+ * styles only with the shared design tokens.
15
+ */
16
+ import { type ReactNode } from 'react';
17
+ /** Props for {@link ReasoningRow}: the fields of a `ChatReasoningState`, plus presentation. */
18
+ export interface ReasoningRowProps {
19
+ /** The reasoning so far. While it is blank the row renders nothing. */
20
+ text: string;
21
+ /** When the model started reasoning (epoch ms). The live timer counts from here; without it, from when the row first saw the model thinking. */
22
+ startedAt?: number;
23
+ /** When the reasoning ended (epoch ms). With `startedAt`, the settled row reads "Thought for N seconds". */
24
+ endedAt?: number;
25
+ /** The model is still reasoning. Defaults to true while `startedAt` is set and `endedAt` is not. */
26
+ thinking?: boolean;
27
+ /** Open a settled row. Default false: once thinking ends the row is collapsed until the reader opens it. */
28
+ defaultOpen?: boolean;
29
+ /** Render the reasoning text. Default: the shared markdown renderer. */
30
+ renderText?: (text: string) => ReactNode;
31
+ className?: string;
32
+ }
33
+ /** The model's reasoning for one message: live while it thinks, collapsed once it answers. */
34
+ export declare function ReasoningRow({ text, startedAt, endedAt, thinking: thinkingProp, defaultOpen, renderText, className, }: ReasoningRowProps): import("react").JSX.Element | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-app",
3
- "version": "0.60.142",
3
+ "version": "0.60.143",
4
4
  "packageManager": "pnpm@11.24.0",
5
5
  "description": "Build agent applications with typed chat, tools, sandboxes, integrations, billing, and evaluation.",
6
6
  "keywords": [