@dudko.dev/agent-web-ui 0.0.0 → 0.0.2

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 (283) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +316 -5
  3. package/dist/canvas.cjs +266 -0
  4. package/dist/canvas.cjs.map +1 -0
  5. package/dist/canvas.d.cts +105 -0
  6. package/dist/canvas.d.ts +105 -0
  7. package/dist/canvas.js +200 -0
  8. package/dist/canvas.js.map +1 -0
  9. package/dist/chunk-7O64ZI6Z.js +125 -0
  10. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  11. package/dist/chunk-EL2YCROY.js +127 -0
  12. package/dist/chunk-EL2YCROY.js.map +1 -0
  13. package/dist/chunk-GB7RZJMG.js +98 -0
  14. package/dist/chunk-GB7RZJMG.js.map +1 -0
  15. package/dist/chunk-KZQB35LS.js +22 -0
  16. package/dist/chunk-KZQB35LS.js.map +1 -0
  17. package/dist/chunk-SVYHDLAZ.js +348 -0
  18. package/dist/chunk-SVYHDLAZ.js.map +1 -0
  19. package/dist/chunk-VCR7LU7J.js +348 -0
  20. package/dist/chunk-VCR7LU7J.js.map +1 -0
  21. package/dist/chunk-WFM6B7CL.js +406 -0
  22. package/dist/chunk-WFM6B7CL.js.map +1 -0
  23. package/dist/chunk-WZ7K7JIP.js +348 -0
  24. package/dist/chunk-WZ7K7JIP.js.map +1 -0
  25. package/dist/chunk-ZBHESK6V.js +1440 -0
  26. package/dist/chunk-ZBHESK6V.js.map +1 -0
  27. package/dist/controller.cjs +1891 -0
  28. package/dist/controller.cjs.map +1 -0
  29. package/dist/controller.d.cts +253 -0
  30. package/dist/controller.d.ts +253 -0
  31. package/dist/controller.js +482 -0
  32. package/dist/controller.js.map +1 -0
  33. package/dist/en-Dg2MtzcJ.d.cts +348 -0
  34. package/dist/en-Dg2MtzcJ.d.ts +348 -0
  35. package/dist/index.cjs +4276 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +997 -0
  38. package/dist/index.d.ts +997 -0
  39. package/dist/index.js +2494 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/labels-B5xpIGf_.d.cts +25 -0
  42. package/dist/labels-B5xpIGf_.d.ts +25 -0
  43. package/dist/labels-CmiTBLWD.d.cts +1176 -0
  44. package/dist/labels-DH1ESUtm.d.ts +1176 -0
  45. package/dist/locales/be.cjs +806 -0
  46. package/dist/locales/be.cjs.map +1 -0
  47. package/dist/locales/be.d.cts +16 -0
  48. package/dist/locales/be.d.ts +16 -0
  49. package/dist/locales/be.js +380 -0
  50. package/dist/locales/be.js.map +1 -0
  51. package/dist/locales/bg.cjs +759 -0
  52. package/dist/locales/bg.cjs.map +1 -0
  53. package/dist/locales/bg.d.cts +16 -0
  54. package/dist/locales/bg.d.ts +16 -0
  55. package/dist/locales/bg.js +333 -0
  56. package/dist/locales/bg.js.map +1 -0
  57. package/dist/locales/ca.cjs +785 -0
  58. package/dist/locales/ca.cjs.map +1 -0
  59. package/dist/locales/ca.d.cts +16 -0
  60. package/dist/locales/ca.d.ts +16 -0
  61. package/dist/locales/ca.js +359 -0
  62. package/dist/locales/ca.js.map +1 -0
  63. package/dist/locales/cs.cjs +806 -0
  64. package/dist/locales/cs.cjs.map +1 -0
  65. package/dist/locales/cs.d.cts +16 -0
  66. package/dist/locales/cs.d.ts +16 -0
  67. package/dist/locales/cs.js +380 -0
  68. package/dist/locales/cs.js.map +1 -0
  69. package/dist/locales/da.cjs +759 -0
  70. package/dist/locales/da.cjs.map +1 -0
  71. package/dist/locales/da.d.cts +16 -0
  72. package/dist/locales/da.d.ts +16 -0
  73. package/dist/locales/da.js +333 -0
  74. package/dist/locales/da.js.map +1 -0
  75. package/dist/locales/de.cjs +768 -0
  76. package/dist/locales/de.cjs.map +1 -0
  77. package/dist/locales/de.d.cts +16 -0
  78. package/dist/locales/de.d.ts +16 -0
  79. package/dist/locales/de.js +342 -0
  80. package/dist/locales/de.js.map +1 -0
  81. package/dist/locales/el.cjs +768 -0
  82. package/dist/locales/el.cjs.map +1 -0
  83. package/dist/locales/el.d.cts +16 -0
  84. package/dist/locales/el.d.ts +16 -0
  85. package/dist/locales/el.js +342 -0
  86. package/dist/locales/el.js.map +1 -0
  87. package/dist/locales/en.cjs +765 -0
  88. package/dist/locales/en.cjs.map +1 -0
  89. package/dist/locales/en.d.cts +12 -0
  90. package/dist/locales/en.d.ts +12 -0
  91. package/dist/locales/en.js +339 -0
  92. package/dist/locales/en.js.map +1 -0
  93. package/dist/locales/es-419.cjs +793 -0
  94. package/dist/locales/es-419.cjs.map +1 -0
  95. package/dist/locales/es-419.d.cts +18 -0
  96. package/dist/locales/es-419.d.ts +18 -0
  97. package/dist/locales/es-419.js +26 -0
  98. package/dist/locales/es-419.js.map +1 -0
  99. package/dist/locales/es.cjs +781 -0
  100. package/dist/locales/es.cjs.map +1 -0
  101. package/dist/locales/es.d.cts +16 -0
  102. package/dist/locales/es.d.ts +16 -0
  103. package/dist/locales/es.js +14 -0
  104. package/dist/locales/es.js.map +1 -0
  105. package/dist/locales/fi.cjs +765 -0
  106. package/dist/locales/fi.cjs.map +1 -0
  107. package/dist/locales/fi.d.cts +16 -0
  108. package/dist/locales/fi.d.ts +16 -0
  109. package/dist/locales/fi.js +339 -0
  110. package/dist/locales/fi.js.map +1 -0
  111. package/dist/locales/fr-CA.cjs +789 -0
  112. package/dist/locales/fr-CA.cjs.map +1 -0
  113. package/dist/locales/fr-CA.d.cts +19 -0
  114. package/dist/locales/fr-CA.d.ts +19 -0
  115. package/dist/locales/fr-CA.js +22 -0
  116. package/dist/locales/fr-CA.js.map +1 -0
  117. package/dist/locales/fr.cjs +781 -0
  118. package/dist/locales/fr.cjs.map +1 -0
  119. package/dist/locales/fr.d.cts +16 -0
  120. package/dist/locales/fr.d.ts +16 -0
  121. package/dist/locales/fr.js +14 -0
  122. package/dist/locales/fr.js.map +1 -0
  123. package/dist/locales/gn.cjs +762 -0
  124. package/dist/locales/gn.cjs.map +1 -0
  125. package/dist/locales/gn.d.cts +18 -0
  126. package/dist/locales/gn.d.ts +18 -0
  127. package/dist/locales/gn.js +336 -0
  128. package/dist/locales/gn.js.map +1 -0
  129. package/dist/locales/hr.cjs +781 -0
  130. package/dist/locales/hr.cjs.map +1 -0
  131. package/dist/locales/hr.d.cts +16 -0
  132. package/dist/locales/hr.d.ts +16 -0
  133. package/dist/locales/hr.js +355 -0
  134. package/dist/locales/hr.js.map +1 -0
  135. package/dist/locales/ht.cjs +762 -0
  136. package/dist/locales/ht.cjs.map +1 -0
  137. package/dist/locales/ht.d.cts +18 -0
  138. package/dist/locales/ht.d.ts +18 -0
  139. package/dist/locales/ht.js +336 -0
  140. package/dist/locales/ht.js.map +1 -0
  141. package/dist/locales/hu.cjs +765 -0
  142. package/dist/locales/hu.cjs.map +1 -0
  143. package/dist/locales/hu.d.cts +16 -0
  144. package/dist/locales/hu.d.ts +16 -0
  145. package/dist/locales/hu.js +339 -0
  146. package/dist/locales/hu.js.map +1 -0
  147. package/dist/locales/index.cjs +543 -0
  148. package/dist/locales/index.cjs.map +1 -0
  149. package/dist/locales/index.d.cts +40 -0
  150. package/dist/locales/index.d.ts +40 -0
  151. package/dist/locales/index.js +105 -0
  152. package/dist/locales/index.js.map +1 -0
  153. package/dist/locales/it.cjs +789 -0
  154. package/dist/locales/it.cjs.map +1 -0
  155. package/dist/locales/it.d.cts +16 -0
  156. package/dist/locales/it.d.ts +16 -0
  157. package/dist/locales/it.js +363 -0
  158. package/dist/locales/it.js.map +1 -0
  159. package/dist/locales/nb.cjs +759 -0
  160. package/dist/locales/nb.cjs.map +1 -0
  161. package/dist/locales/nb.d.cts +16 -0
  162. package/dist/locales/nb.d.ts +16 -0
  163. package/dist/locales/nb.js +333 -0
  164. package/dist/locales/nb.js.map +1 -0
  165. package/dist/locales/nl.cjs +765 -0
  166. package/dist/locales/nl.cjs.map +1 -0
  167. package/dist/locales/nl.d.cts +16 -0
  168. package/dist/locales/nl.d.ts +16 -0
  169. package/dist/locales/nl.js +339 -0
  170. package/dist/locales/nl.js.map +1 -0
  171. package/dist/locales/pl.cjs +806 -0
  172. package/dist/locales/pl.cjs.map +1 -0
  173. package/dist/locales/pl.d.cts +16 -0
  174. package/dist/locales/pl.d.ts +16 -0
  175. package/dist/locales/pl.js +380 -0
  176. package/dist/locales/pl.js.map +1 -0
  177. package/dist/locales/pt-BR.cjs +785 -0
  178. package/dist/locales/pt-BR.cjs.map +1 -0
  179. package/dist/locales/pt-BR.d.cts +16 -0
  180. package/dist/locales/pt-BR.d.ts +16 -0
  181. package/dist/locales/pt-BR.js +359 -0
  182. package/dist/locales/pt-BR.js.map +1 -0
  183. package/dist/locales/pt.cjs +789 -0
  184. package/dist/locales/pt.cjs.map +1 -0
  185. package/dist/locales/pt.d.cts +16 -0
  186. package/dist/locales/pt.d.ts +16 -0
  187. package/dist/locales/pt.js +363 -0
  188. package/dist/locales/pt.js.map +1 -0
  189. package/dist/locales/qu.cjs +768 -0
  190. package/dist/locales/qu.cjs.map +1 -0
  191. package/dist/locales/qu.d.cts +18 -0
  192. package/dist/locales/qu.d.ts +18 -0
  193. package/dist/locales/qu.js +342 -0
  194. package/dist/locales/qu.js.map +1 -0
  195. package/dist/locales/ro.cjs +781 -0
  196. package/dist/locales/ro.cjs.map +1 -0
  197. package/dist/locales/ro.d.cts +16 -0
  198. package/dist/locales/ro.d.ts +16 -0
  199. package/dist/locales/ro.js +355 -0
  200. package/dist/locales/ro.js.map +1 -0
  201. package/dist/locales/ru.cjs +801 -0
  202. package/dist/locales/ru.cjs.map +1 -0
  203. package/dist/locales/ru.d.cts +16 -0
  204. package/dist/locales/ru.d.ts +16 -0
  205. package/dist/locales/ru.js +375 -0
  206. package/dist/locales/ru.js.map +1 -0
  207. package/dist/locales/sk.cjs +806 -0
  208. package/dist/locales/sk.cjs.map +1 -0
  209. package/dist/locales/sk.d.cts +16 -0
  210. package/dist/locales/sk.d.ts +16 -0
  211. package/dist/locales/sk.js +380 -0
  212. package/dist/locales/sk.js.map +1 -0
  213. package/dist/locales/sq.cjs +765 -0
  214. package/dist/locales/sq.cjs.map +1 -0
  215. package/dist/locales/sq.d.cts +16 -0
  216. package/dist/locales/sq.d.ts +16 -0
  217. package/dist/locales/sq.js +339 -0
  218. package/dist/locales/sq.js.map +1 -0
  219. package/dist/locales/sr-Latn.cjs +853 -0
  220. package/dist/locales/sr-Latn.cjs.map +1 -0
  221. package/dist/locales/sr-Latn.d.cts +19 -0
  222. package/dist/locales/sr-Latn.d.ts +19 -0
  223. package/dist/locales/sr-Latn.js +86 -0
  224. package/dist/locales/sr-Latn.js.map +1 -0
  225. package/dist/locales/sr.cjs +781 -0
  226. package/dist/locales/sr.cjs.map +1 -0
  227. package/dist/locales/sr.d.cts +16 -0
  228. package/dist/locales/sr.d.ts +16 -0
  229. package/dist/locales/sr.js +14 -0
  230. package/dist/locales/sr.js.map +1 -0
  231. package/dist/locales/sv.cjs +765 -0
  232. package/dist/locales/sv.cjs.map +1 -0
  233. package/dist/locales/sv.d.cts +16 -0
  234. package/dist/locales/sv.d.ts +16 -0
  235. package/dist/locales/sv.js +339 -0
  236. package/dist/locales/sv.js.map +1 -0
  237. package/dist/locales/tr.cjs +762 -0
  238. package/dist/locales/tr.cjs.map +1 -0
  239. package/dist/locales/tr.d.cts +16 -0
  240. package/dist/locales/tr.d.ts +16 -0
  241. package/dist/locales/tr.js +336 -0
  242. package/dist/locales/tr.js.map +1 -0
  243. package/dist/locales/uk.cjs +806 -0
  244. package/dist/locales/uk.cjs.map +1 -0
  245. package/dist/locales/uk.d.cts +16 -0
  246. package/dist/locales/uk.d.ts +16 -0
  247. package/dist/locales/uk.js +380 -0
  248. package/dist/locales/uk.js.map +1 -0
  249. package/dist/markdown.cjs +620 -0
  250. package/dist/markdown.cjs.map +1 -0
  251. package/dist/markdown.d.cts +153 -0
  252. package/dist/markdown.d.ts +153 -0
  253. package/dist/markdown.js +573 -0
  254. package/dist/markdown.js.map +1 -0
  255. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  256. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  257. package/dist/mcp-app-sandbox.cjs +323 -0
  258. package/dist/mcp-app-sandbox.cjs.map +1 -0
  259. package/dist/mcp-app-sandbox.d.cts +70 -0
  260. package/dist/mcp-app-sandbox.d.ts +70 -0
  261. package/dist/mcp-app-sandbox.js +209 -0
  262. package/dist/mcp-app-sandbox.js.map +1 -0
  263. package/dist/mcp-app.cjs +980 -0
  264. package/dist/mcp-app.cjs.map +1 -0
  265. package/dist/mcp-app.d.cts +491 -0
  266. package/dist/mcp-app.d.ts +491 -0
  267. package/dist/mcp-app.js +816 -0
  268. package/dist/mcp-app.js.map +1 -0
  269. package/dist/pipeline.cjs +845 -0
  270. package/dist/pipeline.cjs.map +1 -0
  271. package/dist/pipeline.css +1407 -0
  272. package/dist/pipeline.d.cts +348 -0
  273. package/dist/pipeline.d.ts +348 -0
  274. package/dist/pipeline.js +778 -0
  275. package/dist/pipeline.js.map +1 -0
  276. package/dist/questions-Dw--IEjT.d.cts +100 -0
  277. package/dist/questions-Dw--IEjT.d.ts +100 -0
  278. package/dist/styles.css +4109 -0
  279. package/dist/types-CQquuZpl.d.cts +19 -0
  280. package/dist/types-CXZfZVP5.d.ts +19 -0
  281. package/dist/types-DnBCok3z.d.cts +994 -0
  282. package/dist/types-DnBCok3z.d.ts +994 -0
  283. package/package.json +165 -8
