@dxos/plugin-automation 0.7.5-labs.e27f9b9 → 0.7.5-labs.f5080a1

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 (154) hide show
  1. package/dist/lib/browser/AutomationPanel-YPD3AGQN.mjs +8 -0
  2. package/dist/lib/browser/ChatContainer-ODZECATM.mjs +12 -0
  3. package/dist/lib/browser/{ai-client-AARXEMMJ.mjs → ai-client-UJLNYP7B.mjs} +3 -3
  4. package/dist/lib/browser/{app-graph-builder-B4U34VSR.mjs → app-graph-builder-3H5TCRG4.mjs} +2 -2
  5. package/dist/lib/browser/{chunk-7XADMUOW.mjs → chunk-43WRHV2L.mjs} +21 -76
  6. package/dist/lib/browser/chunk-43WRHV2L.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-HZ4TA7HY.mjs → chunk-BQHXJZ4K.mjs} +2 -2
  8. package/dist/lib/browser/{chunk-5SLV6AUA.mjs → chunk-DL7XA62G.mjs} +344 -180
  9. package/dist/lib/browser/chunk-DL7XA62G.mjs.map +7 -0
  10. package/dist/lib/browser/{chunk-HKX3D3ZP.mjs → chunk-DQ7ZSYJJ.mjs} +2 -2
  11. package/dist/lib/browser/{chunk-HKX3D3ZP.mjs.map → chunk-DQ7ZSYJJ.mjs.map} +2 -2
  12. package/dist/lib/browser/{chunk-IYSMXX6Q.mjs → chunk-PQGFC2ZO.mjs} +13 -12
  13. package/dist/lib/{node-esm/chunk-3KB5HRXA.mjs.map → browser/chunk-PQGFC2ZO.mjs.map} +3 -3
  14. package/dist/lib/browser/{chunk-RAVNWHNE.mjs → chunk-Z54KIF6H.mjs} +5 -5
  15. package/dist/lib/browser/chunk-Z54KIF6H.mjs.map +7 -0
  16. package/dist/lib/browser/index.mjs +11 -10
  17. package/dist/lib/browser/index.mjs.map +3 -3
  18. package/dist/lib/browser/{intent-resolver-754MPV7H.mjs → intent-resolver-5YVZJFS3.mjs} +3 -3
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/{react-surface-4QZ6AKBF.mjs → react-surface-WRHRCEV5.mjs} +9 -9
  21. package/dist/lib/browser/react-surface-WRHRCEV5.mjs.map +7 -0
  22. package/dist/lib/browser/types/index.mjs +6 -6
  23. package/dist/lib/node/{AutomationPanel-LRDEDGXI.cjs → AutomationPanel-CO26O75P.cjs} +7 -7
  24. package/dist/lib/node/{AutomationPanel-LRDEDGXI.cjs.map → AutomationPanel-CO26O75P.cjs.map} +2 -2
  25. package/dist/lib/node/{ChatContainer-6LZX4K2Z.cjs → ChatContainer-5URBEXQD.cjs} +10 -10
  26. package/dist/lib/node/ChatContainer-5URBEXQD.cjs.map +7 -0
  27. package/dist/lib/node/{ai-client-SA35GN5Q.cjs → ai-client-AOB6TLNW.cjs} +7 -7
  28. package/dist/lib/node/{app-graph-builder-ENVDOPS4.cjs → app-graph-builder-CDEQJEHY.cjs} +14 -14
  29. package/dist/lib/node/{chunk-ZS5RZ7RM.cjs → chunk-AWZVJZ2I.cjs} +6 -6
  30. package/dist/lib/node/{chunk-HEYQONXC.cjs → chunk-D2QQXWOY.cjs} +26 -26
  31. package/dist/lib/node/{chunk-HEYQONXC.cjs.map → chunk-D2QQXWOY.cjs.map} +3 -3
  32. package/dist/lib/node/chunk-H3RSMGJG.cjs +173 -0
  33. package/dist/lib/node/chunk-H3RSMGJG.cjs.map +7 -0
  34. package/dist/lib/node/{chunk-6VMSH4P6.cjs → chunk-NH7STAX6.cjs} +392 -241
  35. package/dist/lib/node/chunk-NH7STAX6.cjs.map +7 -0
  36. package/dist/lib/node/{chunk-WWU5FVAO.cjs → chunk-OCW5GAVZ.cjs} +9 -9
  37. package/dist/lib/node/chunk-OCW5GAVZ.cjs.map +7 -0
  38. package/dist/lib/node/{chunk-5VF5JKUN.cjs → chunk-TQEDPRY5.cjs} +5 -5
  39. package/dist/lib/node/{chunk-5VF5JKUN.cjs.map → chunk-TQEDPRY5.cjs.map} +2 -2
  40. package/dist/lib/node/index.cjs +73 -72
  41. package/dist/lib/node/index.cjs.map +3 -3
  42. package/dist/lib/node/{intent-resolver-CNVBSG4E.cjs → intent-resolver-MJFZT5IU.cjs} +8 -8
  43. package/dist/lib/node/meta.json +1 -1
  44. package/dist/lib/node/{react-surface-5HYLBDC3.cjs → react-surface-HDAVE6NU.cjs} +18 -18
  45. package/dist/lib/node/react-surface-HDAVE6NU.cjs.map +7 -0
  46. package/dist/lib/node/types/index.cjs +13 -13
  47. package/dist/lib/node/types/index.cjs.map +1 -1
  48. package/dist/lib/node-esm/{AutomationPanel-ZV7VEEPP.mjs → AutomationPanel-VQZUKPK2.mjs} +3 -3
  49. package/dist/lib/node-esm/{ChatContainer-PPVMC2FC.mjs → ChatContainer-23QIVDG5.mjs} +5 -5
  50. package/dist/lib/node-esm/{ai-client-2ZA4TYFZ.mjs → ai-client-RUCCJ7JZ.mjs} +3 -3
  51. package/dist/lib/node-esm/{app-graph-builder-IYOUCQZT.mjs → app-graph-builder-GR3URVNX.mjs} +2 -2
  52. package/dist/lib/node-esm/{chunk-EVTLHDM2.mjs → chunk-7JO77AAS.mjs} +21 -76
  53. package/dist/lib/node-esm/chunk-7JO77AAS.mjs.map +7 -0
  54. package/dist/lib/node-esm/{chunk-X3LPRWIL.mjs → chunk-JFHI22MF.mjs} +2 -2
  55. package/dist/lib/node-esm/{chunk-X3LPRWIL.mjs.map → chunk-JFHI22MF.mjs.map} +2 -2
  56. package/dist/lib/node-esm/{chunk-WISKXX7U.mjs → chunk-JJFWFS6P.mjs} +344 -180
  57. package/dist/lib/node-esm/chunk-JJFWFS6P.mjs.map +7 -0
  58. package/dist/lib/node-esm/{chunk-ISYLEDVU.mjs → chunk-LSSWQIQD.mjs} +2 -2
  59. package/dist/lib/node-esm/{chunk-MS7OIGVR.mjs → chunk-NSVQZ3EH.mjs} +5 -5
  60. package/dist/lib/node-esm/chunk-NSVQZ3EH.mjs.map +7 -0
  61. package/dist/lib/node-esm/{chunk-3KB5HRXA.mjs → chunk-VN2AFV25.mjs} +13 -12
  62. package/dist/lib/{browser/chunk-IYSMXX6Q.mjs.map → node-esm/chunk-VN2AFV25.mjs.map} +3 -3
  63. package/dist/lib/node-esm/index.mjs +11 -10
  64. package/dist/lib/node-esm/index.mjs.map +3 -3
  65. package/dist/lib/node-esm/{intent-resolver-RQBXW442.mjs → intent-resolver-FCKNRTKQ.mjs} +3 -3
  66. package/dist/lib/node-esm/meta.json +1 -1
  67. package/dist/lib/node-esm/{react-surface-SS5WCRJ2.mjs → react-surface-FZ5OFRDE.mjs} +9 -9
  68. package/dist/lib/node-esm/react-surface-FZ5OFRDE.mjs.map +7 -0
  69. package/dist/lib/node-esm/types/index.mjs +6 -6
  70. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  71. package/dist/types/src/components/ChatContainer/ChatContainer.d.ts +0 -1
  72. package/dist/types/src/components/ChatContainer/ChatContainer.d.ts.map +1 -1
  73. package/dist/types/src/components/ServiceRegistry/ServiceRegistry.stories.d.ts.map +1 -1
  74. package/dist/types/src/components/Thread/ThreadMessage.d.ts.map +1 -1
  75. package/dist/types/src/components/TriggerEditor/TriggerEditor.d.ts.map +1 -1
  76. package/dist/types/src/hooks/index.d.ts +3 -1
  77. package/dist/types/src/hooks/index.d.ts.map +1 -1
  78. package/dist/types/src/hooks/processor.d.ts +7 -2
  79. package/dist/types/src/hooks/processor.d.ts.map +1 -1
  80. package/dist/types/src/hooks/useChatProcessor.d.ts +7 -0
  81. package/dist/types/src/hooks/useChatProcessor.d.ts.map +1 -0
  82. package/dist/types/src/hooks/useMessageQueue.d.ts +41 -0
  83. package/dist/types/src/hooks/useMessageQueue.d.ts.map +1 -0
  84. package/dist/types/src/hooks/useServices.d.ts +7 -0
  85. package/dist/types/src/hooks/useServices.d.ts.map +1 -0
  86. package/dist/types/src/meta.d.ts.map +1 -1
  87. package/dist/types/src/testing/index.d.ts +2 -1
  88. package/dist/types/src/testing/index.d.ts.map +1 -1
  89. package/dist/types/src/testing/{testing.d.ts → test-functions.d.ts} +1 -1
  90. package/dist/types/src/testing/test-functions.d.ts.map +1 -0
  91. package/dist/types/src/testing/test-services.d.ts +5 -0
  92. package/dist/types/src/testing/test-services.d.ts.map +1 -0
  93. package/dist/types/src/types/registry.d.ts +7 -6
  94. package/dist/types/src/types/registry.d.ts.map +1 -1
  95. package/dist/types/src/types/schema.d.ts +94 -69
  96. package/dist/types/src/types/schema.d.ts.map +1 -1
  97. package/package.json +50 -50
  98. package/src/AutomationPlugin.tsx +2 -2
  99. package/src/capabilities/react-surface.tsx +4 -2
  100. package/src/components/ChatContainer/ChatContainer.tsx +15 -80
  101. package/src/components/ServiceRegistry/ServiceRegistry.stories.tsx +2 -1
  102. package/src/components/ServiceRegistry/ServiceRegistry.tsx +7 -7
  103. package/src/components/Thread/StatusLine.tsx +1 -1
  104. package/src/components/Thread/Tabbed.stories.tsx +1 -1
  105. package/src/components/Thread/Thread.tsx +1 -1
  106. package/src/components/Thread/ThreadMessage.tsx +24 -16
  107. package/src/components/Thread/ToggleContainer.stories.tsx +1 -1
  108. package/src/components/TriggerEditor/TriggerEditor.tsx +2 -4
  109. package/src/hooks/index.ts +3 -1
  110. package/src/hooks/processor.ts +16 -7
  111. package/src/hooks/useChatProcessor.tsx +86 -0
  112. package/src/hooks/useMessageQueue.ts +23 -0
  113. package/src/hooks/{useServiceRegistry.ts → useServices.ts} +8 -2
  114. package/src/meta.ts +2 -1
  115. package/src/testing/index.ts +2 -1
  116. package/src/testing/test-services.ts +131 -0
  117. package/src/types/registry.ts +17 -80
  118. package/src/types/schema.ts +20 -8
  119. package/dist/lib/browser/AutomationPanel-WFJZAW4F.mjs +0 -8
  120. package/dist/lib/browser/ChatContainer-OFCOZ5T2.mjs +0 -12
  121. package/dist/lib/browser/chunk-5SLV6AUA.mjs.map +0 -7
  122. package/dist/lib/browser/chunk-7XADMUOW.mjs.map +0 -7
  123. package/dist/lib/browser/chunk-RAVNWHNE.mjs.map +0 -7
  124. package/dist/lib/browser/react-surface-4QZ6AKBF.mjs.map +0 -7
  125. package/dist/lib/node/ChatContainer-6LZX4K2Z.cjs.map +0 -7
  126. package/dist/lib/node/chunk-6VMSH4P6.cjs.map +0 -7
  127. package/dist/lib/node/chunk-LU4HQWJD.cjs +0 -226
  128. package/dist/lib/node/chunk-LU4HQWJD.cjs.map +0 -7
  129. package/dist/lib/node/chunk-WWU5FVAO.cjs.map +0 -7
  130. package/dist/lib/node/react-surface-5HYLBDC3.cjs.map +0 -7
  131. package/dist/lib/node-esm/chunk-EVTLHDM2.mjs.map +0 -7
  132. package/dist/lib/node-esm/chunk-MS7OIGVR.mjs.map +0 -7
  133. package/dist/lib/node-esm/chunk-WISKXX7U.mjs.map +0 -7
  134. package/dist/lib/node-esm/react-surface-SS5WCRJ2.mjs.map +0 -7
  135. package/dist/types/src/hooks/useServiceRegistry.d.ts +0 -3
  136. package/dist/types/src/hooks/useServiceRegistry.d.ts.map +0 -1
  137. package/dist/types/src/testing/testing.d.ts.map +0 -1
  138. /package/dist/lib/browser/{AutomationPanel-WFJZAW4F.mjs.map → AutomationPanel-YPD3AGQN.mjs.map} +0 -0
  139. /package/dist/lib/browser/{ChatContainer-OFCOZ5T2.mjs.map → ChatContainer-ODZECATM.mjs.map} +0 -0
  140. /package/dist/lib/browser/{ai-client-AARXEMMJ.mjs.map → ai-client-UJLNYP7B.mjs.map} +0 -0
  141. /package/dist/lib/browser/{app-graph-builder-B4U34VSR.mjs.map → app-graph-builder-3H5TCRG4.mjs.map} +0 -0
  142. /package/dist/lib/browser/{chunk-HZ4TA7HY.mjs.map → chunk-BQHXJZ4K.mjs.map} +0 -0
  143. /package/dist/lib/browser/{intent-resolver-754MPV7H.mjs.map → intent-resolver-5YVZJFS3.mjs.map} +0 -0
  144. /package/dist/lib/node/{ai-client-SA35GN5Q.cjs.map → ai-client-AOB6TLNW.cjs.map} +0 -0
  145. /package/dist/lib/node/{app-graph-builder-ENVDOPS4.cjs.map → app-graph-builder-CDEQJEHY.cjs.map} +0 -0
  146. /package/dist/lib/node/{chunk-ZS5RZ7RM.cjs.map → chunk-AWZVJZ2I.cjs.map} +0 -0
  147. /package/dist/lib/node/{intent-resolver-CNVBSG4E.cjs.map → intent-resolver-MJFZT5IU.cjs.map} +0 -0
  148. /package/dist/lib/node-esm/{AutomationPanel-ZV7VEEPP.mjs.map → AutomationPanel-VQZUKPK2.mjs.map} +0 -0
  149. /package/dist/lib/node-esm/{ChatContainer-PPVMC2FC.mjs.map → ChatContainer-23QIVDG5.mjs.map} +0 -0
  150. /package/dist/lib/node-esm/{ai-client-2ZA4TYFZ.mjs.map → ai-client-RUCCJ7JZ.mjs.map} +0 -0
  151. /package/dist/lib/node-esm/{app-graph-builder-IYOUCQZT.mjs.map → app-graph-builder-GR3URVNX.mjs.map} +0 -0
  152. /package/dist/lib/node-esm/{chunk-ISYLEDVU.mjs.map → chunk-LSSWQIQD.mjs.map} +0 -0
  153. /package/dist/lib/node-esm/{intent-resolver-RQBXW442.mjs.map → intent-resolver-FCKNRTKQ.mjs.map} +0 -0
  154. /package/src/testing/{testing.ts → test-functions.ts} +0 -0
