@dxos/plugin-assistant 0.8.2-main.2f9c567 → 0.8.2-main.5885341

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 (109) hide show
  1. package/dist/lib/browser/{AssistantDialog-WX6EKSXI.mjs → AssistantDialog-I47GUXWR.mjs} +3 -3
  2. package/dist/lib/browser/{ChatContainer-HMNWYDQ5.mjs → ChatContainer-GAYN3FEF.mjs} +3 -3
  3. package/dist/lib/browser/{app-graph-builder-J5ISIFTE.mjs → app-graph-builder-ZXKGE3H5.mjs} +2 -2
  4. package/dist/lib/browser/{chunk-4EXBK6UE.mjs → chunk-7CAHKTZQ.mjs} +66 -45
  5. package/dist/lib/browser/chunk-7CAHKTZQ.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-J3V74ZRF.mjs → chunk-BGMQ2YYP.mjs} +4 -4
  7. package/dist/lib/browser/{chunk-J3V74ZRF.mjs.map → chunk-BGMQ2YYP.mjs.map} +2 -2
  8. package/dist/lib/browser/chunk-E7BN4QKP.mjs +190 -0
  9. package/dist/lib/browser/chunk-E7BN4QKP.mjs.map +7 -0
  10. package/dist/lib/browser/index.mjs +3 -3
  11. package/dist/lib/browser/{intent-resolver-MGHOSZY3.mjs → intent-resolver-W6XREK5F.mjs} +2 -2
  12. package/dist/lib/browser/meta.json +1 -1
  13. package/dist/lib/browser/{react-surface-VP4ABBMH.mjs → react-surface-QMI5KG4H.mjs} +4 -4
  14. package/dist/lib/browser/{settings-OZX7J65A.mjs → settings-LAJZQI4H.mjs} +2 -2
  15. package/dist/lib/browser/types/index.mjs +1 -1
  16. package/dist/lib/node/{AssistantDialog-2OTAZADX.cjs → AssistantDialog-SDS2TE5L.cjs} +7 -7
  17. package/dist/lib/node/{ChatContainer-3CTBKBS2.cjs → ChatContainer-U6AVMAHY.cjs} +7 -7
  18. package/dist/lib/node/{app-graph-builder-BBNLIGYJ.cjs → app-graph-builder-TXHPXIIC.cjs} +11 -11
  19. package/dist/lib/node/{chunk-VG2UQY4S.cjs → chunk-5UELRDHQ.cjs} +72 -74
  20. package/dist/lib/node/chunk-5UELRDHQ.cjs.map +7 -0
  21. package/dist/lib/node/{chunk-XC7A3KUG.cjs → chunk-CWHFK36A.cjs} +70 -55
  22. package/dist/lib/node/chunk-CWHFK36A.cjs.map +7 -0
  23. package/dist/lib/node/{chunk-WFSXNO4H.cjs → chunk-XBJO453B.cjs} +9 -9
  24. package/dist/lib/node/{chunk-WFSXNO4H.cjs.map → chunk-XBJO453B.cjs.map} +2 -2
  25. package/dist/lib/node/index.cjs +39 -39
  26. package/dist/lib/node/{intent-resolver-Z2NTL2FV.cjs → intent-resolver-MUJMV7II.cjs} +9 -9
  27. package/dist/lib/node/meta.json +1 -1
  28. package/dist/lib/node/{react-surface-HNXDAZ7C.cjs → react-surface-SAJF4XBB.cjs} +16 -16
  29. package/dist/lib/node/{settings-WLTC7XO5.cjs → settings-NPXTE6ND.cjs} +6 -6
  30. package/dist/lib/node/types/index.cjs +13 -13
  31. package/dist/lib/node/types/index.cjs.map +1 -1
  32. package/dist/lib/node-esm/{AssistantDialog-GNLPYXY4.mjs → AssistantDialog-KGA5HBFO.mjs} +3 -3
  33. package/dist/lib/node-esm/{ChatContainer-FGHDDORQ.mjs → ChatContainer-XPNXNPSW.mjs} +3 -3
  34. package/dist/lib/node-esm/{app-graph-builder-245AWCPJ.mjs → app-graph-builder-SV4WC2E2.mjs} +2 -2
  35. package/dist/lib/node-esm/chunk-ECYNZYEG.mjs +191 -0
  36. package/dist/lib/node-esm/chunk-ECYNZYEG.mjs.map +7 -0
  37. package/dist/lib/node-esm/{chunk-G5LUEW72.mjs → chunk-R7Q3OHWG.mjs} +4 -4
  38. package/dist/lib/node-esm/{chunk-G5LUEW72.mjs.map → chunk-R7Q3OHWG.mjs.map} +2 -2
  39. package/dist/lib/node-esm/{chunk-JX73NOSL.mjs → chunk-XFUXN5QU.mjs} +66 -45
  40. package/dist/lib/node-esm/chunk-XFUXN5QU.mjs.map +7 -0
  41. package/dist/lib/node-esm/index.mjs +3 -3
  42. package/dist/lib/node-esm/{intent-resolver-DMQXPV2H.mjs → intent-resolver-DZY2O2DG.mjs} +2 -2
  43. package/dist/lib/node-esm/meta.json +1 -1
  44. package/dist/lib/node-esm/{react-surface-NYXMBFPY.mjs → react-surface-R43NHNMC.mjs} +4 -4
  45. package/dist/lib/node-esm/{settings-CLE57WEP.mjs → settings-K3JDH2I5.mjs} +2 -2
  46. package/dist/lib/node-esm/types/index.mjs +1 -1
  47. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  48. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  49. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts +2 -2
  50. package/dist/types/src/components/TemplateEditor/TemplateForm.d.ts.map +1 -1
  51. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts +2 -2
  52. package/dist/types/src/components/Thread/ThreadContainer.stories.d.ts.map +1 -1
  53. package/dist/types/src/components/Toolbox/Toolbox.d.ts +1 -1
  54. package/dist/types/src/components/Toolbox/Toolbox.d.ts.map +1 -1
  55. package/dist/types/src/hooks/index.d.ts +1 -0
  56. package/dist/types/src/hooks/index.d.ts.map +1 -1
  57. package/dist/types/src/hooks/invocation-handler.d.ts +5 -0
  58. package/dist/types/src/hooks/invocation-handler.d.ts.map +1 -0
  59. package/dist/types/src/hooks/useLocalTriggerManager.d.ts +3 -0
  60. package/dist/types/src/hooks/useLocalTriggerManager.d.ts.map +1 -0
  61. package/dist/types/src/tools/function.d.ts +1 -1
  62. package/dist/types/src/tools/function.d.ts.map +1 -1
  63. package/dist/types/src/tools/openapi.d.ts.map +1 -1
  64. package/dist/types/src/types/service.d.ts +95 -96
  65. package/dist/types/src/types/service.d.ts.map +1 -1
  66. package/dist/types/src/types/template.d.ts +52 -52
  67. package/dist/types/src/types/template.d.ts.map +1 -1
  68. package/dist/types/src/types/types.d.ts +19 -19
  69. package/dist/types/src/types/types.d.ts.map +1 -1
  70. package/package.json +57 -60
  71. package/src/components/PromptSettings.tsx +2 -2
  72. package/src/components/TemplateEditor/TemplateForm.tsx +2 -2
  73. package/src/components/Thread/ThreadContainer.stories.tsx +2 -3
  74. package/src/components/Toolbox/Toolbox.tsx +1 -1
  75. package/src/hooks/index.ts +1 -0
  76. package/src/hooks/invocation-handler.ts +107 -0
  77. package/src/hooks/useChatProcessor.tsx +1 -1
  78. package/src/hooks/useLocalTriggerManager.ts +82 -0
  79. package/src/tools/function.ts +2 -2
  80. package/src/tools/openapi.ts +3 -4
  81. package/src/types/service.ts +37 -39
  82. package/src/types/template.ts +25 -27
  83. package/src/types/types.ts +18 -18
  84. package/dist/lib/browser/chunk-4EXBK6UE.mjs.map +0 -7
  85. package/dist/lib/browser/chunk-5P7U35RJ.mjs +0 -192
  86. package/dist/lib/browser/chunk-5P7U35RJ.mjs.map +0 -7
  87. package/dist/lib/node/chunk-VG2UQY4S.cjs.map +0 -7
  88. package/dist/lib/node/chunk-XC7A3KUG.cjs.map +0 -7
  89. package/dist/lib/node-esm/chunk-JX73NOSL.mjs.map +0 -7
  90. package/dist/lib/node-esm/chunk-UZWYXNR5.mjs +0 -193
  91. package/dist/lib/node-esm/chunk-UZWYXNR5.mjs.map +0 -7
  92. /package/dist/lib/browser/{AssistantDialog-WX6EKSXI.mjs.map → AssistantDialog-I47GUXWR.mjs.map} +0 -0
  93. /package/dist/lib/browser/{ChatContainer-HMNWYDQ5.mjs.map → ChatContainer-GAYN3FEF.mjs.map} +0 -0
  94. /package/dist/lib/browser/{app-graph-builder-J5ISIFTE.mjs.map → app-graph-builder-ZXKGE3H5.mjs.map} +0 -0
  95. /package/dist/lib/browser/{intent-resolver-MGHOSZY3.mjs.map → intent-resolver-W6XREK5F.mjs.map} +0 -0
  96. /package/dist/lib/browser/{react-surface-VP4ABBMH.mjs.map → react-surface-QMI5KG4H.mjs.map} +0 -0
  97. /package/dist/lib/browser/{settings-OZX7J65A.mjs.map → settings-LAJZQI4H.mjs.map} +0 -0
  98. /package/dist/lib/node/{AssistantDialog-2OTAZADX.cjs.map → AssistantDialog-SDS2TE5L.cjs.map} +0 -0
  99. /package/dist/lib/node/{ChatContainer-3CTBKBS2.cjs.map → ChatContainer-U6AVMAHY.cjs.map} +0 -0
  100. /package/dist/lib/node/{app-graph-builder-BBNLIGYJ.cjs.map → app-graph-builder-TXHPXIIC.cjs.map} +0 -0
  101. /package/dist/lib/node/{intent-resolver-Z2NTL2FV.cjs.map → intent-resolver-MUJMV7II.cjs.map} +0 -0
  102. /package/dist/lib/node/{react-surface-HNXDAZ7C.cjs.map → react-surface-SAJF4XBB.cjs.map} +0 -0
  103. /package/dist/lib/node/{settings-WLTC7XO5.cjs.map → settings-NPXTE6ND.cjs.map} +0 -0
  104. /package/dist/lib/node-esm/{AssistantDialog-GNLPYXY4.mjs.map → AssistantDialog-KGA5HBFO.mjs.map} +0 -0
  105. /package/dist/lib/node-esm/{ChatContainer-FGHDDORQ.mjs.map → ChatContainer-XPNXNPSW.mjs.map} +0 -0
  106. /package/dist/lib/node-esm/{app-graph-builder-245AWCPJ.mjs.map → app-graph-builder-SV4WC2E2.mjs.map} +0 -0
  107. /package/dist/lib/node-esm/{intent-resolver-DMQXPV2H.mjs.map → intent-resolver-DZY2O2DG.mjs.map} +0 -0
  108. /package/dist/lib/node-esm/{react-surface-NYXMBFPY.mjs.map → react-surface-R43NHNMC.mjs.map} +0 -0
  109. /package/dist/lib/node-esm/{settings-CLE57WEP.mjs.map → settings-K3JDH2I5.mjs.map} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/plugin-assistant",
