@dudko.dev/agent-web-ui 0.0.0-stage → 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (273) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +254 -2
  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-4EHUITGU.js +342 -0
  10. package/dist/chunk-4EHUITGU.js.map +1 -0
  11. package/dist/chunk-7O64ZI6Z.js +125 -0
  12. package/dist/chunk-7O64ZI6Z.js.map +1 -0
  13. package/dist/chunk-A55Q377T.js +342 -0
  14. package/dist/chunk-A55Q377T.js.map +1 -0
  15. package/dist/chunk-EL2YCROY.js +127 -0
  16. package/dist/chunk-EL2YCROY.js.map +1 -0
  17. package/dist/chunk-GB7RZJMG.js +98 -0
  18. package/dist/chunk-GB7RZJMG.js.map +1 -0
  19. package/dist/chunk-KZQB35LS.js +22 -0
  20. package/dist/chunk-KZQB35LS.js.map +1 -0
  21. package/dist/chunk-P2F2P3JC.js +400 -0
  22. package/dist/chunk-P2F2P3JC.js.map +1 -0
  23. package/dist/chunk-TPK25QGK.js +342 -0
  24. package/dist/chunk-TPK25QGK.js.map +1 -0
  25. package/dist/en-CcNUz2tN.d.cts +342 -0
  26. package/dist/en-CcNUz2tN.d.ts +342 -0
  27. package/dist/index.cjs +4143 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +919 -0
  30. package/dist/index.d.ts +919 -0
  31. package/dist/index.js +3771 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/labels-B5xpIGf_.d.cts +25 -0
  34. package/dist/labels-B5xpIGf_.d.ts +25 -0
  35. package/dist/labels-D5BrHct4.d.cts +1208 -0
  36. package/dist/labels-UuWI7wPo.d.ts +1208 -0
  37. package/dist/locales/be.cjs +794 -0
  38. package/dist/locales/be.cjs.map +1 -0
  39. package/dist/locales/be.d.cts +14 -0
  40. package/dist/locales/be.d.ts +14 -0
  41. package/dist/locales/be.js +374 -0
  42. package/dist/locales/be.js.map +1 -0
  43. package/dist/locales/bg.cjs +747 -0
  44. package/dist/locales/bg.cjs.map +1 -0
  45. package/dist/locales/bg.d.cts +14 -0
  46. package/dist/locales/bg.d.ts +14 -0
  47. package/dist/locales/bg.js +327 -0
  48. package/dist/locales/bg.js.map +1 -0
  49. package/dist/locales/ca.cjs +773 -0
  50. package/dist/locales/ca.cjs.map +1 -0
  51. package/dist/locales/ca.d.cts +14 -0
  52. package/dist/locales/ca.d.ts +14 -0
  53. package/dist/locales/ca.js +353 -0
  54. package/dist/locales/ca.js.map +1 -0
  55. package/dist/locales/cs.cjs +794 -0
  56. package/dist/locales/cs.cjs.map +1 -0
  57. package/dist/locales/cs.d.cts +14 -0
  58. package/dist/locales/cs.d.ts +14 -0
  59. package/dist/locales/cs.js +374 -0
  60. package/dist/locales/cs.js.map +1 -0
  61. package/dist/locales/da.cjs +747 -0
  62. package/dist/locales/da.cjs.map +1 -0
  63. package/dist/locales/da.d.cts +14 -0
  64. package/dist/locales/da.d.ts +14 -0
  65. package/dist/locales/da.js +327 -0
  66. package/dist/locales/da.js.map +1 -0
  67. package/dist/locales/de.cjs +756 -0
  68. package/dist/locales/de.cjs.map +1 -0
  69. package/dist/locales/de.d.cts +14 -0
  70. package/dist/locales/de.d.ts +14 -0
  71. package/dist/locales/de.js +336 -0
  72. package/dist/locales/de.js.map +1 -0
  73. package/dist/locales/el.cjs +756 -0
  74. package/dist/locales/el.cjs.map +1 -0
  75. package/dist/locales/el.d.cts +14 -0
  76. package/dist/locales/el.d.ts +14 -0
  77. package/dist/locales/el.js +336 -0
  78. package/dist/locales/el.js.map +1 -0
  79. package/dist/locales/en.cjs +753 -0
  80. package/dist/locales/en.cjs.map +1 -0
  81. package/dist/locales/en.d.cts +10 -0
  82. package/dist/locales/en.d.ts +10 -0
  83. package/dist/locales/en.js +333 -0
  84. package/dist/locales/en.js.map +1 -0
  85. package/dist/locales/es-419.cjs +778 -0
  86. package/dist/locales/es-419.cjs.map +1 -0
  87. package/dist/locales/es-419.d.cts +16 -0
  88. package/dist/locales/es-419.d.ts +16 -0
  89. package/dist/locales/es-419.js +23 -0
  90. package/dist/locales/es-419.js.map +1 -0
  91. package/dist/locales/es.cjs +769 -0
  92. package/dist/locales/es.cjs.map +1 -0
  93. package/dist/locales/es.d.cts +14 -0
  94. package/dist/locales/es.d.ts +14 -0
  95. package/dist/locales/es.js +14 -0
  96. package/dist/locales/es.js.map +1 -0
  97. package/dist/locales/fi.cjs +753 -0
  98. package/dist/locales/fi.cjs.map +1 -0
  99. package/dist/locales/fi.d.cts +14 -0
  100. package/dist/locales/fi.d.ts +14 -0
  101. package/dist/locales/fi.js +333 -0
  102. package/dist/locales/fi.js.map +1 -0
  103. package/dist/locales/fr-CA.cjs +777 -0
  104. package/dist/locales/fr-CA.cjs.map +1 -0
  105. package/dist/locales/fr-CA.d.cts +17 -0
  106. package/dist/locales/fr-CA.d.ts +17 -0
  107. package/dist/locales/fr-CA.js +22 -0
  108. package/dist/locales/fr-CA.js.map +1 -0
  109. package/dist/locales/fr.cjs +769 -0
  110. package/dist/locales/fr.cjs.map +1 -0
  111. package/dist/locales/fr.d.cts +14 -0
  112. package/dist/locales/fr.d.ts +14 -0
  113. package/dist/locales/fr.js +14 -0
  114. package/dist/locales/fr.js.map +1 -0
  115. package/dist/locales/gn.cjs +750 -0
  116. package/dist/locales/gn.cjs.map +1 -0
  117. package/dist/locales/gn.d.cts +16 -0
  118. package/dist/locales/gn.d.ts +16 -0
  119. package/dist/locales/gn.js +330 -0
  120. package/dist/locales/gn.js.map +1 -0
  121. package/dist/locales/hr.cjs +769 -0
  122. package/dist/locales/hr.cjs.map +1 -0
  123. package/dist/locales/hr.d.cts +14 -0
  124. package/dist/locales/hr.d.ts +14 -0
  125. package/dist/locales/hr.js +349 -0
  126. package/dist/locales/hr.js.map +1 -0
  127. package/dist/locales/ht.cjs +750 -0
  128. package/dist/locales/ht.cjs.map +1 -0
  129. package/dist/locales/ht.d.cts +16 -0
  130. package/dist/locales/ht.d.ts +16 -0
  131. package/dist/locales/ht.js +330 -0
  132. package/dist/locales/ht.js.map +1 -0
  133. package/dist/locales/hu.cjs +753 -0
  134. package/dist/locales/hu.cjs.map +1 -0
  135. package/dist/locales/hu.d.cts +14 -0
  136. package/dist/locales/hu.d.ts +14 -0
  137. package/dist/locales/hu.js +333 -0
  138. package/dist/locales/hu.js.map +1 -0
  139. package/dist/locales/index.cjs +537 -0
  140. package/dist/locales/index.cjs.map +1 -0
  141. package/dist/locales/index.d.cts +38 -0
  142. package/dist/locales/index.d.ts +38 -0
  143. package/dist/locales/index.js +105 -0
  144. package/dist/locales/index.js.map +1 -0
  145. package/dist/locales/it.cjs +777 -0
  146. package/dist/locales/it.cjs.map +1 -0
  147. package/dist/locales/it.d.cts +14 -0
  148. package/dist/locales/it.d.ts +14 -0
  149. package/dist/locales/it.js +357 -0
  150. package/dist/locales/it.js.map +1 -0
  151. package/dist/locales/nb.cjs +747 -0
  152. package/dist/locales/nb.cjs.map +1 -0
  153. package/dist/locales/nb.d.cts +14 -0
  154. package/dist/locales/nb.d.ts +14 -0
  155. package/dist/locales/nb.js +327 -0
  156. package/dist/locales/nb.js.map +1 -0
  157. package/dist/locales/nl.cjs +753 -0
  158. package/dist/locales/nl.cjs.map +1 -0
  159. package/dist/locales/nl.d.cts +14 -0
  160. package/dist/locales/nl.d.ts +14 -0
  161. package/dist/locales/nl.js +333 -0
  162. package/dist/locales/nl.js.map +1 -0
  163. package/dist/locales/pl.cjs +794 -0
  164. package/dist/locales/pl.cjs.map +1 -0
  165. package/dist/locales/pl.d.cts +14 -0
  166. package/dist/locales/pl.d.ts +14 -0
  167. package/dist/locales/pl.js +374 -0
  168. package/dist/locales/pl.js.map +1 -0
  169. package/dist/locales/pt-BR.cjs +773 -0
  170. package/dist/locales/pt-BR.cjs.map +1 -0
  171. package/dist/locales/pt-BR.d.cts +14 -0
  172. package/dist/locales/pt-BR.d.ts +14 -0
  173. package/dist/locales/pt-BR.js +353 -0
  174. package/dist/locales/pt-BR.js.map +1 -0
  175. package/dist/locales/pt.cjs +777 -0
  176. package/dist/locales/pt.cjs.map +1 -0
  177. package/dist/locales/pt.d.cts +14 -0
  178. package/dist/locales/pt.d.ts +14 -0
  179. package/dist/locales/pt.js +357 -0
  180. package/dist/locales/pt.js.map +1 -0
  181. package/dist/locales/qu.cjs +756 -0
  182. package/dist/locales/qu.cjs.map +1 -0
  183. package/dist/locales/qu.d.cts +16 -0
  184. package/dist/locales/qu.d.ts +16 -0
  185. package/dist/locales/qu.js +336 -0
  186. package/dist/locales/qu.js.map +1 -0
  187. package/dist/locales/ro.cjs +769 -0
  188. package/dist/locales/ro.cjs.map +1 -0
  189. package/dist/locales/ro.d.cts +14 -0
  190. package/dist/locales/ro.d.ts +14 -0
  191. package/dist/locales/ro.js +349 -0
  192. package/dist/locales/ro.js.map +1 -0
  193. package/dist/locales/ru.cjs +789 -0
  194. package/dist/locales/ru.cjs.map +1 -0
  195. package/dist/locales/ru.d.cts +14 -0
  196. package/dist/locales/ru.d.ts +14 -0
  197. package/dist/locales/ru.js +369 -0
  198. package/dist/locales/ru.js.map +1 -0
  199. package/dist/locales/sk.cjs +794 -0
  200. package/dist/locales/sk.cjs.map +1 -0
  201. package/dist/locales/sk.d.cts +14 -0
  202. package/dist/locales/sk.d.ts +14 -0
  203. package/dist/locales/sk.js +374 -0
  204. package/dist/locales/sk.js.map +1 -0
  205. package/dist/locales/sq.cjs +753 -0
  206. package/dist/locales/sq.cjs.map +1 -0
  207. package/dist/locales/sq.d.cts +14 -0
  208. package/dist/locales/sq.d.ts +14 -0
  209. package/dist/locales/sq.js +333 -0
  210. package/dist/locales/sq.js.map +1 -0
  211. package/dist/locales/sr-Latn.cjs +841 -0
  212. package/dist/locales/sr-Latn.cjs.map +1 -0
  213. package/dist/locales/sr-Latn.d.cts +17 -0
  214. package/dist/locales/sr-Latn.d.ts +17 -0
  215. package/dist/locales/sr-Latn.js +86 -0
  216. package/dist/locales/sr-Latn.js.map +1 -0
  217. package/dist/locales/sr.cjs +769 -0
  218. package/dist/locales/sr.cjs.map +1 -0
  219. package/dist/locales/sr.d.cts +14 -0
  220. package/dist/locales/sr.d.ts +14 -0
  221. package/dist/locales/sr.js +14 -0
  222. package/dist/locales/sr.js.map +1 -0
  223. package/dist/locales/sv.cjs +753 -0
  224. package/dist/locales/sv.cjs.map +1 -0
  225. package/dist/locales/sv.d.cts +14 -0
  226. package/dist/locales/sv.d.ts +14 -0
  227. package/dist/locales/sv.js +333 -0
  228. package/dist/locales/sv.js.map +1 -0
  229. package/dist/locales/tr.cjs +750 -0
  230. package/dist/locales/tr.cjs.map +1 -0
  231. package/dist/locales/tr.d.cts +14 -0
  232. package/dist/locales/tr.d.ts +14 -0
  233. package/dist/locales/tr.js +330 -0
  234. package/dist/locales/tr.js.map +1 -0
  235. package/dist/locales/uk.cjs +794 -0
  236. package/dist/locales/uk.cjs.map +1 -0
  237. package/dist/locales/uk.d.cts +14 -0
  238. package/dist/locales/uk.d.ts +14 -0
  239. package/dist/locales/uk.js +374 -0
  240. package/dist/locales/uk.js.map +1 -0
  241. package/dist/markdown.cjs +620 -0
  242. package/dist/markdown.cjs.map +1 -0
  243. package/dist/markdown.d.cts +153 -0
  244. package/dist/markdown.d.ts +153 -0
  245. package/dist/markdown.js +573 -0
  246. package/dist/markdown.js.map +1 -0
  247. package/dist/mcp-app-entry-BA-Ca39z.d.ts +1480 -0
  248. package/dist/mcp-app-entry-tybABaHg.d.cts +1480 -0
  249. package/dist/mcp-app-policy-DXKQ2jjM.d.cts +73 -0
  250. package/dist/mcp-app-policy-DXKQ2jjM.d.ts +73 -0
  251. package/dist/mcp-app-sandbox.cjs +323 -0
  252. package/dist/mcp-app-sandbox.cjs.map +1 -0
  253. package/dist/mcp-app-sandbox.d.cts +70 -0
  254. package/dist/mcp-app-sandbox.d.ts +70 -0
  255. package/dist/mcp-app-sandbox.js +209 -0
  256. package/dist/mcp-app-sandbox.js.map +1 -0
  257. package/dist/mcp-app.cjs +980 -0
  258. package/dist/mcp-app.cjs.map +1 -0
  259. package/dist/mcp-app.d.cts +3 -0
  260. package/dist/mcp-app.d.ts +3 -0
  261. package/dist/mcp-app.js +816 -0
  262. package/dist/mcp-app.js.map +1 -0
  263. package/dist/pipeline.cjs +845 -0
  264. package/dist/pipeline.cjs.map +1 -0
  265. package/dist/pipeline.css +1407 -0
  266. package/dist/pipeline.d.cts +348 -0
  267. package/dist/pipeline.d.ts +348 -0
  268. package/dist/pipeline.js +778 -0
  269. package/dist/pipeline.js.map +1 -0
  270. package/dist/styles.css +4109 -0
  271. package/dist/types-BmvgYUzF.d.cts +19 -0
  272. package/dist/types-Cr5gmUts.d.ts +19 -0
  273. package/package.json +182 -3
