@teaflask/assistant 0.6.0 → 0.7.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 (330) hide show
  1. package/README.md +1 -1
  2. package/custom-elements.json +264 -0
  3. package/dist/affordances/aria-dropdowns.js +315 -0
  4. package/dist/affordances/aria-toggles.js +39 -0
  5. package/dist/affordances/dropdown-display.js +129 -0
  6. package/dist/affordances/page-gestures.js +91 -0
  7. package/dist/affordances/prefill-reasons.js +75 -0
  8. package/dist/affordances/prefill.js +113 -62
  9. package/dist/appearance/theme.d.ts +138 -0
  10. package/dist/components/approval-card.js +3 -3
  11. package/dist/components/approval-context.d.ts +20 -0
  12. package/dist/components/assistant-companion.d.ts +15 -0
  13. package/dist/components/assistant-page.d.ts +61 -0
  14. package/dist/components/assistant-palette.d.ts +12 -0
  15. package/dist/components/assistant-palette.js +2 -2
  16. package/dist/components/child-transcript.js +1 -1
  17. package/dist/components/companion-header-disclosure.js +1 -1
  18. package/dist/components/companion-history-menu.js +1 -1
  19. package/dist/components/composer.js +11 -65
  20. package/dist/components/conversation-context.d.ts +6 -0
  21. package/dist/components/conversation-gate-card.js +1 -1
  22. package/dist/components/conversation-view.d.ts +11 -0
  23. package/dist/components/elicitation-context.d.ts +39 -0
  24. package/dist/components/model-picker-chip.js +4 -2
  25. package/dist/components/primitives/button.js +25 -17
  26. package/dist/components/primitives/floating-panel.js +1 -1
  27. package/dist/components/provider-chip.js +8 -1
  28. package/dist/components/question-panel-footer.js +1 -1
  29. package/dist/components/react-tool-view.d.ts +7 -0
  30. package/dist/components/subagent-count-pill.js +2 -2
  31. package/dist/components/subagent-group-row.js +1 -26
  32. package/dist/components/subagent-preview-popover.js +1 -1
  33. package/dist/components/subscription-connect-arms.js +6 -4
  34. package/dist/components/subscription-connect-flow.js +30 -45
  35. package/dist/components/subscription-connected-standing.js +9 -6
  36. package/dist/components/subscription-plan-notice.js +4 -2
  37. package/dist/components/teaflask-assistant-provider.d.ts +99 -0
  38. package/dist/components/teaflask-assistant.d.ts +33 -0
  39. package/dist/components/tool-views/action-view.js +1 -1
  40. package/dist/components/tool-views/parts-classes.d.ts +5 -5
  41. package/dist/components/tool-views/parts-classes.js +5 -5
  42. package/dist/components/tool-views/parts.d.ts +44 -0
  43. package/dist/components/tool-views/questions-view.js +2 -2
  44. package/dist/components/tool-views/view-dom.d.ts +76 -0
  45. package/dist/components/transcript.js +2 -2
  46. package/dist/components/use-assistant-activity.d.ts +5 -0
  47. package/dist/components/use-assistant-conversation.d.ts +99 -2
  48. package/dist/components/use-store-cell.d.ts +5 -0
  49. package/dist/components/use-thread-dispatches.js +8 -366
  50. package/dist/components/use-transcript-folds.js +2 -1
  51. package/dist/components/use-transcript.d.ts +55 -2
  52. package/dist/components/use-transcript.js +7 -2
  53. package/dist/contract/actions-adapter.d.ts +78 -0
  54. package/dist/contract/errors.d.ts +6 -1
  55. package/dist/contract/events.d.ts +1 -3
  56. package/dist/contract/identity.d.ts +1 -1
  57. package/dist/contract/subscriptions.d.ts +2 -2
  58. package/dist/contract/subscriptions.js +1 -1
  59. package/dist/contract/telemetry.d.ts +45 -0
  60. package/dist/contract/threads.d.ts +5 -1
  61. package/dist/core/activity.d.ts +44 -0
  62. package/dist/core/approval-inbox.d.ts +69 -0
  63. package/dist/core/assistant-session-registry.js +15 -0
  64. package/dist/core/composer-attachments.js +82 -0
  65. package/dist/core/composer-input-state.js +1 -0
  66. package/dist/core/composer-policy.d.ts +20 -0
  67. package/dist/core/connection-epoch.d.ts +65 -2
  68. package/dist/core/conversation-adoption.js +3 -0
  69. package/dist/core/conversation-contract.d.ts +112 -1
  70. package/dist/core/conversation-publish.js +1 -0
  71. package/dist/core/conversation-store.d.ts +3 -0
  72. package/dist/core/conversation-store.js +7 -0
  73. package/dist/core/dispatch-poll.js +81 -0
  74. package/dist/core/elicitation-answers.js +12 -0
  75. package/dist/core/elicitation-cards.d.ts +14 -0
  76. package/dist/core/elicitation-pickers.d.ts +16 -0
  77. package/dist/core/execution-handlers.js +3 -3
  78. package/dist/core/memory-provenance-anchors.d.ts +16 -0
  79. package/dist/core/observable-cell.d.ts +12 -0
  80. package/dist/core/pending-decision-gap.d.ts +9 -0
  81. package/dist/core/question-drafts.d.ts +59 -0
  82. package/dist/core/receipt-anchors.d.ts +9 -0
  83. package/dist/core/segment-timing.d.ts +23 -0
  84. package/dist/core/subagent-delivery-anchors.d.ts +7 -0
  85. package/dist/core/subagent-ledger-join.js +176 -0
  86. package/dist/core/subagent-rows.d.ts +68 -0
  87. package/dist/core/thread-dispatch-ledger.js +303 -0
  88. package/dist/core/tool-call-display.d.ts +71 -0
  89. package/dist/core/tool-call-presentation.d.ts +34 -1
  90. package/dist/core/tool-call-presentation.js +0 -1
  91. package/dist/core/tool-schema-anchors.d.ts +6 -0
  92. package/dist/core/tool-view.d.ts +174 -1
  93. package/dist/core/transcript-rows.d.ts +138 -3
  94. package/dist/core/turn-failed-anchors.d.ts +4 -0
  95. package/dist/core/user-turn-ledger.d.ts +3 -0
  96. package/dist/generated/models/apiErrorCode.d.ts +1 -0
  97. package/dist/generated/models/apiErrorCode.js +1 -0
  98. package/dist/generated/models/assistantTurnStatus.d.ts +16 -0
  99. package/dist/generated/models/servingAssistantThreadResponse.d.ts +23 -0
  100. package/dist/generated/models/servingAttachmentResponse.d.ts +29 -0
  101. package/dist/generated/models/servingErrorCode.d.ts +18 -0
  102. package/dist/generated/models/servingTurnAttachmentResponse.d.ts +12 -0
  103. package/dist/generated/models/siteTheme.d.ts +1 -0
  104. package/dist/generated/models/thinkingEffort.d.ts +10 -0
  105. package/dist/generated/models/threadModelPickResponse.d.ts +12 -0
  106. package/dist/headless.d.ts +9 -4
  107. package/dist/index.d.ts +2 -6
  108. package/dist/index.js +0 -3
  109. package/dist/persistence/stored-thread.d.ts +5 -0
  110. package/dist/reader/render.js +7 -4
  111. package/dist/reader/roles.js +28 -1
  112. package/dist/reader/snapshot-node.js +2 -29
  113. package/dist/reader/snapshot-root.js +14 -8
  114. package/dist/reader/snapshot.js +6 -1
  115. package/dist/styles.css +1 -1
  116. package/dist/transport/serving-error.d.ts +21 -0
  117. package/package.json +6 -25
  118. package/dist/affordances/highlight.d.ts +0 -3
  119. package/dist/affordances/prefill.d.ts +0 -14
  120. package/dist/components/activity-rail.d.ts +0 -12
  121. package/dist/components/activity-shelf.d.ts +0 -7
  122. package/dist/components/agent-identity-mark.d.ts +0 -7
  123. package/dist/components/appearance-context.d.ts +0 -14
  124. package/dist/components/approval-card.d.ts +0 -7
  125. package/dist/components/assistant-palette-body.d.ts +0 -3
  126. package/dist/components/assistant-transcript.d.ts +0 -47
  127. package/dist/components/attachment-chips.d.ts +0 -4
  128. package/dist/components/child-transcript.d.ts +0 -22
  129. package/dist/components/companion-drawer-body.d.ts +0 -1
  130. package/dist/components/companion-drawer.d.ts +0 -10
  131. package/dist/components/companion-header-disclosure.d.ts +0 -20
  132. package/dist/components/companion-history-menu.d.ts +0 -15
  133. package/dist/components/companion-mark-image.d.ts +0 -3
  134. package/dist/components/companion-mark-image.js +0 -18
  135. package/dist/components/companion-mark.d.ts +0 -1
  136. package/dist/components/companion-mode-menu.d.ts +0 -15
  137. package/dist/components/composer-attachment-chip.d.ts +0 -7
  138. package/dist/components/composer-banner.d.ts +0 -4
  139. package/dist/components/composer.d.ts +0 -4
  140. package/dist/components/conversation-gate-card.d.ts +0 -8
  141. package/dist/components/conversation-surfaces-provider.d.ts +0 -6
  142. package/dist/components/copy-text-button.d.ts +0 -5
  143. package/dist/components/elicitation-receipt-row.d.ts +0 -4
  144. package/dist/components/human-file-size.d.ts +0 -1
  145. package/dist/components/icons.d.ts +0 -15
  146. package/dist/components/lazy-body.d.ts +0 -4
  147. package/dist/components/markdown/assistant-markdown.d.ts +0 -3
  148. package/dist/components/markdown/code-block.d.ts +0 -4
  149. package/dist/components/markdown/highlight.d.ts +0 -1
  150. package/dist/components/markdown/markdown-structure.d.ts +0 -16
  151. package/dist/components/markdown/memoized-blocks.d.ts +0 -6
  152. package/dist/components/markdown/paced-assistant-markdown.d.ts +0 -4
  153. package/dist/components/markdown/reveal-pacer.d.ts +0 -20
  154. package/dist/components/markdown/shiki-highlighter.d.ts +0 -1
  155. package/dist/components/markdown/streaming-repair.d.ts +0 -1
  156. package/dist/components/markdown/use-highlighted-html.d.ts +0 -1
  157. package/dist/components/markdown/use-paced-reveal.d.ts +0 -5
  158. package/dist/components/memory-updated-footer.d.ts +0 -4
  159. package/dist/components/message-list-row.d.ts +0 -13
  160. package/dist/components/message-list-slots.d.ts +0 -25
  161. package/dist/components/message-list-slots.js +0 -1
  162. package/dist/components/message-list.d.ts +0 -23
  163. package/dist/components/model-picker-chip.d.ts +0 -1
  164. package/dist/components/model-picker-effort.d.ts +0 -4
  165. package/dist/components/model-picker-panels.d.ts +0 -22
  166. package/dist/components/notice-banner.d.ts +0 -8
  167. package/dist/components/operation-icons.d.ts +0 -19
  168. package/dist/components/pretty-print.d.ts +0 -1
  169. package/dist/components/primitives/autofocus.d.ts +0 -1
  170. package/dist/components/primitives/button.d.ts +0 -10
  171. package/dist/components/primitives/cx.d.ts +0 -1
  172. package/dist/components/primitives/dialog.d.ts +0 -7
  173. package/dist/components/primitives/disclosure.d.ts +0 -22
  174. package/dist/components/primitives/file-input.d.ts +0 -5
  175. package/dist/components/primitives/floating-panel.d.ts +0 -15
  176. package/dist/components/primitives/kbd.d.ts +0 -2
  177. package/dist/components/primitives/sheet.d.ts +0 -11
  178. package/dist/components/primitives/sheet.js +0 -18
  179. package/dist/components/primitives/textarea.d.ts +0 -7
  180. package/dist/components/primitives/use-dock-reflow.d.ts +0 -2
  181. package/dist/components/primitives/use-swipe-dismiss.d.ts +0 -17
  182. package/dist/components/provider-chip.d.ts +0 -8
  183. package/dist/components/question-panel-answers.d.ts +0 -29
  184. package/dist/components/question-panel-footer.d.ts +0 -9
  185. package/dist/components/question-panel.d.ts +0 -4
  186. package/dist/components/reasoning-row.d.ts +0 -4
  187. package/dist/components/receipt-rows.d.ts +0 -3
  188. package/dist/components/run-status-announcer.d.ts +0 -5
  189. package/dist/components/scroll-follow-guards.d.ts +0 -1
  190. package/dist/components/served-suggestions.d.ts +0 -3
  191. package/dist/components/slot-boundary.d.ts +0 -11
  192. package/dist/components/standing-poll.d.ts +0 -1
  193. package/dist/components/streaming-states.d.ts +0 -12
  194. package/dist/components/subagent-count-pill.d.ts +0 -8
  195. package/dist/components/subagent-current-work.d.ts +0 -6
  196. package/dist/components/subagent-delegation-surface.d.ts +0 -9
  197. package/dist/components/subagent-delivery-divider.d.ts +0 -5
  198. package/dist/components/subagent-drill-in.d.ts +0 -8
  199. package/dist/components/subagent-execution-work.d.ts +0 -3
  200. package/dist/components/subagent-group-row.d.ts +0 -26
  201. package/dist/components/subagent-preview-popover.d.ts +0 -8
  202. package/dist/components/subscription-connect-arms.d.ts +0 -25
  203. package/dist/components/subscription-connect-flow.d.ts +0 -60
  204. package/dist/components/subscription-connected-standing.d.ts +0 -16
  205. package/dist/components/subscription-plan-notice.d.ts +0 -1
  206. package/dist/components/subscription-recheck.d.ts +0 -10
  207. package/dist/components/surface-boundary.d.ts +0 -8
  208. package/dist/components/suspension-surfaces.d.ts +0 -3
  209. package/dist/components/thread-list.d.ts +0 -16
  210. package/dist/components/tool-arguments-summary.d.ts +0 -2
  211. package/dist/components/tool-call-rows.d.ts +0 -10
  212. package/dist/components/tool-row.d.ts +0 -7
  213. package/dist/components/tool-view-registry-context.d.ts +0 -3
  214. package/dist/components/tool-view-slot.d.ts +0 -11
  215. package/dist/components/tool-views/action-view.d.ts +0 -1
  216. package/dist/components/tool-views/command-view.d.ts +0 -1
  217. package/dist/components/tool-views/docs-search-view.d.ts +0 -10
  218. package/dist/components/tool-views/file-edit-view.d.ts +0 -1
  219. package/dist/components/tool-views/questions-view.d.ts +0 -1
  220. package/dist/components/transcript.d.ts +0 -3
  221. package/dist/components/use-agent-subscriber.d.ts +0 -3
  222. package/dist/components/use-agent-subscriber.js +0 -13
  223. package/dist/components/use-answer-list-fold.d.ts +0 -6
  224. package/dist/components/use-assistant-surface-presence.d.ts +0 -2
  225. package/dist/components/use-child-replay-stream.d.ts +0 -20
  226. package/dist/components/use-latest-ref.d.ts +0 -2
  227. package/dist/components/use-member-toggle-outrank.d.ts +0 -6
  228. package/dist/components/use-perch-clearance.d.ts +0 -2
  229. package/dist/components/use-question-panel-keys.d.ts +0 -32
  230. package/dist/components/use-register-assistant-surface.d.ts +0 -2
  231. package/dist/components/use-resolved-theme-mode.d.ts +0 -3
  232. package/dist/components/use-roster-disclosure.d.ts +0 -20
  233. package/dist/components/use-roster-preview.d.ts +0 -24
  234. package/dist/components/use-thread-dispatches.d.ts +0 -8
  235. package/dist/components/use-transcript-folds.d.ts +0 -26
  236. package/dist/components/user-message.d.ts +0 -6
  237. package/dist/contract/actions-adapter.js +0 -1
  238. package/dist/contract/assistant-config.js +0 -1
  239. package/dist/contract/dispatches.d.ts +0 -15
  240. package/dist/contract/errors.js +0 -1
  241. package/dist/contract/identity.js +0 -1
  242. package/dist/core/activity-title.d.ts +0 -1
  243. package/dist/core/agent-identity.d.ts +0 -2
  244. package/dist/core/approval-decision.d.ts +0 -6
  245. package/dist/core/approval-resolved.d.ts +0 -7
  246. package/dist/core/assistant-prose.d.ts +0 -2
  247. package/dist/core/assistant-session-registry.d.ts +0 -51
  248. package/dist/core/attachment-uploads.d.ts +0 -5
  249. package/dist/core/block-timing-anchors.d.ts +0 -5
  250. package/dist/core/companion-drawer-flag.d.ts +0 -4
  251. package/dist/core/companion-presence.d.ts +0 -7
  252. package/dist/core/composer-input-state.d.ts +0 -8
  253. package/dist/core/connection-driver.d.ts +0 -3
  254. package/dist/core/conversation-adoption.d.ts +0 -13
  255. package/dist/core/conversation-contract.js +0 -1
  256. package/dist/core/conversation-publish.d.ts +0 -8
  257. package/dist/core/conversation-refresh.d.ts +0 -4
  258. package/dist/core/conversation-send.d.ts +0 -6
  259. package/dist/core/disposable-subscriber.d.ts +0 -6
  260. package/dist/core/disposable-subscriber.js +0 -18
  261. package/dist/core/dock-reflow.d.ts +0 -5
  262. package/dist/core/elicitation-answers.d.ts +0 -7
  263. package/dist/core/epoch-sync.d.ts +0 -12
  264. package/dist/core/error-copy.d.ts +0 -3
  265. package/dist/core/execution-driver.d.ts +0 -37
  266. package/dist/core/host-fill.d.ts +0 -1
  267. package/dist/core/hotkey.d.ts +0 -18
  268. package/dist/core/identity-pair.d.ts +0 -14
  269. package/dist/core/idle-recheck.d.ts +0 -3
  270. package/dist/core/messages-cell.d.ts +0 -11
  271. package/dist/core/perch-clearance.d.ts +0 -19
  272. package/dist/core/question-receipt.d.ts +0 -11
  273. package/dist/core/reasoning-copy.d.ts +0 -2
  274. package/dist/core/run-folds.d.ts +0 -43
  275. package/dist/core/run-status.d.ts +0 -4
  276. package/dist/core/settle-refresh.d.ts +0 -9
  277. package/dist/core/step-caption.d.ts +0 -2
  278. package/dist/core/stop-copy.d.ts +0 -1
  279. package/dist/core/stop-settle.d.ts +0 -5
  280. package/dist/core/stream-trouble.d.ts +0 -5
  281. package/dist/core/subagent-brief.d.ts +0 -3
  282. package/dist/core/subagent-presence.d.ts +0 -10
  283. package/dist/core/subagent-roster.d.ts +0 -35
  284. package/dist/core/surface-registry.d.ts +0 -16
  285. package/dist/core/suspension-queue.d.ts +0 -14
  286. package/dist/core/tail-slot-pool.d.ts +0 -13
  287. package/dist/core/time-labels.d.ts +0 -7
  288. package/dist/core/tool-call-display-anchors.d.ts +0 -11
  289. package/dist/core/tool-cancel-anchors.d.ts +0 -5
  290. package/dist/core/tool-decision-anchors.d.ts +0 -6
  291. package/dist/core/tool-error-anchors.d.ts +0 -5
  292. package/dist/core/tool-flag-anchors.d.ts +0 -9
  293. package/dist/core/tool-offload-anchors.d.ts +0 -5
  294. package/dist/core/tool-outcome.d.ts +0 -9
  295. package/dist/core/tool-refusal-anchors.d.ts +0 -5
  296. package/dist/core/tool-result-envelope.d.ts +0 -3
  297. package/dist/core/tool-sentence-anchors.d.ts +0 -11
  298. package/dist/core/transcript-lease.d.ts +0 -2
  299. package/dist/core/turn-failure-copy.d.ts +0 -4
  300. package/dist/core/turns-backfill.d.ts +0 -14
  301. package/dist/core/wire-sentence-cap.d.ts +0 -1
  302. package/dist/generated/serving.d.ts +0 -38
  303. package/dist/markdown.d.ts +0 -4
  304. package/dist/markdown.js +0 -4
  305. package/dist/persistence/execution-ledger.d.ts +0 -7
  306. package/dist/persistence/panel-mode.d.ts +0 -6
  307. package/dist/persistence/plan-notice.d.ts +0 -3
  308. package/dist/reader/accessible-name.d.ts +0 -3
  309. package/dist/reader/interactivity.d.ts +0 -11
  310. package/dist/reader/layout-probe.d.ts +0 -29
  311. package/dist/reader/line-diff.d.ts +0 -1
  312. package/dist/reader/read-page.d.ts +0 -12
  313. package/dist/reader/redaction.d.ts +0 -3
  314. package/dist/reader/render.d.ts +0 -3
  315. package/dist/reader/roles.d.ts +0 -8
  316. package/dist/reader/snapshot-compaction.d.ts +0 -5
  317. package/dist/reader/snapshot-node.d.ts +0 -4
  318. package/dist/reader/snapshot-root.d.ts +0 -15
  319. package/dist/reader/snapshot.d.ts +0 -60
  320. package/dist/reader/visibility.d.ts +0 -8
  321. package/dist/scroll.d.ts +0 -1
  322. package/dist/scroll.js +0 -1
  323. package/dist/transcript-ui.d.ts +0 -15
  324. package/dist/transcript-ui.js +0 -8
  325. package/dist/transcript.d.ts +0 -43
  326. package/dist/transcript.js +0 -38
  327. package/dist/transport/actions-adapter.d.ts +0 -4
  328. package/dist/transport/door-budget.d.ts +0 -4
  329. package/dist/transport/serving-api.d.ts +0 -33
  330. package/dist/transport/serving-fetch.d.ts +0 -11