@@ -1,32 +1,18 @@
1
1
  import {
2
2
  AutomationCapabilities
3
- } from "./chunk-HZ4TA7HY.mjs";
3
+ } from "./chunk-BQHXJZ4K.mjs";
4
4
  import {
5
- MockServiceRegistry
6
- } from "./chunk-7XADMUOW.mjs";
5
+ ServiceType,
6
+ categoryIcons
7
+ } from "./chunk-43WRHV2L.mjs";
7
8
  import {
8
9
  AUTOMATION_PLUGIN
9
- } from "./chunk-HKX3D3ZP.mjs";
10
+ } from "./chunk-DQ7ZSYJJ.mjs";
10
11
 
11
12
  // packages/plugins/experimental/plugin-automation/src/components/ChatContainer/ChatContainer.tsx
12
- import React7, { useCallback as useCallback3, useEffect as useEffect6, useMemo as useMemo3, useState as useState7 } from "react";
13
- import { Capabilities, useCapabilities, useCapability, useIntentDispatcher } from "@dxos/app-framework";
14
- import { createSystemPrompt } from "@dxos/artifact";
15
- import { FunctionType as FunctionType2 } from "@dxos/functions";
13
+ import React7, { useCallback as useCallback3 } from "react";
16
14
  import { invariant as invariant7 } from "@dxos/invariant";
