@teaflask/assistant 0.6.0 → 0.7.0

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 (318) hide show
  1. package/README.md +1 -1
  2. package/custom-elements.json +264 -0
  3. package/dist/appearance/theme.d.ts +138 -0
  4. package/dist/components/approval-card.js +3 -3
  5. package/dist/components/approval-context.d.ts +20 -0
  6. package/dist/components/assistant-companion.d.ts +15 -0
  7. package/dist/components/assistant-page.d.ts +61 -0
  8. package/dist/components/assistant-palette.d.ts +12 -0
  9. package/dist/components/assistant-palette.js +2 -2
  10. package/dist/components/child-transcript.js +1 -1
  11. package/dist/components/companion-header-disclosure.js +1 -1
  12. package/dist/components/companion-history-menu.js +1 -1
  13. package/dist/components/composer.js +11 -65
  14. package/dist/components/conversation-context.d.ts +6 -0
  15. package/dist/components/conversation-gate-card.js +1 -1
  16. package/dist/components/conversation-view.d.ts +11 -0
  17. package/dist/components/elicitation-context.d.ts +39 -0
  18. package/dist/components/model-picker-chip.js +4 -2
  19. package/dist/components/primitives/button.js +25 -17
  20. package/dist/components/primitives/floating-panel.js +1 -1
  21. package/dist/components/provider-chip.js +8 -1
  22. package/dist/components/question-panel-footer.js +1 -1
  23. package/dist/components/react-tool-view.d.ts +7 -0
  24. package/dist/components/subagent-count-pill.js +2 -2
  25. package/dist/components/subagent-group-row.js +1 -26
  26. package/dist/components/subagent-preview-popover.js +1 -1
  27. package/dist/components/subscription-connect-arms.js +6 -4
  28. package/dist/components/subscription-connect-flow.js +30 -45
  29. package/dist/components/subscription-connected-standing.js +9 -6
  30. package/dist/components/subscription-plan-notice.js +4 -2
  31. package/dist/components/teaflask-assistant-provider.d.ts +99 -0
  32. package/dist/components/teaflask-assistant.d.ts +33 -0
  33. package/dist/components/tool-views/action-view.js +1 -1
  34. package/dist/components/tool-views/parts-classes.d.ts +5 -5
  35. package/dist/components/tool-views/parts-classes.js +5 -5
  36. package/dist/components/tool-views/parts.d.ts +44 -0
  37. package/dist/components/tool-views/questions-view.js +2 -2
  38. package/dist/components/tool-views/view-dom.d.ts +76 -0
  39. package/dist/components/transcript.js +2 -2
  40. package/dist/components/use-assistant-activity.d.ts +5 -0
  41. package/dist/components/use-assistant-conversation.d.ts +99 -2
  42. package/dist/components/use-store-cell.d.ts +5 -0
  43. package/dist/components/use-thread-dispatches.js +8 -366
  44. package/dist/components/use-transcript-folds.js +2 -1
  45. package/dist/components/use-transcript.d.ts +55 -2
  46. package/dist/components/use-transcript.js +7 -2
  47. package/dist/contract/actions-adapter.d.ts +78 -0
  48. package/dist/contract/errors.d.ts +6 -1
  49. package/dist/contract/events.d.ts +1 -3
  50. package/dist/contract/identity.d.ts +1 -1
  51. package/dist/contract/subscriptions.d.ts +2 -2
  52. package/dist/contract/subscriptions.js +1 -1
  53. package/dist/contract/telemetry.d.ts +45 -0
  54. package/dist/contract/threads.d.ts +5 -1
  55. package/dist/core/activity.d.ts +44 -0
  56. package/dist/core/approval-inbox.d.ts +69 -0
  57. package/dist/core/assistant-session-registry.js +15 -0
  58. package/dist/core/composer-attachments.js +82 -0
  59. package/dist/core/composer-input-state.js +1 -0
  60. package/dist/core/composer-policy.d.ts +20 -0
  61. package/dist/core/connection-epoch.d.ts +65 -2
  62. package/dist/core/conversation-adoption.js +3 -0
  63. package/dist/core/conversation-contract.d.ts +112 -1
  64. package/dist/core/conversation-publish.js +1 -0
  65. package/dist/core/conversation-store.d.ts +3 -0
  66. package/dist/core/conversation-store.js +7 -0
  67. package/dist/core/dispatch-poll.js +81 -0
  68. package/dist/core/elicitation-answers.js +12 -0
  69. package/dist/core/elicitation-cards.d.ts +14 -0
  70. package/dist/core/elicitation-pickers.d.ts +16 -0
  71. package/dist/core/memory-provenance-anchors.d.ts +16 -0
  72. package/dist/core/observable-cell.d.ts +12 -0
  73. package/dist/core/pending-decision-gap.d.ts +9 -0
  74. package/dist/core/question-drafts.d.ts +59 -0
  75. package/dist/core/receipt-anchors.d.ts +9 -0
  76. package/dist/core/segment-timing.d.ts +23 -0
  77. package/dist/core/subagent-delivery-anchors.d.ts +7 -0
  78. package/dist/core/subagent-ledger-join.js +176 -0
  79. package/dist/core/subagent-rows.d.ts +68 -0
  80. package/dist/core/thread-dispatch-ledger.js +303 -0
  81. package/dist/core/tool-call-display.d.ts +71 -0
  82. package/dist/core/tool-call-presentation.d.ts +34 -1
  83. package/dist/core/tool-call-presentation.js +0 -1
  84. package/dist/core/tool-schema-anchors.d.ts +6 -0
  85. package/dist/core/tool-view.d.ts +174 -1
  86. package/dist/core/transcript-rows.d.ts +138 -3
  87. package/dist/core/turn-failed-anchors.d.ts +4 -0
  88. package/dist/core/user-turn-ledger.d.ts +3 -0
  89. package/dist/generated/models/apiErrorCode.d.ts +1 -0
  90. package/dist/generated/models/apiErrorCode.js +1 -0
  91. package/dist/generated/models/assistantTurnStatus.d.ts +16 -0
  92. package/dist/generated/models/servingAssistantThreadResponse.d.ts +23 -0
  93. package/dist/generated/models/servingAttachmentResponse.d.ts +29 -0
  94. package/dist/generated/models/servingErrorCode.d.ts +18 -0
  95. package/dist/generated/models/servingTurnAttachmentResponse.d.ts +12 -0
  96. package/dist/generated/models/siteTheme.d.ts +1 -0
  97. package/dist/generated/models/thinkingEffort.d.ts +10 -0
  98. package/dist/generated/models/threadModelPickResponse.d.ts +12 -0
  99. package/dist/headless.d.ts +9 -4
  100. package/dist/index.d.ts +2 -6
  101. package/dist/index.js +0 -3
  102. package/dist/persistence/stored-thread.d.ts +5 -0
  103. package/dist/styles.css +1 -1
  104. package/dist/transport/serving-error.d.ts +21 -0
  105. package/package.json +6 -25
  106. package/dist/affordances/highlight.d.ts +0 -3
  107. package/dist/affordances/prefill.d.ts +0 -14
  108. package/dist/components/activity-rail.d.ts +0 -12
  109. package/dist/components/activity-shelf.d.ts +0 -7
  110. package/dist/components/agent-identity-mark.d.ts +0 -7
  111. package/dist/components/appearance-context.d.ts +0 -14
  112. package/dist/components/approval-card.d.ts +0 -7
  113. package/dist/components/assistant-palette-body.d.ts +0 -3
  114. package/dist/components/assistant-transcript.d.ts +0 -47
  115. package/dist/components/attachment-chips.d.ts +0 -4
  116. package/dist/components/child-transcript.d.ts +0 -22
  117. package/dist/components/companion-drawer-body.d.ts +0 -1
  118. package/dist/components/companion-drawer.d.ts +0 -10
  119. package/dist/components/companion-header-disclosure.d.ts +0 -20
  120. package/dist/components/companion-history-menu.d.ts +0 -15
  121. package/dist/components/companion-mark-image.d.ts +0 -3
  122. package/dist/components/companion-mark-image.js +0 -18
  123. package/dist/components/companion-mark.d.ts +0 -1
  124. package/dist/components/companion-mode-menu.d.ts +0 -15
  125. package/dist/components/composer-attachment-chip.d.ts +0 -7
  126. package/dist/components/composer-banner.d.ts +0 -4
  127. package/dist/components/composer.d.ts +0 -4
  128. package/dist/components/conversation-gate-card.d.ts +0 -8
  129. package/dist/components/conversation-surfaces-provider.d.ts +0 -6
  130. package/dist/components/copy-text-button.d.ts +0 -5
  131. package/dist/components/elicitation-receipt-row.d.ts +0 -4
  132. package/dist/components/human-file-size.d.ts +0 -1
  133. package/dist/components/icons.d.ts +0 -15
  134. package/dist/components/lazy-body.d.ts +0 -4
  135. package/dist/components/markdown/assistant-markdown.d.ts +0 -3
  136. package/dist/components/markdown/code-block.d.ts +0 -4
  137. package/dist/components/markdown/highlight.d.ts +0 -1
  138. package/dist/components/markdown/markdown-structure.d.ts +0 -16
  139. package/dist/components/markdown/memoized-blocks.d.ts +0 -6
  140. package/dist/components/markdown/paced-assistant-markdown.d.ts +0 -4
  141. package/dist/components/markdown/reveal-pacer.d.ts +0 -20
  142. package/dist/components/markdown/shiki-highlighter.d.ts +0 -1
  143. package/dist/components/markdown/streaming-repair.d.ts +0 -1
  144. package/dist/components/markdown/use-highlighted-html.d.ts +0 -1
  145. package/dist/components/markdown/use-paced-reveal.d.ts +0 -5
  146. package/dist/components/memory-updated-footer.d.ts +0 -4
  147. package/dist/components/message-list-row.d.ts +0 -13
  148. package/dist/components/message-list-slots.d.ts +0 -25
  149. package/dist/components/message-list-slots.js +0 -1
  150. package/dist/components/message-list.d.ts +0 -23
  151. package/dist/components/model-picker-chip.d.ts +0 -1
  152. package/dist/components/model-picker-effort.d.ts +0 -4
  153. package/dist/components/model-picker-panels.d.ts +0 -22
  154. package/dist/components/notice-banner.d.ts +0 -8
  155. package/dist/components/operation-icons.d.ts +0 -19
  156. package/dist/components/pretty-print.d.ts +0 -1
  157. package/dist/components/primitives/autofocus.d.ts +0 -1
  158. package/dist/components/primitives/button.d.ts +0 -10
  159. package/dist/components/primitives/cx.d.ts +0 -1
  160. package/dist/components/primitives/dialog.d.ts +0 -7
  161. package/dist/components/primitives/disclosure.d.ts +0 -22
  162. package/dist/components/primitives/file-input.d.ts +0 -5
  163. package/dist/components/primitives/floating-panel.d.ts +0 -15
  164. package/dist/components/primitives/kbd.d.ts +0 -2
  165. package/dist/components/primitives/sheet.d.ts +0 -11
  166. package/dist/components/primitives/sheet.js +0 -18
  167. package/dist/components/primitives/textarea.d.ts +0 -7
  168. package/dist/components/primitives/use-dock-reflow.d.ts +0 -2
  169. package/dist/components/primitives/use-swipe-dismiss.d.ts +0 -17
  170. package/dist/components/provider-chip.d.ts +0 -8
  171. package/dist/components/question-panel-answers.d.ts +0 -29
  172. package/dist/components/question-panel-footer.d.ts +0 -9
  173. package/dist/components/question-panel.d.ts +0 -4
  174. package/dist/components/reasoning-row.d.ts +0 -4
  175. package/dist/components/receipt-rows.d.ts +0 -3
  176. package/dist/components/run-status-announcer.d.ts +0 -5
  177. package/dist/components/scroll-follow-guards.d.ts +0 -1
  178. package/dist/components/served-suggestions.d.ts +0 -3
  179. package/dist/components/slot-boundary.d.ts +0 -11
  180. package/dist/components/standing-poll.d.ts +0 -1
  181. package/dist/components/streaming-states.d.ts +0 -12
  182. package/dist/components/subagent-count-pill.d.ts +0 -8
  183. package/dist/components/subagent-current-work.d.ts +0 -6
  184. package/dist/components/subagent-delegation-surface.d.ts +0 -9
  185. package/dist/components/subagent-delivery-divider.d.ts +0 -5
  186. package/dist/components/subagent-drill-in.d.ts +0 -8
  187. package/dist/components/subagent-execution-work.d.ts +0 -3
  188. package/dist/components/subagent-group-row.d.ts +0 -26
  189. package/dist/components/subagent-preview-popover.d.ts +0 -8
  190. package/dist/components/subscription-connect-arms.d.ts +0 -25
  191. package/dist/components/subscription-connect-flow.d.ts +0 -60
  192. package/dist/components/subscription-connected-standing.d.ts +0 -16
  193. package/dist/components/subscription-plan-notice.d.ts +0 -1
  194. package/dist/components/subscription-recheck.d.ts +0 -10
  195. package/dist/components/surface-boundary.d.ts +0 -8
  196. package/dist/components/suspension-surfaces.d.ts +0 -3
  197. package/dist/components/thread-list.d.ts +0 -16
  198. package/dist/components/tool-arguments-summary.d.ts +0 -2
  199. package/dist/components/tool-call-rows.d.ts +0 -10
  200. package/dist/components/tool-row.d.ts +0 -7
  201. package/dist/components/tool-view-registry-context.d.ts +0 -3
  202. package/dist/components/tool-view-slot.d.ts +0 -11
  203. package/dist/components/tool-views/action-view.d.ts +0 -1
  204. package/dist/components/tool-views/command-view.d.ts +0 -1
  205. package/dist/components/tool-views/docs-search-view.d.ts +0 -10
  206. package/dist/components/tool-views/file-edit-view.d.ts +0 -1
  207. package/dist/components/tool-views/questions-view.d.ts +0 -1
  208. package/dist/components/transcript.d.ts +0 -3
  209. package/dist/components/use-agent-subscriber.d.ts +0 -3
  210. package/dist/components/use-agent-subscriber.js +0 -13
  211. package/dist/components/use-answer-list-fold.d.ts +0 -6
  212. package/dist/components/use-assistant-surface-presence.d.ts +0 -2
  213. package/dist/components/use-child-replay-stream.d.ts +0 -20
  214. package/dist/components/use-latest-ref.d.ts +0 -2
  215. package/dist/components/use-member-toggle-outrank.d.ts +0 -6
  216. package/dist/components/use-perch-clearance.d.ts +0 -2
  217. package/dist/components/use-question-panel-keys.d.ts +0 -32
  218. package/dist/components/use-register-assistant-surface.d.ts +0 -2
  219. package/dist/components/use-resolved-theme-mode.d.ts +0 -3
  220. package/dist/components/use-roster-disclosure.d.ts +0 -20
  221. package/dist/components/use-roster-preview.d.ts +0 -24
  222. package/dist/components/use-thread-dispatches.d.ts +0 -8
  223. package/dist/components/use-transcript-folds.d.ts +0 -26
  224. package/dist/components/user-message.d.ts +0 -6
  225. package/dist/contract/actions-adapter.js +0 -1
  226. package/dist/contract/assistant-config.js +0 -1
  227. package/dist/contract/dispatches.d.ts +0 -15
  228. package/dist/contract/errors.js +0 -1
  229. package/dist/contract/identity.js +0 -1
  230. package/dist/core/activity-title.d.ts +0 -1
  231. package/dist/core/agent-identity.d.ts +0 -2
  232. package/dist/core/approval-decision.d.ts +0 -6
  233. package/dist/core/approval-resolved.d.ts +0 -7
  234. package/dist/core/assistant-prose.d.ts +0 -2
  235. package/dist/core/assistant-session-registry.d.ts +0 -51
  236. package/dist/core/attachment-uploads.d.ts +0 -5
  237. package/dist/core/block-timing-anchors.d.ts +0 -5
  238. package/dist/core/companion-drawer-flag.d.ts +0 -4
  239. package/dist/core/companion-presence.d.ts +0 -7
  240. package/dist/core/composer-input-state.d.ts +0 -8
  241. package/dist/core/connection-driver.d.ts +0 -3
  242. package/dist/core/conversation-adoption.d.ts +0 -13
  243. package/dist/core/conversation-contract.js +0 -1
  244. package/dist/core/conversation-publish.d.ts +0 -8
  245. package/dist/core/conversation-refresh.d.ts +0 -4
  246. package/dist/core/conversation-send.d.ts +0 -6
  247. package/dist/core/disposable-subscriber.d.ts +0 -6
  248. package/dist/core/disposable-subscriber.js +0 -18
  249. package/dist/core/dock-reflow.d.ts +0 -5
  250. package/dist/core/elicitation-answers.d.ts +0 -7
  251. package/dist/core/epoch-sync.d.ts +0 -12
  252. package/dist/core/error-copy.d.ts +0 -3
  253. package/dist/core/execution-driver.d.ts +0 -37
  254. package/dist/core/host-fill.d.ts +0 -1
  255. package/dist/core/hotkey.d.ts +0 -18
  256. package/dist/core/identity-pair.d.ts +0 -14
  257. package/dist/core/idle-recheck.d.ts +0 -3
  258. package/dist/core/messages-cell.d.ts +0 -11
  259. package/dist/core/perch-clearance.d.ts +0 -19
  260. package/dist/core/question-receipt.d.ts +0 -11
  261. package/dist/core/reasoning-copy.d.ts +0 -2
  262. package/dist/core/run-folds.d.ts +0 -43
  263. package/dist/core/run-status.d.ts +0 -4
  264. package/dist/core/settle-refresh.d.ts +0 -9
  265. package/dist/core/step-caption.d.ts +0 -2
  266. package/dist/core/stop-copy.d.ts +0 -1
  267. package/dist/core/stop-settle.d.ts +0 -5
  268. package/dist/core/stream-trouble.d.ts +0 -5
  269. package/dist/core/subagent-brief.d.ts +0 -3
  270. package/dist/core/subagent-presence.d.ts +0 -10
  271. package/dist/core/subagent-roster.d.ts +0 -35
  272. package/dist/core/surface-registry.d.ts +0 -16
  273. package/dist/core/suspension-queue.d.ts +0 -14
  274. package/dist/core/tail-slot-pool.d.ts +0 -13
  275. package/dist/core/time-labels.d.ts +0 -7
  276. package/dist/core/tool-call-display-anchors.d.ts +0 -11
  277. package/dist/core/tool-cancel-anchors.d.ts +0 -5
  278. package/dist/core/tool-decision-anchors.d.ts +0 -6
  279. package/dist/core/tool-error-anchors.d.ts +0 -5
  280. package/dist/core/tool-flag-anchors.d.ts +0 -9
  281. package/dist/core/tool-offload-anchors.d.ts +0 -5
  282. package/dist/core/tool-outcome.d.ts +0 -9
  283. package/dist/core/tool-refusal-anchors.d.ts +0 -5
  284. package/dist/core/tool-result-envelope.d.ts +0 -3
  285. package/dist/core/tool-sentence-anchors.d.ts +0 -11
  286. package/dist/core/transcript-lease.d.ts +0 -2
  287. package/dist/core/turn-failure-copy.d.ts +0 -4
  288. package/dist/core/turns-backfill.d.ts +0 -14
  289. package/dist/core/wire-sentence-cap.d.ts +0 -1
  290. package/dist/generated/serving.d.ts +0 -38
  291. package/dist/markdown.d.ts +0 -4
  292. package/dist/markdown.js +0 -4
  293. package/dist/persistence/execution-ledger.d.ts +0 -7
  294. package/dist/persistence/panel-mode.d.ts +0 -6
  295. package/dist/persistence/plan-notice.d.ts +0 -3
  296. package/dist/reader/accessible-name.d.ts +0 -3
  297. package/dist/reader/interactivity.d.ts +0 -11
  298. package/dist/reader/layout-probe.d.ts +0 -29
  299. package/dist/reader/line-diff.d.ts +0 -1
  300. package/dist/reader/read-page.d.ts +0 -12
  301. package/dist/reader/redaction.d.ts +0 -3
  302. package/dist/reader/render.d.ts +0 -3
  303. package/dist/reader/roles.d.ts +0 -8
  304. package/dist/reader/snapshot-compaction.d.ts +0 -5
  305. package/dist/reader/snapshot-node.d.ts +0 -4
  306. package/dist/reader/snapshot-root.d.ts +0 -15
  307. package/dist/reader/snapshot.d.ts +0 -60
  308. package/dist/reader/visibility.d.ts +0 -8
  309. package/dist/scroll.d.ts +0 -1
  310. package/dist/scroll.js +0 -1
  311. package/dist/transcript-ui.d.ts +0 -15
  312. package/dist/transcript-ui.js +0 -8
  313. package/dist/transcript.d.ts +0 -43
  314. package/dist/transcript.js +0 -38
  315. package/dist/transport/actions-adapter.d.ts +0 -4
  316. package/dist/transport/door-budget.d.ts +0 -4
  317. package/dist/transport/serving-api.d.ts +0 -33
  318. package/dist/transport/serving-fetch.d.ts +0 -11