@@ -8,28 +8,96 @@ export interface DispatchCall {
8
8
  errorText: string | undefined;
9
9
  argsText: string;
10
10
  }
11
+ /**
12
+ * The sub-agent tool's immediate reply confirming a dispatch, parsed. It is not
13
+ * the sub-agent's result, which arrives later in its own turn.
14
+ */
11
15
  export interface DispatchReceipt {
16
+ /**
17
+ * launched means a new sub-agent was started, attached means the same task
18
+ * was re-issued and joined the sub-agent already working on it, and
19
+ * already_settled means that sub-agent had already finished, with its
20
+ * outcome in `settled`.
21
+ */
12
22
  outcome: "launched" | "attached" | "already_settled";
23
+ /**
24
+ * The sub-agent's number within the conversation, counting from 0; the same
25
+ * number identifies it in DeliveredResult.ordinal.
26
+ */
13
27
  ordinal: number;
28
+ /**
29
+ * A short excerpt of the task given to the sub-agent. Can be empty when the
30
+ * stored reply was cut short.
31
+ */
14
32
  label: string;
33
+ /**
34
+ * The id of the sub-agent's own session. Null when the stored reply was cut
35
+ * short.
36
+ */
15
37
  childSessionId: string | null;
38
+ /**
39
+ * The finished sub-agent's outcome (whether it failed, plus an optional
40
+ * note) when outcome is already_settled; null otherwise.
41
+ */
16
42
  settled: {
17
43
  failed: boolean;
18
44
  note: string | null;
19
45
  } | null;
20
46
  }