@@ -0,0 +1,994 @@
1
+ import { AgentToolSet, McpAppResource, McpAppToolResult, IPlanStep, ModelTier, TierReason, EscalationReason, DecisionPoint, DecisionFallbackReason, McpSkillConsentView, IUsage, IPlan, AskUserOption, AskUserAction, SessionHolder, ReplanMode, AgentEvent } from '@dudko.dev/agent-web';
2
+
3
+ /**
4
+ * Structural types for the core's OPTIONAL `@dudko.dev/agent-web/mcp` subpath.
5
+ *
6
+ * The subpath is loaded with a dynamic import and typed here rather than
7
+ * imported, for two reasons: it drags in `@modelcontextprotocol/client` (an
8
+ * optional peer of the core, which apps without MCP must not have to install),
9
+ * and the OAuth half only exists in newer cores while this package supports
10
+ * `@dudko.dev/agent-web >= 0.0.6`. `useMcp` feature-detects at runtime and
11
+ * reports `oauthSupported: false` on an older core instead of crashing.
12
+ */
13
+ interface McpCatalogEntry {
14
+ name: string;
15
+ description: string;
16
+ server: string;
17
+ /** The server marked the tool read-only (newer cores). */
18
+ readOnly?: boolean;
19
+ /** With `apps: true`: the MCP App (`ui://…`) the tool declares (newer cores). */
20
+ app?: string;
21
+ }
22
+ interface McpServerResult {
23
+ name: string;
24
+ connected: boolean;
25
+ error?: string;
26
+ needsAuthorization?: boolean;
27
+ }
28
+ /** The `instructions` one connected server returned in its `initialize` result. */
29
+ interface McpServerInstructions {
30
+ /** The server's name: its key in the configuration. */
31
+ server: string;
32
+ instructions: string;
33
+ }
34
+ /**
35
+ * Which revisions of the MCP protocol a connection may use (the core's per-server `protocol`):
36
+ * `'legacy'` (default) the 2025 revisions, `'auto'` 2026-07-28 when the server offers it and the
37
+ * 2025 ones otherwise, `'modern'` 2026-07-28 only.
38
+ */
39
+ type McpProtocolMode = 'legacy' | 'auto' | 'modern';
40
+ /** What a connection negotiated with one server. */
41
+ interface McpServerProtocol {
42
+ /** The server's name: its key in the configuration. */
43
+ server: string;
44
+ /** The protocol revision in use, e.g. `2025-11-25` or `2026-07-28`. */
45
+ version: string;
46
+ era: 'legacy' | 'modern';
47
+ }
48
+ interface ConnectedMcp {
49
+ tools: AgentToolSet;
50
+ catalog: McpCatalogEntry[];
51
+ results: McpServerResult[];
52
+ /**
53
+ * What each connected server told the agent in its handshake (newer cores; absent on older
54
+ * ones). THIRD-PARTY text: the core puts it in the system prompt of an agent that uses the
55
+ * server's tools, so a host should let the user see it.
56
+ */
57
+ instructions?: McpServerInstructions[];
58
+ /** The protocol revision negotiated with each connected server (cores with `protocol`). */
59
+ protocols?: McpServerProtocol[];
60
+ refreshServer?: (name: string) => Promise<void>;
61
+ close: () => Promise<void>;
62
+ /** MCP Apps, on a connection made with `apps: true` (newer cores; absent otherwise). */
63
+ apps?: McpAppsConnectionLike;
64
+ }
65
+ interface McpHttpServerConfig {
66
+ url: string;
67
+ headers?: Record<string, string>;
68
+ authProvider?: unknown;
69
+ /** Per-server connect deadline (newer cores; ignored by older ones). */
70
+ connectTimeoutMs?: number;
71
+ /**
72
+ * The MCP protocol revisions this connection may use (newer cores; an older one ignores the
73
+ * field and speaks the 2025 revisions). The hooks set it only for a server that was given a
74
+ * `protocol`. From a page, `'auto'` and `'modern'` need `Mcp-Method` and `Mcp-Name` in the
75
+ * server's `Access-Control-Allow-Headers`.
76
+ */
77
+ protocol?: McpProtocolMode;
78
+ /**
79
+ * EXPERIMENTAL: load the server's skills (the `io.modelcontextprotocol/skills` extension) into
80
+ * the agent's catalog, as `<server>/<skill>` (cores with MCP skills; an older one ignores the
81
+ * field). Needs `protocol: 'auto'` or `'modern'`. The hooks set it only for a server that was
82
+ * given `skills` (`true`, or `{ consent, dynamic }` - a core with skill consent; an older one
83
+ * reads any object as off). `dynamic: true` also takes the server's generated skills (a core
84
+ * with snapshots of them; an older one ignores it and declines them).
85
+ */
86
+ skills?: true | {
87
+ consent?: 'ask' | 'once-per-skill' | 'never';
88
+ dynamic?: boolean;
89
+ };
90
+ /**
91
+ * MCP Apps for this server alone, over the connection's `apps` (cores with per-server apps;
92
+ * an older one ignores it). `false`: its apps are not shown - nothing declared, no app read,
93
+ * its app-only tools not mounted. The hooks set it only for a server that was given `apps`.
94
+ */
95
+ apps?: boolean;
96
+ }
97
+ /**
98
+ * One field of a form a server asks the user to fill in (MCP elicitation): the flat subset of
99
+ * JSON Schema the specification allows. The core has already checked, cleaned and capped it.
100
+ */
101
+ interface McpElicitationFieldSchema {
102
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
103
+ title?: string;
104
+ description?: string;
105
+ default?: string | number | boolean | string[];
106
+ minLength?: number;
107
+ maxLength?: number;
108
+ format?: 'email' | 'uri' | 'date' | 'date-time';
109
+ /** Single-select, plain (`enumNames`: the older titled form). */
110
+ enum?: string[];
111
+ enumNames?: string[];
112
+ /** Single-select with titles. */
113
+ oneOf?: {
114
+ const: string;
115
+ title: string;
116
+ }[];
117
+ minimum?: number;
118
+ maximum?: number;
119
+ /** Multi-select. */
120
+ minItems?: number;
121
+ maxItems?: number;
122
+ items?: {
123
+ type?: 'string';
124
+ enum?: string[];
125
+ anyOf?: {
126
+ const: string;
127
+ title: string;
128
+ }[];
129
+ };
130
+ }
131
+ /** The form of an elicitation, as the core hands it to a host. */
132
+ interface McpElicitationSchema {
133
+ type: 'object';
134
+ properties: Record<string, McpElicitationFieldSchema>;
135
+ required?: string[];
136
+ }
137
+ /**
138
+ * What the core's `onElicitation` callback is given: an MCP server asks the user for input in
139
+ * the middle of a tool call. Every string in it is the SERVER's text, never instructions.
140
+ */
141
+ interface McpElicitationRequest {
142
+ /** Unique per question; the `mcp.elicitation-*` events carry the same id. */
143
+ id: string;
144
+ server: string;
145
+ /** The tool call during which the server asks: the tool's name as the model called it. */
146
+ tool: string;
147
+ mode: 'form' | 'url';
148
+ message: string;
149
+ /** Form mode: the fields to fill in. */
150
+ requestedSchema?: McpElicitationSchema;
151
+ /** URL mode: a link the server wants the user to open. The core never opens it. */
152
+ url?: string;
153
+ elicitationId?: string;
154
+ runId?: string;
155
+ /** Set when a helper (a subagent) is the one whose call asks. */
156
+ subagent?: {
157
+ id: string;
158
+ depth: number;
159
+ };
160
+ }
161
+ /** The answer to an elicitation. `accept` carries the form's values (form mode only). */
162
+ type McpElicitationResult = {
163
+ action: 'accept';
164
+ content?: Record<string, string | number | boolean | string[]>;
165
+ } | {
166
+ action: 'decline';
167
+ } | {
168
+ action: 'cancel';
169
+ };
170
+ /** The core's `onElicitation`. `ctx.signal` aborts when the answer is no longer wanted. */
171
+ type McpElicitationHandler = (request: McpElicitationRequest, ctx: {
172
+ signal: AbortSignal;
173
+ }) => McpElicitationResult | Promise<McpElicitationResult>;
174
+ /** The core's `elicitation` settings (all optional; see the core's README). */
175
+ interface McpElicitationOptions {
176
+ timeoutMs?: number;
177
+ maxPerToolCall?: number;
178
+ maxPerRun?: number;
179
+ /** Also accept URL mode. Default false. */
180
+ url?: boolean;
181
+ /** Let a subagent's call ask the user too. Default false. */
182
+ subagents?: boolean;
183
+ }
184
+ interface McpOAuthCallback {
185
+ code?: string;
186
+ state?: string;
187
+ /** The `iss` parameter of the response (RFC 9207); the core checks it. */
188
+ iss?: string;
189
+ error?: string;
190
+ errorDescription?: string;
191
+ }
192
+ /**
193
+ * How a server's OAuth client is registered (the core's `McpOAuthRegistration`): `'auto'` the
194
+ * client ID metadata document (CIMD) where the authorization server supports it and dynamic
195
+ * registration (DCR) otherwise, `'cimd'` the document only, `'dcr'` dynamic registration only.
196
+ */
197
+ type McpOAuthRegistration = 'auto' | 'cimd' | 'dcr';
198
+ /** How a stored OAuth client was registered (the core's `McpOAuthRegistrationKind`). */
199
+ type McpOAuthRegistrationKind = 'cimd' | 'dcr';
200
+ interface BrowserOAuthProvider {
201
+ serverUrl: string;
202
+ authorizationUrl?: URL;
203
+ /** The provider's `registration`. Absent on cores older than the option. */
204
+ readonly registration?: McpOAuthRegistration;
205
+ /** How the stored client was registered. Absent on cores older than the option. */
206
+ registrationKind?(): Promise<McpOAuthRegistrationKind | undefined>;
207
+ isAuthorized(): Promise<boolean>;
208
+ reset(): Promise<void>;
209
+ }
210
+ interface BrowserOAuthProviderOptions {
211
+ serverUrl: string;
212
+ redirectUrl: string;
213
+ clientName?: string;
214
+ scope?: string;
215
+ /** Client ID metadata document URL (CIMD). Cores without it ignore the field. */
216
+ clientMetadataUrl?: string;
217
+ /**
218
+ * How the client is registered. Cores without it ignore the field - which is why the hooks
219
+ * refuse a `'cimd'` / `'dcr'` such a core did not take (`newMcpOAuthProvider`).
220
+ */
221
+ registration?: McpOAuthRegistration;
222
+ }
223
+ /** The shape of the subpath module, as far as this package uses it. */
224
+ interface McpModule {
225
+ connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opts?: {
226
+ clientName?: string;
227
+ onLog?: (level: string, message: string) => void;
228
+ connectTimeoutMs?: number;
229
+ /**
230
+ * Answer a server's question to the user (cores with MCP elicitation; an older core
231
+ * ignores both fields and declares no capability). The hooks set them only when their
232
+ * `elicitation` option is on.
233
+ */
234
+ onElicitation?: McpElicitationHandler;
235
+ elicitation?: McpElicitationOptions;
236
+ /** MCP Apps (cores with the extension; an older core ignores it and declares nothing). */
237
+ apps?: boolean;
238
+ }) => Promise<ConnectedMcp>;
239
+ BrowserOAuthProvider?: new (opts: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
240
+ readOAuthCallback?: (input?: string | URL) => McpOAuthCallback | undefined;
241
+ finishMcpOAuth?: (provider: BrowserOAuthProvider, callback: McpOAuthCallback) => Promise<void>;
242
+ /**
243
+ * The SDK's error class, re-exported by the core so an authorization failure
244
+ * can be recognised by identity (`@modelcontextprotocol/client` on a core on
245
+ * the 2.x MCP SDK, `@modelcontextprotocol/sdk` before). Absent on cores older
246
+ * than 0.0.12.
247
+ */
248
+ UnauthorizedError?: new (message?: string) => Error;
249
+ }
250
+ /**
251
+ * The connection's side of MCP Apps, structurally: the core's `ConnectedMcp.apps` (`./mcp`,
252
+ * `apps: true`), or the one `useMcp` / `useMcpServers` return. Every method names the server,
253
+ * and the host always passes the app's OWN server: an app reads and calls only what its server
254
+ * declared.
255
+ */
256
+ interface McpAppsConnectionLike {
257
+ readUiResource: (server: string, uri: string, options?: {
258
+ signal?: AbortSignal;
259
+ }) => Promise<McpAppResource>;
260
+ appTool: (server: string, name: string) => {
261
+ key: string;
262
+ readOnly: boolean;
263
+ description?: string;
264
+ inputSchema?: unknown;
265
+ /** The server's identity on its connection (newer cores): what a grant is kept under. */
266
+ serverId?: string;
267
+ } | undefined;
268
+ callAppTool: (server: string, name: string, args: Record<string, unknown>, options?: {
269
+ signal?: AbortSignal;
270
+ }) => Promise<McpAppToolResult>;
271
+ /**
272
+ * A resource of that server for a file its app asks to save (a `resource_link`): the core's
273
+ * `ConnectedMcp.apps.readResource` - `resources/read` on that server, never a fetch. Older
274
+ * cores have none: a linked file is then refused.
275
+ */
276
+ readResource?: (server: string, uri: string, options?: {
277
+ signal?: AbortSignal;
278
+ maxBytes?: number;
279
+ }) => Promise<{
280
+ uri: string;
281
+ mimeType?: string;
282
+ bytes: Uint8Array;
283
+ }>;
284
+ }
285
+
286
+ /** Why a run stopped early (a `budget.exceeded` event). */
287
+ interface BudgetView {
288
+ kind: 'input' | 'output' | 'reasoning' | 'total' | 'tool-calls';
289
+ tokens: number;
290
+ cap: number;
291
+ }
292
+ /**
293
+ * Lifecycle of the agent instance the hook owns.
294
+ * - `idle` — no config yet, nothing built.
295
+ * - `initializing` — building the agent (dynamic provider imports, vault key
296
+ * fetch, and — for WebLLM — weight download).
297
+ * - `ready` — the agent is built and can run.
298
+ * - `running` — a run is in flight.
299
+ * - `error` — the agent failed to build (a run error keeps it `ready`).
300
+ */
301
+ type AgentStatus = 'idle' | 'initializing' | 'ready' | 'running' | 'error';
302
+ /** A file or image shown with a message (and, for images, sent to the model). */
303
+ interface ChatAttachment {
304
+ name: string;
305
+ mediaType: string;
306
+ /** A data URL (images: thumbnail + full view) — kept so a saved chat can show it again. */
307
+ dataUrl?: string;
308
+ /** Where it was stored in the virtual file system, if it was. */
309
+ path?: string;
310
+ size?: number;
311
+ /** A recording's length in milliseconds, as the recorder measured it (a voice message). */
312
+ durationMs?: number;
313
+ }
314
+ /** One turn of the chat transcript that a chat UI renders. */
315
+ interface ChatMessage {
316
+ id: string;
317
+ role: 'user' | 'assistant';
318
+ content: string;
319
+ /** An assistant message that is still streaming (no final/stopped/error yet). */
320
+ pending: boolean;
321
+ /**
322
+ * A turn of a run in another tab, as relayed here (`AgentUiState.remote`): that tab saves it.
323
+ * `useChatHistory` saves a chat from here with that tab's own copy, never this one.
324
+ */
325
+ remote?: true;
326
+ /**
327
+ * When the run of its turn began (ms epoch: the hook's `at` on `run.start`); the user message and
328
+ * the answer of a turn carry the same. Absent without the hook's timestamps and on chats saved
329
+ * before it existed. It keeps a turn in its place when two tabs save one chat: one run of a
330
+ * conversation goes at a time (the session lock), so the turn that began first is the earlier
331
+ * one, whichever tab saved first (`mergeChatRecord`).
332
+ */
333
+ startedAt?: number;
334
+ /** User turn: what was attached (images, files). */
335
+ attachments?: ChatAttachment[];
336
+ /** Assistant turn: the run's steps — tool calls, thoughts, subagents — as they happened. */
337
+ steps?: StepView[];
338
+ /** Assistant turn: consent decisions of the run. */
339
+ approvals?: ApprovalView[];
340
+ /** Assistant turn: subagent delegations of the run. */
341
+ subagents?: SubagentView[];
342
+ /** Assistant turn: what the user said while the run was going, and where it reached the agent. */
343
+ notes?: UserNoteView[];
344
+ /** Assistant turn: the synthesizer's thoughts. */
345
+ reasoning?: string;
346
+ /** Assistant turn: tokens the run spent, by kind. */
347
+ usage?: IUsage;
348
+ /** Assistant turn: wall-clock duration of the run (needs timestamps from the hook). */
349
+ durationMs?: number;
350
+ /** Assistant turn: skills the run used. */
351
+ skills?: string[];
352
+ /** Assistant turn: lessons the agent wrote down during the run (names). */
353
+ learned?: string[];
354
+ /** Assistant turn: what the model fetched from the web during the run. */
355
+ fetches?: FetchView[];
356
+ /** Assistant turn: the images and audio the run generated (`config.media`); absent when none. */
357
+ media?: MediaView[];
358
+ /** Assistant turn: the audio the run transcribed (`config.media`); absent when none. */
359
+ transcripts?: TranscriptView[];
360
+ /**
361
+ * Assistant turn: the files the run wrote to the workspace and did not delete again (the file
362
+ * tools and the sandbox; a subagent's are here too). Absent until the first one.
363
+ */
364
+ writtenFiles?: WrittenFileView[];
365
+ /**
366
+ * Assistant turn: the MCP Apps its tool calls came with (the core's `mcp.app`, on a
367
+ * connection made with `apps: true`). Absent until the first one. Holds the call's input and
368
+ * result for the app - never the app's HTML, which is read from its server when it is shown.
369
+ */
370
+ apps?: AppView[];
371
+ /** Assistant turn ended with an error. */
372
+ error?: boolean;
373
+ /**
374
+ * Assistant turn: the run was stopped (by the user, here or in another tab) before it was done.
375
+ * `content` is what it had written by then - `''` when nothing: the chat shows the
376
+ * `answerStopped` label in its place (the reducer keeps no UI text). A chat saved before this
377
+ * existed has the old `'Stopped.'` as its content, and shows that.
378
+ */
379
+ stopped?: true;
380
+ }
381
+ /** A single tool call as it appears in a step, streamed then finalized. */
382
+ interface ToolCallView {
383
+ name: string;
384
+ input: unknown;
385
+ output?: unknown;
386
+ ok?: boolean;
387
+ status: 'calling' | 'done';
388
+ /** When the call started (ms epoch; set when the hook stamps events). */
389
+ startedAt?: number;
390
+ /** How long the call took. */
391
+ durationMs?: number;
392
+ /** ≈ tokens of the arguments the model wrote (chars / 4). */
393
+ inputTokens?: number;
394
+ /** ≈ tokens of the result fed back to the model (chars / 4). */
395
+ outputTokens?: number;
396
+ /**
397
+ * Set on a call of an attempt that was escalated (model tiers): the attempt it belongs to,
398
+ * 1 for the step's first. A call of the attempt the step is on now (or finished on) has none.
399
+ */
400
+ attempt?: number;
401
+ /**
402
+ * The core did NOT run this call again: the same write already succeeded in an earlier attempt
403
+ * at the step, and the model was handed that result (`output` carries the core's note).
404
+ */
405
+ replayed?: boolean;
406
+ /** The call came with an MCP App (an `mcp.app` event): the `AppView` id. */
407
+ app?: string;
408
+ }
409
+ /**
410
+ * An MCP App that came with a tool call (the core's `mcp.app` event): which server, which tool,
411
+ * which `ui://` resource, and the call's input and result - what the app is shown. Never the
412
+ * app itself: `<McpAppFrame>` reads it from the server that declared it when it is drawn.
413
+ */
414
+ interface AppView {
415
+ /** The core's event id: unique per call. */
416
+ id: string;
417
+ server: string;
418
+ /** The tool as the model called it (`server__tool`). */
419
+ tool: string;
420
+ /** The server's own name for it. */
421
+ toolName: string;
422
+ resourceUri: string;
423
+ input: Record<string, unknown>;
424
+ /** What the app is given; absent when the result was too large to hand to it. */
425
+ result?: McpAppToolResult;
426
+ stepId?: string;
427
+ /** A subagent's (or helper's) call: who made it. */
428
+ by?: {
429
+ id: string;
430
+ name: string;
431
+ role?: string;
432
+ };
433
+ }
434
+ /**
435
+ * One escalation of a step (a `step.escalated` event): the attempt on tier `from` failed for
436
+ * `reason` and the step was retried on the stronger tier `to`.
437
+ */
438
+ interface StepEscalationView {
439
+ from: ModelTier;
440
+ to: ModelTier;
441
+ reason: EscalationReason;
442
+ /** The model id of `to` (absent only when the escalation is known from the step's result alone). */
443
+ model?: string;
444
+ /** What the failed attempt had written when it was escalated (its streamed text), if anything. */
445
+ text?: string;
446
+ }
447
+ /**
448
+ * A lesson in the agent's notebook (`config.learning`): a skill the agent wrote down itself.
449
+ * `revision` goes up each time it rewrites the lesson.
450
+ */
451
+ interface LessonView {
452
+ name: string;
453
+ /** WHEN the lesson applies - the line the planner sees. */
454
+ description: string;
455
+ revision: number;
456
+ /** Size of the instructions, in characters. */
457
+ chars: number;
458
+ /** What it consulted: the sources it named, then the pages `web_fetch` read in that run. */
459
+ sources: string[];
460
+ }
461
+ /** One request the model made through `web_fetch` (an `egress.request` event). */
462
+ interface FetchView {
463
+ /** Origin and path only - the core never reports the query string. */
464
+ url: string;
465
+ allowed: boolean;
466
+ status?: number;
467
+ /** Why it was refused. */
468
+ reason?: string;
469
+ }
470
+ /**
471
+ * A file a media tool wrote (a `media.generated` event). The bytes are in the virtual file system
472
+ * at `path` - never in the state.
473
+ */
474
+ interface MediaView {
475
+ kind: 'image' | 'speech';
476
+ path: string;
477
+ mediaType: string;
478
+ /** Size of the file. */
479
+ bytes: number;
480
+ /** The media model that made it. */
481
+ model: string;
482
+ /**
483
+ * The reference pictures of a `generate_image` call that had `images`: whether they were sent
484
+ * to the image model (`used`; false: it takes none, the picture was made from the text), how
485
+ * many, and their paths. Never their bytes.
486
+ */
487
+ references?: {
488
+ used: boolean;
489
+ count: number;
490
+ paths: string[];
491
+ };
492
+ /** The step whose tool call made it, when the event named one. */
493
+ stepId?: string;
494
+ }
495
+ /**
496
+ * A file the run wrote to the virtual file system (the core's `file.written` event: `fs_write`,
497
+ * or the sandbox's `fs.writeFile`). One entry per path however many times it was written; a
498
+ * `file.deleted` takes it away. The content is in the file system at `path` - never in the state.
499
+ */
500
+ interface WrittenFileView {
501
+ path: string;
502
+ /** The MIME type the file system gave it. */
503
+ mediaType: string;
504
+ /** Size after the last write. */
505
+ bytes: number;
506
+ /** How many times the run wrote it. */
507
+ writes: number;
508
+ /** The step whose tool call wrote it last, when the event named one (never a subagent's step). */
509
+ stepId?: string;
510
+ /** The subagent that wrote it last; absent when the agent itself did. */
511
+ by?: {
512
+ id: string;
513
+ name: string;
514
+ role?: string;
515
+ };
516
+ }
517
+ /**
518
+ * An audio file that was transcribed (a `media.transcribed` event): one the user attached
519
+ * (`attachment`) or one the model asked about (`tool`). `text` is the content of that file -
520
+ * third-party text, never instructions.
521
+ */
522
+ interface TranscriptView {
523
+ source: 'attachment' | 'tool';
524
+ /** The file's name. */
525
+ name: string;
526
+ text: string;
527
+ language?: string;
528
+ durationInSeconds?: number;
529
+ model: string;
530
+ }
531
+ /**
532
+ * One question put to `config.decisionModel` (a `decision` event): its answer was used
533
+ * (`accepted`), or the ordinary model call ran and `reason` says why.
534
+ */
535
+ interface DecisionView {
536
+ point: DecisionPoint;
537
+ accepted: boolean;
538
+ choice?: string;
539
+ /** The probability the decision model gave its choice, 0..1. */
540
+ confidence?: number;
541
+ threshold: number;
542
+ reason?: DecisionFallbackReason;
543
+ durationMs: number;
544
+ model?: string;
545
+ }
546
+ /** A tool call waiting for (or decided by) the user's consent. */
547
+ interface ApprovalView {
548
+ id: string;
549
+ name: string;
550
+ input: unknown;
551
+ readOnly: boolean;
552
+ /** The step the call belongs to, when known. */
553
+ stepId?: string;
554
+ /**
555
+ * Set when a helper the model started is asking, not the run itself: its id (a node of
556
+ * `subagents`), its depth, and - when its `subagent.start` was seen - its name and role.
557
+ */
558
+ subagent?: {
559
+ id: string;
560
+ depth: number;
561
+ name?: string;
562
+ role?: string;
563
+ };
564
+ status: 'pending' | 'approved' | 'denied';
565
+ reason?: string;
566
+ /** Decided by policy (rule / read-only mode), not by a person. */
567
+ automatic?: boolean;
568
+ /**
569
+ * Set when an MCP App asks, not the model (`useAgent().approveAppToolCall`): its server, the
570
+ * tool's own name there and the app's resource. `name` is then the key the consent rules
571
+ * match. Such a request outlives a run (it is the user's, not the run's) and is never kept on
572
+ * a message. `frame` is the host's id of the frame that asked (`AppView.id`, from
573
+ * `AppToolCall.frame`): two frames of one app each have their own requests.
574
+ */
575
+ app?: {
576
+ server: string;
577
+ tool: string;
578
+ resourceUri: string;
579
+ frame?: string;
580
+ };
581
+ /**
582
+ * Asked in another tab, by a run of this conversation going on there (`AgentUiState.remote`):
583
+ * shown, never answered here - consent stays with the tab that runs the tool. `useAgent`'s
584
+ * `pendingApprovals` leaves it out.
585
+ */
586
+ remote?: true;
587
+ /**
588
+ * Set when the request is about an MCP server's skill about to enter the model's context, not
589
+ * a tool call (the core's `ToolApprovalRequest.skill`): the server, the skill, its description,
590
+ * size and files, and - while the request is pending - `body`, the very text the model would
591
+ * read. All of it is the SERVER's text: show it as plain text. `body` is dropped once the
592
+ * request is decided, so a saved conversation does not keep a server's instructions.
593
+ */
594
+ skill?: SkillConsentView;
595
+ /**
596
+ * Set when an explicit `'ask'` rule asked (the core's `ToolApprovalRequest.rule`): its name or
597
+ * pattern. The core asks such a call EVERY time - no "always allow" answers a rule -, so
598
+ * `<ToolApprovalPrompt>` offers no "Always allow" on it by default.
599
+ */
600
+ rule?: string;
601
+ }
602
+ /** What a person is shown of an MCP server's skill (the core's `McpSkillConsentView`). */
603
+ type SkillConsentView = Omit<McpSkillConsentView, 'body'> & {
604
+ body?: string;
605
+ };
606
+ /**
607
+ * A question an MCP server put to the user in the middle of a tool call (MCP elicitation; the
608
+ * core's `mcp.elicitation-*` events). `message`, `requestedSchema` and `url` are the SERVER's
609
+ * text - show them as such, never as the application's own. The view never holds what the user
610
+ * answered: `fields` are the names of the fields an accepted form was answered with.
611
+ */
612
+ interface ElicitationView {
613
+ /** The question's id: the same as `McpElicitationRequest.id` handed to `onElicitation`. */
614
+ id: string;
615
+ server: string;
616
+ /** The tool call during which the server asked. */
617
+ tool: string;
618
+ /** Absent only for a question that was refused before it could be shown. */
619
+ mode?: 'form' | 'url';
620
+ message: string;
621
+ /** Form mode: the fields to fill in. */
622
+ requestedSchema?: McpElicitationSchema;
623
+ /** URL mode: the link the server wants opened. Nothing opens it for the user. */
624
+ url?: string;
625
+ /** Asked in another tab, by a run followed here (`AgentUiState.remote`): answered there. */
626
+ remote?: true;
627
+ /** The step the tool call belongs to, when known. */
628
+ stepId?: string;
629
+ /** Set when a helper (a subagent) is the one whose call asks. */
630
+ subagent?: {
631
+ id: string;
632
+ depth: number;
633
+ name?: string;
634
+ role?: string;
635
+ };
636
+ status: 'pending' | 'accepted' | 'declined' | 'cancelled';
637
+ /** Answered without anybody deciding (a guard, a cap, a timeout, a stopped run). */
638
+ automatic?: boolean;
639
+ /** Why it was answered automatically (the core's reason, or `stopped`). */
640
+ reason?: string;
641
+ /** The names of the fields an accepted form was answered with. */
642
+ fields?: string[];
643
+ }
644
+ /**
645
+ * A question the MODEL put to the person (the core's `ask_user`, `config.askUser`; its
646
+ * `user.question-*` events): the question and the options are the model's text, cleaned - show
647
+ * them as plain text, never as markup. The view never holds what the person typed: an answer in
648
+ * their own words is `status: 'other'` and nothing more; `choice` holds labels that were offered.
649
+ */
650
+ interface QuestionView {
651
+ /** The question's id: the same as `AskUserRequest.id` handed to `onQuestion`. */
652
+ id: string;
653
+ question: string;
654
+ options: AskUserOption[];
655
+ /** The person may pick several options. */
656
+ multiple: boolean;
657
+ /** The person may answer in their own words. */
658
+ allowOther: boolean;
659
+ /** The step whose tool call asks (for a helper's question: the step that delegated it). */
660
+ stepId?: string;
661
+ /**
662
+ * Set when a helper or a subagent asks, not the run itself: its id (a node of `subagents`), its
663
+ * depth, and - when its `subagent.start` was seen - its name and role.
664
+ */
665
+ subagent?: {
666
+ id: string;
667
+ depth: number;
668
+ name?: string;
669
+ role?: string;
670
+ };
671
+ /** Asked in another tab, by a run followed here (`AgentUiState.remote`): answered there only. */
672
+ remote?: true;
673
+ /** `pending`, then how it ended (the core's `AskUserAction`). */
674
+ status: 'pending' | AskUserAction;
675
+ /** Ended without anybody deciding: a time limit, a stop, a failed handler, an unusable answer. */
676
+ automatic?: boolean;
677
+ /** `status: 'choice'`: the labels picked. */
678
+ choice?: string[];
679
+ /** Why it ended `declined` automatically (the core's `AskUserReason`), or `stopped`. */
680
+ reason?: string;
681
+ }
682
+ /** A message sent to the agent while it works, still waiting for a boundary to be shown to the model. */
683
+ interface QueuedMessageView {
684
+ id: string;
685
+ text: string;
686
+ /** Another tab of the site sent it to this run (the core's session relay). */
687
+ origin?: 'another-tab';
688
+ /**
689
+ * What the user sent waits with a run of this tab's that waits for the SESSION (`sessionBusy`):
690
+ * the other run of the conversation holds it - in another tab, or in this one. The entry is
691
+ * there only while that wait lasts (the run then starts with it); the chat shows
692
+ * `queuedForSession` for it, not `queuedWaiting`.
693
+ */
694
+ session?: SessionHolder;
695
+ /**
696
+ * What THIS tab said to the conversation's run in another tab (`sendRemote`), while that tab has
697
+ * not answered: the chat shows `queuedForOtherTab` for it. That tab answers when it takes the
698
+ * message - then its own entry (`message.queued`, marked `origin: 'another-tab'`) takes this
699
+ * one's place - or refuses it, or its run ends without it: then the text comes back in
700
+ * `undelivered`. A tab the browser froze in the background answers when it wakes; until then the
701
+ * entry stays.
702
+ */
703
+ sentTo?: 'another-tab';
704
+ }
705
+ /**
706
+ * A message the user sent while the run was going, after it reached the agent.
707
+ * `at` says where: `round` = between tool calls inside a step, `step` = at the end
708
+ * of a step (the replanner then re-checked the plan), `final` = just before the
709
+ * answer was written.
710
+ */
711
+ interface UserNoteView {
712
+ id: string;
713
+ text: string;
714
+ at: 'round' | 'step' | 'final';
715
+ /** The step it was delivered in (`round`) or after (`step`); none for `final`. */
716
+ stepId?: string;
717
+ /** Another tab of the site sent it (the core's session relay). */
718
+ origin?: 'another-tab';
719
+ }
720
+ /**
721
+ * A delegated task running in a subagent: one the host defined (`createSubagentTool`, in-process
722
+ * or a Web Worker) or a helper the model started (`spawn_subagent`). Each is a NODE OF A TREE:
723
+ * `parentId` / `depth` say where, and {@link subagentTree} nests the flat list.
724
+ */
725
+ interface SubagentView {
726
+ id: string;
727
+ /** The subagent's name (`spawn_subagent` for a helper the model started). */
728
+ name: string;
729
+ /** Empty when only its events were seen (its `subagent.start` never arrived). */
730
+ task: string;
731
+ /**
732
+ * The subagent that started this one; absent for the run's own subagents (depth 1). A parent
733
+ * that is not in the list (its start was never seen) leaves the node at the top of the tree.
734
+ */
735
+ parentId?: string;
736
+ /** 1 for the run's own subagents, 2 for theirs, ... */
737
+ depth: number;
738
+ /** A helper the model started itself (`subagents.dynamic`). */
739
+ dynamic?: true;
740
+ /** What the model wrote for a helper it started. Model-written text. */
741
+ role?: string;
742
+ /** The tool names a helper was given. */
743
+ tools?: string[];
744
+ /** The model and tier its latest step ran on - known only when the child uses model tiers. */
745
+ model?: string;
746
+ tier?: ModelTier;
747
+ /** When it started (ms epoch; set when the hook stamps events). */
748
+ startedAt?: number;
749
+ /** How long it ran, once it ended. */
750
+ durationMs?: number;
751
+ /** `stopped`: the user stopped this subagent; the run went on without it. */
752
+ status: 'running' | 'done' | 'error' | 'stopped';
753
+ /** The profile the parent model chose for this delegation, when there are profiles. */
754
+ profile?: string;
755
+ /** The step that delegated it, when known. */
756
+ stepId?: string;
757
+ /** What the child is doing right now ("step 2: …", "→ tool"). */
758
+ activity: string;
759
+ /** Steps the child started. */
760
+ steps: number;
761
+ /** Tool calls the child made. */
762
+ toolCalls: number;
763
+ /** The child's answer (streamed, then final). */
764
+ text: string;
765
+ /**
766
+ * Tokens spent under this node, its own subagents included: counted live from its `usage`
767
+ * events, then replaced by the total its end reports.
768
+ */
769
+ usage: IUsage;
770
+ error?: string;
771
+ }
772
+ /** A {@link SubagentView} with the subagents it started (see {@link subagentTree}). */
773
+ interface SubagentNode extends SubagentView {
774
+ children: SubagentNode[];
775
+ }
776
+ /** One compaction of the context (a `context.compacted` event). */
777
+ interface CompactionView {
778
+ scope: 'history' | 'trace' | 'tool-results';
779
+ beforeTokens: number;
780
+ afterTokens: number;
781
+ }
782
+ /** An execution step with its accumulated text and tool calls. */
783
+ interface StepView {
784
+ id: string;
785
+ /** Its place in the run (1-based). */
786
+ index: number;
787
+ /**
788
+ * The plan's length as the run's LATEST step started: a replan that grew or cut the plan
789
+ * renumbers the earlier rows too (1/2, 2/2 - not 1/1, 2/2).
790
+ */
791
+ total: number;
792
+ step: IPlanStep;
793
+ /** Streamed executor text for this step (step.text-delta). */
794
+ text: string;
795
+ /** Streamed executor thoughts for this step (step.reasoning-delta). */
796
+ reasoning: string;
797
+ toolCalls: ToolCallView[];
798
+ status: 'running' | 'done';
799
+ summary?: string;
800
+ blocked: boolean;
801
+ /**
802
+ * Model tiers (`config.executorTiers`) - all four are absent when tiers are off.
803
+ * `tier` / `model`: the tier the step is on NOW (where it started, then where an escalation
804
+ * took it, then where it finished) and that tier's model id.
805
+ */
806
+ tier?: ModelTier;
807
+ model?: string;
808
+ /** Why the step STARTED on its tier: the planner's rating, the default, or a fallback. */
809
+ tierReason?: TierReason;
810
+ /**
811
+ * The step's escalations, in order. `text` / `reasoning` above hold the current attempt only;
812
+ * the calls of the attempts before it stay in `toolCalls`, marked with their `attempt`.
813
+ */
814
+ escalations?: StepEscalationView[];
815
+ /**
816
+ * The replanner call that followed this step failed (the provider's error): the run went on
817
+ * with the plan it had. A warning, not a failed step.
818
+ */
819
+ replanFailed?: string;
820
+ /** What `config.decisionModel` was asked after this step; absent without a decision model. */
821
+ decisions?: DecisionView[];
822
+ /** The files this step's media tools wrote (also in the turn's `media`); absent when none. */
823
+ media?: MediaView[];
824
+ }
825
+ /** WebLLM weight-download / engine-init progress (model.load events). */
826
+ interface ModelLoadState {
827
+ progress: number;
828
+ text: string;
829
+ }
830
+ interface ReplanState {
831
+ mode: ReplanMode;
832
+ reason: string;
833
+ /** The replanner ran because the user sent a message, not because a step failed. */
834
+ byUser?: boolean;
835
+ /**
836
+ * The replanner call itself failed and `continue` is the fallback, not the model's decision.
837
+ * `error` is the failure (the `error` event of phase `replan` that came just before).
838
+ */
839
+ failed?: true;
840
+ error?: string;
841
+ /** `config.decisionModel` made this decision: the probability it gave its choice. */
842
+ confidence?: number;
843
+ }
844
+ /**
845
+ * The whole UI-facing view of an agent run, rebuilt purely from the stream of
846
+ * `AgentEvent`s by {@link agentStateReducer}. `status` is owned by the hook
847
+ * (build/run lifecycle) and layered on top; everything else here is derived
848
+ * only from events, so the reducer is deterministic and testable without React.
849
+ */
850
+ interface AgentUiState {
851
+ status: AgentStatus;
852
+ /** The goal of the current / most recent run. */
853
+ goal?: string;
854
+ /** The last plan the agent produced (created or revised). */
855
+ plan?: IPlan;
856
+ /** Streamed planner "thinking" text (plan.thought-delta). */
857
+ planThought: string;
858
+ /** Execution steps, in order, with their tool calls. */
859
+ steps: StepView[];
860
+ /** The final answer (streamed via final.text-delta, finalized on final). */
861
+ finalText: string;
862
+ /** The synthesizer's streamed thoughts (final.reasoning-delta). */
863
+ finalReasoning: string;
864
+ /** Tool calls that asked for consent in this run, pending first-come. */
865
+ approvals: ApprovalView[];
866
+ /**
867
+ * Subagent delegations of this run - static subagents and the helpers the model started, at
868
+ * every depth, in the order they started. A tree: see `SubagentView.parentId` / `subagentTree`.
869
+ */
870
+ subagents: SubagentView[];
871
+ /**
872
+ * Questions MCP servers put to the user in this run (MCP elicitation), in the order they
873
+ * arrived; absent until the first one. Per-run view only: they are not copied into the
874
+ * transcript, so a saved conversation never holds a server's form.
875
+ */
876
+ elicitations?: ElicitationView[];
877
+ /**
878
+ * Questions the model put to the person in this run (`ask_user`, `config.askUser`), in the
879
+ * order they were asked, a helper's included; absent until the first one. Per-run view only:
880
+ * they are not copied into the transcript, and none holds what the person typed.
881
+ */
882
+ questions?: QuestionView[];
883
+ /** Messages sent while the run goes that have not yet been shown to the model. */
884
+ queued: QueuedMessageView[];
885
+ /** What the user said during this run and when it reached the agent. */
886
+ notes: UserNoteView[];
887
+ /**
888
+ * Messages the run ended without showing the model (sent while the answer was being
889
+ * written, or still queued when the run was stopped). The hook sends them as a
890
+ * follow-up unless the run was stopped; see `useAgent`'s `followUp`.
891
+ */
892
+ undelivered: string[];
893
+ /** Skills activated in this run. */
894
+ skills: string[];
895
+ /**
896
+ * The agent's notebook: the lessons it wrote down (`config.learning`). It belongs to the
897
+ * agent, not to a conversation - it survives `reset` and a chat switch, and the hook
898
+ * re-reads it whenever the agent is rebuilt.
899
+ */
900
+ learned: LessonView[];
901
+ /** Names of the lessons written in this run. */
902
+ learnedNow: string[];
903
+ /** What the model fetched from the web in this run (`config.egress`). */
904
+ fetches: FetchView[];
905
+ /** Images and audio generated in this run (`config.media`). Absent until the first one. */
906
+ media?: MediaView[];
907
+ /** Audio transcribed in this run (`config.media`). Absent until the first one. */
908
+ transcripts?: TranscriptView[];
909
+ /** Files written in this run and still there (`file.written` / `file.deleted`). Absent until the first one. */
910
+ writtenFiles?: WrittenFileView[];
911
+ /** MCP Apps this run's tool calls came with (`mcp.app`). Absent until the first one. */
912
+ apps?: AppView[];
913
+ /**
914
+ * Questions put to `config.decisionModel` before any step existed (a decision that follows a
915
+ * step is on that step). Absent until the first one.
916
+ */
917
+ decisions?: DecisionView[];
918
+ /** Tools activated by find_tools in this run. */
919
+ discoveredTools: string[];
920
+ /** Compactions in this run. */
921
+ compactions: CompactionView[];
922
+ /** Set when a run-level limit stopped the run early. */
923
+ budget?: BudgetView;
924
+ /** Running token total across the current run. */
925
+ usage: IUsage;
926
+ /** Token total across the whole conversation (every run since the last reset). */
927
+ totalUsage: IUsage;
928
+ /** When the current run started (ms epoch; set when the hook stamps events). */
929
+ runStartedAt?: number;
930
+ /** The id of the assistant message the current run streams into. */
931
+ runMessageId?: string;
932
+ /** WebLLM progress, present only while a local model is loading. */
933
+ modelLoad?: ModelLoadState;
934
+ /** The most recent replan decision, if any. */
935
+ replan?: ReplanState;
936
+ /**
937
+ * Error message from the last run error / build failure. A non-fatal `plan` / `execute` /
938
+ * `synthesize` error is kept here too while the run goes on; a replanner failure is not (see
939
+ * `replan.failed` and `StepView.replanFailed`).
940
+ */
941
+ error?: string;
942
+ /**
943
+ * The core's code of a run error a host may want to say in its own words: `'no-plan'` (the
944
+ * planner returned nothing readable) or `'no-answer'` (the model wrote no answer). Absent for
945
+ * every other error.
946
+ */
947
+ errorCode?: 'no-plan' | 'no-answer';
948
+ /** True when the last run was aborted via stop(). */
949
+ stopped: boolean;
950
+ /** A chat-style transcript built from every run, for chat UIs. */
951
+ messages: ChatMessage[];
952
+ /** The raw event log (most recent last), capped by `maxEvents`. */
953
+ events: AgentEvent[];
954
+ /** Monotonic counter; mints stable message ids without Date/Math.random. */
955
+ seq: number;
956
+ /**
957
+ * The run in view is another tab's: this conversation runs in another tab of the origin, and
958
+ * `useAgent` follows it (the core's `watchSession`) - its steps, answer and usage are folded
959
+ * into the rest of the state like a run of this tab's. Absent once a run of this tab starts or
960
+ * a chat is loaded.
961
+ */
962
+ remote?: RemoteRunView;
963
+ /**
964
+ * This tab's run waits for the session: another run of it is going (`session.busy`) - in
965
+ * another tab, or in this one. Cleared when it gets the session, or is stopped.
966
+ */
967
+ sessionBusy?: {
968
+ heldBy: SessionHolder;
969
+ goal?: string;
970
+ };
971
+ /**
972
+ * The turn the user just sent, shown at once while the run gets going (its `run.start` comes
973
+ * after the session's lock is granted - a round trip to the browser's lock manager): the ids of
974
+ * its user and pending assistant messages. `run.start` replaces them; a wait for the session
975
+ * turns the text into a queued item instead.
976
+ */
977
+ submitted?: {
978
+ userId: string;
979
+ assistantId: string;
980
+ };
981
+ }
982
+ /** Another tab's run of this conversation, as this tab sees it. */
983
+ interface RemoteRunView {
984
+ /** It is going now (`useAgent` reports `isRunning`; `send` / `stop` go to that tab). */
985
+ running: boolean;
986
+ runId?: string;
987
+ /**
988
+ * How it ended: `done`, `stopped`, or `gone` - that tab closed or crashed before it said so
989
+ * (its answer, if any, is what had arrived).
990
+ */
991
+ ended?: 'done' | 'stopped' | 'gone';
992
+ }
993
+
994
+ export type { AgentUiState as A, BrowserOAuthProvider as B, ChatAttachment as C, DecisionView as D, ElicitationView as E, FetchView as F, ModelLoadState as G, QueuedMessageView as H, ReplanState as I, SkillConsentView as J, StepEscalationView as K, LessonView as L, McpElicitationFieldSchema as M, StepView as N, TranscriptView as O, QuestionView as Q, RemoteRunView as R, SubagentView as S, ToolCallView as T, UserNoteView as U, WrittenFileView as W, ChatMessage as a, ApprovalView as b, McpElicitationHandler as c, McpElicitationRequest as d, McpElicitationResult as e, McpElicitationOptions as f, McpElicitationSchema as g, AgentStatus as h, SubagentNode as i, AppView as j, BrowserOAuthProviderOptions as k, BudgetView as l, CompactionView as m, ConnectedMcp as n, McpAppsConnectionLike as o, McpCatalogEntry as p, McpHttpServerConfig as q, McpModule as r, McpOAuthCallback as s, McpOAuthRegistration as t, McpOAuthRegistrationKind as u, McpProtocolMode as v, McpServerInstructions as w, McpServerProtocol as x, McpServerResult as y, MediaView as z };