3
- "version": "0.8.2-main.2f9c567",
3
+ "version": "0.8.2-main.5885341",
4
4
  "description": "Assistant plugin",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -46,78 +46,75 @@
46
46
  "jsonpointer": "^5.0.1",
47
47
  "lodash.get": "^4.4.2",
48
48
  "unified": "^11.0.0",
49
- "@dxos/app-framework": "0.8.2-main.2f9c567",
50
- "@dxos/assistant": "0.8.2-main.2f9c567",
51
- "@dxos/artifact": "0.8.2-main.2f9c567",
52
- "@dxos/client": "0.8.2-main.2f9c567",
53
- "@dxos/compute": "0.8.2-main.2f9c567",
54
- "@dxos/conductor": "0.8.2-main.2f9c567",
55
- "@dxos/async": "0.8.2-main.2f9c567",
56
- "@dxos/echo": "0.8.2-main.2f9c567",
57
- "@dxos/echo-db": "0.8.2-main.2f9c567",
58
- "@dxos/echo-protocol": "0.8.2-main.2f9c567",
59
- "@dxos/echo-schema": "0.8.2-main.2f9c567",
60
- "@dxos/context": "0.8.2-main.2f9c567",
61
- "@dxos/edge-client": "0.8.2-main.2f9c567",
62
- "@dxos/effect": "0.8.2-main.2f9c567",
63
- "@dxos/invariant": "0.8.2-main.2f9c567",
64
- "@dxos/functions": "0.8.2-main.2f9c567",
65
- "@dxos/keys": "0.8.2-main.2f9c567",
66
- "@dxos/log": "0.8.2-main.2f9c567",
67
- "@dxos/local-storage": "0.8.2-main.2f9c567",
68
- "@dxos/live-object": "0.8.2-main.2f9c567",
69
- "@dxos/plugin-deck": "0.8.2-main.2f9c567",
70
- "@dxos/plugin-client": "0.8.2-main.2f9c567",
71
- "@dxos/plugin-markdown": "0.8.2-main.2f9c567",
72
- "@dxos/plugin-graph": "0.8.2-main.2f9c567",
73
- "@dxos/plugin-inbox": "0.8.2-main.2f9c567",
74
- "@dxos/plugin-script": "0.8.2-main.2f9c567",
75
- "@dxos/plugin-sketch": "0.8.2-main.2f9c567",
76
- "@dxos/plugin-space": "0.8.2-main.2f9c567",
77
- "@dxos/plugin-stack": "0.8.2-main.2f9c567",
78
- "@dxos/plugin-transcription": "0.8.2-main.2f9c567",
79
- "@dxos/plugin-wnfs": "0.8.2-main.2f9c567",
80
- "@dxos/react-client": "0.8.2-main.2f9c567",
81
- "@dxos/react-edge-client": "0.8.2-main.2f9c567",
82
- "@dxos/react-ui-canvas-editor": "0.8.2-main.2f9c567",
83
- "@dxos/react-ui-components": "0.8.2-main.2f9c567",
84
- "@dxos/react-ui-editor": "0.8.2-main.2f9c567",
85
- "@dxos/react-ui-dnd": "0.8.2-main.2f9c567",
86
- "@dxos/react-ui-canvas-compute": "0.8.2-main.2f9c567",
87
- "@dxos/react-ui-form": "0.8.2-main.2f9c567",
88
- "@dxos/react-ui-list": "0.8.2-main.2f9c567",
89
- "@dxos/react-ui-stack": "0.8.2-main.2f9c567",
90
- "@dxos/react-ui-sfx": "0.8.2-main.2f9c567",
91
- "@dxos/react-ui-syntax-highlighter": "0.8.2-main.2f9c567",
92
- "@dxos/schema": "0.8.2-main.2f9c567",
93
- "@dxos/util": "0.8.2-main.2f9c567"
49
+ "@dxos/app-framework": "0.8.2-main.5885341",
50
+ "@dxos/artifact": "0.8.2-main.5885341",
51
+ "@dxos/assistant": "0.8.2-main.5885341",
52
+ "@dxos/async": "0.8.2-main.5885341",
53
+ "@dxos/client": "0.8.2-main.5885341",
54
+ "@dxos/conductor": "0.8.2-main.5885341",
55
+ "@dxos/context": "0.8.2-main.5885341",
56
+ "@dxos/compute": "0.8.2-main.5885341",
57
+ "@dxos/echo-protocol": "0.8.2-main.5885341",
58
+ "@dxos/edge-client": "0.8.2-main.5885341",
59
+ "@dxos/echo-db": "0.8.2-main.5885341",
60
+ "@dxos/echo-schema": "0.8.2-main.5885341",
61
+ "@dxos/functions": "0.8.2-main.5885341",
62
+ "@dxos/invariant": "0.8.2-main.5885341",
63
+ "@dxos/keys": "0.8.2-main.5885341",
64
+ "@dxos/live-object": "0.8.2-main.5885341",
65
+ "@dxos/effect": "0.8.2-main.5885341",
66
+ "@dxos/local-storage": "0.8.2-main.5885341",
67
+ "@dxos/plugin-client": "0.8.2-main.5885341",
68
+ "@dxos/plugin-deck": "0.8.2-main.5885341",
69
+ "@dxos/log": "0.8.2-main.5885341",
70
+ "@dxos/plugin-graph": "0.8.2-main.5885341",
71
+ "@dxos/plugin-script": "0.8.2-main.5885341",
72
+ "@dxos/plugin-sketch": "0.8.2-main.5885341",
73
+ "@dxos/plugin-inbox": "0.8.2-main.5885341",
74
+ "@dxos/plugin-markdown": "0.8.2-main.5885341",
75
+ "@dxos/plugin-space": "0.8.2-main.5885341",
76
+ "@dxos/plugin-stack": "0.8.2-main.5885341",
77
+ "@dxos/plugin-transcription": "0.8.2-main.5885341",
78
+ "@dxos/plugin-wnfs": "0.8.2-main.5885341",
79
+ "@dxos/react-ui-canvas-compute": "0.8.2-main.5885341",
80
+ "@dxos/react-client": "0.8.2-main.5885341",
81
+ "@dxos/react-ui-canvas-editor": "0.8.2-main.5885341",
82
+ "@dxos/react-ui-components": "0.8.2-main.5885341",
83
+ "@dxos/react-ui-dnd": "0.8.2-main.5885341",
84
+ "@dxos/react-ui-editor": "0.8.2-main.5885341",
85
+ "@dxos/react-ui-form": "0.8.2-main.5885341",
86
+ "@dxos/react-edge-client": "0.8.2-main.5885341",
87
+ "@dxos/react-ui-sfx": "0.8.2-main.5885341",
88
+ "@dxos/react-ui-list": "0.8.2-main.5885341",
89
+ "@dxos/react-ui-syntax-highlighter": "0.8.2-main.5885341",
90
+ "@dxos/util": "0.8.2-main.5885341",
91
+ "@dxos/schema": "0.8.2-main.5885341",
92
+ "@dxos/react-ui-stack": "0.8.2-main.5885341"
94
93
  },