47
+ /** One sub-agent in a group of dispatches. */
21
48
  export interface SubagentGroupEntry {
49
+ /** The id of the tool call that dispatched this sub-agent. */
22
50
  toolCallId: string;
51
+ /**
52
+ * The dispatch's confirmation. Null until it arrives, or when the dispatch
53
+ * failed.
54
+ */
23
55
  receipt: DispatchReceipt | null;
56
+ /**
57
+ * A short excerpt of the sub-agent's task, read from the confirmation or,
58
+ * before it arrives, from the task text still streaming. Null when nothing
59
+ * readable is available yet.
60
+ */
24
61
  label: string | null;
62
+ /**
63
+ * True while the sub-agent is still working as of the package's latest
64
+ * successful check, and false once a check has seen it finish, whether or
65
+ * not the built-in transcript is on screen; before any check lands, or for
66
+ * a sub-agent whose confirmation never arrived, it reads as the dispatch
67
+ * reply last showed it. The package re-checks the conversation's sub-agents
68
+ * while any is unfinished and the checks keep succeeding; a
69
+ * subagent-delivery row then reports the result.
70
+ */
25
71
  running: boolean;
72
+ /**
73
+ * True when the dispatch failed, or when the dispatch's confirmation or the
74
+ * package's latest successful check reports that the sub-agent failed; a
75
+ * failure no check has seen yet reads false.
76
+ */
26
77
  failed: boolean;
78
+ /**
79
+ * True when the dispatch was cancelled or abandoned by a retry; the
80
+ * built-in UI labels this "interrupted".
81
+ */
27
82
  cancelled: boolean;
83
+ /**
84
+ * An explanation to show beside the entry: why the dispatch failed, why the
85
+ * sub-agent failed, or the note its confirmation carried for a sub-agent
86
+ * that had already finished. Null when there is none; a sub-agent that
87
+ * finishes successfully while you watch leaves it null.
88
+ */
28
89
  note: string | null;
29
90
  }