@@ -2,14 +2,32 @@ import type { ToolViewAdapter, ToolViewCall, ToolViewProps } from "../../core/to
2
2
  import { LABEL_CLASS, PANE_CLASS, PANE_WRAPPER_CLASS } from "./parts-classes.js";
3
3
  export { LABEL_CLASS, PANE_CLASS, PANE_WRAPPER_CLASS };
4
4
  export declare function el<K extends keyof HTMLElementTagNameMap>(tag: K, className: string, text?: string): HTMLElementTagNameMap[K];
5
+ /**
6
+ * A labelled block of monospace text on a muted background, for raw text such
7
+ * as output or a diff.
8
+ */
5
9
  export declare function pane(label: string, text: string): HTMLElement;
10
+ /**
11
+ * A terminal-style block showing `$ command`, then its output, then stderr in a
12
+ * quieter tone. Pass `command: null` to show output only; empty parts are left
13
+ * out.
14
+ */
6
15
  export declare function terminal(options: {
7
16
  command: string | null;
8
17
  output?: string;
9
18
  stderr?: string;
10
19
  }): HTMLElement;
20
+ /** The plain-DOM version of ToolViewScroll, holding the given elements. */
11
21
  export declare function scrollRegion(children: readonly HTMLElement[]): HTMLElement;