95
94
  "devDependencies": {
96
95
  "@types/lodash.get": "^4.4.7",
97
96
  "@types/react": "~18.2.0",
98
97
  "@types/react-dom": "~18.2.0",
99
- "effect": "3.14.21",
100
98
  "openapi-types": "^12.1.3",
101
99
  "react": "~18.2.0",
102
100
  "react-dom": "~18.2.0",
103
101
  "vite": "5.4.7",
104
- "@dxos/artifact-testing": "0.8.2-main.2f9c567",
105
- "@dxos/echo-db": "0.8.2-main.2f9c567",
106
- "@dxos/plugin-chess": "0.8.2-main.2f9c567",
107
- "@dxos/plugin-inbox": "0.8.2-main.2f9c567",
108
- "@dxos/plugin-table": "0.8.2-main.2f9c567",
109
- "@dxos/plugin-map": "0.8.2-main.2f9c567",
110
- "@dxos/random": "0.8.2-main.2f9c567",
111
- "@dxos/react-ui-theme": "0.8.2-main.2f9c567",
112
- "@dxos/react-ui": "0.8.2-main.2f9c567",
113
- "@dxos/storybook-utils": "0.8.2-main.2f9c567"
102
+ "@dxos/artifact-testing": "0.8.2-main.5885341",
103
+ "@dxos/echo-db": "0.8.2-main.5885341",
104
+ "@dxos/plugin-map": "0.8.2-main.5885341",
105
+ "@dxos/plugin-chess": "0.8.2-main.5885341",
106
+ "@dxos/plugin-inbox": "0.8.2-main.5885341",
107
+ "@dxos/plugin-table": "0.8.2-main.5885341",
108
+ "@dxos/random": "0.8.2-main.5885341",
109
+ "@dxos/react-ui": "0.8.2-main.5885341",
110
+ "@dxos/react-ui-theme": "0.8.2-main.5885341",
111
+ "@dxos/storybook-utils": "0.8.2-main.5885341"
114
112
  },