17
- import { DXN as DXN2, QueueSubspaceTags } from "@dxos/keys";
18
- import { useConfig } from "@dxos/react-client";
19
- import { Filter as Filter2, getSpace, useQuery as useQuery2 } from "@dxos/react-client/echo";
20
- import { useEdgeClient, useQueue } from "@dxos/react-edge-client";
21
15
  import { StackItem } from "@dxos/react-ui-stack";
22
- import { isNotNullOrUndefined } from "@dxos/util";
23
-
24
- // packages/plugins/experimental/plugin-automation/src/capabilities/index.ts
25
- import { lazy } from "@dxos/app-framework";
26
- var AiClient = lazy(() => import("./ai-client-AARXEMMJ.mjs"));
27
- var AppGraphBuilder = lazy(() => import("./app-graph-builder-B4U34VSR.mjs"));
28
- var IntentResolver = lazy(() => import("./intent-resolver-754MPV7H.mjs"));
29
- var ReactSurface = lazy(() => import("./react-surface-4QZ6AKBF.mjs"));
30
16
 
31
17
  // packages/plugins/experimental/plugin-automation/src/hooks/processor.ts
32
18
  import { batch, computed, signal } from "@preact/signals-core";
@@ -38,7 +24,7 @@ import { log } from "@dxos/log";
38
24
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/hooks/processor.ts";
39
25
  var defaultOptions = {
40
26
  model: "@anthropic/claude-3-5-sonnet-20241022",
41
- systemPrompt: ""
27
+ systemPrompt: "you are a helpful assistant"
42
28
  };