22
+ /**
23
+ * The plain-DOM version of ToolViewCard, holding the given elements under an
24
+ * optional title.
25
+ */
12
26
  export declare function card(children: readonly HTMLElement[], title?: string): HTMLElement;
27
+ /**
28
+ * The plain-DOM version of ToolViewRow, without a link; `below` adds an element
29
+ * under the title and second line.
30
+ */
13
31
  export declare function listRow(options: {
14
32
  title: string;
15
33
  secondary?: string;
@@ -17,25 +35,73 @@ export declare function listRow(options: {
17
35
  icon?: Element;
18
36
  below?: HTMLElement;
19
37
  }): HTMLElement;
38
+ /**
39
+ * The plain-DOM version of ToolViewFacts, from `[label, value]` pairs in order.
40
+ */
20
41
  export declare function factRows(facts: readonly (readonly [label: string, value: string | HTMLElement])[]): HTMLElement;
42
+ /**
43
+ * The plain-DOM version of ToolViewCaption, with optional trailing content on
44
+ * the right.
45
+ */
21
46
  export declare function captionRow(text: string, trailing?: HTMLElement | string): HTMLElement;
22
47
  export declare function badge(text: string): HTMLElement;
48
+ /** The plain-DOM version of ToolViewBones, with `count` skeleton lines. */
23
49
  export declare function boneRows(count: number): HTMLElement;
50
+ /** The plain-DOM version of ToolViewNote. */
24
51
  export declare function note(text: string): HTMLElement;
52
+ /**
53
+ * Returns the value if it is a plain object (not null and not an array), else
54
+ * null. Handy for reading `call.args` or `call.result` safely.
55
+ */
25
56
  export declare function recordOf(value: unknown): Record<string, unknown> | null;
26
57
  export declare function stringOf(value: unknown): string | null;
27
58
  export declare function statelessToolView(render: (props: ToolViewProps) => HTMLElement): ToolViewAdapter;
59
+ /**
60
+ * True when the call finished successfully and its own result is available
61
+ * (status "output-available" and not offloaded). Check it before drawing a
62
+ * result.
63
+ */
28
64
  export declare function settledWithResult(call: ToolViewCall): boolean;
65
+ /**
66
+ * The same as settledOutcomeNoteOf, as a list of zero or one note elements
67
+ * ready to append in a plain-DOM view.
68
+ */
29
69
  export declare function settledOutcomeNotesOf(call: ToolViewCall): HTMLElement[];
70
+ /**
71
+ * A short sentence for a call that ended without a usable result (failed,
72
+ * declined, not approved, didn't run, interrupted, or result replaced by a
73
+ * preview). Null while the call is running or when it finished normally.
74
+ */
30
75
  export declare function settledOutcomeNoteOf(call: ToolViewCall): string | null;
76
+ /** An action's recorded HTTP response, as read by actionEnvelopeOf. */
31
77
  export interface ActionEnvelope {
78
+ /** The HTTP status code your API returned, or null if none was recorded. */
32
79
  status: number | null;
80
+ /** Your API's response body as recorded. */
33
81
  body: unknown;
82
+ /**
83
+ * True when the body was cut to fit a size limit, so it is not complete.
84
+ */
34
85
  truncated: boolean;
35
86
  }
87
+ /**
88
+ * Reads an action call's `resultText` into your API's HTTP status, response
89
+ * body and whether the body was cut short. Returns null when the text is not an
90
+ * action's successful result.
91
+ */
36
92
  export declare function actionEnvelopeOf(resultText: string | undefined): ActionEnvelope | null;
93
+ /** A failed action's reason, as read by actionFailureOf. */
37
94
  export interface ActionFailure {
95
+ /**
96
+ * The failure sentence as recorded, including wording meant for the agent.
97
+ * Use humanFailureSentenceOf to show it to a user.
98
+ */
38
99
  message: string;
100
+ /**
101
+ * The HTTP status, your API's error code and its per-field problems (`path`
102
+ * and `message`, in the API's order) when the failure named them, else
103
+ * null. `fieldsOmitted` counts further problems left out of `fields`.
104
+ */
39
105
  detail: {
40
106
  status: number;
41
107
  code: string;
@@ -46,6 +112,16 @@ export interface ActionFailure {
46
112
  fieldsOmitted?: number;
47
113
  } | null;
48
114
  }
115
+ /**
116
+ * Reads a failed action call's `errorText` into its message plus, when the
117
+ * failure named them, the HTTP status, error code and per-field problems.
118
+ * Returns null when there is no error text or it is not a failure.
119
+ */
49
120
  export declare function actionFailureOf(errorText: string | undefined): ActionFailure | null;
121
+ /**
122
+ * Turns a call's `errorText` into a sentence fit to show the user, removing the
123
+ * HTTP status and code, the field problems and the instructions meant for the
124
+ * agent. Text that is not an action failure comes back unchanged.
125
+ */
50
126
  export declare function humanFailureSentenceOf(errorText: string): string;
51
127
  export declare function fileGlyph(): SVGElement;
@@ -23,9 +23,9 @@ export function Transcript({ surface }) {
23
23
  const { pendingSend } = useConversation();
24
24
  const connection = useCell(store.connection);
25
25
  const { approvalCards, approvalSurface, elicitationSurface } = useDecisionSurfaces(store);
26
- const { rows, displayRows, running, turnOpen, decisionsPending, activity } = useTranscript({ surface });
26
+ const { displayRows, running, turnOpen, decisionsPending, activity } = useTranscript({ surface });
27
27
  const rowIndexByToolCallId = useMemo(() => _rowIndexByToolCallIdOf(displayRows), [displayRows]);
28
- const dispatches = useThreadDispatches(session, connection?.threadId ?? null, rows, store.noteDispatchSettled, store.noteDispatchPaused);
28
+ const dispatches = useThreadDispatches(session, connection?.threadId ?? null);
29
29
  const dispatchesJoin = useMemo(() => ({ byOrdinal: dispatches }), [dispatches]);
30
30
  const coworkerWork = useCell(store.coworkerWork);
31
31
  if (connection === null) {
@@ -1,2 +1,7 @@
1
1
  import type { AssistantActivitySnapshot } from "../core/activity.js";
2
+ /**
3
+ * Returns a live summary of the assistant's state for badges or presence
4
+ * indicators elsewhere in your UI, updating as the conversation changes on any
5
+ * surface. Call it inside the provider or `TeaflaskAssistant`.
6
+ */
2
7
  export declare function useAssistantActivity(): AssistantActivitySnapshot;
@@ -1,23 +1,120 @@
1
1
  import type { ServingAssistantThread } from "../contract/threads.js";
2
- import type { ActiveConversation, ComposerContract } from "../core/conversation-store.js";
2
+ import type { ComposerContract } from "../core/conversation-store.js";
3
3
  import type { PendingDecisionGap } from "../core/pending-decision-gap.js";
4
4
  import type { ServingApiError } from "../transport/serving-error.js";
5
+ /** The conversation on screen. */
6
+ export interface OpenConversation {
7
+ /**
8
+ * The conversation's server record, including its id, title, whether a
9
+ * reply is running, timestamps and saved model choice.
10
+ */
11
+ thread: ServingAssistantThread;
12
+ }
13
+ /**
14
+ * The open conversation, the visitor's history, the notices worth showing, and
15
+ * the actions that move between conversations, as returned by
16
+ * useAssistantConversation().
17
+ */
5
18
  export interface AssistantConversation {
19
+ /**
20
+ * Set when the assistant cannot start because of a configuration problem
21
+ * (code PUBLISHABLE_KEY_INVALID, ORIGIN_NOT_ALLOWED, END_USER_TOKEN_INVALID
22
+ * or END_USER_ID_MISMATCH); show it instead of the conversation. Null
23
+ * otherwise, and cleared once a session starts successfully.
24
+ */
6
25
  setupError: ServingApiError | null;
7
- conversation: ActiveConversation | null;
26
+ /**
27
+ * The conversation on screen, or null when none is open (a fresh
28
+ * conversation has no record until its first message is sent).
29
+ */
30
+ conversation: OpenConversation | null;
31
+ /**
32
+ * The visitor's past conversations (up to 200), for a history list. Only
33
+ * loaded for an identified visitor; empty for anonymous visitors.
34
+ */
8
35
  threads: ServingAssistantThread[];
36
+ /**
37
+ * True when the visitor is identified (you passed a userId, or their
38
+ * session is signed in), so a history list makes sense; false for an
39
+ * anonymous visitor.
40
+ */
9
41
  historyExpected: boolean;
42
+ /**
43
+ * True while a conversation is loading (a stored conversation at startup,
44
+ * or one picked with openThread); show a loading state rather than the
45
+ * empty state.
46
+ */
10
47
  threadOpening: boolean;
48
+ /**
49
+ * Increases each time the live connection restarts (after each send, a
50
+ * retry, or an automatic reconnect). Use it with the conversation id as a
51
+ * React key if you want your transcript subtree to remount on reconnect.
52
+ */
11
53
  reconnectNonce: number;
54
+ /**
55
+ * The composer's state and controls for this conversation, the same value
56
+ * useConversation() returns.
57
+ */
12
58
  composerContract: ComposerContract;
59
+ /**
60
+ * A sentence to show the visitor when sending a message, opening a
61
+ * conversation or stopping a reply failed. Null otherwise; cleared by the
62
+ * next send, open or new conversation.
63
+ */
13
64
  sendError: string | null;
65
+ /**
66
+ * A sentence to show when the newest reply failed. Null when it didn't, and
67
+ * also once the transcript itself shows that failure as a receipt row, so
68
+ * you never show it twice.
69
+ */
14
70
  turnFailure: string | null;
71
+ /**
72
+ * True when the connection dropped while a reply was in progress; show a
73
+ * notice with a Retry button that calls retryStream. Never true while the
74
+ * visitor is stopping a reply.
75
+ */
15
76
  showInterruptionBanner: boolean;
77
+ /**
78
+ * Set when the agent is waiting on an approval or question that this page
79
+ * could not display (after a short grace period). Show a notice with a
80
+ * Retry button that calls refreshConversation; null otherwise.
81
+ */
16
82
  pendingDecisionGap: PendingDecisionGap | null;
83
+ /**
84
+ * Reconnects to the conversation and replays it from the start, clearing
85
+ * the interruption notice. Use it as the interruption notice's Retry.
86
+ */
17
87
  retryStream: () => void;
88
+ /**
89
+ * Re-reads the open conversation from the server and applies what it finds.
90
+ * Does nothing when no conversation is open; network failures are ignored.
91
+ */
18
92
  refreshConversation: () => Promise<void>;
93
+ /**
94
+ * Opens one of the visitor's past conversations (from threads) and makes it
95
+ * the one resumed next time. While it loads, threadOpening is true; if it
96
+ * can't be opened, sendError is set, and a conversation that no longer
97
+ * exists is removed from threads.
98
+ */
19
99
  openThread: (thread: ServingAssistantThread) => void;
100
+ /**
101
+ * Leaves the current conversation and shows an empty one. Clears the unsent
102
+ * draft, staged attachments, unsent question answers and model choice; the
103
+ * new conversation is created when the first message is sent.
104
+ */
20
105
  startNewConversation: () => void;
106
+ /**
107
+ * Re-opens the conversation this browser last used, as saved for this
108
+ * publishable key; if none is saved, an open conversation is closed. The
109
+ * provider calls it once at startup; call it again when your UI reopens if
110
+ * another surface may have switched conversations meanwhile.
111
+ */
21
112
  resumeStoredThread: () => void;
22
113
  }
114
+ /**
115
+ * Returns the live state and controls of the assistant conversation, for
116
+ * building your own UI. Must be called inside <TeaflaskAssistantProvider> (it
117
+ * throws otherwise); every component that calls it reads the same conversation
118
+ * as the widget, drawer, palette and full-page assistant.
119
+ */
23
120
  export declare function useAssistantConversation(): AssistantConversation;
@@ -1,2 +1,7 @@
1
1
  import type { ReadonlyCell } from "../core/observable-cell.js";
2
+ /**
3
+ * Subscribes a React component to an observable value such as composerInput and
4
+ * returns its current value, re-rendering when it changes. Server rendering
5
+ * gets the initial value.
6
+ */
2
7
  export declare function useCell<T>(cell: ReadonlyCell<T>): T;
@@ -1,374 +1,16 @@
1
1
  "use client";
2
2
  import { useCallback, useEffect, useMemo } from "react";
3
- import { dispatchIsPaused, dispatchIsRunning, } from "../contract/dispatches.js";
4
- import { ObservableCell } from "../core/observable-cell.js";
5
- import { dispatchReceiptOf } from "../core/subagent-rows.js";
6
- import { listThreadDispatches } from "../transport/serving-api.js";
7
- import { resolvedSubagentEntryOf } from "./subagent-group-row.js";
3
+ import { dispatchIsRunning, } from "../contract/dispatches.js";
4
+ import { EMPTY_THREAD_DISPATCHES, newestRowForSession, threadDispatchLedgerFor, } from "../core/thread-dispatch-ledger.js";
8
5
  import { useCell } from "./use-store-cell.js";
9
- const POLL_INTERVAL_MS = 10_000;
10
- const MAX_CONSECUTIVE_READ_FAILURES = 3;
11
- const READ_BOUND_MS = 2 * POLL_INTERVAL_MS;
12
- const EMPTY_LEDGER = new Map();
13
- const RESUME_SUBAGENT_TOOL_NAME = "resume_subagent";
14
- function aResumeAwaitsLedgerTruth(rows, ledger) {
15
- return rows.some((row) => {
16
- if (row.kind !== "tool-call" ||
17
- row.toolName !== RESUME_SUBAGENT_TOOL_NAME) {
18
- return false;
19
- }
20
- const receipt = dispatchReceiptOf(row.result);
21
- if (receipt === null || receipt.outcome === "already_settled") {
22
- return false;
23
- }
24
- const dispatched = ledger.get(receipt.ordinal);
25
- return dispatched === undefined || dispatchIsRunning(dispatched);
26
- });
27
- }
28
- function newestRowForSession(map, childSessionId) {
29
- let newest;
30
- for (const dispatch of map.values()) {
31
- if (dispatch.child_session_id !== childSessionId) {
32
- continue;
33
- }
34
- if (newest === undefined || dispatch.ordinal > newest.ordinal) {
35
- newest = dispatch;
36
- }
37
- }
38
- return newest;
39
- }
40
- function anySubagentStillRunning(rows, ledger) {
41
- return rows.some((row) => row.kind === "subagent-group" &&
42
- row.entries.some((entry) => entry.receipt != null &&
43
- resolvedSubagentEntryOf(entry, ledger).running));
44
- }
45
- class ThreadDispatchLedger {
46
- session;
47
- cell = new ObservableCell(null);
48
- demands = new Map();
49
- timer = null;
50
- timerThreadId = null;
51
- busy = false;
52
- readThreadId = null;
53
- pendingThreadId = null;
54
- failedThreadId = null;
55
- consecutiveFailures = 0;
56
- constructor(session) {
57
- this.session = session;
58
- }
59
- settleListeners = new Map();
60
- setSettleListener(token, listener) {
61
- if (listener === null) {
62
- this.settleListeners.delete(token);
63
- }
64
- else {
65
- this.settleListeners.set(token, listener);
66
- }
67
- }
68
- pauseListeners = new Map();
69
- setPauseListener(token, listener) {
70
- if (listener === null) {
71
- this.pauseListeners.delete(token);
72
- }
73
- else {
74
- this.pauseListeners.set(token, listener);
75
- }
76
- }
77
- setDemand(token, demand) {
78
- if (demand === null) {
79
- this.demands.delete(token);
80
- }
81
- else {
82
- this.demands.set(token, demand);
83
- }
84
- this._reconcile();
85
- }
86
- refresh(threadId) {
87
- if (!this.busy) {
88
- return this._readOnce(threadId);
89
- }
90
- if (this.followUp === null || this.followUpThreadId !== threadId) {
91
- this.followUpThreadId = threadId;
92
- this.followUp = (this.flight ?? Promise.resolve()).then(() => {
93
- this.followUp = null;
94
- this.followUpThreadId = null;
95
- return this._readOnce(threadId);
96
- });
97
- }
98
- return this.followUp;
99
- }
100
- followUp = null;
101
- followUpThreadId = null;
102
- _reconcile() {
103
- let threadId = null;
104
- let delegated = false;
105
- let stillMoving = false;
106
- for (const demand of this.demands.values()) {
107
- threadId ??= demand.threadId;
108
- delegated ||= demand.delegated;
109
- stillMoving ||= demand.stillMoving;
110
- }
111
- if (this.pendingThreadId !== null && this.pendingThreadId !== threadId) {
112
- this.pendingThreadId = null;
113
- }
114
- if (threadId === null || !delegated) {
115
- this._stopTimer();
116
- return;
117
- }
118
- if (this.readThreadId !== threadId) {
119
- void this._readOnce(threadId);
120
- }
121
- if (!stillMoving) {
122
- this._stopTimer();
123
- return;
124
- }
125
- if (this.timer === null || this.timerThreadId !== threadId) {
126
- this._stopTimer();
127
- void this._readOnce(threadId);
128
- this.timerThreadId = threadId;
129
- this.timer = window.setInterval(() => {
130
- void this._readOnce(threadId);
131
- }, POLL_INTERVAL_MS);
132
- }
133
- }
134
- _sameAsCurrent(next) {
135
- const current = this.cell.get();
136
- if (current?.threadId !== next.threadId) {
137
- return false;
138
- }
139
- if (current.map.size !== next.map.size) {
140
- return false;
141
- }
142
- for (const [ordinal, dispatch] of next.map) {
143
- const held = current.map.get(ordinal);
144
- if (held?.status !== dispatch.status ||
145
- held.error !== dispatch.error ||
146
- held.updated_at !== dispatch.updated_at) {
147
- return false;
148
- }
149
- }
150
- return true;
151
- }
152
- _stopTimer() {
153
- if (this.timer !== null) {
154
- window.clearInterval(this.timer);
155
- this.timer = null;
156
- this.timerThreadId = null;
157
- }
158
- }
159
- _readOnce(threadId) {
160
- if (this.busy) {
161
- if (threadId !== this.readThreadId) {
162
- this.pendingThreadId = threadId;
163
- }
164
- return this.flight ?? Promise.resolve();
165
- }
166
- this.busy = true;
167
- this.readThreadId = threadId;
168
- this.generation += 1;
169
- const generation = this.generation;
170
- let settleFlight;
171
- const flight = new Promise((resolve) => {
172
- settleFlight = resolve;
173
- });
174
- this.flight = flight;
175
- window.setTimeout(() => {
176
- this._releaseBoundedOutRead(threadId, generation);
177
- settleFlight();
178
- }, READ_BOUND_MS);
179
- void this._read(threadId, generation, settleFlight);
180
- return flight;
181
- }
182
- flight = null;
183
- generation = 0;
184
- _releaseBoundedOutRead(threadId, generation) {
185
- if (generation !== this.generation || !this.busy) {
186
- return;
187
- }
188
- this.generation += 1;
189
- this.busy = false;
190
- this.flight = null;
191
- this._noteReadFailure(threadId);
192
- this._replayParkedSwitch();
193
- }
194
- _noteReadFailure(threadId) {
195
- this.consecutiveFailures =
196
- this.failedThreadId === threadId ? this.consecutiveFailures + 1 : 1;
197
- this.failedThreadId = threadId;
198
- if (this.consecutiveFailures >= MAX_CONSECUTIVE_READ_FAILURES &&
199
- this.timerThreadId === threadId) {
200
- this._stopTimer();
201
- }
202
- if (this.cell.get()?.threadId !== threadId) {
203
- this.readThreadId = null;
204
- }
205
- }
206
- _replayParkedSwitch() {
207
- const pending = this.pendingThreadId;
208
- this.pendingThreadId = null;
209
- if (pending !== null && pending !== this.readThreadId) {
210
- void this._readOnce(pending);
211
- }
212
- }
213
- adoptedThrough = 0;
214
- async _read(threadId, generation, settleFlight) {
215
- const live = () => generation === this.generation;
216
- try {
217
- const dispatches = await listThreadDispatches(this.session, threadId);
218
- const adopts = live() ||
219
- (generation > this.adoptedThrough &&
220
- (this.readThreadId === threadId || this.readThreadId === null));
221
- if (!adopts) {
222
- if (this.failedThreadId === threadId) {
223
- this.failedThreadId = null;
224
- this.consecutiveFailures = 0;
225
- }
226
- return;
227
- }
228
- this.readThreadId ??= threadId;
229
- this.adoptedThrough = generation;
230
- const previous = this.cell.get();
231
- const next = {
232
- threadId,
233
- map: new Map(dispatches.map((dispatch) => [dispatch.ordinal, dispatch])),
234
- };
235
- if (!this._sameAsCurrent(next)) {
236
- this.cell.set(next);
237
- }
238
- this.failedThreadId = null;
239
- this.consecutiveFailures = 0;
240
- if (_observedASettle(previous, next)) {
241
- _fireEach(this.settleListeners);
242
- }
243
- if (_observedAPause(previous, next)) {
244
- _fireEach(this.pauseListeners);
245
- }
246
- }
247
- catch {
248
- if (!live()) {
249
- return;
250
- }
251
- this._noteReadFailure(threadId);
252
- }
253
- finally {
254
- if (live()) {
255
- this.busy = false;
256
- this.flight = null;
257
- settleFlight();
258
- this._replayParkedSwitch();
259
- }
260
- }
261
- }
262
- }
263
- function _fireEach(listeners) {
264
- for (const listener of new Set(listeners.values())) {
265
- try {
266
- listener();
267
- }
268
- catch {
269
- }
270
- }
271
- }
272
- function _observedAPause(previous, next) {
273
- const comparable = previous?.threadId === next.threadId ? previous : null;
274
- for (const [ordinal, dispatch] of next.map) {
275
- if (!dispatchIsPaused(dispatch)) {
276
- continue;
277
- }
278
- const held = comparable?.map.get(ordinal);
279
- if (held === undefined ||
280
- !dispatchIsPaused(held) ||
281
- held.updated_at !== dispatch.updated_at) {
282
- return true;
283
- }
284
- }
285
- return false;
286
- }
287
- function _observedASettle(previous, next) {
288
- if (previous?.threadId !== next.threadId) {
289
- return false;
290
- }
291
- for (const [ordinal, dispatch] of next.map) {
292
- if (dispatchIsRunning(dispatch)) {
293
- continue;
294
- }
295
- const held = previous.map.get(ordinal);
296
- if (held === undefined || dispatchIsRunning(held)) {
297
- return true;
298
- }
299
- }
300
- return false;
301
- }
302
- const _ledgers = new WeakMap();
303
- function _ledgerFor(session) {
304
- let ledger = _ledgers.get(session);
305
- if (ledger === undefined) {
306
- ledger = new ThreadDispatchLedger(session);
307
- _ledgers.set(session, ledger);
308
- }
309
- return ledger;
310
- }
311
- export function useThreadDispatches(session, threadId, rows, onDispatchSettled, onDispatchPaused) {
312
- const ledger = _ledgerFor(session);
313
- const read = useCell(ledger.cell);
314
- const map = read !== null && read.threadId === threadId ? read.map : EMPTY_LEDGER;
315
- const delegated = useMemo(() => rows.some((row) => row.kind === "subagent-group") ||
316
- aResumeAwaitsLedgerTruth(rows, EMPTY_LEDGER), [rows]);
317
- const stillMoving = useMemo(() => anySubagentStillRunning(rows, map) || aResumeAwaitsLedgerTruth(rows, map), [rows, map]);
318
- const token = useMemo(() => ({}), []);
319
- useEffect(() => {
320
- if (threadId === null) {
321
- return;
322
- }
323
- ledger.setDemand(token, { threadId, delegated, stillMoving });
324
- return () => {
325
- ledger.setDemand(token, null);
326
- };
327
- }, [ledger, token, threadId, delegated, stillMoving]);
328
- useEffect(() => {
329
- if (onDispatchSettled === undefined) {
330
- return;
331
- }
332
- ledger.setSettleListener(token, onDispatchSettled);
333
- return () => {
334
- ledger.setSettleListener(token, null);
335
- };
336
- }, [ledger, token, onDispatchSettled]);
337
- useEffect(() => {
338
- if (onDispatchPaused === undefined) {
339
- return;
340
- }
341
- ledger.setPauseListener(token, onDispatchPaused);
342
- return () => {
343
- ledger.setPauseListener(token, null);
344
- };
345
- }, [ledger, token, onDispatchPaused]);
346
- const staleDeliveredOrdinals = useMemo(() => {
347
- const delivered = new Set();
348
- for (const row of rows) {
349
- if (row.kind === "subagent-delivery") {
350
- for (const result of row.results) {
351
- delivered.add(result.ordinal);
352
- }
353
- }
354
- }
355
- return [...delivered]
356
- .filter((ordinal) => {
357
- const ledgerRow = map.get(ordinal);
358
- return ledgerRow !== undefined && dispatchIsRunning(ledgerRow);
359
- })
360
- .sort((a, b) => a - b)
361
- .join(",");
362
- }, [rows, map]);
363
- useEffect(() => {
364
- if (threadId !== null && staleDeliveredOrdinals !== "") {
365
- void ledger.refresh(threadId);
366
- }
367
- }, [ledger, threadId, staleDeliveredOrdinals]);
368
- return map;
6
+ export function useThreadDispatches(session, threadId) {
7
+ const read = useCell(threadDispatchLedgerFor(session).cell);
8
+ return read !== null && read.threadId === threadId
9
+ ? read.map
10
+ : EMPTY_THREAD_DISPATCHES;
369
11
  }
370
12
  export function useChildDispatch(session, threadId, childSessionId) {
371
- const ledger = _ledgerFor(session);
13
+ const ledger = threadDispatchLedgerFor(session);
372
14
  const read = useCell(ledger.cell);
373
15
  const dispatch = read !== null && read.threadId === threadId
374
16
  ? newestRowForSession(read.map, childSessionId)
@@ -4,7 +4,8 @@ import { hostFillDeclines } from "../core/host-fill.js";
4
4
  import { currentTurnStartOf, foldedBlocksOf, runFoldsOf, } from "../core/run-folds.js";
5
5
  import { subagentOutcomeCountsOf } from "../core/subagent-rows.js";
6
6
  import { ElicitationsContext } from "./elicitation-context.js";
7
- import { resolvedSubagentEntryOf, SubagentDispatchesContext, } from "./subagent-group-row.js";
7
+ import { resolvedSubagentEntryOf } from "../core/subagent-ledger-join.js";
8
+ import { SubagentDispatchesContext, } from "./subagent-group-row.js";
8
9
  export function useMessageListDerivations(source, { live, typing, turnOpen, markerBoundaries, turnStartIds, decisionSurfacesInShelf, frameClaimsLiveness, emptyFallback, }) {
9
10
  const { cards: elicitationCards } = useContext(ElicitationsContext);
10
11
  const { foldedBlocks, flatRows, displayRows } = useTranscriptFolds(source, {