@@ -0,0 +1,1480 @@
1
+ import { AgentToolSet, McpAppResource, McpAppToolResult, IPlan, IPlanStep, ModelTier, TierReason, EscalationReason, DecisionPoint, DecisionFallbackReason, McpSkillConsentView, IUsage, AskUserOption, AskUserAction, SessionHolder, ReplanMode, AgentEvent, McpAppCsp } from '@dudko.dev/agent-web';
2
+ import { a as McpAppColorScheme } from './mcp-app-policy-DXKQ2jjM.cjs';
3
+
4
+ /**
5
+ * Structural types for the core's OPTIONAL `@dudko.dev/agent-web/mcp` subpath.
6
+ *
7
+ * The subpath is loaded with a dynamic import and typed here rather than
8
+ * imported, for two reasons: it drags in `@modelcontextprotocol/client` (an
9
+ * optional peer of the core, which apps without MCP must not have to install),
10
+ * and the OAuth half only exists in newer cores while this package supports
11
+ * `@dudko.dev/agent-web >= 0.0.6`. `useMcp` feature-detects at runtime and
12
+ * reports `oauthSupported: false` on an older core instead of crashing.
13
+ */
14
+ interface McpCatalogEntry {
15
+ name: string;
16
+ description: string;
17
+ server: string;
18
+ /** The server marked the tool read-only (newer cores). */
19
+ readOnly?: boolean;
20
+ /** With `apps: true`: the MCP App (`ui://…`) the tool declares (newer cores). */
21
+ app?: string;
22
+ }
23
+ interface McpServerResult {
24
+ name: string;
25
+ connected: boolean;
26
+ error?: string;
27
+ needsAuthorization?: boolean;
28
+ }
29
+ /** The `instructions` one connected server returned in its `initialize` result. */
30
+ interface McpServerInstructions {
31
+ /** The server's name: its key in the configuration. */
32
+ server: string;
33
+ instructions: string;
34
+ }
35
+ /**
36
+ * Which revisions of the MCP protocol a connection may use (the core's per-server `protocol`):
37
+ * `'legacy'` (default) the 2025 revisions, `'auto'` 2026-07-28 when the server offers it and the
38
+ * 2025 ones otherwise, `'modern'` 2026-07-28 only.
39
+ */
40
+ type McpProtocolMode = 'legacy' | 'auto' | 'modern';
41
+ /** What a connection negotiated with one server. */
42
+ interface McpServerProtocol {
43
+ /** The server's name: its key in the configuration. */
44
+ server: string;
45
+ /** The protocol revision in use, e.g. `2025-11-25` or `2026-07-28`. */
46
+ version: string;
47
+ era: 'legacy' | 'modern';
48
+ }
49
+ interface ConnectedMcp {
50
+ tools: AgentToolSet;
51
+ catalog: McpCatalogEntry[];
52
+ results: McpServerResult[];
53
+ /**
54
+ * What each connected server told the agent in its handshake (newer cores; absent on older
55
+ * ones). THIRD-PARTY text: the core puts it in the system prompt of an agent that uses the
56
+ * server's tools, so a host should let the user see it.
57
+ */
58
+ instructions?: McpServerInstructions[];
59
+ /** The protocol revision negotiated with each connected server (cores with `protocol`). */
60
+ protocols?: McpServerProtocol[];
61
+ refreshServer?: (name: string) => Promise<void>;
62
+ close: () => Promise<void>;
63
+ /** MCP Apps, on a connection made with `apps: true` (newer cores; absent otherwise). */
64
+ apps?: McpAppsConnectionLike;
65
+ }
66
+ interface McpHttpServerConfig {
67
+ url: string;
68
+ headers?: Record<string, string>;
69
+ authProvider?: unknown;
70
+ /** Per-server connect deadline (newer cores; ignored by older ones). */
71
+ connectTimeoutMs?: number;
72
+ /**
73
+ * The MCP protocol revisions this connection may use (newer cores; an older one ignores the
74
+ * field and speaks the 2025 revisions). The hooks set it only for a server that was given a
75
+ * `protocol`. From a page, `'auto'` and `'modern'` need `Mcp-Method` and `Mcp-Name` in the
76
+ * server's `Access-Control-Allow-Headers`.
77
+ */
78
+ protocol?: McpProtocolMode;
79
+ /**
80
+ * EXPERIMENTAL: load the server's skills (the `io.modelcontextprotocol/skills` extension) into
81
+ * the agent's catalog, as `<server>/<skill>` (cores with MCP skills; an older one ignores the
82
+ * field). Needs `protocol: 'auto'` or `'modern'`. The hooks set it only for a server that was
83
+ * given `skills` (`true`, or `{ consent, dynamic }` - a core with skill consent; an older one
84
+ * reads any object as off). `dynamic: true` also takes the server's generated skills (a core
85
+ * with snapshots of them; an older one ignores it and declines them).
86
+ */
87
+ skills?: true | {
88
+ consent?: 'ask' | 'once-per-skill' | 'never';
89
+ dynamic?: boolean;
90
+ };
91
+ /**
92
+ * MCP Apps for this server alone, over the connection's `apps` (cores with per-server apps;
93
+ * an older one ignores it). `false`: its apps are not shown - nothing declared, no app read,
94
+ * its app-only tools not mounted. The hooks set it only for a server that was given `apps`.
95
+ */
96
+ apps?: boolean;
97
+ }
98
+ /**
99
+ * One field of a form a server asks the user to fill in (MCP elicitation): the flat subset of
100
+ * JSON Schema the specification allows. The core has already checked, cleaned and capped it.
101
+ */
102
+ interface McpElicitationFieldSchema {
103
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
104
+ title?: string;
105
+ description?: string;
106
+ default?: string | number | boolean | string[];
107
+ minLength?: number;
108
+ maxLength?: number;
109
+ format?: 'email' | 'uri' | 'date' | 'date-time';
110
+ /** Single-select, plain (`enumNames`: the older titled form). */
111
+ enum?: string[];
112
+ enumNames?: string[];
113
+ /** Single-select with titles. */
114
+ oneOf?: {
115
+ const: string;
116
+ title: string;
117
+ }[];
118
+ minimum?: number;
119
+ maximum?: number;
120
+ /** Multi-select. */
121
+ minItems?: number;
122
+ maxItems?: number;
123
+ items?: {
124
+ type?: 'string';
125
+ enum?: string[];
126
+ anyOf?: {
127
+ const: string;
128
+ title: string;
129
+ }[];
130
+ };
131
+ }
132
+ /** The form of an elicitation, as the core hands it to a host. */
133
+ interface McpElicitationSchema {
134
+ type: 'object';
135
+ properties: Record<string, McpElicitationFieldSchema>;
136
+ required?: string[];
137
+ }
138
+ /**
139
+ * What the core's `onElicitation` callback is given: an MCP server asks the user for input in
140
+ * the middle of a tool call. Every string in it is the SERVER's text, never instructions.
141
+ */
142
+ interface McpElicitationRequest {
143
+ /** Unique per question; the `mcp.elicitation-*` events carry the same id. */
144
+ id: string;
145
+ server: string;
146
+ /** The tool call during which the server asks: the tool's name as the model called it. */
147
+ tool: string;
148
+ mode: 'form' | 'url';
149
+ message: string;
150
+ /** Form mode: the fields to fill in. */
151
+ requestedSchema?: McpElicitationSchema;
152
+ /** URL mode: a link the server wants the user to open. The core never opens it. */
153
+ url?: string;
154
+ elicitationId?: string;
155
+ runId?: string;
156
+ /** Set when a helper (a subagent) is the one whose call asks. */
157
+ subagent?: {
158
+ id: string;
159
+ depth: number;
160
+ };
161
+ }
162
+ /** The answer to an elicitation. `accept` carries the form's values (form mode only). */
163
+ type McpElicitationResult = {
164
+ action: 'accept';
165
+ content?: Record<string, string | number | boolean | string[]>;
166
+ } | {
167
+ action: 'decline';
168
+ } | {
169
+ action: 'cancel';
170
+ };
171
+ /** The core's `onElicitation`. `ctx.signal` aborts when the answer is no longer wanted. */
172
+ type McpElicitationHandler = (request: McpElicitationRequest, ctx: {
173
+ signal: AbortSignal;
174
+ }) => McpElicitationResult | Promise<McpElicitationResult>;
175
+ /** The core's `elicitation` settings (all optional; see the core's README). */
176
+ interface McpElicitationOptions {
177
+ timeoutMs?: number;
178
+ maxPerToolCall?: number;
179
+ maxPerRun?: number;
180
+ /** Also accept URL mode. Default false. */
181
+ url?: boolean;
182
+ /** Let a subagent's call ask the user too. Default false. */
183
+ subagents?: boolean;
184
+ }
185
+ interface McpOAuthCallback {
186
+ code?: string;
187
+ state?: string;
188
+ /** The `iss` parameter of the response (RFC 9207); the core checks it. */
189
+ iss?: string;
190
+ error?: string;
191
+ errorDescription?: string;
192
+ }
193
+ /**
194
+ * How a server's OAuth client is registered (the core's `McpOAuthRegistration`): `'auto'` the
195
+ * client ID metadata document (CIMD) where the authorization server supports it and dynamic
196
+ * registration (DCR) otherwise, `'cimd'` the document only, `'dcr'` dynamic registration only.
197
+ */
198
+ type McpOAuthRegistration = 'auto' | 'cimd' | 'dcr';
199
+ /** How a stored OAuth client was registered (the core's `McpOAuthRegistrationKind`). */
200
+ type McpOAuthRegistrationKind = 'cimd' | 'dcr';
201
+ interface BrowserOAuthProvider {
202
+ serverUrl: string;
203
+ authorizationUrl?: URL;
204
+ /** The provider's `registration`. Absent on cores older than the option. */
205
+ readonly registration?: McpOAuthRegistration;
206
+ /** How the stored client was registered. Absent on cores older than the option. */
207
+ registrationKind?(): Promise<McpOAuthRegistrationKind | undefined>;
208
+ isAuthorized(): Promise<boolean>;
209
+ reset(): Promise<void>;
210
+ }
211
+ interface BrowserOAuthProviderOptions {
212
+ serverUrl: string;
213
+ redirectUrl: string;
214
+ clientName?: string;
215
+ scope?: string;
216
+ /** Client ID metadata document URL (CIMD). Cores without it ignore the field. */
217
+ clientMetadataUrl?: string;
218
+ /**
219
+ * How the client is registered. Cores without it ignore the field - which is why the hooks
220
+ * refuse a `'cimd'` / `'dcr'` such a core did not take (`newMcpOAuthProvider`).
221
+ */
222
+ registration?: McpOAuthRegistration;
223
+ }
224
+ /** The shape of the subpath module, as far as this package uses it. */
225
+ interface McpModule {
226
+ connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opts?: {
227
+ clientName?: string;
228
+ onLog?: (level: string, message: string) => void;
229
+ connectTimeoutMs?: number;
230
+ /**
231
+ * Answer a server's question to the user (cores with MCP elicitation; an older core
232
+ * ignores both fields and declares no capability). The hooks set them only when their
233
+ * `elicitation` option is on.
234
+ */
235
+ onElicitation?: McpElicitationHandler;
236
+ elicitation?: McpElicitationOptions;
237
+ /** MCP Apps (cores with the extension; an older core ignores it and declares nothing). */
238
+ apps?: boolean;
239
+ }) => Promise<ConnectedMcp>;
240
+ BrowserOAuthProvider?: new (opts: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
241
+ readOAuthCallback?: (input?: string | URL) => McpOAuthCallback | undefined;
242
+ finishMcpOAuth?: (provider: BrowserOAuthProvider, callback: McpOAuthCallback) => Promise<void>;
243
+ /**
244
+ * The SDK's error class, re-exported by the core so an authorization failure
245
+ * can be recognised by identity (`@modelcontextprotocol/client` on a core on
246
+ * the 2.x MCP SDK, `@modelcontextprotocol/sdk` before). Absent on cores older
247
+ * than 0.0.12.
248
+ */
249
+ UnauthorizedError?: new (message?: string) => Error;
250
+ }
251
+ /**
252
+ * The connection's side of MCP Apps, structurally: the core's `ConnectedMcp.apps` (`./mcp`,
253
+ * `apps: true`), or the one `useMcp` / `useMcpServers` return. Every method names the server,
254
+ * and the host always passes the app's OWN server: an app reads and calls only what its server
255
+ * declared.
256
+ */
257
+ interface McpAppsConnectionLike {
258
+ readUiResource: (server: string, uri: string, options?: {
259
+ signal?: AbortSignal;
260
+ }) => Promise<McpAppResource>;
261
+ appTool: (server: string, name: string) => {
262
+ key: string;
263
+ readOnly: boolean;
264
+ description?: string;
265
+ inputSchema?: unknown;
266
+ /** The server's identity on its connection (newer cores): what a grant is kept under. */
267
+ serverId?: string;
268
+ } | undefined;
269
+ callAppTool: (server: string, name: string, args: Record<string, unknown>, options?: {
270
+ signal?: AbortSignal;
271
+ }) => Promise<McpAppToolResult>;
272
+ /**
273
+ * A resource of that server for a file its app asks to save (a `resource_link`): the core's
274
+ * `ConnectedMcp.apps.readResource` - `resources/read` on that server, never a fetch. Older
275
+ * cores have none: a linked file is then refused.
276
+ */
277
+ readResource?: (server: string, uri: string, options?: {
278
+ signal?: AbortSignal;
279
+ maxBytes?: number;
280
+ }) => Promise<{
281
+ uri: string;
282
+ mimeType?: string;
283
+ bytes: Uint8Array;
284
+ }>;
285
+ }
286
+
287
+ /** Why a run stopped early (a `budget.exceeded` event). */
288
+ interface BudgetView {
289
+ kind: 'input' | 'output' | 'reasoning' | 'total' | 'tool-calls';
290
+ tokens: number;
291
+ cap: number;
292
+ }
293
+ /**
294
+ * Lifecycle of the agent instance the hook owns.
295
+ * - `idle` — no config yet, nothing built.
296
+ * - `initializing` — building the agent (dynamic provider imports, vault key
297
+ * fetch, and — for WebLLM — weight download).
298
+ * - `ready` — the agent is built and can run.
299
+ * - `running` — a run is in flight.
300
+ * - `error` — the agent failed to build (a run error keeps it `ready`).
301
+ */
302
+ type AgentStatus = 'idle' | 'initializing' | 'ready' | 'running' | 'error';
303
+ /** A file or image shown with a message (and, for images, sent to the model). */
304
+ interface ChatAttachment {
305
+ name: string;
306
+ mediaType: string;
307
+ /** A data URL (images: thumbnail + full view) — kept so a saved chat can show it again. */
308
+ dataUrl?: string;
309
+ /** Where it was stored in the virtual file system, if it was. */
310
+ path?: string;
311
+ size?: number;
312
+ /** A recording's length in milliseconds, as the recorder measured it (a voice message). */
313
+ durationMs?: number;
314
+ }
315
+ /** One turn of the chat transcript that a chat UI renders. */
316
+ interface ChatMessage {
317
+ id: string;
318
+ role: 'user' | 'assistant';
319
+ content: string;
320
+ /** An assistant message that is still streaming (no final/stopped/error yet). */
321
+ pending: boolean;
322
+ /**
323
+ * A turn of a run in another tab, as relayed here (`AgentUiState.remote`): that tab saves it.
324
+ * `useChatHistory` saves a chat from here with that tab's own copy, never this one.
325
+ */
326
+ remote?: true;
327
+ /**
328
+ * When the run of its turn began (ms epoch: the hook's `at` on `run.start`); the user message and
329
+ * the answer of a turn carry the same. Absent without the hook's timestamps and on chats saved
330
+ * before it existed. It keeps a turn in its place when two tabs save one chat: one run of a
331
+ * conversation goes at a time (the session lock), so the turn that began first is the earlier
332
+ * one, whichever tab saved first (`mergeChatRecord`).
333
+ */
334
+ startedAt?: number;
335
+ /** User turn: what was attached (images, files). */
336
+ attachments?: ChatAttachment[];
337
+ /** Assistant turn: the run's steps — tool calls, thoughts, subagents — as they happened. */
338
+ steps?: StepView[];
339
+ /** Assistant turn: consent decisions of the run. */
340
+ approvals?: ApprovalView[];
341
+ /** Assistant turn: subagent delegations of the run. */
342
+ subagents?: SubagentView[];
343
+ /** Assistant turn: what the user said while the run was going, and where it reached the agent. */
344
+ notes?: UserNoteView[];
345
+ /** Assistant turn: the synthesizer's thoughts. */
346
+ reasoning?: string;
347
+ /** Assistant turn: tokens the run spent, by kind. */
348
+ usage?: IUsage;
349
+ /** Assistant turn: wall-clock duration of the run (needs timestamps from the hook). */
350
+ durationMs?: number;
351
+ /** Assistant turn: skills the run used. */
352
+ skills?: string[];
353
+ /** Assistant turn: lessons the agent wrote down during the run (names). */
354
+ learned?: string[];
355
+ /** Assistant turn: what the model fetched from the web during the run. */
356
+ fetches?: FetchView[];
357
+ /** Assistant turn: the images and audio the run generated (`config.media`); absent when none. */
358
+ media?: MediaView[];
359
+ /** Assistant turn: the audio the run transcribed (`config.media`); absent when none. */
360
+ transcripts?: TranscriptView[];
361
+ /**
362
+ * Assistant turn: the files the run wrote to the workspace and did not delete again (the file
363
+ * tools and the sandbox; a subagent's are here too). Absent until the first one.
364
+ */
365
+ writtenFiles?: WrittenFileView[];
366
+ /**
367
+ * Assistant turn: the MCP Apps its tool calls came with (the core's `mcp.app`, on a
368
+ * connection made with `apps: true`). Absent until the first one. Holds the call's input and
369
+ * result for the app - never the app's HTML, which is read from its server when it is shown.
370
+ */
371
+ apps?: AppView[];
372
+ /** Assistant turn ended with an error. */
373
+ error?: boolean;
374
+ /**
375
+ * Assistant turn: the run was stopped (by the user, here or in another tab) before it was done.
376
+ * `content` is what it had written by then - `''` when nothing: the chat shows the
377
+ * `answerStopped` label in its place (the reducer keeps no UI text). A chat saved before this
378
+ * existed has the old `'Stopped.'` as its content, and shows that.
379
+ */
380
+ stopped?: true;
381
+ }
382
+ /** A single tool call as it appears in a step, streamed then finalized. */
383
+ interface ToolCallView {
384
+ name: string;
385
+ input: unknown;
386
+ output?: unknown;
387
+ ok?: boolean;
388
+ status: 'calling' | 'done';
389
+ /** When the call started (ms epoch; set when the hook stamps events). */
390
+ startedAt?: number;
391
+ /** How long the call took. */
392
+ durationMs?: number;
393
+ /** ≈ tokens of the arguments the model wrote (chars / 4). */
394
+ inputTokens?: number;
395
+ /** ≈ tokens of the result fed back to the model (chars / 4). */
396
+ outputTokens?: number;
397
+ /**
398
+ * Set on a call of an attempt that was escalated (model tiers): the attempt it belongs to,
399
+ * 1 for the step's first. A call of the attempt the step is on now (or finished on) has none.
400
+ */
401
+ attempt?: number;
402
+ /**
403
+ * The core did NOT run this call again: the same write already succeeded in an earlier attempt
404
+ * at the step, and the model was handed that result (`output` carries the core's note).
405
+ */
406
+ replayed?: boolean;
407
+ /** The call came with an MCP App (an `mcp.app` event): the `AppView` id. */
408
+ app?: string;
409
+ }
410
+ /**
411
+ * An MCP App that came with a tool call (the core's `mcp.app` event): which server, which tool,
412
+ * which `ui://` resource, and the call's input and result - what the app is shown. Never the
413
+ * app itself: `<McpAppFrame>` reads it from the server that declared it when it is drawn.
414
+ */
415
+ interface AppView {
416
+ /** The core's event id: unique per call. */
417
+ id: string;
418
+ server: string;
419
+ /** The tool as the model called it (`server__tool`). */
420
+ tool: string;
421
+ /** The server's own name for it. */
422
+ toolName: string;
423
+ resourceUri: string;
424
+ input: Record<string, unknown>;
425
+ /** What the app is given; absent when the result was too large to hand to it. */
426
+ result?: McpAppToolResult;
427
+ stepId?: string;
428
+ /** A subagent's (or helper's) call: who made it. */
429
+ by?: {
430
+ id: string;
431
+ name: string;
432
+ role?: string;
433
+ };
434
+ }
435
+ /**
436
+ * One escalation of a step (a `step.escalated` event): the attempt on tier `from` failed for
437
+ * `reason` and the step was retried on the stronger tier `to`.
438
+ */
439
+ interface StepEscalationView {
440
+ from: ModelTier;
441
+ to: ModelTier;
442
+ reason: EscalationReason;
443
+ /** The model id of `to` (absent only when the escalation is known from the step's result alone). */
444
+ model?: string;
445
+ /** What the failed attempt had written when it was escalated (its streamed text), if anything. */
446
+ text?: string;
447
+ }
448
+ /**
449
+ * A lesson in the agent's notebook (`config.learning`): a skill the agent wrote down itself.
450
+ * `revision` goes up each time it rewrites the lesson.
451
+ */
452
+ interface LessonView {
453
+ name: string;
454
+ /** WHEN the lesson applies - the line the planner sees. */
455
+ description: string;
456
+ revision: number;
457
+ /** Size of the instructions, in characters. */
458
+ chars: number;
459
+ /** What it consulted: the sources it named, then the pages `web_fetch` read in that run. */
460
+ sources: string[];
461
+ }
462
+ /** One request the model made through `web_fetch` (an `egress.request` event). */
463
+ interface FetchView {
464
+ /** Origin and path only - the core never reports the query string. */
465
+ url: string;
466
+ allowed: boolean;
467
+ status?: number;
468
+ /** Why it was refused. */
469
+ reason?: string;
470
+ }
471
+ /**
472
+ * A file a media tool wrote (a `media.generated` event). The bytes are in the virtual file system
473
+ * at `path` - never in the state.
474
+ */
475
+ interface MediaView {
476
+ kind: 'image' | 'speech';
477
+ path: string;
478
+ mediaType: string;
479
+ /** Size of the file. */
480
+ bytes: number;
481
+ /** The media model that made it. */
482
+ model: string;
483
+ /**
484
+ * The reference pictures of a `generate_image` call that had `images`: whether they were sent
485
+ * to the image model (`used`; false: it takes none, the picture was made from the text), how
486
+ * many, and their paths. Never their bytes.
487
+ */
488
+ references?: {
489
+ used: boolean;
490
+ count: number;
491
+ paths: string[];
492
+ };
493
+ /** The step whose tool call made it, when the event named one. */
494
+ stepId?: string;
495
+ }
496
+ /**
497
+ * A file the run wrote to the virtual file system (the core's `file.written` event: `fs_write`,
498
+ * or the sandbox's `fs.writeFile`). One entry per path however many times it was written; a
499
+ * `file.deleted` takes it away. The content is in the file system at `path` - never in the state.
500
+ */
501
+ interface WrittenFileView {
502
+ path: string;
503
+ /** The MIME type the file system gave it. */
504
+ mediaType: string;
505
+ /** Size after the last write. */
506
+ bytes: number;
507
+ /** How many times the run wrote it. */
508
+ writes: number;
509
+ /** The step whose tool call wrote it last, when the event named one (never a subagent's step). */
510
+ stepId?: string;
511
+ /** The subagent that wrote it last; absent when the agent itself did. */
512
+ by?: {
513
+ id: string;
514
+ name: string;
515
+ role?: string;
516
+ };
517
+ }
518
+ /**
519
+ * An audio file that was transcribed (a `media.transcribed` event): one the user attached
520
+ * (`attachment`) or one the model asked about (`tool`). `text` is the content of that file -
521
+ * third-party text, never instructions.
522
+ */
523
+ interface TranscriptView {
524
+ source: 'attachment' | 'tool';
525
+ /** The file's name. */
526
+ name: string;
527
+ text: string;
528
+ language?: string;
529
+ durationInSeconds?: number;
530
+ model: string;
531
+ }
532
+ /**
533
+ * One question put to `config.decisionModel` (a `decision` event): its answer was used
534
+ * (`accepted`), or the ordinary model call ran and `reason` says why.
535
+ */
536
+ interface DecisionView {
537
+ point: DecisionPoint;
538
+ accepted: boolean;
539
+ choice?: string;
540
+ /** The probability the decision model gave its choice, 0..1. */
541
+ confidence?: number;
542
+ threshold: number;
543
+ reason?: DecisionFallbackReason;
544
+ durationMs: number;
545
+ model?: string;
546
+ }
547
+ /** A tool call waiting for (or decided by) the user's consent. */
548
+ interface ApprovalView {
549
+ id: string;
550
+ name: string;
551
+ input: unknown;
552
+ readOnly: boolean;
553
+ /** The step the call belongs to, when known. */
554
+ stepId?: string;
555
+ /**
556
+ * Set when a helper the model started is asking, not the run itself: its id (a node of
557
+ * `subagents`), its depth, and - when its `subagent.start` was seen - its name and role.
558
+ */
559
+ subagent?: {
560
+ id: string;
561
+ depth: number;
562
+ name?: string;
563
+ role?: string;
564
+ };
565
+ status: 'pending' | 'approved' | 'denied';
566
+ reason?: string;
567
+ /** Decided by policy (rule / read-only mode), not by a person. */
568
+ automatic?: boolean;
569
+ /**
570
+ * Set when an MCP App asks, not the model (`useAgent().approveAppToolCall`): its server, the
571
+ * tool's own name there and the app's resource. `name` is then the key the consent rules
572
+ * match. Such a request outlives a run (it is the user's, not the run's) and is never kept on
573
+ * a message. `frame` is the host's id of the frame that asked (`AppView.id`, from
574
+ * `AppToolCall.frame`): two frames of one app each have their own requests.
575
+ */
576
+ app?: {
577
+ server: string;
578
+ tool: string;
579
+ resourceUri: string;
580
+ frame?: string;
581
+ };
582
+ /**
583
+ * Asked in another tab, by a run of this conversation going on there (`AgentUiState.remote`):
584
+ * shown, never answered here - consent stays with the tab that runs the tool. `useAgent`'s
585
+ * `pendingApprovals` leaves it out.
586
+ */
587
+ remote?: true;
588
+ /**
589
+ * Set when the request is about an MCP server's skill about to enter the model's context, not
590
+ * a tool call (the core's `ToolApprovalRequest.skill`): the server, the skill, its description,
591
+ * size and files, and - while the request is pending - `body`, the very text the model would
592
+ * read. All of it is the SERVER's text: show it as plain text. `body` is dropped once the
593
+ * request is decided, so a saved conversation does not keep a server's instructions.
594
+ */
595
+ skill?: SkillConsentView;
596
+ /**
597
+ * Set when an explicit `'ask'` rule asked (the core's `ToolApprovalRequest.rule`): its name or
598
+ * pattern. The core asks such a call EVERY time - no "always allow" answers a rule -, so
599
+ * `<ToolApprovalPrompt>` offers no "Always allow" on it by default.
600
+ */
601
+ rule?: string;
602
+ }
603
+ /** What a person is shown of an MCP server's skill (the core's `McpSkillConsentView`). */
604
+ type SkillConsentView = Omit<McpSkillConsentView, 'body'> & {
605
+ body?: string;
606
+ };
607
+ /**
608
+ * A question an MCP server put to the user in the middle of a tool call (MCP elicitation; the
609
+ * core's `mcp.elicitation-*` events). `message`, `requestedSchema` and `url` are the SERVER's
610
+ * text - show them as such, never as the application's own. The view never holds what the user
611
+ * answered: `fields` are the names of the fields an accepted form was answered with.
612
+ */
613
+ interface ElicitationView {
614
+ /** The question's id: the same as `McpElicitationRequest.id` handed to `onElicitation`. */
615
+ id: string;
616
+ server: string;
617
+ /** The tool call during which the server asked. */
618
+ tool: string;
619
+ /** Absent only for a question that was refused before it could be shown. */
620
+ mode?: 'form' | 'url';
621
+ message: string;
622
+ /** Form mode: the fields to fill in. */
623
+ requestedSchema?: McpElicitationSchema;
624
+ /** URL mode: the link the server wants opened. Nothing opens it for the user. */
625
+ url?: string;
626
+ /** Asked in another tab, by a run followed here (`AgentUiState.remote`): answered there. */
627
+ remote?: true;
628
+ /** The step the tool call belongs to, when known. */
629
+ stepId?: string;
630
+ /** Set when a helper (a subagent) is the one whose call asks. */
631
+ subagent?: {
632
+ id: string;
633
+ depth: number;
634
+ name?: string;
635
+ role?: string;
636
+ };
637
+ status: 'pending' | 'accepted' | 'declined' | 'cancelled';
638
+ /** Answered without anybody deciding (a guard, a cap, a timeout, a stopped run). */
639
+ automatic?: boolean;
640
+ /** Why it was answered automatically (the core's reason, or `stopped`). */
641
+ reason?: string;
642
+ /** The names of the fields an accepted form was answered with. */
643
+ fields?: string[];
644
+ }
645
+ /**
646
+ * A question the MODEL put to the person (the core's `ask_user`, `config.askUser`; its
647
+ * `user.question-*` events): the question and the options are the model's text, cleaned - show
648
+ * them as plain text, never as markup. The view never holds what the person typed: an answer in
649
+ * their own words is `status: 'other'` and nothing more; `choice` holds labels that were offered.
650
+ */
651
+ interface QuestionView {
652
+ /** The question's id: the same as `AskUserRequest.id` handed to `onQuestion`. */
653
+ id: string;
654
+ question: string;
655
+ options: AskUserOption[];
656
+ /** The person may pick several options. */
657
+ multiple: boolean;
658
+ /** The person may answer in their own words. */
659
+ allowOther: boolean;
660
+ /** The step whose tool call asks (for a helper's question: the step that delegated it). */
661
+ stepId?: string;
662
+ /**
663
+ * Set when a helper or a subagent asks, not the run itself: its id (a node of `subagents`), its
664
+ * depth, and - when its `subagent.start` was seen - its name and role.
665
+ */
666
+ subagent?: {
667
+ id: string;
668
+ depth: number;
669
+ name?: string;
670
+ role?: string;
671
+ };
672
+ /** Asked in another tab, by a run followed here (`AgentUiState.remote`): answered there only. */
673
+ remote?: true;
674
+ /** `pending`, then how it ended (the core's `AskUserAction`). */
675
+ status: 'pending' | AskUserAction;
676
+ /** Ended without anybody deciding: a time limit, a stop, a failed handler, an unusable answer. */
677
+ automatic?: boolean;
678
+ /** `status: 'choice'`: the labels picked. */
679
+ choice?: string[];
680
+ /** Why it ended `declined` automatically (the core's `AskUserReason`), or `stopped`. */
681
+ reason?: string;
682
+ }
683
+ /** A message sent to the agent while it works, still waiting for a boundary to be shown to the model. */
684
+ interface QueuedMessageView {
685
+ id: string;
686
+ text: string;
687
+ /** Another tab of the site sent it to this run (the core's session relay). */
688
+ origin?: 'another-tab';
689
+ /**
690
+ * What the user sent waits with a run of this tab's that waits for the SESSION (`sessionBusy`):
691
+ * the other run of the conversation holds it - in another tab, or in this one. The entry is
692
+ * there only while that wait lasts (the run then starts with it); the chat shows
693
+ * `queuedForSession` for it, not `queuedWaiting`.
694
+ */
695
+ session?: SessionHolder;
696
+ /**
697
+ * What THIS tab said to the conversation's run in another tab (`sendRemote`), while that tab has
698
+ * not answered: the chat shows `queuedForOtherTab` for it. That tab answers when it takes the
699
+ * message - then its own entry (`message.queued`, marked `origin: 'another-tab'`) takes this
700
+ * one's place - or refuses it, or its run ends without it: then the text comes back in
701
+ * `undelivered`. A tab the browser froze in the background answers when it wakes; until then the
702
+ * entry stays.
703
+ */
704
+ sentTo?: 'another-tab';
705
+ }
706
+ /**
707
+ * A message the user sent while the run was going, after it reached the agent.
708
+ * `at` says where: `round` = between tool calls inside a step, `step` = at the end
709
+ * of a step (the replanner then re-checked the plan), `final` = just before the
710
+ * answer was written.
711
+ */
712
+ interface UserNoteView {
713
+ id: string;
714
+ text: string;
715
+ at: 'round' | 'step' | 'final';
716
+ /** The step it was delivered in (`round`) or after (`step`); none for `final`. */
717
+ stepId?: string;
718
+ /** Another tab of the site sent it (the core's session relay). */
719
+ origin?: 'another-tab';
720
+ }
721
+ /**
722
+ * A delegated task running in a subagent: one the host defined (`createSubagentTool`, in-process
723
+ * or a Web Worker) or a helper the model started (`spawn_subagent`). Each is a NODE OF A TREE:
724
+ * `parentId` / `depth` say where, and {@link subagentTree} nests the flat list.
725
+ */
726
+ interface SubagentView {
727
+ id: string;
728
+ /** The subagent's name (`spawn_subagent` for a helper the model started). */
729
+ name: string;
730
+ /** Empty when only its events were seen (its `subagent.start` never arrived). */
731
+ task: string;
732
+ /**
733
+ * The subagent that started this one; absent for the run's own subagents (depth 1). A parent
734
+ * that is not in the list (its start was never seen) leaves the node at the top of the tree.
735
+ */
736
+ parentId?: string;
737
+ /** 1 for the run's own subagents, 2 for theirs, ... */
738
+ depth: number;
739
+ /** A helper the model started itself (`subagents.dynamic`). */
740
+ dynamic?: true;
741
+ /** What the model wrote for a helper it started. Model-written text. */
742
+ role?: string;
743
+ /** The tool names a helper was given. */
744
+ tools?: string[];
745
+ /** The model and tier its latest step ran on - known only when the child uses model tiers. */
746
+ model?: string;
747
+ tier?: ModelTier;
748
+ /** When it started (ms epoch; set when the hook stamps events). */
749
+ startedAt?: number;
750
+ /** How long it ran, once it ended. */
751
+ durationMs?: number;
752
+ /** `stopped`: the user stopped this subagent; the run went on without it. */
753
+ status: 'running' | 'done' | 'error' | 'stopped';
754
+ /** The profile the parent model chose for this delegation, when there are profiles. */
755
+ profile?: string;
756
+ /** The step that delegated it, when known. */
757
+ stepId?: string;
758
+ /** What the child is doing right now ("step 2: …", "→ tool"). */
759
+ activity: string;
760
+ /** Steps the child started. */
761
+ steps: number;
762
+ /** Tool calls the child made. */
763
+ toolCalls: number;
764
+ /** The child's answer (streamed, then final). */
765
+ text: string;
766
+ /**
767
+ * Tokens spent under this node, its own subagents included: counted live from its `usage`
768
+ * events, then replaced by the total its end reports.
769
+ */
770
+ usage: IUsage;
771
+ error?: string;
772
+ }
773
+ /** A {@link SubagentView} with the subagents it started (see {@link subagentTree}). */
774
+ interface SubagentNode extends SubagentView {
775
+ children: SubagentNode[];
776
+ }
777
+ /** One compaction of the context (a `context.compacted` event). */
778
+ interface CompactionView {
779
+ scope: 'history' | 'trace' | 'tool-results';
780
+ beforeTokens: number;
781
+ afterTokens: number;
782
+ }
783
+ /** An execution step with its accumulated text and tool calls. */
784
+ interface StepView {
785
+ id: string;
786
+ /** Its place in the run (1-based). */
787
+ index: number;
788
+ /**
789
+ * The plan's length as the run's LATEST step started: a replan that grew or cut the plan
790
+ * renumbers the earlier rows too (1/2, 2/2 - not 1/1, 2/2).
791
+ */
792
+ total: number;
793
+ step: IPlanStep;
794
+ /** Streamed executor text for this step (step.text-delta). */
795
+ text: string;
796
+ /** Streamed executor thoughts for this step (step.reasoning-delta). */
797
+ reasoning: string;
798
+ toolCalls: ToolCallView[];
799
+ status: 'running' | 'done';
800
+ summary?: string;
801
+ blocked: boolean;
802
+ /**
803
+ * Model tiers (`config.executorTiers`) - all four are absent when tiers are off.
804
+ * `tier` / `model`: the tier the step is on NOW (where it started, then where an escalation
805
+ * took it, then where it finished) and that tier's model id.
806
+ */
807
+ tier?: ModelTier;
808
+ model?: string;
809
+ /** Why the step STARTED on its tier: the planner's rating, the default, or a fallback. */
810
+ tierReason?: TierReason;
811
+ /**
812
+ * The step's escalations, in order. `text` / `reasoning` above hold the current attempt only;
813
+ * the calls of the attempts before it stay in `toolCalls`, marked with their `attempt`.
814
+ */
815
+ escalations?: StepEscalationView[];
816
+ /**
817
+ * The replanner call that followed this step failed (the provider's error): the run went on
818
+ * with the plan it had. A warning, not a failed step.
819
+ */
820
+ replanFailed?: string;
821
+ /** What `config.decisionModel` was asked after this step; absent without a decision model. */
822
+ decisions?: DecisionView[];
823
+ /** The files this step's media tools wrote (also in the turn's `media`); absent when none. */
824
+ media?: MediaView[];
825
+ }
826
+ /** WebLLM weight-download / engine-init progress (model.load events). */
827
+ interface ModelLoadState {
828
+ progress: number;
829
+ text: string;
830
+ }
831
+ interface ReplanState {
832
+ mode: ReplanMode;
833
+ reason: string;
834
+ /** The replanner ran because the user sent a message, not because a step failed. */
835
+ byUser?: boolean;
836
+ /**
837
+ * The replanner call itself failed and `continue` is the fallback, not the model's decision.
838
+ * `error` is the failure (the `error` event of phase `replan` that came just before).
839
+ */
840
+ failed?: true;
841
+ error?: string;
842
+ /** `config.decisionModel` made this decision: the probability it gave its choice. */
843
+ confidence?: number;
844
+ }
845
+ /**
846
+ * The whole UI-facing view of an agent run, rebuilt purely from the stream of
847
+ * `AgentEvent`s by {@link agentStateReducer}. `status` is owned by the hook
848
+ * (build/run lifecycle) and layered on top; everything else here is derived
849
+ * only from events, so the reducer is deterministic and testable without React.
850
+ */
851
+ interface AgentUiState {
852
+ status: AgentStatus;
853
+ /** The goal of the current / most recent run. */
854
+ goal?: string;
855
+ /** The last plan the agent produced (created or revised). */
856
+ plan?: IPlan;
857
+ /** Streamed planner "thinking" text (plan.thought-delta). */
858
+ planThought: string;
859
+ /** Execution steps, in order, with their tool calls. */
860
+ steps: StepView[];
861
+ /** The final answer (streamed via final.text-delta, finalized on final). */
862
+ finalText: string;
863
+ /** The synthesizer's streamed thoughts (final.reasoning-delta). */
864
+ finalReasoning: string;
865
+ /** Tool calls that asked for consent in this run, pending first-come. */
866
+ approvals: ApprovalView[];
867
+ /**
868
+ * Subagent delegations of this run - static subagents and the helpers the model started, at
869
+ * every depth, in the order they started. A tree: see `SubagentView.parentId` / `subagentTree`.
870
+ */
871
+ subagents: SubagentView[];
872
+ /**
873
+ * Questions MCP servers put to the user in this run (MCP elicitation), in the order they
874
+ * arrived; absent until the first one. Per-run view only: they are not copied into the
875
+ * transcript, so a saved conversation never holds a server's form.
876
+ */
877
+ elicitations?: ElicitationView[];
878
+ /**
879
+ * Questions the model put to the person in this run (`ask_user`, `config.askUser`), in the
880
+ * order they were asked, a helper's included; absent until the first one. Per-run view only:
881
+ * they are not copied into the transcript, and none holds what the person typed.
882
+ */
883
+ questions?: QuestionView[];
884
+ /** Messages sent while the run goes that have not yet been shown to the model. */
885
+ queued: QueuedMessageView[];
886
+ /** What the user said during this run and when it reached the agent. */
887
+ notes: UserNoteView[];
888
+ /**
889
+ * Messages the run ended without showing the model (sent while the answer was being
890
+ * written, or still queued when the run was stopped). The hook sends them as a
891
+ * follow-up unless the run was stopped; see `useAgent`'s `followUp`.
892
+ */
893
+ undelivered: string[];
894
+ /** Skills activated in this run. */
895
+ skills: string[];
896
+ /**
897
+ * The agent's notebook: the lessons it wrote down (`config.learning`). It belongs to the
898
+ * agent, not to a conversation - it survives `reset` and a chat switch, and the hook
899
+ * re-reads it whenever the agent is rebuilt.
900
+ */
901
+ learned: LessonView[];
902
+ /** Names of the lessons written in this run. */
903
+ learnedNow: string[];
904
+ /** What the model fetched from the web in this run (`config.egress`). */
905
+ fetches: FetchView[];
906
+ /** Images and audio generated in this run (`config.media`). Absent until the first one. */
907
+ media?: MediaView[];
908
+ /** Audio transcribed in this run (`config.media`). Absent until the first one. */
909
+ transcripts?: TranscriptView[];
910
+ /** Files written in this run and still there (`file.written` / `file.deleted`). Absent until the first one. */
911
+ writtenFiles?: WrittenFileView[];
912
+ /** MCP Apps this run's tool calls came with (`mcp.app`). Absent until the first one. */
913
+ apps?: AppView[];
914
+ /**
915
+ * Questions put to `config.decisionModel` before any step existed (a decision that follows a
916
+ * step is on that step). Absent until the first one.
917
+ */
918
+ decisions?: DecisionView[];
919
+ /** Tools activated by find_tools in this run. */
920
+ discoveredTools: string[];
921
+ /** Compactions in this run. */
922
+ compactions: CompactionView[];
923
+ /** Set when a run-level limit stopped the run early. */
924
+ budget?: BudgetView;
925
+ /** Running token total across the current run. */
926
+ usage: IUsage;
927
+ /** Token total across the whole conversation (every run since the last reset). */
928
+ totalUsage: IUsage;
929
+ /** When the current run started (ms epoch; set when the hook stamps events). */
930
+ runStartedAt?: number;
931
+ /** The id of the assistant message the current run streams into. */
932
+ runMessageId?: string;
933
+ /** WebLLM progress, present only while a local model is loading. */
934
+ modelLoad?: ModelLoadState;
935
+ /** The most recent replan decision, if any. */
936
+ replan?: ReplanState;
937
+ /**
938
+ * Error message from the last run error / build failure. A non-fatal `plan` / `execute` /
939
+ * `synthesize` error is kept here too while the run goes on; a replanner failure is not (see
940
+ * `replan.failed` and `StepView.replanFailed`).
941
+ */
942
+ error?: string;
943
+ /**
944
+ * The core's code of a run error a host may want to say in its own words: `'no-plan'` (the
945
+ * planner returned nothing readable) or `'no-answer'` (the model wrote no answer). Absent for
946
+ * every other error.
947
+ */
948
+ errorCode?: 'no-plan' | 'no-answer';
949
+ /** True when the last run was aborted via stop(). */
950
+ stopped: boolean;
951
+ /** A chat-style transcript built from every run, for chat UIs. */
952
+ messages: ChatMessage[];
953
+ /** The raw event log (most recent last), capped by `maxEvents`. */
954
+ events: AgentEvent[];
955
+ /** Monotonic counter; mints stable message ids without Date/Math.random. */
956
+ seq: number;
957
+ /**
958
+ * The run in view is another tab's: this conversation runs in another tab of the origin, and
959
+ * `useAgent` follows it (the core's `watchSession`) - its steps, answer and usage are folded
960
+ * into the rest of the state like a run of this tab's. Absent once a run of this tab starts or
961
+ * a chat is loaded.
962
+ */
963
+ remote?: RemoteRunView;
964
+ /**
965
+ * This tab's run waits for the session: another run of it is going (`session.busy`) - in
966
+ * another tab, or in this one. Cleared when it gets the session, or is stopped.
967
+ */
968
+ sessionBusy?: {
969
+ heldBy: SessionHolder;
970
+ goal?: string;
971
+ };
972
+ /**
973
+ * The turn the user just sent, shown at once while the run gets going (its `run.start` comes
974
+ * after the session's lock is granted - a round trip to the browser's lock manager): the ids of
975
+ * its user and pending assistant messages. `run.start` replaces them; a wait for the session
976
+ * turns the text into a queued item instead.
977
+ */
978
+ submitted?: {
979
+ userId: string;
980
+ assistantId: string;
981
+ };
982
+ }
983
+ /** Another tab's run of this conversation, as this tab sees it. */
984
+ interface RemoteRunView {
985
+ /** It is going now (`useAgent` reports `isRunning`; `send` / `stop` go to that tab). */
986
+ running: boolean;
987
+ runId?: string;
988
+ /**
989
+ * How it ended: `done`, `stopped`, or `gone` - that tab closed or crashed before it said so
990
+ * (its answer, if any, is what had arrived).
991
+ */
992
+ ended?: 'done' | 'stopped' | 'gone';
993
+ }
994
+
995
+ /**
996
+ * MCP Apps, the host's side: the security core of `<McpAppFrame>`, as pure code - no React, no
997
+ * DOM - so every guard is unit-tested (`tests/apps.test.ts`) and proved in a real browser
998
+ * (`e2e/apps.spec.ts`).
999
+ *
1000
+ * The frame: an app is third-party HTML WITH scripts that must talk to the page, so it gets the
1001
+ * HTML preview's boundary (`html-preview.ts`) and one addition, a relay:
1002
+ *
1003
+ * 1. The outer `<iframe sandbox="allow-scripts">` (never `allow-same-origin`): an opaque origin,
1004
+ * no access to the page's DOM, storage, IndexedDB (the key vault) or cookies; no top
1005
+ * navigation, popups, forms, modals, downloads. No `allow` attribute: no camera, microphone,
1006
+ * geolocation or clipboard, whatever the app asked for.
1007
+ * 2. It holds a SHELL of ours (`buildMcpAppDocument`): the policy built from the resource's
1008
+ * declared origins and nothing else (`mcpAppCsp`), one inner frame - the app, also
1009
+ * `sandbox="allow-scripts"`, with the same policy first in its own document - and a relay
1010
+ * script. The shell's `frame-src 'none'` is what stops the app navigating itself (a frame
1011
+ * may always navigate itself; only the EMBEDDING document's policy decides where to).
1012
+ * 3. The relay forwards messages between the page and the app, and nothing else: from the
1013
+ * app's window to the page, from the page to the app's window, never the
1014
+ * `ui/notifications/sandbox-*` messages the specification reserves. The app talks to
1015
+ * `window.parent` as the extension's SDK does; the page accepts messages only from the outer
1016
+ * frame (`event.source`), so the app writing to `window.top` directly is ignored.
1017
+ * 4. The bridge (`McpAppBridge`) answers the app: a method allow-list, checked parameters, a
1018
+ * cap on requests in flight, and every request that DOES something (a tool call, a link, a
1019
+ * message) handed to the host, which asks the user.
1020
+ *
1021
+ * That is the default. Opt-in, the app runs on an origin of its own instead, behind a sandbox
1022
+ * page the host serves on another origin (the specification's "sandbox proxy"): 1 - 3 change
1023
+ * (see "An app on an origin of its own" below and `mcp-app-policy.ts`), 4 does not.
1024
+ */
1025
+ /** The revision of the extension this host speaks. */
1026
+ declare const MCP_APP_PROTOCOL_VERSION = "2026-01-26";
1027
+ /** An app's frame height, before it says how tall it is. */
1028
+ declare const APP_DEFAULT_HEIGHT = 360;
1029
+ /**
1030
+ * The frame's height is the host's: the app's wish, clamped to `APP_MIN_HEIGHT` .. the cap. The
1031
+ * cap is `appHeightCap` of the chat's visible height - a few screens, never less than
1032
+ * `APP_MAX_HEIGHT` - so an app as tall as its content has no scroller of its own inside the
1033
+ * transcript (one scroller: the chat's), and an app that grows forever stops there.
1034
+ */
1035
+ declare const APP_MIN_HEIGHT = 120;
1036
+ /** The least the cap is (and the cap where nothing says how tall the chat is). */
1037
+ declare const APP_MAX_HEIGHT = 800;
1038
+ /** The cap is this many of the chat's visible heights. */
1039
+ declare const APP_HEIGHT_SCREENS = 3;
1040
+ /** ... and never more than this, whatever the screen. */
1041
+ declare const APP_HEIGHT_CEILING = 6000;
1042
+ /**
1043
+ * The tallest an inline app's frame is drawn, for a chat body (or viewport) `viewHeight` px tall:
1044
+ * `APP_HEIGHT_SCREENS` of it, rounded down to 100 px (the app is told it in
1045
+ * `containerDimensions.maxHeight`, and a resize of a few pixels must not tell it again), at least
1046
+ * `APP_MAX_HEIGHT`, at most `APP_HEIGHT_CEILING`.
1047
+ */
1048
+ declare const appHeightCap: (viewHeight: number | undefined) => number;
1049
+ /**
1050
+ * The cap of a frame that is already drawn, when the chat's height changes: `appHeightCap` of the
1051
+ * new height, but never less than the cap the frame had (`current`) - a rotation, a keyboard
1052
+ * resizing the page or a relayout for a touch screen must not give an app that was drawn whole a
1053
+ * scroller of its own. The cap only grows while the frame is shown (at most
1054
+ * `APP_HEIGHT_CEILING`); a new frame starts from the cap of its moment.
1055
+ */
1056
+ declare const nextAppHeightCap: (current: number, viewHeight: number | undefined) => number;
1057
+ /** At most this many requests of one app wait at once (tool calls, links, messages). */
1058
+ declare const MCP_APP_MAX_IN_FLIGHT = 3;
1059
+ /** A message an app puts in the chat: at most this many characters. */
1060
+ declare const MCP_APP_MAX_MESSAGE_CHARS = 4000;
1061
+ /** A link an app asks to open: at most this many characters. */
1062
+ declare const MCP_APP_MAX_URL_CHARS = 2048;
1063
+ /** The arguments of a tool call an app makes: at most this many characters as JSON. */
1064
+ declare const MCP_APP_MAX_ARGS_CHARS = 64000;
1065
+ /** An app's wish for a height, as the frame draws it: within `APP_MIN_HEIGHT` .. `max` (the cap). */
1066
+ declare const clampAppHeight: (height: number, max?: number) => number;
1067
+ /**
1068
+ * The policy of an app's document: scripts and styles inline, `data:` / `blob:` media, and the
1069
+ * network ONLY where the resource declared it - `connectDomains` for `fetch` / XHR / WebSocket,
1070
+ * `resourceDomains` for scripts, styles, images, fonts and media. Nothing declared, nothing
1071
+ * reached. Nested frames, workers, plugins, forms and `<base>` are refused whatever was declared
1072
+ * (`frameDomains` / `baseUriDomains` are not granted: a frame the app may embed would also be a
1073
+ * place it may navigate itself to). Each entry is checked again with the core's `mcpAppOrigin`.
1074
+ */
1075
+ declare const mcpAppCsp: (csp?: Partial<McpAppCsp>) => string;
1076
+ /** The origins the policy actually grants: what the app is told in `hostCapabilities.sandbox`. */
1077
+ declare const grantedAppCsp: (csp?: Partial<McpAppCsp>) => {
1078
+ connectDomains: string[];
1079
+ resourceDomains: string[];
1080
+ };
1081
+ /**
1082
+ * The relay of the shell: the app's messages to the page, the page's to the app - matched by
1083
+ * `event.source`, never by anything the message says - and not the reserved
1084
+ * `ui/notifications/sandbox-*` ones. It reads nothing else and runs nothing it is sent.
1085
+ */
1086
+ declare const MCP_APP_RELAY: string;
1087
+ /**
1088
+ * What goes into the OUTER frame's `srcdoc`: the shell (the app's policy first, one inner frame
1089
+ * that fills it, the relay) carrying the app, escaped, as the inner frame's `srcdoc` - with the
1090
+ * same policy first in it. Give the outer `<iframe>` `sandbox="allow-scripts"` and nothing else.
1091
+ * `scheme` (the theme the app is told) is declared by the shell and its inner frame; give the
1092
+ * outer `<iframe>` the same `color-scheme`. Only `light` / `dark` are declared.
1093
+ */
1094
+ declare const buildMcpAppDocument: (html: string, csp?: Partial<McpAppCsp>, scheme?: McpAppColorScheme) => string;
1095
+ /** A link an app asks to open, taken apart for the prompt: the host is what the user checks. */
1096
+ interface AppLink {
1097
+ /** The normalised URL (what is opened). */
1098
+ href: string;
1099
+ /** `https://` */
1100
+ scheme: string;
1101
+ /** The host (and port), as the browser will go there - an internationalised name in punycode. */
1102
+ host: string;
1103
+ /** Everything after the host. */
1104
+ rest: string;
1105
+ }
1106
+ /** An `http(s)` URL with a host and no credentials, at most `MCP_APP_MAX_URL_CHARS`; else none. */
1107
+ declare const appLinkOf: (value: unknown) => AppLink | undefined;
1108
+ /**
1109
+ * The text of a `ui/message` an app sends: text blocks only (one, or a list of at most 20),
1110
+ * joined, without invisible characters, at most `MCP_APP_MAX_MESSAGE_CHARS`. Anything else -
1111
+ * an image, a resource, an empty or a longer text - is refused (`undefined`).
1112
+ */
1113
+ declare const appMessageTextOf: (content: unknown) => string | undefined;
1114
+ /** A JSON-RPC message as the bridge sends it. */
1115
+ type McpAppRpcMessage = {
1116
+ jsonrpc: '2.0';
1117
+ id: string | number;
1118
+ method: string;
1119
+ params?: unknown;
1120
+ } | {
1121
+ jsonrpc: '2.0';
1122
+ method: string;
1123
+ params?: unknown;
1124
+ } | {
1125
+ jsonrpc: '2.0';
1126
+ id: string | number;
1127
+ result: unknown;
1128
+ } | {
1129
+ jsonrpc: '2.0';
1130
+ id: string | number;
1131
+ error: {
1132
+ code: number;
1133
+ message: string;
1134
+ };
1135
+ };
1136
+ /** The requests an app may make of this host. Any other is answered "method not found". */
1137
+ declare const MCP_APP_REQUESTS: readonly ["ui/initialize", "ping", "tools/call", "ui/open-link", "ui/message", "ui/request-display-mode"];
1138
+ /**
1139
+ * Requests answered only when the host turned the feature on (`downloadFile` / `sampling` in
1140
+ * `hostCapabilities`, a handler given to the bridge); otherwise "method not found", as before.
1141
+ */
1142
+ declare const MCP_APP_OPTIONAL_REQUESTS: readonly ["ui/download-file", "sampling/createMessage"];
1143
+ /** The notifications this host reads. Any other is dropped. */
1144
+ declare const MCP_APP_NOTIFICATIONS: readonly ["ui/notifications/initialized", "ui/notifications/size-changed"];
1145
+ /** An error the bridge answers with: a JSON-RPC code and a message for the app. */
1146
+ declare class McpAppRpcError extends Error {
1147
+ readonly code: number;
1148
+ constructor(code: number, message: string);
1149
+ }
1150
+ /** The host refused: the user said no, too many requests, not initialized. */
1151
+ declare const MCP_APP_REFUSED = -32000;
1152
+ /** How an app is shown (`hostContext.displayMode`). This host offers `inline` and `fullscreen`. */
1153
+ type McpAppDisplayMode = 'inline' | 'fullscreen' | 'pip';
1154
+ /** The modes the extension names (a request for any other is invalid). */
1155
+ declare const MCP_APP_DISPLAY_MODES: readonly McpAppDisplayMode[];
1156
+ /** A file an app asks the host to save (`ui/download-file`), as checked by `appDownloadOf`. */
1157
+ type AppDownload = {
1158
+ kind: 'embedded';
1159
+ /** The file name, sanitized (`appFileNameOf`): what it is saved as. */
1160
+ name: string;
1161
+ /** The type the app declared, if it is a MIME type at all. */
1162
+ mimeType?: string;
1163
+ bytes: Uint8Array;
1164
+ } | {
1165
+ /** A `resource_link`: read with `resources/read` on the app's own server, never fetched. */
1166
+ kind: 'link';
1167
+ uri: string;
1168
+ name: string;
1169
+ mimeType?: string;
1170
+ };
1171
+ /** What the host does for an app (the user is asked inside these, never by the bridge). */
1172
+ interface McpAppBridgeHandlers {
1173
+ /** A `tools/call`: resolves with the result the app is given; throws when refused. */
1174
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
1175
+ /** A link (already checked): resolves true when it was opened, false when the user said no. */
1176
+ openLink: (link: AppLink) => Promise<boolean>;
1177
+ /** A message (already cleaned): resolves true when it was accepted, false when not. */
1178
+ message: (text: string) => Promise<boolean>;
1179
+ /** The app's wish for a height (the caller clamps it). */
1180
+ resize: (height: number) => void;
1181
+ /**
1182
+ * `ui/request-display-mode` for a mode the host offers and the app declared (or `inline`):
1183
+ * the mode the app is in afterwards - the host may say no and answer the current one.
1184
+ * Without it, an app stays where it is.
1185
+ */
1186
+ displayMode?: (mode: McpAppDisplayMode) => McpAppDisplayMode | Promise<McpAppDisplayMode>;
1187
+ /**
1188
+ * `ui/download-file` (already checked): true once the file was saved, false when the user said
1189
+ * no. Without it the method is not offered (`hostCapabilities.downloadFile` absent).
1190
+ */
1191
+ downloadFile?: (file: AppDownload) => Promise<boolean>;
1192
+ /**
1193
+ * `sampling/createMessage`: the result for the app; throws (an `McpAppRpcError`) when refused.
1194
+ * Without it the method is not offered (`hostCapabilities.sampling` absent).
1195
+ */
1196
+ sample?: (params: Record<string, unknown>) => Promise<unknown>;
1197
+ }
1198
+ interface McpAppBridgeOptions {
1199
+ /** Send a message to the app (the page posts it to the outer frame). */
1200
+ post: (message: McpAppRpcMessage) => void;
1201
+ handlers: McpAppBridgeHandlers;
1202
+ hostInfo: {
1203
+ name: string;
1204
+ version: string;
1205
+ };
1206
+ hostCapabilities: Record<string, unknown>;
1207
+ hostContext: Record<string, unknown>;
1208
+ /** The tool call's arguments: sent once the app says it is initialized. */
1209
+ toolInput: Record<string, unknown>;
1210
+ /** Its result; `undefined` = the app is told the call was cancelled (`reason`). */
1211
+ toolResult?: unknown;
1212
+ cancelledReason?: string;
1213
+ maxInFlight?: number;
1214
+ }
1215
+ /**
1216
+ * One app's conversation with the host (the extension's JSON-RPC over `postMessage`). It never
1217
+ * touches the DOM: `receive` is given what arrived - from the right frame, the caller checked
1218
+ * `event.source` - and `post` sends. Requests outside the allow-list get "method not found";
1219
+ * before `ui/initialize`, only `ping` is answered; parameters are checked before a handler sees
1220
+ * them; at most `maxInFlight` requests run at once. The tool's input and result are sent once,
1221
+ * after the app's `ui/notifications/initialized`, as the specification requires.
1222
+ */
1223
+ declare class McpAppBridge {
1224
+ private readonly o;
1225
+ private initializeSeen;
1226
+ private delivered;
1227
+ private inFlight;
1228
+ private closed;
1229
+ private seq;
1230
+ private appModes;
1231
+ constructor(options: McpAppBridgeOptions);
1232
+ /** The app said it is ready, and was given the tool's input and result. */
1233
+ get initialized(): boolean;
1234
+ /** Stop answering: the frame is gone or was reloaded. */
1235
+ close(): void;
1236
+ /** Tell the app it is being torn down (not waited for: the frame goes anyway). */
1237
+ teardown(reason: string): void;
1238
+ /** The display modes the app declared at `ui/initialize` (undefined: none, or not yet). */
1239
+ get appDisplayModes(): readonly McpAppDisplayMode[] | undefined;
1240
+ /** How the app is shown now (`hostContext.displayMode`). */
1241
+ get displayMode(): McpAppDisplayMode;
1242
+ /** Tell an initialized app that part of the host context changed (the theme). */
1243
+ updateContext(patch: Record<string, unknown>): void;
1244
+ /** One message from the app's frame. */
1245
+ receive(data: unknown): void;
1246
+ private send;
1247
+ private error;
1248
+ private notification;
1249
+ private request;
1250
+ }
1251
+ /**
1252
+ * What this host tells an app it can do (`hostCapabilities` of `ui/initialize`): only what it
1253
+ * does. `downloadFile` and `sampling` (never `sampling.tools`) only when the host turned them on.
1254
+ */
1255
+ declare const mcpAppHostCapabilities: (csp?: Partial<McpAppCsp>, features?: {
1256
+ downloadFile?: boolean;
1257
+ sampling?: boolean;
1258
+ }) => Record<string, unknown>;
1259
+ /**
1260
+ * Whether a display mode an app asks for may be given: `inline` always (the way back needs no
1261
+ * permission); any other only when the host offers it AND the app declared it in
1262
+ * `appCapabilities.availableDisplayModes` - an app that declared nothing stays inline (the
1263
+ * specification lets a host decline it).
1264
+ */
1265
+ declare const appDisplayModeAllowed: (o: {
1266
+ requested: McpAppDisplayMode;
1267
+ current: McpAppDisplayMode;
1268
+ host: readonly McpAppDisplayMode[];
1269
+ app: readonly McpAppDisplayMode[] | undefined;
1270
+ }) => boolean;
1271
+ /**
1272
+ * Whether the user just acted INSIDE the app's frame: the page's frame element has the focus
1273
+ * (a click or a key in a frame focuses it) and the page has transient user activation (an
1274
+ * activation in a frame reaches every page above it, for a few seconds). Where the browser has
1275
+ * no `navigator.userActivation`, the focus alone.
1276
+ */
1277
+ declare const appGestureOf: (o: {
1278
+ focused: boolean;
1279
+ activation: boolean | undefined;
1280
+ }) => boolean;
1281
+ /** A file an app asks to save: at most this many bytes. */
1282
+ declare const MCP_APP_MAX_DOWNLOAD_BYTES: number;
1283
+ /** A saved file's name: at most this many characters (the extension kept). */
1284
+ declare const MCP_APP_MAX_FILE_NAME_CHARS = 100;
1285
+ /**
1286
+ * Extensions this host never saves: programs, scripts, installers, shortcuts, disk images - and
1287
+ * documents a browser runs scripts in when they are opened (HTML, SVG, XML).
1288
+ */
1289
+ declare const MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS: readonly string[];
1290
+ /** Types this host never saves (the same kinds), and any `…+xml`. */
1291
+ declare const MCP_APP_REFUSED_DOWNLOAD_TYPES: readonly string[];
1292
+ /** A declared type as a bare MIME type (`text/plain`), or undefined when it is not one. */
1293
+ declare const appMimeTypeOf: (value: unknown) => string | undefined;
1294
+ /**
1295
+ * The name a file is saved under: the last segment of a path or URI (`file:///x/report.json` →
1296
+ * `report.json`; percent-encoding decoded, and split again), without what cannot be seen or
1297
+ * reserved characters (`<>:"/\|?*`, controls), no leading dots (a hidden file) or trailing dots
1298
+ * and spaces, not a Windows device name, at most `MCP_APP_MAX_FILE_NAME_CHARS` with the extension
1299
+ * kept; `download` when nothing is left.
1300
+ */
1301
+ declare const appFileNameOf: (value: unknown) => string;
1302
+ /** The extension of a (sanitized) file name, lowercased, without the dot; '' when none. */
1303
+ declare const appFileExtensionOf: (name: string) => string;
1304
+ /**
1305
+ * Why a file may not be saved, or undefined when it may: an extension or a type of the refused
1306
+ * lists (a program, a script, a page a browser would run), checked on the sanitized name and
1307
+ * the declared type both.
1308
+ */
1309
+ declare const appDownloadRefusal: (name: string, mimeType?: string) => string | undefined;
1310
+ /**
1311
+ * What `ui/download-file` asks for, checked - or why not (a message for the app): ONE item of
1312
+ * `contents` (one file per request, one prompt); an `EmbeddedResource` (`resource.uri` names
1313
+ * it, `text` as UTF-8 or base64 `blob`, at most `maxBytes`) or a `ResourceLink` (a one-line URI,
1314
+ * read later from the app's own server: the name is its last segment, else its `name`); the
1315
+ * name sanitized and the name and type not refused (`appDownloadRefusal`).
1316
+ */
1317
+ declare const appDownloadOf: (params: unknown, maxBytes?: number) => AppDownload | string;
1318
+ /** A file ready to be put to the user: its name, type, bytes, and where the bytes came from. */
1319
+ interface AppReadyDownload {
1320
+ name: string;
1321
+ mimeType?: string;
1322
+ bytes: Uint8Array;
1323
+ source: 'embedded' | 'link';
1324
+ }
1325
+ /** How a linked file is read: `resources/read` on the app's OWN server (the connection's). */
1326
+ type AppResourceReader = (server: string, uri: string, options: {
1327
+ signal?: AbortSignal;
1328
+ maxBytes: number;
1329
+ }) => Promise<{
1330
+ mimeType?: string;
1331
+ bytes: Uint8Array;
1332
+ }>;
1333
+ /**
1334
+ * The bytes of a checked file: an embedded one as it came; a linked one read from `server` -
1335
+ * the app's own - through `read` (never a fetch of its URI), at most `maxBytes`, and the type the
1336
+ * SERVER gives it judged again (an app cannot pass a page off as a text file through a link).
1337
+ * Throws an `McpAppRpcError` for the app: no reader, a failed read, a refused type, too large.
1338
+ */
1339
+ declare const resolveAppDownload: (file: AppDownload, server: string, read: AppResourceReader | undefined, signal?: AbortSignal, maxBytes?: number) => Promise<AppReadyDownload>;
1340
+ /**
1341
+ * The error an app is told when the agent did not answer its sampling request: the core's
1342
+ * `AppSamplingError` carries its JSON-RPC code (`-1`: the user said no, `-32602`: not a request
1343
+ * this host takes, `-32000`: too many); anything else is a refusal.
1344
+ */
1345
+ declare const appSamplingErrorOf: (err: unknown) => McpAppRpcError;
1346
+ /** What `saveAppFile` uses of the page (passed in: this module touches no DOM by itself). */
1347
+ interface AppFileSaverEnv {
1348
+ document: {
1349
+ createElement: (tag: 'a') => HTMLAnchorElement;
1350
+ body: {
1351
+ append: (n: Node) => void;
1352
+ };
1353
+ };
1354
+ URL: {
1355
+ createObjectURL: (blob: Blob) => string;
1356
+ revokeObjectURL: (url: string) => void;
1357
+ };
1358
+ setTimeout: (fn: () => void, ms: number) => unknown;
1359
+ }
1360
+ /**
1361
+ * Save a checked file the user agreed to: a `Blob` of type `application/octet-stream` (the
1362
+ * browser never renders or sniffs it as a page), a `blob:` URL of THIS page, an `<a download>`
1363
+ * made here and clicked once. No navigation, no `data:` or `javascript:` URL, nothing of the app
1364
+ * in the page; the URL is revoked a minute later.
1365
+ */
1366
+ declare const saveAppFile: (file: {
1367
+ name: string;
1368
+ bytes: Uint8Array;
1369
+ }, env: AppFileSaverEnv) => void;
1370
+ /** `<AgentChat appSandbox>` / `useMcpAppHost({ sandbox })`. */
1371
+ interface McpAppSandboxOptions {
1372
+ /**
1373
+ * The sandbox page's base URL on another origin you serve (`mcpAppSandboxResponse` of the
1374
+ * `./mcp-app-sandbox` entry), e.g. `https://apps.example.com/sandbox/v1`; an app's frame loads
1375
+ * `<url>/<policy>`. `{server}` in the host name gives each server an origin of its own
1376
+ * (`https://{server}.apps.example.com/sandbox/v1`; the server's name must be a DNS label - it
1377
+ * needs a wildcard certificate). `https://` only; `http://` on `localhost` / `127.0.0.1`.
1378
+ */
1379
+ url: string;
1380
+ /** How long a frame waits for the page's handshake before it falls back (default 5000 ms). */
1381
+ timeoutMs?: number;
1382
+ }
1383
+ /** Why an app runs in the opaque frame although a sandbox URL is set. */
1384
+ type McpAppSandboxReason = 'invalid' | 'insecure' | 'same-origin' | 'no-page-origin' | 'server-name' | 'too-many-origins' | 'no-answer';
1385
+ type McpAppSandboxTarget = {
1386
+ ok: true;
1387
+ origin: string;
1388
+ base: string;
1389
+ } | {
1390
+ ok: false;
1391
+ reason: McpAppSandboxReason;
1392
+ };
1393
+ /** The placeholder for the server's name in `McpAppSandboxOptions.url`. */
1394
+ declare const MCP_APP_SANDBOX_SERVER = "{server}";
1395
+ declare const MCP_APP_SANDBOX_TIMEOUT_MS = 5000;
1396
+ /** After the shell has loaded (the proxy loaded or failed), the handshake gets this much longer. */
1397
+ declare const MCP_APP_SANDBOX_GRACE_MS = 1000;
1398
+ /**
1399
+ * The sandbox flags of the shell's frame and of the proxy's: scripts and an origin - the shell
1400
+ * must keep YOUR origin (else the proxy below it would get an opaque one) and runs no script; the
1401
+ * proxy is on the sandbox origin. Nothing else: no navigation, popup, form, modal, download.
1402
+ */
1403
+ declare const MCP_APP_SANDBOX_FRAME_TOKENS = "allow-scripts allow-same-origin";
1404
+ /**
1405
+ * Where an app of `server` runs, for a page on `pageOrigin`: the sandbox's origin and base URL,
1406
+ * or why not. Refused: not a URL; credentials, a query or a fragment; not `https://` (`http://`
1407
+ * only on `localhost` / `127.0.0.1`); a path a policy cannot name; `{server}` anywhere but the
1408
+ * host name, more than once, or a server name that is not a lowercase DNS label; a page without
1409
+ * an origin; and the sandbox on the PAGE'S OWN origin - `allow-same-origin` there would hand the
1410
+ * app your storage and the key vault.
1411
+ */
1412
+ declare const mcpAppSandboxTarget: (options: McpAppSandboxOptions | undefined, server: string, pageOrigin: string | undefined) => McpAppSandboxTarget;
1413
+ /** The proxy page's URL for an app's declared origins (`<base>/<policy>`), or none if too long. */
1414
+ declare const mcpAppSandboxProxyUrl: (base: string, csp?: Partial<McpAppCsp>) => string | undefined;
1415
+ /**
1416
+ * The policy of the shell: no script at all, and frames from the proxy's exact URL only - a
1417
+ * `frame-src` with a path matches that path and nothing else (the query is not part of the
1418
+ * match), so the proxy's frame can never be navigated anywhere else.
1419
+ */
1420
+ declare const mcpAppSandboxShellCsp: (proxyUrl: string) => string;
1421
+ /**
1422
+ * What goes into the OUTER frame's `srcdoc` in sandbox mode: the shell - its policy first, one
1423
+ * frame of the proxy page, no script, nothing of the app. Give the outer `<iframe>`
1424
+ * `sandbox={MCP_APP_SANDBOX_FRAME_TOKENS}` and nothing else. Throws on a URL that is not a proxy
1425
+ * URL this package builds (`mcpAppSandboxProxyUrl`). `scheme` is declared by the shell and its
1426
+ * frame, and handed to the proxy page as `?scheme=` on its frame's `src` ONLY: the shell's
1427
+ * `frame-src` stays the path (a source expression carries no query, and a path source ignores
1428
+ * one), so the pin is the same with or without it.
1429
+ */
1430
+ declare const buildMcpAppSandboxShell: (proxyUrl: string, scheme?: McpAppColorScheme) => string;
1431
+ /** What one message from the proxy's frame is, for the page (`McpAppSandboxLink.receive`). */
1432
+ type McpAppSandboxInput = 'drop' | 'ready' | 'broken' | 'app';
1433
+ interface McpAppSandboxLinkOptions {
1434
+ /** The sandbox origin (`mcpAppSandboxTarget(…).origin`). */
1435
+ origin: string;
1436
+ /** The app, as read from its server: sent once, on the proxy's first ready. */
1437
+ html: string;
1438
+ csp?: Partial<McpAppCsp>;
1439
+ /** Post to the proxy's window. Always called with the sandbox origin as the target - never `*`. */
1440
+ post: (message: unknown, targetOrigin: string) => void;
1441
+ }
1442
+ /**
1443
+ * The page's side of the sandbox proxy, without the DOM: which messages are the proxy's, the
1444
+ * handshake, and every post to the sandbox origin. A message is the proxy's only when it comes
1445
+ * from the proxy's window (`event.source`) AND from the sandbox origin (`event.origin`). The
1446
+ * first `sandbox-proxy-ready` is answered with the app (`sandbox-resource-ready`); another one
1447
+ * means the proxy page was loaded again - by the app - and the link breaks (`'broken'`: stop the
1448
+ * app). Every other `ui/notifications/sandbox-*` message is dropped; nothing reaches the bridge
1449
+ * (`'app'`) before the app was handed over.
1450
+ */
1451
+ declare class McpAppSandboxLink {
1452
+ private readonly o;
1453
+ private state;
1454
+ constructor(options: McpAppSandboxLinkOptions);
1455
+ /** The proxy answered and was given the app. */
1456
+ get ready(): boolean;
1457
+ /** The proxy page was loaded a second time: the app must be stopped. */
1458
+ get broken(): boolean;
1459
+ /** Whether a message event is the proxy's: its window, and the sandbox origin. */
1460
+ accepts(event: {
1461
+ source: unknown;
1462
+ origin: string;
1463
+ }, proxy: unknown): boolean;
1464
+ receive(event: {
1465
+ source: unknown;
1466
+ origin: string;
1467
+ data: unknown;
1468
+ }, proxy: unknown): McpAppSandboxInput;
1469
+ /** Send a message to the app, through the proxy, to the sandbox origin. Nothing once broken. */
1470
+ post(message: unknown): void;
1471
+ close(): void;
1472
+ }
1473
+ /**
1474
+ * A pending consent request of THIS frame (`ApprovalView.app.frame`, set by `useAgent`); for a
1475
+ * request that names no frame (a host's own gate), one of this app's server and resource.
1476
+ */
1477
+ declare const isApprovalOfApp: (approval: ApprovalView, app: AppView) => boolean;
1478
+
1479
+ export { APP_DEFAULT_HEIGHT as V, APP_HEIGHT_CEILING as X, APP_HEIGHT_SCREENS as Y, APP_MAX_HEIGHT as Z, APP_MIN_HEIGHT as _, MCP_APP_DISPLAY_MODES as a4, MCP_APP_MAX_ARGS_CHARS as a5, MCP_APP_MAX_DOWNLOAD_BYTES as a6, MCP_APP_MAX_FILE_NAME_CHARS as a7, MCP_APP_MAX_IN_FLIGHT as a8, MCP_APP_MAX_MESSAGE_CHARS as a9, appDownloadRefusal as aA, appFileExtensionOf as aB, appFileNameOf as aC, appGestureOf as aD, appHeightCap as aE, appLinkOf as aF, appMessageTextOf as aG, appMimeTypeOf as aH, appSamplingErrorOf as aI, buildMcpAppDocument as aJ, buildMcpAppSandboxShell as aK, clampAppHeight as aL, grantedAppCsp as aM, isApprovalOfApp as aN, mcpAppCsp as aO, mcpAppHostCapabilities as aP, mcpAppSandboxProxyUrl as aQ, mcpAppSandboxShellCsp as aR, mcpAppSandboxTarget as aS, nextAppHeightCap as aT, resolveAppDownload as aU, saveAppFile as aV, MCP_APP_MAX_URL_CHARS as aa, MCP_APP_NOTIFICATIONS as ab, MCP_APP_OPTIONAL_REQUESTS as ac, MCP_APP_PROTOCOL_VERSION as ad, MCP_APP_REFUSED as ae, MCP_APP_REFUSED_DOWNLOAD_EXTENSIONS as af, MCP_APP_REFUSED_DOWNLOAD_TYPES as ag, MCP_APP_RELAY as ah, MCP_APP_REQUESTS as ai, MCP_APP_SANDBOX_FRAME_TOKENS as aj, MCP_APP_SANDBOX_GRACE_MS as ak, MCP_APP_SANDBOX_SERVER as al, MCP_APP_SANDBOX_TIMEOUT_MS as am, McpAppBridge as an, McpAppRpcError as ar, McpAppSandboxLink as au, appDisplayModeAllowed as ay, appDownloadOf as az };
1480
+ export type { AppDownload as $, AgentUiState as A, BrowserOAuthProvider as B, ChatAttachment as C, DecisionView as D, ElicitationView as E, FetchView as F, MediaView as G, ModelLoadState as H, QueuedMessageView as I, ReplanState as J, SkillConsentView as K, LessonView as L, McpElicitationFieldSchema as M, StepEscalationView as N, StepView as O, TranscriptView as P, QuestionView as Q, RemoteRunView as R, SubagentView as S, ToolCallView as T, UserNoteView as U, WrittenFileView as W, McpElicitationHandler as a, AppFileSaverEnv as a0, AppLink as a1, AppReadyDownload as a2, AppResourceReader as a3, McpAppBridgeHandlers as ao, McpAppBridgeOptions as ap, McpAppDisplayMode as aq, McpAppRpcMessage as as, McpAppSandboxInput as at, McpAppSandboxLinkOptions as av, McpAppSandboxOptions as aw, McpAppSandboxTarget as ax, McpElicitationRequest as b, McpElicitationResult as c, McpElicitationOptions as d, McpElicitationSchema as e, AgentStatus as f, McpAppSandboxReason as g, ChatMessage as h, ApprovalView as i, SubagentNode as j, AppView as k, BrowserOAuthProviderOptions as l, BudgetView as m, CompactionView as n, ConnectedMcp as o, McpAppsConnectionLike as p, McpCatalogEntry as q, McpHttpServerConfig as r, McpModule as s, McpOAuthCallback as t, McpOAuthRegistration as u, McpOAuthRegistrationKind as v, McpProtocolMode as w, McpServerInstructions as x, McpServerProtocol as y, McpServerResult as z };