91
+ /**
92
+ * Consecutive sub-agent dispatches shown as one group, such as "Running 3
93
+ * subagents".
94
+ */
30
95
  export interface SubagentGroupRow {
96
+ /** Identifies a sub-agent group row. */
31
97
  kind: "subagent-group";
98
+ /** Stable unique key for this row, suitable as a React list key. */
32
99
  key: string;
100
+ /** The dispatched sub-agents, in the order they were dispatched. */
33
101
  entries: SubagentGroupEntry[];
34
102
  }
35
103
  export interface SubagentOutcomeCounts {
@@ -0,0 +1,303 @@
1
+ import { dispatchIsPaused, dispatchIsRunning, } from "../contract/dispatches.js";
2
+ import { listThreadDispatches } from "../transport/serving-api.js";
3
+ import { ObservableCell } from "./observable-cell.js";
4
+ const POLL_INTERVAL_MS = 10_000;
5
+ const MAX_CONSECUTIVE_READ_FAILURES = 3;
6
+ const READ_BOUND_MS = 2 * POLL_INTERVAL_MS;
7
+ export const EMPTY_THREAD_DISPATCHES = new Map();
8
+ export function newestRowForSession(map, childSessionId) {
9
+ let newest;
10
+ for (const dispatch of map.values()) {
11
+ if (dispatch.child_session_id !== childSessionId) {
12
+ continue;
13
+ }
14
+ if (newest === undefined || dispatch.ordinal > newest.ordinal) {
15
+ newest = dispatch;
16
+ }
17
+ }
18
+ return newest;
19
+ }
20
+ export class ThreadDispatchLedger {
21
+ session;
22
+ cell = new ObservableCell(null);
23
+ demands = new Map();
24
+ timer = null;
25
+ timerThreadId = null;
26
+ busy = false;
27
+ readThreadId = null;
28
+ pendingThreadId = null;
29
+ failedThreadId = null;
30
+ consecutiveFailures = 0;
31
+ constructor(session) {
32
+ this.session = session;
33
+ }
34
+ settleListeners = new Map();
35
+ setSettleListener(token, listener) {
36
+ if (listener === null) {
37
+ this.settleListeners.delete(token);
38
+ }
39
+ else {
40
+ this.settleListeners.set(token, listener);
41
+ }
42
+ }
43
+ pauseListeners = new Map();
44
+ setPauseListener(token, listener) {
45
+ if (listener === null) {
46
+ this.pauseListeners.delete(token);
47
+ }
48
+ else {
49
+ this.pauseListeners.set(token, listener);
50
+ }
51
+ }
52
+ setDemand(token, demand) {
53
+ const held = this.demands.get(token);
54
+ if (demand === null) {
55
+ if (held === undefined) {
56
+ return;
57
+ }
58
+ this.demands.delete(token);
59
+ }
60
+ else {
61
+ if (held?.threadId === demand.threadId &&
62
+ held.delegated === demand.delegated &&
63
+ held.stillMoving === demand.stillMoving &&
64
+ held.joinKey === demand.joinKey) {
65
+ return;
66
+ }
67
+ this.demands.set(token, demand);
68
+ }
69
+ this._reconcile();
70
+ }
71
+ noteThreadAnswered(threadId) {
72
+ if (this.failedThreadId !== threadId || this.consecutiveFailures === 0) {
73
+ return;
74
+ }
75
+ this.failedThreadId = null;
76
+ this.consecutiveFailures = 0;
77
+ this._reconcile();
78
+ }
79
+ refresh(threadId) {
80
+ if (!this.busy) {
81
+ return this._readOnce(threadId);
82
+ }
83
+ if (this.followUp === null || this.followUpThreadId !== threadId) {
84
+ this.followUpThreadId = threadId;
85
+ this.followUp = (this.flight ?? Promise.resolve()).then(() => {
86
+ this.followUp = null;
87
+ this.followUpThreadId = null;
88
+ return this._readOnce(threadId);
89
+ });
90
+ }
91
+ return this.followUp;
92
+ }
93
+ followUp = null;
94
+ followUpThreadId = null;
95
+ _reconcile() {
96
+ let threadId = null;
97
+ let delegated = false;
98
+ let stillMoving = false;
99
+ for (const demand of this.demands.values()) {
100
+ threadId ??= demand.threadId;
101
+ delegated ||= demand.delegated;
102
+ stillMoving ||= demand.stillMoving;
103
+ }
104
+ if (this.pendingThreadId !== null && this.pendingThreadId !== threadId) {
105
+ this.pendingThreadId = null;
106
+ }
107
+ if (threadId === null || !delegated) {
108
+ this._stopTimer();
109
+ return;
110
+ }
111
+ if (this.readThreadId !== threadId) {
112
+ void this._readOnce(threadId);
113
+ }
114
+ if (!stillMoving) {
115
+ this._stopTimer();
116
+ return;
117
+ }
118
+ if (this.timer === null || this.timerThreadId !== threadId) {
119
+ this._stopTimer();
120
+ void this._readOnce(threadId);
121
+ this.timerThreadId = threadId;
122
+ this.timer = setInterval(() => {
123
+ void this._readOnce(threadId);
124
+ }, POLL_INTERVAL_MS);
125
+ }
126
+ }
127
+ _sameAsCurrent(next) {
128
+ const current = this.cell.get();
129
+ if (current?.threadId !== next.threadId) {
130
+ return false;
131
+ }
132
+ if (current.map.size !== next.map.size) {
133
+ return false;
134
+ }
135
+ for (const [ordinal, dispatch] of next.map) {
136
+ const held = current.map.get(ordinal);
137
+ if (held?.status !== dispatch.status ||
138
+ held.error !== dispatch.error ||
139
+ held.updated_at !== dispatch.updated_at) {
140
+ return false;
141
+ }
142
+ }
143
+ return true;
144
+ }
145
+ _stopTimer() {
146
+ if (this.timer !== null) {
147
+ clearInterval(this.timer);
148
+ this.timer = null;
149
+ this.timerThreadId = null;
150
+ }
151
+ }
152
+ _readOnce(threadId) {
153
+ if (this.busy) {
154
+ if (threadId !== this.readThreadId) {
155
+ this.pendingThreadId = threadId;
156
+ }
157
+ return this.flight ?? Promise.resolve();
158
+ }
159
+ this.busy = true;
160
+ this.readThreadId = threadId;
161
+ this.generation += 1;
162
+ const generation = this.generation;
163
+ let settleFlight;
164
+ const flight = new Promise((resolve) => {
165
+ settleFlight = resolve;
166
+ });
167
+ this.flight = flight;
168
+ setTimeout(() => {
169
+ this._releaseBoundedOutRead(threadId, generation);
170
+ settleFlight();
171
+ }, READ_BOUND_MS);
172
+ void this._read(threadId, generation, settleFlight);
173
+ return flight;
174
+ }
175
+ flight = null;
176
+ generation = 0;
177
+ _releaseBoundedOutRead(threadId, generation) {
178
+ if (generation !== this.generation || !this.busy) {
179
+ return;
180
+ }
181
+ this.generation += 1;
182
+ this.busy = false;
183
+ this.flight = null;
184
+ this._noteReadFailure(threadId);
185
+ this._replayParkedSwitch();
186
+ }
187
+ _noteReadFailure(threadId) {
188
+ this.consecutiveFailures =
189
+ this.failedThreadId === threadId ? this.consecutiveFailures + 1 : 1;
190
+ this.failedThreadId = threadId;
191
+ if (this.consecutiveFailures >= MAX_CONSECUTIVE_READ_FAILURES &&
192
+ this.timerThreadId === threadId) {
193
+ this._stopTimer();
194
+ }
195
+ if (this.cell.get()?.threadId !== threadId) {
196
+ this.readThreadId = null;
197
+ }
198
+ }
199
+ _replayParkedSwitch() {
200
+ const pending = this.pendingThreadId;
201
+ this.pendingThreadId = null;
202
+ if (pending !== null && pending !== this.readThreadId) {
203
+ void this._readOnce(pending);
204
+ }
205
+ }
206
+ adoptedThrough = 0;
207
+ async _read(threadId, generation, settleFlight) {
208
+ const live = () => generation === this.generation;
209
+ try {
210
+ const dispatches = await listThreadDispatches(this.session, threadId);
211
+ const adopts = live() ||
212
+ (generation > this.adoptedThrough &&
213
+ (this.readThreadId === threadId || this.readThreadId === null));
214
+ if (!adopts) {
215
+ if (this.failedThreadId === threadId) {
216
+ this.failedThreadId = null;
217
+ this.consecutiveFailures = 0;
218
+ }
219
+ return;
220
+ }
221
+ this.readThreadId ??= threadId;
222
+ this.adoptedThrough = generation;
223
+ const previous = this.cell.get();
224
+ const next = {
225
+ threadId,
226
+ map: new Map(dispatches.map((dispatch) => [dispatch.ordinal, dispatch])),
227
+ };
228
+ if (!this._sameAsCurrent(next)) {
229
+ this.cell.set(next);
230
+ }
231
+ this.failedThreadId = null;
232
+ this.consecutiveFailures = 0;
233
+ if (_observedASettle(previous, next)) {
234
+ _fireEach(this.settleListeners);
235
+ }
236
+ if (_observedAPause(previous, next)) {
237
+ _fireEach(this.pauseListeners);
238
+ }
239
+ }
240
+ catch {
241
+ if (!live()) {
242
+ return;
243
+ }
244
+ this._noteReadFailure(threadId);
245
+ }
246
+ finally {
247
+ if (live()) {
248
+ this.busy = false;
249
+ this.flight = null;
250
+ settleFlight();
251
+ this._replayParkedSwitch();
252
+ }
253
+ }
254
+ }
255
+ }
256
+ function _fireEach(listeners) {
257
+ for (const listener of new Set(listeners.values())) {
258
+ try {
259
+ listener();
260
+ }
261
+ catch {
262
+ }
263
+ }
264
+ }
265
+ function _observedAPause(previous, next) {
266
+ const comparable = previous?.threadId === next.threadId ? previous : null;
267
+ for (const [ordinal, dispatch] of next.map) {
268
+ if (!dispatchIsPaused(dispatch)) {
269
+ continue;
270
+ }
271
+ const held = comparable?.map.get(ordinal);
272
+ if (held === undefined ||
273
+ !dispatchIsPaused(held) ||
274
+ held.updated_at !== dispatch.updated_at) {
275
+ return true;
276
+ }
277
+ }
278
+ return false;
279
+ }
280
+ function _observedASettle(previous, next) {
281
+ if (previous?.threadId !== next.threadId) {
282
+ return false;
283
+ }
284
+ for (const [ordinal, dispatch] of next.map) {
285
+ if (dispatchIsRunning(dispatch)) {
286
+ continue;
287
+ }
288
+ const held = previous.map.get(ordinal);
289
+ if (held === undefined || dispatchIsRunning(held)) {
290
+ return true;
291
+ }
292
+ }
293
+ return false;
294
+ }
295
+ const _ledgers = new WeakMap();
296
+ export function threadDispatchLedgerFor(session) {
297
+ let ledger = _ledgers.get(session);
298
+ if (ledger === undefined) {
299
+ ledger = new ThreadDispatchLedger(session);
300
+ _ledgers.set(session, ledger);
301
+ }
302
+ return ledger;
303
+ }
@@ -1,27 +1,98 @@
1
+ /**
2
+ * Where a call is in its life. "input-streaming" means the agent is still
3
+ * writing the arguments, "input-available" means they are complete and the call
4
+ * is running or waiting for approval, "output-available" means it finished with
5
+ * a result, and "output-error" means it failed; "denied" means the user didn't
6
+ * approve it, "cancelled" means it never ran, "refused" means Teaflask declined
7
+ * it before it reached the tool, and "superseded" means it started but was cut
8
+ * off when the run restarted, so its result never arrived.
9
+ */
1
10
  export type ToolCallState = "input-streaming" | "input-available" | "output-available" | "output-error" | "denied" | "cancelled" | "refused" | "superseded";
11
+ /**
12
+ * Server-supplied display details for one tool call, namely its row's label,
13
+ * icon and view.
14
+ */
2
15
  export interface ToolCallDisplay {
16
+ /**
17
+ * A few words the agent wrote saying what the step is for. When present it
18
+ * is the row's label in every state, followed by a short state word if the
19
+ * call failed, was not approved, didn't run, was declined or didn't finish.
20
+ */
3
21
  caption?: string;
22
+ /** The row's label while the call runs, used when there is no caption. */
4
23
  progressText?: string;
24
+ /**
25
+ * The row's label once the call succeeds, used when there is no caption.
26
+ */
5
27
  completeText?: string;
28
+ /** The row's label when the call fails, used when there is no caption. */
6
29
  errorText?: string;
30
+ /**
31
+ * The kind of work the call is, one of TOOL_CALL_ICONS. Any other value
32
+ * shows the generic icon.
33
+ */
7
34
  icon?: string;
35
+ /**
36
+ * The view the server names for this call, as a key and version. A registry
37
+ * entry under that exact key with the same version is preferred over a
38
+ * match by tool name; Teaflask's own tools name built-in views with keys
39
+ * starting `teaflask.`.
40
+ */
8
41
  view?: {
9
42
  key: string;
10
43
  version: number;
11
44
  };
12
45
  }
46
+ /**
47
+ * One tool or action call as a transcript row renders it. A custom `toolRow`
48
+ * receives it as `view`, and toolCallPresentationOf takes it.
49
+ */
13
50
  export interface ToolCallViewModel {
51
+ /** The tool's name. For an action, `action__<slug>`. */
14
52
  toolName: string;
53
+ /** Where the call is in its life. See ToolCallState. */
15
54
  state: ToolCallState;
55
+ /** Unique id of the call, when known. */
16
56
  toolCallId?: string;
57
+ /**
58
+ * The arguments as pretty-printed JSON, or the raw text while it is still
59
+ * streaming in.
60
+ */
17
61
  input: string;
62
+ /** The arguments as raw JSON text, exactly as streamed. */
18
63
  argsText?: string;
64
+ /**
65
+ * The raw result text. Undefined until the call finishes, and withheld for
66
+ * calls that failed, were not approved, didn't run, were declined or had
67
+ * their result replaced by a preview.
68
+ */
19
69
  output?: string;
70
+ /**
71
+ * True when the result was too large for the agent and was replaced by a
72
+ * shortened preview. `output` is then withheld.
73
+ */
20
74
  offloaded?: boolean;
75
+ /** Why the call failed, set when it failed. */
21
76
  errorText?: string;
77
+ /**
78
+ * Teaflask's reason for declining the call, set only when `state` is
79
+ * "refused".
80
+ */
22
81
  refusalText?: string;
82
+ /**
83
+ * The server's display details for the call (label text, icon, view), when
84
+ * it sent any.
85
+ */
23
86
  display?: ToolCallDisplay;
87
+ /**
88
+ * The JSON Schema of the tool's arguments, when it declared one. Undefined
89
+ * otherwise, never `{}`.
90
+ */
24
91
  argsSchema?: Record<string, unknown>;
92
+ /**
93
+ * The JSON Schema of the tool's successful result, when it declared one.
94
+ * Undefined otherwise.
95
+ */
25
96
  resultSchema?: Record<string, unknown>;
26
97
  }
27
98
  export declare function humanizedToolName(name: string): string;
@@ -1,15 +1,48 @@
1
1
  import type { ToolCallState, ToolCallViewModel } from "./tool-call-display.js";
2
2
  import type { ToolViewRegistry, ToolViewResolution } from "./tool-view.js";
3
+ /**
4
+ * Every icon kind a tool call row can show: search, file, terminal (running a
5
+ * command), question (asking the user), memory, delegation (sub-agents),
6
+ * routine (finding or preparing actions), todo, navigation (opening, reading or
7
+ * filling in your page) and generic.
8
+ */
3
9
  export declare const TOOL_CALL_ICONS: readonly ["search", "file", "terminal", "question", "memory", "delegation", "routine", "todo", "navigation", "generic"];
10
+ /** One icon kind from TOOL_CALL_ICONS. */
4
11
  export type ToolCallIcon = (typeof TOOL_CALL_ICONS)[number];
12
+ /**
13
+ * Everything needed to render one tool call row, as returned by
14
+ * toolCallPresentationOf.
15
+ */
5
16
  export interface ToolCallPresentation {
17
+ /**
18
+ * The row's label. It is the agent's caption or the server's text when
19
+ * there is one, else wording built from the tool name and state, such as
20
+ * "Running create ticket…" or "create ticket failed".
21
+ */
6
22
  headline: string;
23
+ /**
24
+ * The icon kind to show; "generic" when the server named none or one this
25
+ * version doesn't know.
26
+ */
7
27
  icon: ToolCallIcon;
28
+ /** The call's state. */
8
29
  status: ToolCallState;
9
- settledSummary: string;
30
+ /**
31
+ * The call's running-state label, whatever its actual state. Used for a
32
+ * sub-agent's line saying what it is doing now.
33
+ */
10
34
  currentWorkLabel: string;
35
+ /**
36
+ * The tool views and icons that match the call, and the call they receive.
37
+ */
11
38
  toolView: ToolViewResolution;
12
39
  }
40
+ /**
41
+ * Works out everything needed to render one tool call row: its label, icon,
42
+ * state, its running-state label and matching tool view. Pass your `toolViews`
43
+ * registry, and `awaitingDecision: true` while an approval or question tied to
44
+ * the call is waiting on the user.
45
+ */
13
46
  export declare function toolCallPresentationOf(view: ToolCallViewModel, registry?: ToolViewRegistry, options?: {
14
47
  awaitingDecision?: boolean;
15
48
  }): ToolCallPresentation;
@@ -23,7 +23,6 @@ export function toolCallPresentationOf(view, registry, options) {
23
23
  headline,
24
24
  icon: _iconOf(view.display?.icon),
25
25
  status: view.state,
26
- settledSummary: headline,
27
26
  currentWorkLabel: toolRowHeadlineOf({ ...view, state: "input-available" }),
28
27
  toolView: {
29
28
  views: resolved.views,
@@ -1,7 +1,13 @@
1
1
  import type { AgentSubscriber } from "@ag-ui/client";
2
2
  import type { JsonSchema } from "./tool-view.js";
3
+ /**
4
+ * The JSON Schemas a tool declared. Either field is absent when that schema was
5
+ * not declared.
6
+ */
3
7
  export interface ToolCallSchemas {
8
+ /** The JSON Schema of the tool's arguments. */
4
9
  argsSchema?: JsonSchema;
10
+ /** The JSON Schema of the tool's successful result. */
5
11
  resultSchema?: JsonSchema;
6
12
  }
7
13
  export declare const EMPTY_TOOL_SCHEMA_ANCHORS: ReadonlyMap<string, ToolCallSchemas>;