43
29
  var ChatProcessor = class {
44
30
  constructor(_client, _tools, _extensions, _options = defaultOptions) {
@@ -59,7 +45,7 @@ var ChatProcessor = class {
59
45
  const current = messages.pop();
60
46
  invariant(current, void 0, {
61
47
  F: __dxlog_file,
62
- L: 76,
48
+ L: 78,
63
49
  S: this,
64
50
  A: [
65
51
  "current",
@@ -94,6 +80,12 @@ var ChatProcessor = class {
94
80
  });
95
81
  }
96
82
  /**
83
+ * Update tools.
84
+ */
85
+ setTools(tools) {
86
+ this._tools = tools;
87
+ }
88
+ /**
97
89
  * Make GPT request.
98
90
  */
99
91
  async request(message, options = {}) {
@@ -123,7 +115,7 @@ var ChatProcessor = class {
123
115
  async cancel() {
124
116
  log.info("cancelling...", void 0, {
125
117
  F: __dxlog_file,
126
- L: 132,
118
+ L: 141,
127
119
  S: this,
128
120
  C: (f, a) => f(...a)
129
121
  });
@@ -152,7 +144,7 @@ var ChatProcessor = class {
152
144
  messages: this._pending.value.length
153
145
  }, {
154
146
  F: __dxlog_file,
155
- L: 156,
147
+ L: 165,
156
148
  S: this,
157
149
  C: (f, a) => f(...a)
158
150
  });
@@ -171,7 +163,7 @@ var ChatProcessor = class {
171
163
  messages: this._pending.value
172
164
  }, {
173
165
  F: __dxlog_file,
174
- L: 169,
166
+ L: 178,
175
167
  S: this,
176
168
  C: (f, a) => f(...a)
177
169
  });
@@ -179,7 +171,7 @@ var ChatProcessor = class {
179
171
  const message = this._pending.value.at(-1);
180
172
  invariant(message, void 0, {
181
173
  F: __dxlog_file,
182
- L: 174,
174
+ L: 183,
183
175
  S: this,
184
176
  A: [
185
177
  "message",
@@ -189,7 +181,7 @@ var ChatProcessor = class {
189
181
  if (isToolUse(message)) {
190
182
  log.info("tool request...", void 0, {
191
183
  F: __dxlog_file,
192
- L: 176,
184
+ L: 185,
193
185
  S: this,
194
186
  C: (f, a) => f(...a)
195
187
  });
@@ -202,7 +194,7 @@ var ChatProcessor = class {
202
194
  response
203
195
  }, {
204
196
  F: __dxlog_file,
205
- L: 183,
197
+ L: 192,
206
198
  S: this,
207
199
  C: (f, a) => f(...a)
208
200
  });
@@ -223,14 +215,14 @@ var ChatProcessor = class {
223
215
  err
224
216
  }, {
225
217
  F: __dxlog_file,
226
- L: 195,
218
+ L: 204,
227
219
  S: this,
228
220
  C: (f, a) => f(...a)
229
221
  });
230
222
  } finally {
231
223
  log.info("done", void 0, {
232
224
  F: __dxlog_file,
233
- L: 197,
225
+ L: 206,
234
226
  S: this,
235
227
  C: (f, a) => f(...a)
236
228
  });
@@ -239,51 +231,27 @@ var ChatProcessor = class {
239
231
  }
240
232
  };
241
233
 
242
- // packages/plugins/experimental/plugin-automation/src/hooks/useServiceRegistry.ts
234
+ // packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx
243
235
  import { useEffect, useMemo, useState } from "react";
244
- var useServiceRegistry = (query) => {
245
- const registry = useMemo(() => new MockServiceRegistry(), []);
246
- const [services, setServices] = useState([]);
247
- useEffect(() => {
248
- const t = setTimeout(async () => {
249
- const services2 = await registry.queryServices(query);
250
- setServices(services2);
251
- });
252
- return () => clearTimeout(t);
253
- }, [
254
- query,
255
- registry
256
- ]);
257
- return services;
258
- };
259
-
260
- // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
261
- import { useEffect as useEffect2, useState as useState2 } from "react";
262
- import { Mutex } from "@dxos/async";
263
- import { Context } from "@dxos/context";
264
- import { createSubscriptionTrigger } from "@dxos/functions";
265
- import { FunctionTrigger } from "@dxos/functions";
266
- import { invariant as invariant3 } from "@dxos/invariant";
267
- import { log as log3 } from "@dxos/log";
268
- import { useClient } from "@dxos/react-client";
269
- import { Filter, useQuery } from "@dxos/react-client/echo";
270
-
271
- // packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
272
- import { sleep } from "@dxos/async";
273
- import { getObjectCore, ResultFormat } from "@dxos/echo-db";
236
+ import { Capabilities, useCapabilities, useCapability, useIntentDispatcher } from "@dxos/app-framework";
237
+ import { createSystemPrompt } from "@dxos/artifact";
274
238
  import { FunctionType } from "@dxos/functions";
275
- import { invariant as invariant2 } from "@dxos/invariant";
276
- import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
277
- import { log as log2 } from "@dxos/log";
239
+ import { useConfig } from "@dxos/react-client";
240
+ import { Filter, getSpace, useQuery } from "@dxos/react-client/echo";
241
+ import { isNotNullOrUndefined } from "@dxos/util";
278
242
 
279
- // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
280
- var registerTriggersMutex = new Mutex();
243
+ // packages/plugins/experimental/plugin-automation/src/capabilities/index.ts
244
+ import { lazy } from "@dxos/app-framework";
245
+ var AiClient = lazy(() => import("./ai-client-UJLNYP7B.mjs"));
246
+ var AppGraphBuilder = lazy(() => import("./app-graph-builder-3H5TCRG4.mjs"));
247
+ var IntentResolver = lazy(() => import("./intent-resolver-5YVZJFS3.mjs"));
248
+ var ReactSurface = lazy(() => import("./react-surface-WRHRCEV5.mjs"));
281
249
 
282
250
  // packages/plugins/experimental/plugin-automation/src/tools/function.ts
283
251
  import { defineTool, ToolResult } from "@dxos/artifact";
284
252
  import { toEffectSchema } from "@dxos/echo-schema";
285
253
  import { getInvocationUrl, getUserFunctionUrlInMetadata } from "@dxos/functions";
286
- import { log as log4 } from "@dxos/log";
254
+ import { log as log2 } from "@dxos/log";
287
255
  import { getMeta } from "@dxos/react-client/echo";
288
256
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/tools/function.ts";
289
257
  var covertFunctionToTool = (fn, edgeUrl, spaceId) => {
@@ -302,7 +270,7 @@ var covertFunctionToTool = (fn, edgeUrl, spaceId) => {
302
270
  description: fn.description,
303
271
  schema: toEffectSchema(fn.inputSchema),
304
272
  execute: async (input) => {
305
- log4.info("execute function tool", {
273
+ log2.info("execute function tool", {
306
274
  name: fn.name,
307
275
  url,
308
276
  input
@@ -328,12 +296,12 @@ var covertFunctionToTool = (fn, edgeUrl, spaceId) => {
328
296
  import jsonpointer from "jsonpointer";
329
297
  import { ToolResult as ToolResult2 } from "@dxos/artifact";
330
298
  import { JsonSchemaType, normalizeSchema, S, toEffectSchema as toEffectSchema2 } from "@dxos/echo-schema";
331
- import { invariant as invariant4 } from "@dxos/invariant";
332
- import { log as log5 } from "@dxos/log";
299
+ import { invariant as invariant2 } from "@dxos/invariant";
300
+ import { log as log3 } from "@dxos/log";
333
301
  import { deepMapValues } from "@dxos/util";
334
302
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/tools/openapi.ts";
335
303
  var createToolsFromService = async (service) => {
336
- invariant4(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
304
+ invariant2(service.interfaces?.length === 1 && service.interfaces[0].kind === "api", void 0, {
337
305
  F: __dxlog_file3,
338
306
  L: 22,
339
307
  S: void 0,
@@ -343,7 +311,7 @@ var createToolsFromService = async (service) => {
343
311
  ]
344
312
  });
345
313
  const iface = service.interfaces[0];
346
- invariant4(iface.schemaUrl, void 0, {
314
+ invariant2(iface.schemaUrl, void 0, {
347
315
  F: __dxlog_file3,
348
316
  L: 24,
349
317
  S: void 0,
@@ -352,7 +320,7 @@ var createToolsFromService = async (service) => {
352
320
  ""
353
321
  ]
354
322
  });
355
- invariant4(iface.schemaUrl, void 0, {
323
+ invariant2(iface.schemaUrl, void 0, {
356
324
  F: __dxlog_file3,
357
325
  L: 25,
358
326
  S: void 0,
@@ -368,7 +336,7 @@ var createToolsFromService = async (service) => {
368
336
  var createToolsFromApi = async (url, options) => {
369
337
  const res = await fetch(url);
370
338
  const spec = await res.json();
371
- log5("spec", {
339
+ log3("spec", {
372
340
  spec
373
341
  }, {
374
342
  F: __dxlog_file3,
@@ -384,7 +352,7 @@ var createToolsFromApi = async (url, options) => {
384
352
  const { ...methods } = pathItem;
385
353
  for (const [method, m] of Object.entries(methods)) {
386
354
  const methodItem = m;
387
- log5("methodItem", {
355
+ log3("methodItem", {
388
356
  path,
389
357
  method,
390
358
  methodItem
@@ -404,7 +372,7 @@ var createToolsFromApi = async (url, options) => {
404
372
  };
405
373
  const endpointParameters = [];
406
374
  for (const parameter of parametersResolved) {
407
- log5("parameter", {
375
+ log3("parameter", {
408
376
  parameter
409
377
  }, {
410
378
  F: __dxlog_file3,
@@ -427,7 +395,7 @@ var createToolsFromApi = async (url, options) => {
427
395
  }
428
396
  }
429
397
  }
430
- log5("inputSchema", {
398
+ log3("inputSchema", {
431
399
  inputSchema
432
400
  }, {
433
401
  F: __dxlog_file3,
@@ -438,7 +406,7 @@ var createToolsFromApi = async (url, options) => {
438
406
  S.validateSync(JsonSchemaType)(inputSchema);
439
407
  const description = methodItem.description ?? methodItem.summary;
440
408
  if (!description) {
441
- log5.warn("no description", {
409
+ log3.warn("no description", {
442
410
  path,
443
411
  method
444
412
  }, {
@@ -513,7 +481,7 @@ var GENERIC_WORDS = [
513
481
  "endpoint"
514
482
  ];
515
483
  var callApiEndpoint = async (endpoint, input) => {
516
- log5.info("endpoint", {
484
+ log3.info("endpoint", {
517
485
  method: endpoint.method,
518
486
  name: endpoint.path,
519
487
  input
@@ -573,7 +541,7 @@ var callApiEndpoint = async (endpoint, input) => {
573
541
  request.body = JSON.stringify(body);
574
542
  request.headers["Content-Type"] = "application/json";
575
543
  }
576
- log5.info("request", {
544
+ log3.info("request", {
577
545
  url,
578
546
  request
579
547
  }, {
@@ -583,7 +551,7 @@ var callApiEndpoint = async (endpoint, input) => {
583
551
  C: (f, a) => f(...a)
584
552
  });
585
553
  const response = await fetch(url, request);
586
- log5.info("response", {
554
+ log3.info("response", {
587
555
  ok: response.ok,
588
556
  status: response.status,
589
557
  statusText: response.statusText
@@ -609,7 +577,7 @@ var callApiEndpoint = async (endpoint, input) => {
609
577
  } catch {
610
578
  error = responseBody;
611
579
  }
612
- log5.error("error", {
580
+ log3.error("error", {
613
581
  error
614
582
  }, {
615
583
  F: __dxlog_file3,
@@ -620,7 +588,7 @@ var callApiEndpoint = async (endpoint, input) => {
620
588
  throw new Error(error.message);
621
589
  } else {
622
590
  const error = await response.text();
623
- log5.error("error", {
591
+ log3.error("error", {
624
592
  error
625
593
  }, {
626
594
  F: __dxlog_file3,
@@ -637,7 +605,7 @@ var getEndpointUrl = (endpoint) => {
637
605
  if (isV3_1(endpoint.document) && endpoint.document.servers && endpoint.document.servers.length > 0) {
638
606
  url = endpoint.document.servers[0].url;
639
607
  } else {
640
- invariant4(!isV3_1(endpoint.document), void 0, {
608
+ invariant2(!isV3_1(endpoint.document), void 0, {
641
609
  F: __dxlog_file3,
642
610
  L: 272,
643
611
  S: void 0,
@@ -657,7 +625,7 @@ var getEndpointUrl = (endpoint) => {
657
625
  var resolveAuthorization = async (authorization) => {
658
626
  switch (authorization.type) {
659
627
  case "api-key": {
660
- invariant4(authorization.placement.type === "authorization-header", void 0, {
628
+ invariant2(authorization.placement.type === "authorization-header", void 0, {
661
629
  F: __dxlog_file3,
662
630
  L: 288,
663
631
  S: void 0,
@@ -692,7 +660,7 @@ var resolveJsonSchema = (schema, base) => {
692
660
  if (resolved) {
693
661
  return recurse(resolved);
694
662
  } else {
695
- log5.warn("unresolved", {
663
+ log3.warn("unresolved", {
696
664
  ref: value.$ref,
697
665
  base
698
666
  }, {
@@ -711,14 +679,248 @@ var isV3_1 = (document) => {
711
679
  return document.openapi === "3.0.1";
712
680
  };
713
681
 
682
+ // packages/plugins/experimental/plugin-automation/src/hooks/useChatProcessor.tsx
683
+ var useChatProcessor = (chat) => {
684
+ const aiClient = useCapability(AutomationCapabilities.AiClient);
685
+ const globalTools = useCapabilities(Capabilities.Tools);
686
+ const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
687
+ const { dispatchPromise: dispatch } = useIntentDispatcher();
688
+ const space = getSpace(chat);
689
+ const services = useQuery(space, Filter.schema(ServiceType));
690
+ const [serviceTools, setServiceTools] = useState([]);
691
+ useEffect(() => {
692
+ queueMicrotask(async () => {
693
+ const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
694
+ setServiceTools(tools2.flat());
695
+ });
696
+ }, [
697
+ services
698
+ ]);
699
+ const config = useConfig();
700
+ const functions2 = useQuery(space, Filter.schema(FunctionType));
701
+ const tools = useMemo(() => [
702
+ ...globalTools.flat(),
703
+ ...artifactDefinitions.flatMap((definition) => definition.tools),
704
+ ...serviceTools,
705
+ ...functions2.map((fn) => covertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNotNullOrUndefined)
706
+ ], [
707
+ globalTools,
708
+ artifactDefinitions,
709
+ serviceTools,
710
+ functions2,
711
+ space?.id
712
+ ]);
713
+ const systemPrompt = useMemo(() => createSystemPrompt({
714
+ artifacts: artifactDefinitions.map((definition) => definition.instructions)
715
+ }), [
716
+ artifactDefinitions
717
+ ]);
718
+ const processor = useMemo(() => new ChatProcessor(aiClient, tools, {
719
+ space,
720
+ dispatch
721
+ }, {
722
+ model: "@anthropic/claude-3-5-sonnet-20241022",
723
+ systemPrompt
724
+ }), [
725
+ aiClient,
726
+ tools,
727
+ space,
728
+ dispatch,
729
+ systemPrompt
730
+ ]);
731
+ return processor;
732
+ };
733
+
734
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
735
+ import { useEffect as useEffect2, useState as useState2 } from "react";
736
+ import { Mutex } from "@dxos/async";
737
+ import { Context } from "@dxos/context";
738
+ import { createSubscriptionTrigger } from "@dxos/functions";
739
+ import { FunctionTrigger } from "@dxos/functions";
740
+ import { invariant as invariant4 } from "@dxos/invariant";
741
+ import { log as log5 } from "@dxos/log";
742
+ import { useClient } from "@dxos/react-client";
743
+ import { Filter as Filter2, useQuery as useQuery2 } from "@dxos/react-client/echo";
744
+
745
+ // packages/plugins/experimental/plugin-automation/src/hooks/invocation-handler.ts
746
+ import { sleep } from "@dxos/async";
747
+ import { getObjectCore, ResultFormat } from "@dxos/echo-db";
748
+ import { FunctionType as FunctionType2 } from "@dxos/functions";
749
+ import { invariant as invariant3 } from "@dxos/invariant";
750
+ import { DXN, LOCAL_SPACE_TAG } from "@dxos/keys";
751
+ import { log as log4 } from "@dxos/log";
752
+
753
+ // packages/plugins/experimental/plugin-automation/src/hooks/useLocalTriggerManager.ts
754
+ var registerTriggersMutex = new Mutex();
755
+
756
+ // packages/plugins/experimental/plugin-automation/src/hooks/useMessageQueue.ts
757
+ import { useMemo as useMemo2 } from "react";
758
+ import { DXN as DXN2, QueueSubspaceTags } from "@dxos/keys";
759
+ import { getSpace as getSpace2 } from "@dxos/react-client/echo";
760
+ import { useEdgeClient, useQueue } from "@dxos/react-edge-client";
761
+ var useMessageQueue = (chat) => {
762
+ const edgeClient = useEdgeClient();
763
+ const space = getSpace2(chat);
764
+ const queueDxn = useMemo2(() => new DXN2(DXN2.kind.QUEUE, [
765
+ QueueSubspaceTags.DATA,
766
+ space.id,
767
+ chat.queue.dxn.parts.at(-1)
768
+ ]), [
769
+ chat.queue.dxn
770
+ ]);
771
+ return useQueue(edgeClient, queueDxn);
772
+ };
773
+
774
+ // packages/plugins/experimental/plugin-automation/src/hooks/useServices.ts
775
+ import { useEffect as useEffect3, useMemo as useMemo3, useState as useState3 } from "react";
776
+
777
+ // packages/plugins/experimental/plugin-automation/src/testing/test-functions.ts
778
+ import { createSystemPrompt as createSystemPrompt2 } from "@dxos/artifact";
779
+ import { AST, S as S2, toJsonSchema } from "@dxos/echo-schema";
780
+ var functions = [
781
+ {
782
+ name: "example.com/function/chess",
783
+ version: "0.1.0",
784
+ inputSchema: toJsonSchema(S2.Struct({
785
+ level: S2.Number.annotations({
786
+ [AST.TitleAnnotationId]: "Level"
787
+ })
788
+ }))
789
+ },
790
+ {
791
+ name: "example.com/function/forex",
792
+ version: "0.1.0",
793
+ binding: "FOREX",
794
+ inputSchema: toJsonSchema(S2.Struct({
795
+ from: S2.String.annotations({
796
+ [AST.TitleAnnotationId]: "Currency from"
797
+ }),
798
+ to: S2.String.annotations({
799
+ [AST.TitleAnnotationId]: "Currency to"
800
+ })
801
+ }))
802
+ }
803
+ ];
804
+
805
+ // packages/plugins/experimental/plugin-automation/src/testing/test-services.ts
806
+ import { createStatic as createStatic2 } from "@dxos/echo-schema";
807
+ var MockServiceRegistry = class {
808
+ async queryServices(query) {
809
+ return TEST_SERVICES;
810
+ }
811
+ };
812
+ var AMADEUS_AUTH = {
813
+ type: "oauth",
814
+ clientId: "BOEnpLd1sMyKjAPGKYeAPFFy60u53QEG",
815
+ clientSecret: "n4qldSN7usvD57gm",
816
+ tokenUrl: "https://test.api.amadeus.com/v1/security/oauth2/token",
817
+ grantType: "client_credentials"
818
+ };
819
+ var VISUAL_CROSSING_CREDENTIALS = {
820
+ type: "api-key",
821
+ key: "FDPRVS953KB4GQQLD25GRT975",
822
+ placement: {
823
+ type: "query",
824
+ name: "key"
825
+ }
826
+ };
827
+ var TEST_SERVICES = [
828
+ createStatic2(ServiceType, {
829
+ serviceId: "amadeus.com/service/FlightSearch",
830
+ name: "Amadeus Flight Search",
831
+ description: "Search for local and international flights.",
832
+ category: "travel",
833
+ interfaces: [
834
+ {
835
+ kind: "api",
836
+ schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-flight-availabilities-search/1.0.2/swagger.json",
837
+ authorization: AMADEUS_AUTH
838
+ }
839
+ ]
840
+ }),
841
+ createStatic2(ServiceType, {
842
+ serviceId: "amadeus.com/service/HotelSearch",
843
+ name: "Amadeus Hotel Search",
844
+ description: "Search for local and international hotels.",
845
+ category: "travel",
846
+ interfaces: [
847
+ {
848
+ kind: "api",
849
+ schemaUrl: "https://api.apis.guru/v2/specs/amadeus.com/amadeus-hotel-search/3.0.8/swagger.json",
850
+ authorization: AMADEUS_AUTH
851
+ }
852
+ ]
853
+ }),
854
+ createStatic2(ServiceType, {
855
+ serviceId: "visualcrossing.com/service/Weather",
856
+ name: "Visual Crossing Weather",
857
+ description: "Search for global weather forecasts.",
858
+ category: "weather",
859
+ interfaces: [
860
+ {
861
+ kind: "api",
862
+ schemaUrl: "https://api.apis.guru/v2/specs/visualcrossing.com/weather/4.6/openapi.json",
863
+ authorization: VISUAL_CROSSING_CREDENTIALS
864
+ }
865
+ ]
866
+ }),
867
+ // TODO(burdon): Needs auth.
868
+ createStatic2(ServiceType, {
869
+ serviceId: "abstractapi.com/service/GeoLocation",
870
+ name: "Abstract GeoLocation",
871
+ description: "Get the location of any IP address.",
872
+ category: "geolocation",
873
+ interfaces: [
874
+ {
875
+ kind: "api",
876
+ schemaUrl: "https://api.apis.guru/v2/specs/abstractapi.com/geolocation/1.0.0/openapi.json"
877
+ }
878
+ ]
879
+ }),
880
+ //
881
+ // Testing
882
+ //
883
+ ...Array.from({
884
+ length: 20
885
+ }, (_, i) => createStatic2(ServiceType, {
886
+ serviceId: `example.com/service/test-${i}`,
887
+ name: `Test ${i}`,
888
+ description: `Test ${i}`,
889
+ category: Object.keys(categoryIcons)[Math.floor(Math.random() * Object.keys(categoryIcons).length)],
890
+ interfaces: [
891
+ {
892
+ kind: "api",
893
+ schemaUrl: "https://petstore.swagger.io/v2/swagger.json"
894
+ }
895
+ ]
896
+ }))
897
+ ];
898
+
899
+ // packages/plugins/experimental/plugin-automation/src/hooks/useServices.ts
900
+ var useServices = (space, query) => {
901
+ const registry = useMemo3(() => new MockServiceRegistry(), []);
902
+ const [services, setServices] = useState3([]);
903
+ useEffect3(() => {
904
+ const t = setTimeout(async () => {
905
+ const services2 = await registry.queryServices(query);
906
+ setServices(services2);
907
+ });
908
+ return () => clearTimeout(t);
909
+ }, [
910
+ query,
911
+ registry
912
+ ]);
913
+ return services;
914
+ };
915
+
714
916
  // packages/plugins/experimental/plugin-automation/src/components/Thread/Thread.tsx
715
- import React6, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef3, useState as useState6 } from "react";
917
+ import React6, { useCallback as useCallback2, useMemo as useMemo4, useRef as useRef3, useState as useState7 } from "react";
716
918
  import { IconButton, Input, useTranslation } from "@dxos/react-ui";
717
919
  import { Spinner } from "@dxos/react-ui-sfx";
718
920
  import { mx as mx6 } from "@dxos/react-ui-theme";
719
921
 
720
922
  // packages/plugins/experimental/plugin-automation/src/components/Thread/ScrollContainer.tsx
721
- import React, { forwardRef, useCallback, useEffect as useEffect3, useImperativeHandle, useRef, useState as useState3 } from "react";
923
+ import React, { forwardRef, useCallback, useEffect as useEffect4, useImperativeHandle, useRef, useState as useState4 } from "react";
722
924
  import { invariant as invariant5 } from "@dxos/invariant";
723
925
  import { mx } from "@dxos/react-ui-theme";
724
926
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/Thread/ScrollContainer.tsx";
@@ -743,8 +945,8 @@ var ScrollContainer = /* @__PURE__ */ forwardRef(({ children, classNames }, forw
743
945
  autoScrollRef.current = false;
744
946
  }
745
947
  }), []);
746
- const [sticky, setSticky] = useState3(true);
747
- useEffect3(() => {
948
+ const [sticky, setSticky] = useState4(true);
949
+ useEffect4(() => {
748
950
  if (!sticky || !containerRef.current) {
749
951
  return;
750
952
  }
@@ -756,7 +958,7 @@ var ScrollContainer = /* @__PURE__ */ forwardRef(({ children, classNames }, forw
756
958
  }, [
757
959
  children
758
960
  ]);
759
- useEffect3(() => {
961
+ useEffect4(() => {
760
962
  invariant5(containerRef.current, void 0, {
761
963
  F: __dxlog_file4,
762
964
  L: 62,
@@ -790,30 +992,31 @@ var ScrollContainer = /* @__PURE__ */ forwardRef(({ children, classNames }, forw
790
992
  // packages/plugins/experimental/plugin-automation/src/components/Thread/ThreadMessage.tsx
791
993
  import React5 from "react";
792
994
  import { invariant as invariant6 } from "@dxos/invariant";
995
+ import { log as log6 } from "@dxos/log";
793
996
  import { Button, ButtonGroup, Icon as Icon2 } from "@dxos/react-ui";
794
997
  import { Json } from "@dxos/react-ui-syntax-highlighter";
795
998
  import { mx as mx5 } from "@dxos/react-ui-theme";
796
999
  import { safeParseJson } from "@dxos/util";
797
1000
 
798
1001
  // packages/plugins/experimental/plugin-automation/src/components/Thread/StatusLine.tsx
799
- import React2, { useEffect as useEffect4, useRef as useRef2, useState as useState4 } from "react";
1002
+ import React2, { useEffect as useEffect5, useRef as useRef2, useState as useState5 } from "react";
800
1003
  import { mx as mx2 } from "@dxos/react-ui-theme";
801
1004
  var emptyLines = [];
802
1005
  var StatusLine = ({ classNames, line = -1, lines = emptyLines, transition = 300, advance = 1e3, autoAdvance }) => {
803
1006
  const containerRef = useRef2(null);
804
- const [currentLine, setCurrentLine] = useState4(line);
805
- useEffect4(() => {
1007
+ const [currentLine, setCurrentLine] = useState5(line);
1008
+ useEffect5(() => {
806
1009
  setCurrentLine(line);
807
1010
  }, [
808
1011
  line
809
1012
  ]);
810
- useEffect4(() => {
1013
+ useEffect5(() => {
811
1014
  if (!autoAdvance) {
812
1015
  return;
813
1016
  }
814
1017
  const next = () => {
815
1018
  setCurrentLine((prev) => {
816
- if (prev === lines.length - 1) {
1019
+ if (prev >= lines.length - 1) {
817
1020
  clearInterval(interval);
818
1021
  return prev;
819
1022
  }
@@ -828,7 +1031,7 @@ var StatusLine = ({ classNames, line = -1, lines = emptyLines, transition = 300,
828
1031
  autoAdvance,
829
1032
  advance
830
1033
  ]);
831
- useEffect4(() => {
1034
+ useEffect5(() => {
832
1035
  if (containerRef.current) {
833
1036
  containerRef.current.style.transition = `transform ${transition}ms ease-in-out`;
834
1037
  containerRef.current.style.transform = `translateY(-${currentLine * 24}px)`;
@@ -852,14 +1055,14 @@ var StatusLine = ({ classNames, line = -1, lines = emptyLines, transition = 300,
852
1055
  };
853
1056
 
854
1057
  // packages/plugins/experimental/plugin-automation/src/components/Thread/ToggleContainer.tsx
855
- import React3, { useEffect as useEffect5, useState as useState5 } from "react";
1058
+ import React3, { useEffect as useEffect6, useState as useState6 } from "react";
856
1059
  import { Icon } from "@dxos/react-ui";
857
1060
  import { mx as mx3 } from "@dxos/react-ui-theme";
858
1061
  var ToggleContainer = ({ title, icon, toggle, defaultOpen, duration = 400, shrinkX = false, children, classNames }) => {
859
- const [expand, setExpand] = useState5(defaultOpen || !toggle);
860
- const [expandX, setExpandX] = useState5(shrinkX ? expand : true);
861
- const [expandY, setExpandY] = useState5(expand);
862
- useEffect5(() => {
1062
+ const [expand, setExpand] = useState6(defaultOpen || !toggle);
1063
+ const [expandX, setExpandX] = useState6(shrinkX ? expand : true);
1064
+ const [expandY, setExpandY] = useState6(expand);
1065
+ useEffect6(() => {
863
1066
  let t;
864
1067
  if (expand) {
865
1068
  if (shrinkX) {
@@ -977,29 +1180,42 @@ var ThreadMessage = ({ classNames, message, collapse, debug, onSuggest, onDelete
977
1180
  }, message);
978
1181
  }
979
1182
  const { role, content = [] } = message;
980
- const tools = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
981
- if (collapse && tools.length > 0) {
1183
+ const toolBlocks = content.filter((block) => block.type === "tool_use" || block.type === "tool_result");
1184
+ if (collapse && toolBlocks.length > 0) {
982
1185
  let request;
983
- const lines = tools.map((tool) => {
984
- switch (tool.type) {
1186
+ const json = [];
1187
+ const lines = toolBlocks.map((block) => {
1188
+ switch (block.type) {
985
1189
  case "tool_use": {
986
- request = tool;
987
- return `Calling ${tool.name}...`;
1190
+ request = block;
1191
+ json.push(block);
1192
+ return `Calling ${block.name}...`;
988
1193
  }
989
1194
  case "tool_result": {
990
1195
  if (!request) {
1196
+ log6.warn("unexpected message", {
1197
+ tool: block
1198
+ }, {
1199
+ F: __dxlog_file5,
1200
+ L: 57,
1201
+ S: void 0,
1202
+ C: (f, a) => f(...a)
1203
+ });
991
1204
  return "Error";
992
1205
  }
1206
+ json.push(block);
993
1207
  return `Processed ${request.name}`;
994
1208
  }
995
- default:
1209
+ default: {
1210
+ request = void 0;
996
1211
  return "Error";
1212
+ }
997
1213
  }
998
1214
  });
999
1215
  return /* @__PURE__ */ React5.createElement("div", {
1000
1216
  className: mx5("flex", classNames)
1001
1217
  }, /* @__PURE__ */ React5.createElement("div", {
1002
- className: "w-full p-1 px-2 overflow-hidden rounded-md bg-base"
1218
+ className: "w-full p-1 px-2 overflow-hidden rounded-md bg-baseSurface"
1003
1219
  }, /* @__PURE__ */ React5.createElement(ToggleContainer, {
1004
1220
  title: /* @__PURE__ */ React5.createElement(StatusLine, {
1005
1221
  lines,
@@ -1007,7 +1223,7 @@ var ThreadMessage = ({ classNames, message, collapse, debug, onSuggest, onDelete
1007
1223
  }),
1008
1224
  toggle: true
1009
1225
  }, /* @__PURE__ */ React5.createElement(Json, {
1010
- data: content[content.length - 1],
1226
+ data: json,
1011
1227
  classNames: "!p-1 text-xs"
1012
1228
  }))));
1013
1229
  }
@@ -1031,7 +1247,7 @@ var ThreadMessage = ({ classNames, message, collapse, debug, onSuggest, onDelete
1031
1247
  var Block = ({ block, role, onSuggest }) => {
1032
1248
  const Component = componentMap[block.type] ?? componentMap.default;
1033
1249
  return /* @__PURE__ */ React5.createElement("div", {
1034
- className: mx5("p-1 px-2 overflow-hidden rounded-md", (block.type !== "text" || block.disposition) && "w-full bg-base", block.type === "text" && role === "user" && "bg-blue-200 dark:bg-blue-800")
1250
+ className: mx5("p-1 px-2 overflow-hidden rounded-md", (block.type !== "text" || block.disposition) && "w-full bg-baseSurface", block.type === "text" && role === "user" && "bg-primary-200 dark:bg-primary-500")
1035
1251
  }, /* @__PURE__ */ React5.createElement(Component, {
1036
1252
  block,
1037
1253
  onSuggest
@@ -1039,16 +1255,15 @@ var Block = ({ block, role, onSuggest }) => {
1039
1255
  };
1040
1256
  var titles = {
1041
1257
  ["cot"]: "Chain of thought",
1042
- // TODO(burdon): Only show if debugging.
1258
+ ["artifact"]: "Artifact",
1043
1259
  ["tool_use"]: "Tool request",
1044
- ["tool_result"]: "Tool result",
1045
- ["artifact"]: "Artifact"
1260
+ ["tool_result"]: "Tool result"
1046
1261
  };
1047
1262
  var componentMap = {
1048
1263
  text: ({ block }) => {
1049
1264
  invariant6(block.type === "text", void 0, {
1050
1265
  F: __dxlog_file5,
1051
- L: 128,
1266
+ L: 134,
1052
1267
  S: void 0,
1053
1268
  A: [
1054
1269
  "block.type === 'text'",
@@ -1083,7 +1298,7 @@ var componentMap = {
1083
1298
  json: ({ block, onSuggest }) => {
1084
1299
  invariant6(block.type === "json", void 0, {
1085
1300
  F: __dxlog_file5,
1086
- L: 153,
1301
+ L: 159,
1087
1302
  S: void 0,
1088
1303
  A: [
1089
1304
  "block.type === 'json'",
@@ -1135,7 +1350,7 @@ var componentMap = {
1135
1350
  var Thread = ({ messages, streaming, collapse, debug, onSubmit, onStop, onSuggest, onDelete }) => {
1136
1351
  const { t } = useTranslation(AUTOMATION_PLUGIN);
1137
1352
  const scroller = useRef3(null);
1138
- const [text, setText] = useState6("");
1353
+ const [text, setText] = useState7("");
1139
1354
  const handleKeyDown = useCallback2((ev) => {
1140
1355
  switch (ev.key) {
1141
1356
  case "Escape": {
@@ -1155,7 +1370,7 @@ var Thread = ({ messages, streaming, collapse, debug, onSubmit, onStop, onSugges
1155
1370
  }, [
1156
1371
  text
1157
1372
  ]);
1158
- const { messages: lines = [] } = useMemo2(() => {
1373
+ const { messages: lines = [] } = useMemo4(() => {
1159
1374
  if (!collapse) {
1160
1375
  return {
1161
1376
  messages: messages ?? []
@@ -1232,7 +1447,7 @@ var Thread = ({ messages, streaming, collapse, debug, onSubmit, onStop, onSugges
1232
1447
  active: streaming
1233
1448
  }), /* @__PURE__ */ React6.createElement(Input.Root, null, /* @__PURE__ */ React6.createElement(Input.TextInput, {
1234
1449
  autoFocus: true,
1235
- classNames: "px-2 bg-base rounded",
1450
+ classNames: "px-2 baseSurface rounded",
1236
1451
  placeholder: t("chat input placeholder"),
1237
1452
  value: text,
1238
1453
  onChange: (ev) => setText(ev.target.value),
@@ -1252,79 +1467,26 @@ var Thread = ({ messages, streaming, collapse, debug, onSubmit, onStop, onSugges
1252
1467
  // packages/plugins/experimental/plugin-automation/src/components/ChatContainer/ChatContainer.tsx
1253
1468
  var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-automation/src/components/ChatContainer/ChatContainer.tsx";
1254
1469
  var ChatContainer = ({ chat, role }) => {
1255
- const config = useConfig();
1256
- const space = getSpace(chat);
1257
- const aiClient = useCapability(AutomationCapabilities.AiClient);
1258
- const artifactDefinitions = useCapabilities(Capabilities.ArtifactDefinition);
1259
- const globalTools = useCapabilities(Capabilities.Tools);
1260
- const functions = useQuery2(space, Filter2.schema(FunctionType2));
1261
- const serviceRegistry = useMemo3(() => new MockServiceRegistry(), []);
1262
- const [serviceTools, setServiceTools] = useState7([]);
1263
- useEffect6(() => {
1264
- queueMicrotask(async () => {
1265
- const services = await serviceRegistry.queryServices({});
1266
- const tools2 = await Promise.all(services.map((service) => createToolsFromService(service)));
1267
- setServiceTools(tools2.flat());
1268
- });
1269
- }, []);
1270
- const tools = useMemo3(() => [
1271
- ...globalTools.flat(),
1272
- ...artifactDefinitions.flatMap((definition) => definition.tools),
1273
- ...functions.map((fn) => covertFunctionToTool(fn, config.values.runtime?.services?.edge?.url ?? "", space?.id)).filter(isNotNullOrUndefined),
1274
- ...serviceTools
1275
- ], [
1276
- globalTools,
1277
- artifactDefinitions,
1278
- functions,
1279
- serviceTools,
1280
- space?.id
1281
- ]);
1282
- const systemPrompt = useMemo3(() => createSystemPrompt({
1283
- artifacts: artifactDefinitions.map((definition) => definition.instructions)
1284
- }), [
1285
- artifactDefinitions
1286
- ]);
1287
- const { dispatchPromise: dispatch } = useIntentDispatcher();
1288
- const processor = useMemo3(() => new ChatProcessor(aiClient, tools, {
1289
- space,
1290
- dispatch
1291
- }, {
1292
- model: "@anthropic/claude-3-5-sonnet-20241022",
1293
- systemPrompt
1294
- }), [
1295
- aiClient,
1296
- tools,
1297
- space,
1298
- dispatch,
1299
- systemPrompt
1300
- ]);
1301
- const queueDxn = useMemo3(() => new DXN2(DXN2.kind.QUEUE, [
1302
- QueueSubspaceTags.DATA,
1303
- space.id,
1304
- chat.queue.dxn.parts.at(-1)
1305
- ]), [
1306
- chat.queue.dxn
1307
- ]);
1308
- const edgeClient = useEdgeClient();
1309
- const messageQueue = useQueue(edgeClient, queueDxn);
1470
+ const processor = useChatProcessor(chat);
1471
+ const messageQueue = useMessageQueue(chat);
1310
1472
  const messages = [
1311
1473
  ...messageQueue?.items ?? [],
1312
1474
  ...processor.messages.value
1313
1475
  ];
1314
- const handleSubmit = useCallback3(async (message) => {
1476
+ const handleSubmit = useCallback3(async (text) => {
1315
1477
  if (processor.streaming.value) {
1316
1478
  await processor.cancel();
1317
1479
  }
1318
1480
  invariant7(messageQueue, void 0, {
1319
1481
  F: __dxlog_file6,
1320
- L: 95,
1482
+ L: 25,
1321
1483
  S: void 0,
1322
1484
  A: [
1323
1485
  "messageQueue",
1324
1486
  ""
1325
1487
  ]
1326
1488
  });
1327
- await processor.request(message, {
1489
+ await processor.request(text, {
1328
1490
  history: messageQueue.items,
1329
1491
  onComplete: (messages2) => messageQueue.append(messages2)
1330
1492
  });
@@ -1345,7 +1507,9 @@ var ChatContainer = ({ chat, role }) => {
1345
1507
  }, /* @__PURE__ */ React7.createElement(Thread, {
1346
1508
  messages,
1347
1509
  streaming: processor.streaming.value,
1510
+ collapse: true,
1348
1511
  onSubmit: handleSubmit,
1512
+ onSuggest: handleSubmit,
1349
1513
  onStop: handleStop
1350
1514
  }));
1351
1515
  };
@@ -1354,7 +1518,7 @@ var ChatContainer = ({ chat, role }) => {
1354
1518
  var ChatContainer_default = ChatContainer;
1355
1519
 
1356
1520
  export {
1357
- useServiceRegistry,
1521
+ useServices,
1358
1522
  MarkdownViewer,
1359
1523
  Thread,
1360
1524
  ChatContainer,
@@ -1364,4 +1528,4 @@ export {
1364
1528
  IntentResolver,
1365
1529
  ReactSurface
1366
1530
  };
1367
- //# sourceMappingURL=chunk-5SLV6AUA.mjs.map
1531
+ //# sourceMappingURL=chunk-DL7XA62G.mjs.map