115
113
  "peerDependencies": {
116
- "effect": "^3.13.3",
117
114
  "react": "~18.2.0",
118
115
  "react-dom": "~18.2.0",
119
- "@dxos/react-ui": "0.8.2-main.2f9c567",
120
- "@dxos/react-ui-theme": "0.8.2-main.2f9c567"
116
+ "@dxos/react-ui": "0.8.2-main.5885341",
117
+ "@dxos/react-ui-theme": "0.8.2-main.5885341"
121
118
  },
122
119
  "publishConfig": {
123
120
  "access": "public"
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Match, type Schema } from 'effect';
5
+ import { Match, type Schema as S } from 'effect';
6
6
  import React, { type ChangeEvent, useCallback } from 'react';
7
7
 
8
8
  import { debounce } from '@dxos/async';
@@ -17,7 +17,7 @@ export const PromptSettings = ({ template }: { template: TemplateType }) => {
17
17
  const handleKindChange = useCallback(
18
18
  (value: string) => {
19
19
  const kind = Match.type<string>().pipe(
20
- Match.withReturnType<Schema.Schema.Type<typeof TemplateKindSchema>>(),
20
+ Match.withReturnType<S.Schema.Type<typeof TemplateKindSchema>>(),
21
21
  Match.when('always', () => ({ include: 'always' })),
22
22
  Match.when('schema-matching', () => ({ include: 'schema-matching', typename: '' })),
23
23
  Match.when('automatically', () => ({ include: 'automatically', description: '' })),
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema } from 'effect';
5
+ import { type Schema as S } from 'effect';
6
6
  import React, { Fragment, useEffect } from 'react';
7
7
 
8
8
  import { Input, Select, useTranslation } from '@dxos/react-ui';
@@ -15,7 +15,7 @@ import { type TemplateInput, TemplateInputType, type TemplateType } from '../../
15
15
 
16
16
  export type TemplateFormProps = {
17
17
  template: TemplateType;
18
- schema?: Schema.Schema<any, any, any>;
18
+ schema?: S.Schema<any, any, any>;
19
19
  commandEditable?: boolean;
20
20
  };
21
21
 
@@ -18,9 +18,8 @@ import {
18
18
  } from '@dxos/app-framework';
19
19
  import { withPluginManager } from '@dxos/app-framework/testing';
20
20
  import { Message, type Tool } from '@dxos/artifact';
21
- import { genericTools, localServiceEndpoints } from '@dxos/artifact-testing';
21
+ import { genericTools, localServiceEndpoints, type IsObject } from '@dxos/artifact-testing';
22
22
  import { AIServiceEdgeClient } from '@dxos/assistant';
23
- import { type Type } from '@dxos/echo';
24
23
  import { create, ObjectId } from '@dxos/echo-schema';
25
24
  import { invariant } from '@dxos/invariant';
26
25
  import { DXN } from '@dxos/keys';
@@ -44,7 +43,7 @@ import translations from '../../translations';
44
43
  const endpoints = localServiceEndpoints;
45
44
 
46
45
  type RenderProps = {
47
- items?: Type.AnyObject[];
46
+ items?: IsObject[];
48
47
  prompts?: string[];
49
48
  } & Pick<ThreadProps, 'debug'>;
50
49
 
@@ -6,7 +6,7 @@ import React, { useState, useEffect, Fragment, type FC } from 'react';
6
6
 
7
7
  import { Capabilities, useCapabilities } from '@dxos/app-framework';
8
8
  import { parseToolName, type ArtifactDefinition, type Tool } from '@dxos/artifact';
9
- import { FunctionType } from '@dxos/functions';
9
+ import { FunctionType } from '@dxos/functions/types';
10
10
  import { log } from '@dxos/log';
11
11
  import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
12
12
  import { type ThemedClassName } from '@dxos/react-ui';
@@ -5,6 +5,7 @@
5
5
  export * from './processor';
6
6
 
7
7
  export * from './useChatProcessor';
8
+ export * from './useLocalTriggerManager';
8
9
  export * from './useMessageQueue';
9
10
  export * from './useServices';
10
11
  export * from './useTextInputEvents';
@@ -0,0 +1,107 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { sleep } from '@dxos/async';
6
+ import { getObjectCore, ResultFormat } from '@dxos/echo-db';
7
+ import { type AnyObjectData } from '@dxos/echo-schema';
8
+ import { FunctionType, getUserFunctionUrlInMetadata } from '@dxos/functions/types';
9
+ import { type FunctionTrigger } from '@dxos/functions/types';
10
+ import { invariant } from '@dxos/invariant';
11
+ import { DXN, LOCAL_SPACE_TAG } from '@dxos/keys';
12
+ import { log } from '@dxos/log';
13
+ import { type Client, type Config } from '@dxos/react-client';
14
+ import { type Space } from '@dxos/react-client/echo';
15
+
16
+ const MAX_RETRIES = 3;
17
+ const RETRY_DELAY = 1_000;
18
+
19
+ const callFunction = async (funcUrl: string, trigger: any, data: any) => {
20
+ const body = { event: 'trigger', trigger, data };
21
+
22
+ let retryCount = 0;
23
+ while (retryCount < MAX_RETRIES) {
24
+ log.info('exec', { funcUrl, body, retryCount });
25
+ const response = await fetch(funcUrl, {
26
+ method: 'POST',
27
+ headers: {
28
+ 'Content-Type': 'application/json',
29
+ },
30
+ body: JSON.stringify(body),
31
+ });
32
+
33
+ const data = await response.text();
34
+ log.info('response', { status: response.status, body: data });
35
+ if (response.status === 409) {
36
+ retryCount++;
37
+ await sleep(RETRY_DELAY * Math.min(retryCount, 2));
38
+ continue;
39
+ }
40
+
41
+ return { status: response.status, data };
42
+ }
43
+ return { status: 500 };
44
+ };
45
+
46
+ export const invokeFunction = async (client: Client, space: Space, trigger: FunctionTrigger, data: any) => {
47
+ try {
48
+ invariant(trigger.spec);
49
+ invariant(trigger.function);
50
+
51
+ const script = await space.db.query({ id: trigger.function }, { format: ResultFormat.Plain }).first();
52
+ const { objects: functions } = await space.db
53
+ .query({ __typename: FunctionType.typename }, { format: ResultFormat.Plain })
54
+ .run();
55
+ const func = functions.find((fn) => referenceEquals(fn.source, trigger.function!)) as AnyObjectData | undefined;
56
+ const funcSlug = func && getUserFunctionUrlInMetadata(func.__meta);
57
+ if (!funcSlug) {
58
+ log.warn('function not deployed', { scriptId: script.id, name: script.name });
59
+ return 404;
60
+ }
61
+
62
+ const funcUrl = getFunctionUrl(client.config, funcSlug, space.id);
63
+ const triggerData: AnyObjectData = {
64
+ ...getObjectCore(trigger).toPlainObject(),
65
+ // TODO: Remove when functions can query by DXN.
66
+ promptId: trigger.meta?.prompt?.id,
67
+ };
68
+ // TODO: Remove when functions can add objects and easily modify collections (push, splice).
69
+ return (await callFunction(funcUrl, triggerData, data)).status;
70
+ } catch (err) {
71
+ return 400;
72
+ }
73
+ };
74
+
75
+ const getFunctionUrl = (config: Config, slug: string, spaceId?: string) => {
76
+ const baseUrl = new URL('functions/', config.values.runtime?.services?.edge?.url);
77
+
78
+ // Leading slashes cause the URL to be treated as an absolute path.
79
+ const relativeUrl = slug.replace(/^\//, '');
80
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
81
+ spaceId && url.searchParams.set('spaceId', spaceId);
82
+ url.protocol = 'https';
83
+ return url.toString();
84
+ };
85
+
86
+ // TODO(dmaretskyi): Factor out.
87
+
88
+ type ReferenceLike = { '/': string } | string;
89
+
90
+ const referenceEquals = (a: ReferenceLike, b: ReferenceLike): boolean => {
91
+ const aDXN = toDXN(a);
92
+ const bDXN = toDXN(b);
93
+ return aDXN.toString() === bDXN.toString();
94
+ };
95
+
96
+ const toDXN = (ref: ReferenceLike): DXN => {
97
+ if (typeof ref === 'string') {
98
+ if (ref.startsWith('dxn:')) {
99
+ return DXN.parse(ref);
100
+ } else {
101
+ return new DXN(DXN.kind.ECHO, [LOCAL_SPACE_TAG, ref]);
102
+ }
103
+ }
104
+
105
+ invariant(typeof ref['/'] === 'string');
106
+ return DXN.parse(ref['/']);
107
+ };
@@ -7,7 +7,7 @@ import { useEffect, useMemo, useState } from 'react';
7
7
  import { Capabilities, useCapabilities, useCapability, useIntentDispatcher } from '@dxos/app-framework';
8
8
  import { type AssociatedArtifact, createSystemPrompt, type Tool } from '@dxos/artifact';
9
9
  import { DEFAULT_EDGE_MODEL, DEFAULT_OLLAMA_MODEL } from '@dxos/assistant';
10
- import { FunctionType } from '@dxos/functions';
10
+ import { FunctionType } from '@dxos/functions/types';
11
11
  import { log } from '@dxos/log';
12
12
  import { useConfig } from '@dxos/react-client';
13
13
  import { Filter, fullyQualifiedId, type Space, useQuery } from '@dxos/react-client/echo';
@@ -0,0 +1,82 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { useEffect, useState } from 'react';
6
+
7
+ import { Mutex } from '@dxos/async';
8
+ import { Context } from '@dxos/context';
9
+ import { createSubscriptionTrigger, type TriggerFactory } from '@dxos/functions';
10
+ import { FunctionTrigger } from '@dxos/functions/types';
11
+ import { invariant } from '@dxos/invariant';
12
+ import { log } from '@dxos/log';
13
+ import { useClient } from '@dxos/react-client';
14
+ import { Filter, type Space, useQuery } from '@dxos/react-client/echo';
15
+
16
+ import { invokeFunction } from './invocation-handler';
17
+
18
+ const registerTriggersMutex = new Mutex();
19
+
20
+ export const useLocalTriggerManager = (space: Space) => {
21
+ const client = useClient();
22
+
23
+ // TODO(burdon): Factor out, creating context for plugin (runs outside of component).
24
+ const [registry] = useState(new Map<string, Context>());
25
+ const triggers = useQuery(space, Filter.schema(FunctionTrigger));
26
+ useEffect(() => {
27
+ setTimeout(async () => {
28
+ // Mark-and-sweep removing disabled triggers.
29
+ await registerTriggersMutex.executeSynchronized(async () => {
30
+ const deprecated = new Set(Array.from(registry.keys()));
31
+ log('triggers', {
32
+ deprecated,
33
+ all: triggers.map((t) => t.id),
34
+ enabled: triggers.filter((t) => t.enabled).map((t) => t.id),
35
+ });
36
+
37
+ for (const trigger of triggers) {
38
+ if (trigger.enabled) {
39
+ if (registry.has(trigger.id)) {
40
+ deprecated.delete(trigger.id);
41
+ continue;
42
+ }
43
+ log.info('activating trigger', trigger.id);
44
+
45
+ const ctx = new Context();
46
+ registry.set(trigger.id, ctx);
47
+ const triggerSpec = trigger.spec;
48
+ invariant(triggerSpec);
49
+
50
+ let triggerFactory: TriggerFactory<any>;
51
+ if (triggerSpec.type === 'subscription') {
52
+ triggerFactory = createSubscriptionTrigger;
53
+ } else {
54
+ log.info('unsupported trigger', { type: triggerSpec.type });
55
+ continue;
56
+ }
57
+
58
+ await triggerFactory(ctx, space, trigger.spec, (data: any) => {
59
+ return invokeFunction(client, space, trigger, data);
60
+ });
61
+ }
62
+ }
63
+
64
+ for (const id of deprecated) {
65
+ const ctx = registry.get(id);
66
+ if (ctx) {
67
+ await ctx.dispose();
68
+ registry.delete(id);
69
+ }
70
+ }
71
+ });
72
+ });
73
+ }, [JSON.stringify(triggers)]);
74
+
75
+ useEffect(() => {
76
+ return () => {
77
+ for (const ctx of registry.values()) {
78
+ void ctx.dispose();
79
+ }
80
+ };
81
+ }, []);
82
+ };
@@ -5,8 +5,8 @@
5
5
  import { defineTool, ToolResult } from '@dxos/artifact';
6
6
  import type { Tool } from '@dxos/artifact';
7
7
  import { toEffectSchema } from '@dxos/echo-schema';
8
- import { getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';
9
- import type { FunctionType } from '@dxos/functions';
8
+ import { getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions/types';
9
+ import type { FunctionType } from '@dxos/functions/types';
10
10
  import { log } from '@dxos/log';
11
11
  import type { SpaceId } from '@dxos/react-client/echo';
12
12
  import { getMeta } from '@dxos/react-client/echo';
@@ -2,12 +2,11 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
6
5
  import jsonpointer from 'jsonpointer';
7
6
  import { type OpenAPIV2, type OpenAPIV3_1 } from 'openapi-types';
8
7
 
9
8
  import { ToolResult, type Tool } from '@dxos/artifact';
10
- import { JsonSchemaType, normalizeSchema, toEffectSchema } from '@dxos/echo-schema';
9
+ import { JsonSchemaType, normalizeSchema, S, toEffectSchema } from '@dxos/echo-schema';
11
10
  import { invariant } from '@dxos/invariant';
12
11
  import { log } from '@dxos/log';
13
12
  import { deepMapValues } from '@dxos/util';
@@ -83,7 +82,7 @@ export const createToolsFromApi = async (url: string, options?: CreateToolsFromA
83
82
  }
84
83
 
85
84
  log('inputSchema', { inputSchema });
86
- Schema.validateSync(JsonSchemaType)(inputSchema);
85
+ S.validateSync(JsonSchemaType)(inputSchema);
87
86
 
88
87
  const description = methodItem.description ?? methodItem.summary;
89
88
  if (!description) {
@@ -201,7 +200,7 @@ const callApiEndpoint = async (endpoint: EndpointDescriptor, input: any) => {
201
200
 
202
201
  // Client-side validation
203
202
  const effectSchema = toEffectSchema(parameter.schema);
204
- Schema.validateSync(effectSchema)(value);
203
+ S.validateSync(effectSchema)(value);
205
204
 
206
205
  if (body) {
207
206
  throw new Error(`Duplicate body parameter: ${parameter.name}`);
@@ -2,80 +2,78 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
6
-
7
5
  import { ComputeGraph } from '@dxos/conductor';
8
- import { Ref, TypedObject, type Ref$ } from '@dxos/echo-schema';
9
- import { FunctionType } from '@dxos/functions';
10
-
11
- const ApiAuthorizationKey = Schema.Struct({
12
- type: Schema.Literal('api-key'),
13
- key: Schema.String,
14
- placement: Schema.Union(
15
- Schema.Struct({
16
- type: Schema.Literal('authorization-header'),
6
+ import { Ref, S, TypedObject, type Ref$ } from '@dxos/echo-schema';
7
+ import { FunctionType } from '@dxos/functions/types';
8
+
9
+ const ApiAuthorizationKey = S.Struct({
10
+ type: S.Literal('api-key'),
11
+ key: S.String,
12
+ placement: S.Union(
13
+ S.Struct({
14
+ type: S.Literal('authorization-header'),
17
15
  }),
18
- Schema.Struct({
19
- type: Schema.Literal('query'),
20
- name: Schema.String,
16
+ S.Struct({
17
+ type: S.Literal('query'),
18
+ name: S.String,
21
19
  }),
22
20
  ),
23
21
  });
24
22
 
25
- const ApiAuthorizationOauth = Schema.Struct({
26
- type: Schema.Literal('oauth'),
27
- clientId: Schema.String,
28
- clientSecret: Schema.String,
29
- tokenUrl: Schema.String,
30
- grantType: Schema.String,
23
+ const ApiAuthorizationOauth = S.Struct({
24
+ type: S.Literal('oauth'),
25
+ clientId: S.String,
26
+ clientSecret: S.String,
27
+ tokenUrl: S.String,
28
+ grantType: S.String,
31
29
  });
32
30
 
33
- export const ApiAuthorization = Schema.Union(ApiAuthorizationKey, ApiAuthorizationOauth);
34
- export type ApiAuthorization = Schema.Schema.Type<typeof ApiAuthorization>;
31
+ export const ApiAuthorization = S.Union(ApiAuthorizationKey, ApiAuthorizationOauth);
32
+ export type ApiAuthorization = S.Schema.Type<typeof ApiAuthorization>;
35
33
 
36
- const ServiceInterfaceFunction = Schema.Struct({
37
- kind: Schema.Literal('function'),
34
+ const ServiceInterfaceFunction = S.Struct({
35
+ kind: S.Literal('function'),
38
36
  fn: Ref(FunctionType) as Ref$<FunctionType>,
39
37
  });
40
38
 
41
- const ServiceInterfaceWorkflow = Schema.Struct({
42
- kind: Schema.Literal('workflow'),
39
+ const ServiceInterfaceWorkflow = S.Struct({
40
+ kind: S.Literal('workflow'),
43
41
  workflow: Ref(ComputeGraph) as Ref$<ComputeGraph>,
44
42
  });
45
43
 
46
- const ServiceInterfaceApi = Schema.Struct({
47
- kind: Schema.Literal('api'),
44
+ const ServiceInterfaceApi = S.Struct({
45
+ kind: S.Literal('api'),
48
46
 
49
47
  /**
50
48
  * URL to fetch the openapi schema.
51
49
  */
52
- schemaUrl: Schema.optional(Schema.String),
50
+ schemaUrl: S.optional(S.String),
53
51
 
54
52
  /**
55
53
  * Inlined openapi schema.
56
54
  */
57
- schema: Schema.optional(Schema.Any),
55
+ schema: S.optional(S.Any),
58
56
 
59
57
  /**
60
58
  * Authorization configuration if required.
61
59
  */
62
- authorization: Schema.optional(ApiAuthorization),
60
+ authorization: S.optional(ApiAuthorization),
63
61
  });
64
62
 
65
- const ServiceInterface = Schema.Union(ServiceInterfaceFunction, ServiceInterfaceWorkflow, ServiceInterfaceApi);
66
- export type ServiceInterface = Schema.Schema.Type<typeof ServiceInterface>;
63
+ const ServiceInterface = S.Union(ServiceInterfaceFunction, ServiceInterfaceWorkflow, ServiceInterfaceApi);
64
+ export type ServiceInterface = S.Schema.Type<typeof ServiceInterface>;
67
65
 
68
66
  export class ServiceType extends TypedObject({ typename: 'dxos.org/type/ServiceType', version: '0.1.0' })({
69
- serviceId: Schema.String,
70
- name: Schema.optional(Schema.String),
71
- description: Schema.optional(Schema.String),
72
- category: Schema.optional(Schema.String),
73
- enabled: Schema.optional(Schema.Boolean),
67
+ serviceId: S.String,
68
+ name: S.optional(S.String),
69
+ description: S.optional(S.String),
70
+ category: S.optional(S.String),
71
+ enabled: S.optional(S.Boolean),
74
72
 
75
73
  /**
76
74
  * Entries exposed: functions, workflows, and APIs.
77
75
  */
78
- interfaces: Schema.optional(Schema.Array(ServiceInterface)),
76
+ interfaces: S.optional(S.Array(ServiceInterface)),
79
77
  }) {}
80
78
 
81
79
  //