@dxos/plugin-script 0.7.5-labs.e27f9b9 → 0.7.5-labs.ea4b4c2

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 (167) hide show
  1. package/dist/lib/browser/{AutomationPanel-OOIRJFPJ.mjs → AutomationPanel-J3SZ5L3Y.mjs} +3 -3
  2. package/dist/lib/browser/{ScriptContainer-EBER222J.mjs → ScriptContainer-AL4ZLJID.mjs} +91 -66
  3. package/dist/lib/browser/ScriptContainer-AL4ZLJID.mjs.map +7 -0
  4. package/dist/lib/browser/artifact-UOESRBEZ.mjs +243 -0
  5. package/dist/lib/browser/artifact-UOESRBEZ.mjs.map +7 -0
  6. package/dist/lib/browser/{chunk-SJ4J527G.mjs → chunk-45LXDWNF.mjs} +2 -2
  7. package/dist/lib/browser/{chunk-ZM6T4HPR.mjs → chunk-6MOQ4BP3.mjs} +2 -2
  8. package/dist/lib/browser/{chunk-PEYUXEY6.mjs → chunk-ALQHMUJN.mjs} +6 -6
  9. package/dist/lib/browser/{chunk-PEYUXEY6.mjs.map → chunk-ALQHMUJN.mjs.map} +2 -2
  10. package/dist/lib/browser/chunk-FVVCAWNP.mjs +21 -0
  11. package/dist/lib/browser/chunk-FVVCAWNP.mjs.map +7 -0
  12. package/dist/lib/browser/{chunk-XPGBHZ3L.mjs → chunk-N46LE7FS.mjs} +2 -2
  13. package/dist/lib/browser/{compiler-HT53ILG7.mjs → compiler-YY2XSKHQ.mjs} +4 -6
  14. package/dist/lib/browser/compiler-YY2XSKHQ.mjs.map +7 -0
  15. package/dist/lib/browser/index.mjs +14 -14
  16. package/dist/lib/browser/index.mjs.map +3 -3
  17. package/dist/lib/browser/{intent-resolver-G2REMZHC.mjs → intent-resolver-CMKQTLBG.mjs} +3 -3
  18. package/dist/lib/browser/meta.json +1 -1
  19. package/dist/lib/browser/{react-surface-GH4LL6CF.mjs → react-surface-YELZNYPR.mjs} +5 -5
  20. package/dist/lib/browser/{react-surface-GH4LL6CF.mjs.map → react-surface-YELZNYPR.mjs.map} +2 -2
  21. package/dist/lib/browser/{settings-YQQEU3DF.mjs → settings-SZCDKHWO.mjs} +3 -3
  22. package/dist/lib/browser/types.mjs +2 -2
  23. package/dist/lib/node/{AutomationPanel-EPRDDR3A.cjs → AutomationPanel-4M55FURO.cjs} +8 -8
  24. package/dist/lib/node/{ScriptContainer-UXMQLKDV.cjs → ScriptContainer-FKCNWHBW.cjs} +93 -66
  25. package/dist/lib/node/ScriptContainer-FKCNWHBW.cjs.map +7 -0
  26. package/dist/lib/node/artifact-PDTB4LV4.cjs +262 -0
  27. package/dist/lib/node/artifact-PDTB4LV4.cjs.map +7 -0
  28. package/dist/lib/node/{chunk-EFTZN5X7.cjs → chunk-5UH3F7TA.cjs} +8 -5
  29. package/dist/lib/node/chunk-5UH3F7TA.cjs.map +7 -0
  30. package/dist/lib/node/{chunk-A2DI2G4D.cjs → chunk-ALY3N6PW.cjs} +6 -6
  31. package/dist/lib/node/{chunk-6VKZJ4MH.cjs → chunk-DJGLGRQV.cjs} +6 -6
  32. package/dist/lib/node/{chunk-UAHKFS7F.cjs → chunk-F5Z3DMHA.cjs} +10 -10
  33. package/dist/lib/node/{chunk-UAHKFS7F.cjs.map → chunk-F5Z3DMHA.cjs.map} +2 -2
  34. package/dist/lib/node/{chunk-DQRAVZM7.cjs → chunk-IID7WUQS.cjs} +6 -6
  35. package/dist/lib/node/{compiler-457ZR24G.cjs → compiler-UIBLKJKG.cjs} +9 -9
  36. package/dist/lib/node/compiler-UIBLKJKG.cjs.map +7 -0
  37. package/dist/lib/node/index.cjs +33 -32
  38. package/dist/lib/node/index.cjs.map +3 -3
  39. package/dist/lib/node/{intent-resolver-IWGK77AZ.cjs → intent-resolver-V5ASU5DW.cjs} +7 -7
  40. package/dist/lib/node/meta.json +1 -1
  41. package/dist/lib/node/{react-surface-3JKCVT5O.cjs → react-surface-SMMFAPZD.cjs} +18 -18
  42. package/dist/lib/node/{react-surface-3JKCVT5O.cjs.map → react-surface-SMMFAPZD.cjs.map} +2 -2
  43. package/dist/lib/node/{settings-NGHDYAVK.cjs → settings-SZFSMSKM.cjs} +9 -9
  44. package/dist/lib/node/types.cjs +4 -4
  45. package/dist/lib/node/types.cjs.map +1 -1
  46. package/dist/lib/node-esm/{AutomationPanel-DMLAGQS5.mjs → AutomationPanel-W6SKG35R.mjs} +3 -3
  47. package/dist/lib/node-esm/{ScriptContainer-56ES2HQ5.mjs → ScriptContainer-52KVAFUY.mjs} +91 -66
  48. package/dist/lib/node-esm/ScriptContainer-52KVAFUY.mjs.map +7 -0
  49. package/dist/lib/node-esm/artifact-IX4ZCTUF.mjs +245 -0
  50. package/dist/lib/node-esm/artifact-IX4ZCTUF.mjs.map +7 -0
  51. package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs → chunk-CGF7EOGD.mjs} +2 -2
  52. package/dist/lib/node-esm/{chunk-675XSDRN.mjs → chunk-CP5LXTK5.mjs} +2 -2
  53. package/dist/lib/node-esm/{chunk-TYGM5YLW.mjs → chunk-GXRS4YIV.mjs} +6 -6
  54. package/dist/lib/node-esm/{chunk-TYGM5YLW.mjs.map → chunk-GXRS4YIV.mjs.map} +2 -2
  55. package/dist/lib/node-esm/{chunk-BHP545D7.mjs → chunk-P2V2Y5LV.mjs} +5 -2
  56. package/dist/lib/node-esm/chunk-P2V2Y5LV.mjs.map +7 -0
  57. package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs → chunk-UNQFIERE.mjs} +2 -2
  58. package/dist/lib/node-esm/{compiler-PEARFTFR.mjs → compiler-XTXFGZJM.mjs} +4 -6
  59. package/dist/lib/node-esm/compiler-XTXFGZJM.mjs.map +7 -0
  60. package/dist/lib/node-esm/index.mjs +14 -14
  61. package/dist/lib/node-esm/index.mjs.map +3 -3
  62. package/dist/lib/node-esm/{intent-resolver-KGADFH3H.mjs → intent-resolver-75BHFRUK.mjs} +3 -3
  63. package/dist/lib/node-esm/meta.json +1 -1
  64. package/dist/lib/node-esm/{react-surface-JW776PVP.mjs → react-surface-7PHSWVOU.mjs} +5 -5
  65. package/dist/lib/node-esm/{react-surface-JW776PVP.mjs.map → react-surface-7PHSWVOU.mjs.map} +2 -2
  66. package/dist/lib/node-esm/{settings-XGXDY4NI.mjs → settings-GR4O2WHZ.mjs} +3 -3
  67. package/dist/lib/node-esm/types.mjs +2 -2
  68. package/dist/types/src/ScriptPlugin.d.ts.map +1 -1
  69. package/dist/types/src/capabilities/artifact.d.ts +11 -0
  70. package/dist/types/src/capabilities/artifact.d.ts.map +1 -0
  71. package/dist/types/src/capabilities/index.d.ts +1 -0
  72. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  73. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  74. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts +1 -1
  75. package/dist/types/src/components/FrameContainer/FrameContainer.d.ts.map +1 -1
  76. package/dist/types/src/components/ScriptContainer.d.ts +2 -2
  77. package/dist/types/src/components/ScriptContainer.d.ts.map +1 -1
  78. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts +1 -1
  79. package/dist/types/src/components/ScriptToolbar/ScriptToolbar.d.ts.map +1 -1
  80. package/dist/types/src/components/index.d.ts +1 -1
  81. package/dist/types/src/components/index.d.ts.map +1 -1
  82. package/dist/types/src/hooks/deploy.d.ts.map +1 -0
  83. package/dist/types/src/hooks/format.d.ts.map +1 -0
  84. package/dist/types/src/hooks/index.d.ts +7 -0
  85. package/dist/types/src/hooks/index.d.ts.map +1 -0
  86. package/dist/types/src/{components/ScriptToolbar/templateSelect.d.ts → hooks/template.d.ts} +1 -1
  87. package/dist/types/src/hooks/template.d.ts.map +1 -0
  88. package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarAction.d.ts +1 -1
  89. package/dist/types/src/hooks/useToolbarAction.d.ts.map +1 -0
  90. package/dist/types/src/hooks/useToolbarState.d.ts.map +1 -0
  91. package/dist/types/src/hooks/view.d.ts.map +1 -0
  92. package/dist/types/src/index.d.ts +0 -1
  93. package/dist/types/src/index.d.ts.map +1 -1
  94. package/dist/types/src/meta.d.ts +1 -0
  95. package/dist/types/src/meta.d.ts.map +1 -1
  96. package/package.json +43 -42
  97. package/src/ScriptPlugin.tsx +6 -1
  98. package/src/capabilities/artifact.ts +219 -0
  99. package/src/capabilities/compiler.ts +1 -1
  100. package/src/capabilities/index.ts +1 -0
  101. package/src/capabilities/react-surface.tsx +2 -1
  102. package/src/components/FrameContainer/FrameContainer.tsx +1 -2
  103. package/src/components/ScriptContainer.tsx +10 -5
  104. package/src/components/ScriptSettingsPanel.tsx +2 -2
  105. package/src/components/ScriptToolbar/ScriptToolbar.tsx +8 -6
  106. package/src/{components/ScriptToolbar → hooks}/deploy.ts +14 -3
  107. package/src/{components/ScriptToolbar → hooks}/format.ts +1 -1
  108. package/src/hooks/index.ts +11 -0
  109. package/src/{components/ScriptToolbar/templateSelect.ts → hooks/template.ts} +2 -2
  110. package/src/{components/ScriptToolbar → hooks}/useToolbarAction.ts +1 -1
  111. package/src/{components/ScriptToolbar → hooks}/view.ts +1 -1
  112. package/src/index.ts +0 -1
  113. package/src/meta.ts +3 -1
  114. package/dist/lib/browser/ScriptContainer-EBER222J.mjs.map +0 -7
  115. package/dist/lib/browser/chunk-5BU5ERNU.mjs +0 -18
  116. package/dist/lib/browser/chunk-5BU5ERNU.mjs.map +0 -7
  117. package/dist/lib/browser/chunk-SDHKTS6H.mjs +0 -237
  118. package/dist/lib/browser/chunk-SDHKTS6H.mjs.map +0 -7
  119. package/dist/lib/browser/compiler-HT53ILG7.mjs.map +0 -7
  120. package/dist/lib/node/ScriptContainer-UXMQLKDV.cjs.map +0 -7
  121. package/dist/lib/node/chunk-EFTZN5X7.cjs.map +0 -7
  122. package/dist/lib/node/chunk-T4TXCRN5.cjs +0 -260
  123. package/dist/lib/node/chunk-T4TXCRN5.cjs.map +0 -7
  124. package/dist/lib/node/compiler-457ZR24G.cjs.map +0 -7
  125. package/dist/lib/node-esm/ScriptContainer-56ES2HQ5.mjs.map +0 -7
  126. package/dist/lib/node-esm/chunk-BHP545D7.mjs.map +0 -7
  127. package/dist/lib/node-esm/chunk-G76M6O46.mjs +0 -239
  128. package/dist/lib/node-esm/chunk-G76M6O46.mjs.map +0 -7
  129. package/dist/lib/node-esm/compiler-PEARFTFR.mjs.map +0 -7
  130. package/dist/types/src/bundler/bundler.d.ts +0 -39
  131. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  132. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  133. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  134. package/dist/types/src/bundler/index.d.ts +0 -2
  135. package/dist/types/src/bundler/index.d.ts.map +0 -1
  136. package/dist/types/src/components/ScriptToolbar/deploy.d.ts.map +0 -1
  137. package/dist/types/src/components/ScriptToolbar/format.d.ts.map +0 -1
  138. package/dist/types/src/components/ScriptToolbar/templateSelect.d.ts.map +0 -1
  139. package/dist/types/src/components/ScriptToolbar/useToolbarAction.d.ts.map +0 -1
  140. package/dist/types/src/components/ScriptToolbar/useToolbarState.d.ts.map +0 -1
  141. package/dist/types/src/components/ScriptToolbar/view.d.ts.map +0 -1
  142. package/src/bundler/bundler.test.ts +0 -55
  143. package/src/bundler/bundler.ts +0 -250
  144. package/src/bundler/index.ts +0 -5
  145. /package/dist/lib/browser/{AutomationPanel-OOIRJFPJ.mjs.map → AutomationPanel-J3SZ5L3Y.mjs.map} +0 -0
  146. /package/dist/lib/browser/{chunk-SJ4J527G.mjs.map → chunk-45LXDWNF.mjs.map} +0 -0
  147. /package/dist/lib/browser/{chunk-ZM6T4HPR.mjs.map → chunk-6MOQ4BP3.mjs.map} +0 -0
  148. /package/dist/lib/browser/{chunk-XPGBHZ3L.mjs.map → chunk-N46LE7FS.mjs.map} +0 -0
  149. /package/dist/lib/browser/{intent-resolver-G2REMZHC.mjs.map → intent-resolver-CMKQTLBG.mjs.map} +0 -0
  150. /package/dist/lib/browser/{settings-YQQEU3DF.mjs.map → settings-SZCDKHWO.mjs.map} +0 -0
  151. /package/dist/lib/node/{AutomationPanel-EPRDDR3A.cjs.map → AutomationPanel-4M55FURO.cjs.map} +0 -0
  152. /package/dist/lib/node/{chunk-A2DI2G4D.cjs.map → chunk-ALY3N6PW.cjs.map} +0 -0
  153. /package/dist/lib/node/{chunk-6VKZJ4MH.cjs.map → chunk-DJGLGRQV.cjs.map} +0 -0
  154. /package/dist/lib/node/{chunk-DQRAVZM7.cjs.map → chunk-IID7WUQS.cjs.map} +0 -0
  155. /package/dist/lib/node/{intent-resolver-IWGK77AZ.cjs.map → intent-resolver-V5ASU5DW.cjs.map} +0 -0
  156. /package/dist/lib/node/{settings-NGHDYAVK.cjs.map → settings-SZFSMSKM.cjs.map} +0 -0
  157. /package/dist/lib/node-esm/{AutomationPanel-DMLAGQS5.mjs.map → AutomationPanel-W6SKG35R.mjs.map} +0 -0
  158. /package/dist/lib/node-esm/{chunk-XUWS7OTK.mjs.map → chunk-CGF7EOGD.mjs.map} +0 -0
  159. /package/dist/lib/node-esm/{chunk-675XSDRN.mjs.map → chunk-CP5LXTK5.mjs.map} +0 -0
  160. /package/dist/lib/node-esm/{chunk-JHGOPQVO.mjs.map → chunk-UNQFIERE.mjs.map} +0 -0
  161. /package/dist/lib/node-esm/{intent-resolver-KGADFH3H.mjs.map → intent-resolver-75BHFRUK.mjs.map} +0 -0
  162. /package/dist/lib/node-esm/{settings-XGXDY4NI.mjs.map → settings-GR4O2WHZ.mjs.map} +0 -0
  163. /package/dist/types/src/{components/ScriptToolbar → hooks}/deploy.d.ts +0 -0
  164. /package/dist/types/src/{components/ScriptToolbar → hooks}/format.d.ts +0 -0
  165. /package/dist/types/src/{components/ScriptToolbar → hooks}/useToolbarState.d.ts +0 -0
  166. /package/dist/types/src/{components/ScriptToolbar → hooks}/view.d.ts +0 -0
  167. /package/src/{components/ScriptToolbar → hooks}/useToolbarState.ts +0 -0
@@ -0,0 +1,262 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var artifact_PDTB4LV4_exports = {};
20
+ __export(artifact_PDTB4LV4_exports, {
21
+ default: () => artifact_default
22
+ });
23
+ module.exports = __toCommonJS(artifact_PDTB4LV4_exports);
24
+ var import_app_framework = require("@dxos/app-framework");
25
+ var import_artifact = require("@dxos/artifact");
26
+ var import_assistant = require("@dxos/assistant");
27
+ var import_echo_schema = require("@dxos/echo-schema");
28
+ var import_functions = require("@dxos/functions");
29
+ var import_invariant = require("@dxos/invariant");
30
+ var import_echo = require("@dxos/react-client/echo");
31
+ var import_schema = require("@dxos/schema");
32
+ var import_types = require("@dxos/plugin-space/types");
33
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/capabilities/artifact.ts";
34
+ var artifact_default = () => {
35
+ const definition = (0, import_artifact.defineArtifact)({
36
+ id: "plugin-script",
37
+ // TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,
38
+ // we should offload the work of synthesizing the code to a separate model.
39
+ // The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.
40
+ instructions: `
41
+ If the user explicitly requests you to write a script, you can create one.
42
+ If the user requests you to change one of the existing script, you can update it.
43
+ Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.
44
+ Each script must follow as strict shape for the definition but the body can contain any valid executable code.
45
+ Scripts are written in JavaScript or TypeScript.
46
+ Each script must define an input schema and output schema.
47
+ Each script must have its own detailed description.
48
+
49
+ Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.
50
+
51
+ Description:
52
+ The description is a detailed description of the script.
53
+ It is used to describe the script's purpose, input, and output.
54
+ The description is used to generate the script's documentation.
55
+ The description is also goes into the script metadata.
56
+ The description is used by AI to understand the script and its purpose.
57
+ The description must provide cases on when the script should be used.
58
+
59
+ Schema:
60
+ The schema is defined using a schema-DSL library called Effect Schema.
61
+ The input schema describes the arguments that the script accepts.
62
+ The output schema describes the result that the script produces.
63
+ The schema is used to validate the script's input and output.
64
+ The schema is also goes into the script metadata.
65
+ The properties in the schema must have valid descriptions.
66
+ The input and output schemas must both be a struct of fields.
67
+
68
+ Restricts:
69
+ The scripts can only import code from "dxos:functions" module. No other modules are allowed.
70
+ Some web APIs are available - like fetch.
71
+
72
+ Reasoning:
73
+ Before writing a script, synthesize the following information:
74
+ - Description
75
+ - What APIs will be used.
76
+ - Detailed input schema
77
+ - Detailed output schema
78
+
79
+ <apis>
80
+ export function defineFunction(params: {
81
+ description: string,
82
+ inputSchema: S.Schema,
83
+ outputSchema: S.Schema,
84
+ handler: (params: { event: { data: TInput } }) => Promise<TOutput>
85
+ }): FunctionDefinition
86
+ /**
87
+ * Effect Schema
88
+ */
89
+ export const S;
90
+
91
+ // Examples:
92
+
93
+ S.String
94
+ S.Number
95
+ S.Boolean
96
+ S.Struct({
97
+ from: S.String.annotations({ description: 'The source currency' }),
98
+ to: S.String.annotations({ description: 'The target currency' }),
99
+ })
100
+ S.Array(S.String)
101
+ S.Union(S.String, S.Number)
102
+ S.optional(S.String)
103
+ S.String.annotations({ description: 'The source currency' })
104
+ </apis>
105
+
106
+ <handler_function>
107
+ Async function that takes the argument in the form of:
108
+
109
+ type HandlerFunctionParam = {
110
+ event: {
111
+ data: T // The input schema
112
+ },
113
+ }
114
+
115
+ The function must return the result that matches the output schema.
116
+ </handler_function>
117
+
118
+ <example>
119
+ import { defineFunction, S } from 'dxos:functions';
120
+
121
+ export default defineFunction({
122
+ description: 'Returns the exchange rate between two currencies.',
123
+
124
+ inputSchema: S.Struct({
125
+ from: S.String.annotations({ description: 'The source currency' }),
126
+ to: S.String.annotations({ description: 'The target currency' }),
127
+ }),
128
+
129
+ outputSchema: S.Struct({
130
+ rate: S.String.annotations({ description: 'The exchange rate' }),
131
+ }),
132
+
133
+ handler: async ({
134
+ event: {
135
+ data: { from, to },
136
+ },
137
+ }: any) => {
138
+ const res = await fetch(\`https://free.ratesdb.com/v1/rates?from=\${from}&to=\${to}\`);
139
+ const {
140
+ data: { rates },
141
+ } = await res.json();
142
+
143
+ return { rate: rates[to].toString() };
144
+ },
145
+ });
146
+ </example>
147
+ `,
148
+ schema: import_functions.ScriptType,
149
+ tools: [
150
+ (0, import_artifact.defineTool)({
151
+ name: "script_new",
152
+ description: "Create a new script. Returns the artifact definition for the script",
153
+ schema: import_echo_schema.S.Struct({
154
+ name: import_echo_schema.S.String.annotations({
155
+ description: "The name of the script"
156
+ }),
157
+ code: import_echo_schema.S.String.annotations({
158
+ description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
159
+ })
160
+ }),
161
+ execute: async ({ name, code }, { extensions }) => {
162
+ (0, import_invariant.invariant)(extensions?.space, "No space", {
163
+ F: __dxlog_file,
164
+ L: 149,
165
+ S: void 0,
166
+ A: [
167
+ "extensions?.space",
168
+ "'No space'"
169
+ ]
170
+ });
171
+ (0, import_invariant.invariant)(extensions?.dispatch, "No intent dispatcher", {
172
+ F: __dxlog_file,
173
+ L: 150,
174
+ S: void 0,
175
+ A: [
176
+ "extensions?.dispatch",
177
+ "'No intent dispatcher'"
178
+ ]
179
+ });
180
+ const script = (0, import_echo.create)(import_functions.ScriptType, {
181
+ name,
182
+ source: (0, import_echo.makeRef)((0, import_echo.create)(import_schema.TextType, {
183
+ content: code
184
+ }))
185
+ });
186
+ extensions.space.db.add(script);
187
+ await extensions.space.db.flush();
188
+ const intent = (0, import_app_framework.createIntent)(import_types.SpaceAction.AddObject, {
189
+ target: extensions.space,
190
+ object: script
191
+ });
192
+ const { data, error } = await extensions.dispatch(intent);
193
+ if (!data || error) {
194
+ return import_artifact.ToolResult.Error(error?.message ?? "Failed to create chess game");
195
+ }
196
+ return import_artifact.ToolResult.Success((0, import_assistant.createArtifactElement)(script.id));
197
+ }
198
+ }),
199
+ (0, import_artifact.defineTool)({
200
+ name: "script_inspect",
201
+ description: "Inspect a script. Returns the artifact definition for the script",
202
+ schema: import_echo_schema.S.Struct({
203
+ id: import_echo_schema.ObjectId
204
+ }),
205
+ execute: async ({ id }, { extensions }) => {
206
+ (0, import_invariant.invariant)(extensions?.space, "No space", {
207
+ F: __dxlog_file,
208
+ L: 178,
209
+ S: void 0,
210
+ A: [
211
+ "extensions?.space",
212
+ "'No space'"
213
+ ]
214
+ });
215
+ const script = await extensions.space.db.query({
216
+ id
217
+ }).first();
218
+ const { content } = await script.source.load();
219
+ return import_artifact.ToolResult.Success({
220
+ name: script.name,
221
+ code: content
222
+ });
223
+ }
224
+ }),
225
+ (0, import_artifact.defineTool)({
226
+ name: "script_update",
227
+ description: "Update a script. Returns the artifact definition for the script",
228
+ schema: import_echo_schema.S.Struct({
229
+ id: import_echo_schema.ObjectId,
230
+ code: import_echo_schema.S.String.annotations({
231
+ description: "The full code of the script in JavaScript or TypeScript. Must be valid executable code."
232
+ })
233
+ }),
234
+ execute: async ({ id, code }, { extensions }) => {
235
+ (0, import_invariant.invariant)(extensions?.space, "No space", {
236
+ F: __dxlog_file,
237
+ L: 199,
238
+ S: void 0,
239
+ A: [
240
+ "extensions?.space",
241
+ "'No space'"
242
+ ]
243
+ });
244
+ const script = await extensions.space.db.query({
245
+ id
246
+ }).first();
247
+ const source = await script.source.load();
248
+ if (!source) {
249
+ return import_artifact.ToolResult.Error("Script not found");
250
+ }
251
+ source.content = code;
252
+ await extensions.space?.db.flush();
253
+ return import_artifact.ToolResult.Success({
254
+ name: script.name
255
+ });
256
+ }
257
+ })
258
+ ]
259
+ });
260
+ return (0, import_app_framework.contributes)(import_app_framework.Capabilities.ArtifactDefinition, definition);
261
+ };
262
+ //# sourceMappingURL=artifact-PDTB4LV4.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/artifact.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Capabilities, contributes, createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';\nimport { defineArtifact, defineTool, ToolResult } from '@dxos/artifact';\nimport { createArtifactElement } from '@dxos/assistant';\nimport { ObjectId, S } from '@dxos/echo-schema';\nimport { ScriptType } from '@dxos/functions';\nimport { invariant } from '@dxos/invariant';\nimport { create, makeRef, type Space } from '@dxos/react-client/echo';\nimport { TextType } from '@dxos/schema';\nimport { SpaceAction } from '@dxos/plugin-space/types';\n\n// TODO(burdon): Factor out.\ndeclare global {\n interface ToolContextExtensions {\n space?: Space;\n dispatch?: PromiseIntentDispatcher;\n }\n}\n\nexport default () => {\n const definition = defineArtifact({\n id: 'plugin-script',\n // TODO(dmaretskyi): Since writing scripts requires a lot of domain knowledge,\n // we should offload the work of synthesizing the code to a separate model.\n // The main reasoning model will give it a concrete task and the script model will synthesize the code, knowing all the docs.\n instructions: `\n If the user explicitly requests you to write a script, you can create one.\n If the user requests you to change one of the existing script, you can update it.\n Scripts are short code pieces of executable code that can be used to perform computations, integrate with external systems, and perform automated tasks.\n Each script must follow as strict shape for the definition but the body can contain any valid executable code.\n Scripts are written in JavaScript or TypeScript.\n Each script must define an input schema and output schema.\n Each script must have its own detailed description.\n\n Important: You cannot execute scripts. Scripts are only available as tools after the user deploys them. You must only call the available tools.\n\n Description:\n The description is a detailed description of the script.\n It is used to describe the script's purpose, input, and output.\n The description is used to generate the script's documentation.\n The description is also goes into the script metadata.\n The description is used by AI to understand the script and its purpose.\n The description must provide cases on when the script should be used.\n\n Schema: \n The schema is defined using a schema-DSL library called Effect Schema.\n The input schema describes the arguments that the script accepts.\n The output schema describes the result that the script produces.\n The schema is used to validate the script's input and output.\n The schema is also goes into the script metadata.\n The properties in the schema must have valid descriptions.\n The input and output schemas must both be a struct of fields.\n\n Restricts:\n The scripts can only import code from \"dxos:functions\" module. No other modules are allowed.\n Some web APIs are available - like fetch.\n\n Reasoning:\n Before writing a script, synthesize the following information:\n - Description\n - What APIs will be used.\n - Detailed input schema\n - Detailed output schema\n\n <apis>\n export function defineFunction(params: { \n description: string, \n inputSchema: S.Schema, \n outputSchema: S.Schema, \n handler: (params: { event: { data: TInput } }) => Promise<TOutput> \n }): FunctionDefinition\n /**\n * Effect Schema\n */\n export const S; \n\n // Examples: \n\n S.String\n S.Number\n S.Boolean\n S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n })\n S.Array(S.String)\n S.Union(S.String, S.Number)\n S.optional(S.String)\n S.String.annotations({ description: 'The source currency' })\n </apis>\n\n <handler_function>\n Async function that takes the argument in the form of:\n\n type HandlerFunctionParam = {\n event: {\n data: T // The input schema\n },\n }\n\n The function must return the result that matches the output schema.\n </handler_function>\n \n <example>\n import { defineFunction, S } from 'dxos:functions';\n\n export default defineFunction({\n description: 'Returns the exchange rate between two currencies.',\n\n inputSchema: S.Struct({\n from: S.String.annotations({ description: 'The source currency' }),\n to: S.String.annotations({ description: 'The target currency' }),\n }),\n\n outputSchema: S.Struct({\n rate: S.String.annotations({ description: 'The exchange rate' }),\n }),\n\n handler: async ({\n event: {\n data: { from, to },\n },\n }: any) => {\n const res = await fetch(\\`https://free.ratesdb.com/v1/rates?from=\\${from}&to=\\${to}\\`);\n const {\n data: { rates },\n } = await res.json();\n\n return { rate: rates[to].toString() };\n },\n });\n </example>\n `,\n schema: ScriptType,\n tools: [\n defineTool({\n name: 'script_new',\n description: 'Create a new script. Returns the artifact definition for the script',\n schema: S.Struct({\n name: S.String.annotations({ description: 'The name of the script' }),\n code: S.String.annotations({\n description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',\n }),\n }),\n execute: async ({ name, code }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n invariant(extensions?.dispatch, 'No intent dispatcher');\n const script = create(ScriptType, {\n name,\n source: makeRef(\n create(TextType, {\n content: code,\n }),\n ),\n });\n extensions.space.db.add(script);\n await extensions.space.db.flush();\n\n const intent = createIntent(SpaceAction.AddObject, { target: extensions.space, object: script });\n const { data, error } = await extensions.dispatch(intent);\n if (!data || error) {\n return ToolResult.Error(error?.message ?? 'Failed to create chess game');\n }\n\n return ToolResult.Success(createArtifactElement(script.id));\n },\n }),\n defineTool({\n name: 'script_inspect',\n description: 'Inspect a script. Returns the artifact definition for the script',\n schema: S.Struct({\n id: ObjectId,\n }),\n execute: async ({ id }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query({ id }).first()) as ScriptType;\n const { content } = await script.source.load();\n\n return ToolResult.Success({\n name: script.name,\n code: content,\n });\n },\n }),\n defineTool({\n name: 'script_update',\n description: 'Update a script. Returns the artifact definition for the script',\n schema: S.Struct({\n id: ObjectId,\n code: S.String.annotations({\n description: 'The full code of the script in JavaScript or TypeScript. Must be valid executable code.',\n }),\n }),\n execute: async ({ id, code }, { extensions }) => {\n invariant(extensions?.space, 'No space');\n\n const script = (await extensions.space.db.query({ id }).first()) as ScriptType;\n const source = await script.source.load();\n if (!source) {\n return ToolResult.Error('Script not found');\n }\n\n source.content = code;\n await extensions.space?.db.flush();\n\n return ToolResult.Success({\n name: script.name,\n });\n },\n }),\n ],\n });\n\n return contributes(Capabilities.ArtifactDefinition, definition);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,2BAAsF;AACtF,sBAAuD;AACvD,uBAAsC;AACtC,yBAA4B;AAC5B,uBAA2B;AAC3B,uBAA0B;AAC1B,kBAA4C;AAC5C,oBAAyB;AACzB,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ACN,CAAA;QACA3B,SAAS,OAAO,EAAEb,GAAE,GAAI,EAAEc,WAAU,MAAE;AACpCC,0CAAUD,YAAYE,OAAO,YAAA;;;;;;;;;AAE7B,gBAAME,SAAU,MAAMJ,WAAWE,MAAMQ,GAAGiB,MAAM;YAAEzC;UAAG,CAAA,EAAG0C,MAAK;AAC7D,gBAAM,EAAEnB,QAAO,IAAK,MAAML,OAAOE,OAAOuB,KAAI;AAE5C,iBAAOR,2BAAWG,QAAQ;YACxBhC,MAAMY,OAAOZ;YACbM,MAAMW;UACR,CAAA;QACF;MACF,CAAA;UACAlB,4BAAW;QACTC,MAAM;QACNC,aAAa;QACbL,QAAQM,qBAAEC,OAAO;UACfT,IAAIwC;UACJ5B,MAAMJ,qBAAEE,OAAOC,YAAY;YACzBJ,aAAa;UACf,CAAA;QACF,CAAA;QACAM,SAAS,OAAO,EAAEb,IAAIY,KAAI,GAAI,EAAEE,WAAU,MAAE;AAC1CC,0CAAUD,YAAYE,OAAO,YAAA;;;;;;;;;AAE7B,gBAAME,SAAU,MAAMJ,WAAWE,MAAMQ,GAAGiB,MAAM;YAAEzC;UAAG,CAAA,EAAG0C,MAAK;AAC7D,gBAAMtB,SAAS,MAAMF,OAAOE,OAAOuB,KAAI;AACvC,cAAI,CAACvB,QAAQ;AACX,mBAAOe,2BAAWC,MAAM,kBAAA;UAC1B;AAEAhB,iBAAOG,UAAUX;AACjB,gBAAME,WAAWE,OAAOQ,GAAGE,MAAAA;AAE3B,iBAAOS,2BAAWG,QAAQ;YACxBhC,MAAMY,OAAOZ;UACf,CAAA;QACF;MACF,CAAA;;EAEJ,CAAA;AAEA,aAAOsC,kCAAYC,kCAAaC,oBAAoBhD,UAAAA;AACtD;",
6
+ "names": ["definition", "defineArtifact", "id", "instructions", "schema", "ScriptType", "tools", "defineTool", "name", "description", "S", "Struct", "String", "annotations", "code", "execute", "extensions", "invariant", "space", "dispatch", "script", "create", "source", "makeRef", "TextType", "content", "db", "add", "flush", "intent", "createIntent", "SpaceAction", "AddObject", "target", "object", "data", "error", "ToolResult", "Error", "message", "Success", "createArtifactElement", "ObjectId", "query", "first", "load", "contributes", "Capabilities", "ArtifactDefinition"]
7
+ }
@@ -16,21 +16,24 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_EFTZN5X7_exports = {};
20
- __export(chunk_EFTZN5X7_exports, {
19
+ var chunk_5UH3F7TA_exports = {};
20
+ __export(chunk_5UH3F7TA_exports, {
21
21
  SCRIPT_PLUGIN: () => SCRIPT_PLUGIN,
22
22
  meta: () => meta
23
23
  });
24
- module.exports = __toCommonJS(chunk_EFTZN5X7_exports);
24
+ module.exports = __toCommonJS(chunk_5UH3F7TA_exports);
25
25
  var SCRIPT_PLUGIN = "dxos.org/plugin/script";
26
26
  var meta = {
27
27
  id: SCRIPT_PLUGIN,
28
28
  name: "Scripts",
29
- description: "Distributed functions.",
29
+ description: "Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API\u2019s or external data inside of Composer.",
30
30
  icon: "ph--code--regular",
31
31
  source: "https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer",
32
32
  tags: [
33
33
  "experimental"
34
+ ],
35
+ screenshots: [
36
+ "https://dxos.network/plugin-details-scripts-dark.png"
34
37
  ]
35
38
  };
36
39
  // Annotate the CommonJS export names for ESM import in node:
@@ -38,4 +41,4 @@ var meta = {
38
41
  SCRIPT_PLUGIN,
39
42
  meta
40
43
  });
41
- //# sourceMappingURL=chunk-EFTZN5X7.cjs.map
44
+ //# sourceMappingURL=chunk-5UH3F7TA.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/meta.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type PluginMeta } from '@dxos/app-framework';\n\nexport const SCRIPT_PLUGIN = 'dxos.org/plugin/script';\n\nexport const meta = {\n id: SCRIPT_PLUGIN,\n name: 'Scripts',\n description:\n 'Scripts in Composer allow you to deploy custom functions that run on the edge. These functions can be referenced by your AI agent and called inside of cells in any Sheet. Use scripts to interact with API’s or external data inside of Composer.',\n icon: 'ph--code--regular',\n source: 'https://github.com/dxos/dxos/tree/main/packages/plugins/experimental/plugin-explorer',\n tags: ['experimental'],\n screenshots: ['https://dxos.network/plugin-details-scripts-dark.png'],\n} satisfies PluginMeta;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAMA,gBAAgB;AAEtB,IAAMC,OAAO;EAClBC,IAAIF;EACJG,MAAM;EACNC,aACE;EACFC,MAAM;EACNC,QAAQ;EACRC,MAAM;IAAC;;EACPC,aAAa;IAAC;;AAChB;",
6
+ "names": ["SCRIPT_PLUGIN", "meta", "id", "name", "description", "icon", "source", "tags", "screenshots"]
7
+ }
@@ -16,19 +16,19 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_A2DI2G4D_exports = {};
20
- __export(chunk_A2DI2G4D_exports, {
19
+ var chunk_ALY3N6PW_exports = {};
20
+ __export(chunk_ALY3N6PW_exports, {
21
21
  ScriptCapabilities: () => ScriptCapabilities
22
22
  });
23
- module.exports = __toCommonJS(chunk_A2DI2G4D_exports);
24
- var import_chunk_EFTZN5X7 = require("./chunk-EFTZN5X7.cjs");
23
+ module.exports = __toCommonJS(chunk_ALY3N6PW_exports);
24
+ var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
25
25
  var import_app_framework = require("@dxos/app-framework");
26
26
  var ScriptCapabilities;
27
27
  (function(ScriptCapabilities2) {
28
- ScriptCapabilities2.Compiler = (0, import_app_framework.defineCapability)(`${import_chunk_EFTZN5X7.SCRIPT_PLUGIN}/capability/compiler`);
28
+ ScriptCapabilities2.Compiler = (0, import_app_framework.defineCapability)(`${import_chunk_5UH3F7TA.SCRIPT_PLUGIN}/capability/compiler`);
29
29
  })(ScriptCapabilities || (ScriptCapabilities = {}));
30
30
  // Annotate the CommonJS export names for ESM import in node:
31
31
  0 && (module.exports = {
32
32
  ScriptCapabilities
33
33
  });
34
- //# sourceMappingURL=chunk-A2DI2G4D.cjs.map
34
+ //# sourceMappingURL=chunk-ALY3N6PW.cjs.map
@@ -16,13 +16,13 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_6VKZJ4MH_exports = {};
20
- __export(chunk_6VKZJ4MH_exports, {
19
+ var chunk_DJGLGRQV_exports = {};
20
+ __export(chunk_DJGLGRQV_exports, {
21
21
  ScriptAction: () => ScriptAction,
22
22
  ScriptSettingsSchema: () => ScriptSettingsSchema
23
23
  });
24
- module.exports = __toCommonJS(chunk_6VKZJ4MH_exports);
25
- var import_chunk_EFTZN5X7 = require("./chunk-EFTZN5X7.cjs");
24
+ module.exports = __toCommonJS(chunk_DJGLGRQV_exports);
25
+ var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
26
26
  var import_AST = require("@effect/schema/AST");
27
27
  var import_echo = require("@dxos/client/echo");
28
28
  var import_echo_schema = require("@dxos/echo-schema");
@@ -30,7 +30,7 @@ var import_functions = require("@dxos/functions");
30
30
  var import_react_ui_editor = require("@dxos/react-ui-editor");
31
31
  var ScriptAction;
32
32
  (function(ScriptAction2) {
33
- const SCRIPT_ACTION = `${import_chunk_EFTZN5X7.SCRIPT_PLUGIN}/action`;
33
+ const SCRIPT_ACTION = `${import_chunk_5UH3F7TA.SCRIPT_PLUGIN}/action`;
34
34
  ScriptAction2.CreateScriptSchema = import_echo_schema.S.Struct({
35
35
  name: import_echo_schema.S.optional(import_echo_schema.S.String),
36
36
  // TODO(wittjosiah): Placeholder annotation?
@@ -57,4 +57,4 @@ var ScriptSettingsSchema = import_echo_schema.S.mutable(import_echo_schema.S.Str
57
57
  ScriptAction,
58
58
  ScriptSettingsSchema
59
59
  });
60
- //# sourceMappingURL=chunk-6VKZJ4MH.cjs.map
60
+ //# sourceMappingURL=chunk-DJGLGRQV.cjs.map
@@ -26,15 +26,15 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_UAHKFS7F_exports = {};
30
- __export(chunk_UAHKFS7F_exports, {
29
+ var chunk_F5Z3DMHA_exports = {};
30
+ __export(chunk_F5Z3DMHA_exports, {
31
31
  AutomationPanel: () => AutomationPanel,
32
32
  ScriptContainer: () => ScriptContainer,
33
33
  ScriptSettings: () => ScriptSettings,
34
34
  ScriptSettingsPanel: () => ScriptSettingsPanel
35
35
  });
36
- module.exports = __toCommonJS(chunk_UAHKFS7F_exports);
37
- var import_chunk_EFTZN5X7 = require("./chunk-EFTZN5X7.cjs");
36
+ module.exports = __toCommonJS(chunk_F5Z3DMHA_exports);
37
+ var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
38
38
  var import_react = __toESM(require("react"));
39
39
  var import_react_client = require("@dxos/react-client");
40
40
  var import_react_ui = require("@dxos/react-ui");
@@ -51,7 +51,7 @@ var import_react_ui2 = require("@dxos/react-ui");
51
51
  var import_schema = require("@dxos/schema");
52
52
  var import_react3 = require("react");
53
53
  var ScriptSettings = ({ settings }) => {
54
- const { t } = (0, import_react_ui.useTranslation)(import_chunk_EFTZN5X7.SCRIPT_PLUGIN);
54
+ const { t } = (0, import_react_ui.useTranslation)(import_chunk_5UH3F7TA.SCRIPT_PLUGIN);
55
55
  const client = (0, import_react_client.useClient)();
56
56
  const handleAuthenticate = async () => {
57
57
  const { identityKey } = client.halo.identity.get();
@@ -95,7 +95,7 @@ var ScriptSettings = ({ settings }) => {
95
95
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/ScriptSettingsPanel.tsx";
96
96
  var kebabize = (str) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? "-" : "") + $.toLowerCase());
97
97
  var ScriptSettingsPanel = ({ script }) => {
98
- const { t } = (0, import_react_ui2.useTranslation)(import_chunk_EFTZN5X7.SCRIPT_PLUGIN);
98
+ const { t } = (0, import_react_ui2.useTranslation)(import_chunk_5UH3F7TA.SCRIPT_PLUGIN);
99
99
  const { dispatchPromise: dispatch } = (0, import_app_framework.useIntentDispatcher)();
100
100
  const client = (0, import_react_client2.useClient)();
101
101
  const space = (0, import_echo.getSpace)(script);
@@ -138,7 +138,7 @@ var ScriptSettingsPanel = ({ script }) => {
138
138
  githubToken,
139
139
  gistKey
140
140
  ]);
141
- const [binding, setBinding] = (0, import_react_ui2.useControlledValue)(fn?.binding ?? "");
141
+ const [binding, setBinding] = (0, import_react_ui2.useControlledState)(fn?.binding ?? "");
142
142
  const handleBindingChange = (0, import_react2.useCallback)((event) => {
143
143
  setBinding(event.target.value);
144
144
  }, [
@@ -252,8 +252,8 @@ var ScriptSettingsPanel = ({ script }) => {
252
252
  onClick: handlePublish
253
253
  }, t(publishing ? "publishing label" : "publish label")))));
254
254
  };
255
- var AutomationPanel = (0, import_react3.lazy)(() => import("./AutomationPanel-EPRDDR3A.cjs"));
256
- var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-UXMQLKDV.cjs"));
255
+ var AutomationPanel = (0, import_react3.lazy)(() => import("./AutomationPanel-4M55FURO.cjs"));
256
+ var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-FKCNWHBW.cjs"));
257
257
  // Annotate the CommonJS export names for ESM import in node:
258
258
  0 && (module.exports = {
259
259
  AutomationPanel,
@@ -261,4 +261,4 @@ var ScriptContainer = (0, import_react3.lazy)(() => import("./ScriptContainer-UX
261
261
  ScriptSettings,
262
262
  ScriptSettingsPanel
263
263
  });
264
- //# sourceMappingURL=chunk-UAHKFS7F.cjs.map
264
+ //# sourceMappingURL=chunk-F5Z3DMHA.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/ScriptSettings/ScriptSettings.tsx", "../../../src/components/ScriptSettingsPanel.tsx", "../../../src/components/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { useClient } from '@dxos/react-client';\nimport { Button, Select, useTranslation } from '@dxos/react-ui';\nimport { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';\nimport { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type ScriptSettingsProps } from '../../types';\n\nexport const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n\n // TODO(burdon): Check token.\n const handleAuthenticate = async () => {\n const { identityKey } = client.halo.identity.get()!;\n await client.halo.writeCredentials([\n {\n issuer: identityKey,\n issuanceDate: new Date(),\n subject: {\n id: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.ServiceAccess',\n serverName: 'hub.dxos.network',\n serverKey: identityKey,\n identityKey,\n capabilities: ['composer:beta'],\n },\n },\n } satisfies Credential,\n ]);\n };\n\n return (\n <DeprecatedFormContainer>\n {/* TODO(wittjosiah): Hide outside of dev environments. */}\n <DeprecatedFormInput label={t('authenticate action label')}>\n <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>\n </DeprecatedFormInput>\n\n <DeprecatedFormInput label={t('editor input mode label')}>\n <Select.Root\n value={settings.editorInputMode ?? 'default'}\n onValueChange={(value) => {\n settings.editorInputMode = value as EditorInputMode;\n }}\n >\n <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {EditorInputModes.map((mode) => (\n <Select.Option key={mode} value={mode}>\n {t(`settings editor input mode ${mode} label`)}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </DeprecatedFormInput>\n </DeprecatedFormContainer>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';\n\nimport { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';\nimport { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Button, Clipboard, Input, Separator, useControlledValue, useTranslation } from '@dxos/react-ui';\nimport { AccessTokenType } from '@dxos/schema';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\n// TODO(wittjosiah): Factor out.\n// From https://stackoverflow.com/a/67243723/2804332\nconst kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());\n\nexport type ScriptSettingsPanelProps = {\n script: ScriptType;\n};\n\nexport const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const { dispatchPromise: dispatch } = useIntentDispatcher();\n const client = useClient();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n const [githubToken] = useQuery(space, Filter.schema(AccessTokenType, { source: 'github.com' }));\n const gistKey = getMeta(script).keys.find(({ source }) => source === 'github.com');\n const [gistUrl, setGistUrl] = useState<string | undefined>();\n\n useEffect(() => {\n const token = githubToken?.token;\n const gistId = gistKey?.id;\n if (!token || !gistId) {\n setGistUrl(undefined);\n return;\n }\n\n const timeout = setTimeout(async () => {\n try {\n const octokit = new Octokit({ auth: githubToken.token });\n const response = await octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n });\n setGistUrl(response.data.html_url);\n } catch (err) {\n log.catch(err);\n setGistUrl(undefined);\n }\n });\n\n return () => clearTimeout(timeout);\n }, [githubToken, gistKey]);\n\n const [binding, setBinding] = useControlledValue(fn?.binding ?? '');\n const handleBindingChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setBinding(event.target.value);\n },\n [setBinding],\n );\n const handleBindingBlur = useCallback(() => {\n fn.binding = binding;\n }, [fn, binding]);\n\n const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl =\n functionPath &&\n getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n\n const handleOpenTokenManager = useCallback(\n () => dispatch(createIntent(SettingsAction.Open, { plugin: 'dxos.org/plugin/token-manager' })),\n [],\n );\n\n const [publishing, setPublishing] = useState(false);\n const handlePublish = useCallback(async () => {\n setPublishing(true);\n const octokit = new Octokit({ auth: githubToken.token });\n const source = await script.source.load();\n const filename = script.name ? kebabize(script.name) : 'composer-script';\n const files = { [`${filename}.ts`]: { content: source.content } };\n\n try {\n // TODO(wittjosiah): Factor out to intent.\n const meta = getMeta(script);\n const githubKey = meta.keys.find(({ source }) => source === 'github.com');\n const gistId = githubKey?.id;\n if (gistId) {\n await octokit.request('PATCH /gists/{gist_id}', {\n gist_id: gistId,\n files,\n });\n } else {\n const response = await octokit.request('POST /gists', {\n public: true,\n files,\n });\n if (response.data.id) {\n meta.keys.push({ source: 'github.com', id: response.data.id });\n }\n }\n } finally {\n setPublishing(false);\n }\n }, [script, githubToken]);\n\n return (\n <>\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('description label')}</Input.Label>\n <Input.TextInput\n placeholder={t('description placeholder')}\n value={script.description ?? ''}\n onChange={(event) => {\n script.description = event.target.value;\n }}\n />\n </div>\n </Input.Root>\n </div>\n {fn && functionUrl && (\n <>\n <Separator />\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <h2>{t('remote function settings heading')}</h2>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function url label')}</Input.Label>\n <div role='none' className='flex gap-1'>\n <Input.TextInput\n disabled\n value={functionUrl}\n onChange={(event) => {\n fn.name = event.target.value;\n }}\n />\n <Clipboard.IconButton value={functionUrl} />\n </div>\n </div>\n </Input.Root>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function binding label')}</Input.Label>\n <Input.TextInput\n placeholder={t('function binding placeholder')}\n value={binding}\n onChange={handleBindingChange}\n onBlur={handleBindingBlur}\n />\n </div>\n </Input.Root>\n </div>\n </>\n )}\n <Separator />\n <div className='flex flex-col w-full p-2 gap-4'>\n <div>\n <h2>{t('script publish settings label')}</h2>\n <p className='text-description text-sm'>{t('script publish settings description')}</p>\n </div>\n {!githubToken && (\n <div className='flex flex-col items-center justify-center gap-2'>\n <span>{t('no github token label')}</span>\n <Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>\n </div>\n )}\n {githubToken && (\n <div className='flex justify-end gap-2'>\n {gistUrl && <Clipboard.IconButton value={gistUrl} />}\n <Button disabled={publishing} onClick={handlePublish}>\n {t(publishing ? 'publishing label' : 'publish label')}\n </Button>\n </div>\n )}\n </div>\n </>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { lazy } from 'react';\n\nexport * from './ScriptSettings';\nexport * from './ScriptSettingsPanel';\n\nexport const AutomationPanel = lazy(() => import('./AutomationPanel'));\nexport const ScriptContainer = lazy(() => import('./ScriptContainer'));\n"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React from 'react';\n\nimport { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';\nimport { useClient } from '@dxos/react-client';\nimport { Button, Select, useTranslation } from '@dxos/react-ui';\nimport { type EditorInputMode, EditorInputModes } from '@dxos/react-ui-editor';\nimport { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';\n\nimport { SCRIPT_PLUGIN } from '../../meta';\nimport { type ScriptSettingsProps } from '../../types';\n\nexport const ScriptSettings = ({ settings }: { settings: ScriptSettingsProps }) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const client = useClient();\n\n // TODO(burdon): Check token.\n const handleAuthenticate = async () => {\n const { identityKey } = client.halo.identity.get()!;\n await client.halo.writeCredentials([\n {\n issuer: identityKey,\n issuanceDate: new Date(),\n subject: {\n id: identityKey,\n assertion: {\n '@type': 'dxos.halo.credentials.ServiceAccess',\n serverName: 'hub.dxos.network',\n serverKey: identityKey,\n identityKey,\n capabilities: ['composer:beta'],\n },\n },\n } satisfies Credential,\n ]);\n };\n\n return (\n <DeprecatedFormContainer>\n {/* TODO(wittjosiah): Hide outside of dev environments. */}\n <DeprecatedFormInput label={t('authenticate action label')}>\n <Button onClick={handleAuthenticate}>{t('authenticate button label')}</Button>\n </DeprecatedFormInput>\n\n <DeprecatedFormInput label={t('editor input mode label')}>\n <Select.Root\n value={settings.editorInputMode ?? 'default'}\n onValueChange={(value) => {\n settings.editorInputMode = value as EditorInputMode;\n }}\n >\n <Select.TriggerButton placeholder={t('select editor input mode placeholder')} />\n <Select.Portal>\n <Select.Content>\n <Select.Viewport>\n {EditorInputModes.map((mode) => (\n <Select.Option key={mode} value={mode}>\n {t(`settings editor input mode ${mode} label`)}\n </Select.Option>\n ))}\n </Select.Viewport>\n </Select.Content>\n </Select.Portal>\n </Select.Root>\n </DeprecatedFormInput>\n </DeprecatedFormContainer>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Octokit } from '@octokit/core';\nimport React, { type ChangeEvent, useCallback, useEffect, useState } from 'react';\n\nimport { createIntent, SettingsAction, useIntentDispatcher } from '@dxos/app-framework';\nimport { FunctionType, type ScriptType, getInvocationUrl, getUserFunctionUrlInMetadata } from '@dxos/functions';\nimport { log } from '@dxos/log';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getMeta, getSpace, useQuery } from '@dxos/react-client/echo';\nimport { Button, Clipboard, Input, Separator, useControlledState, useTranslation } from '@dxos/react-ui';\nimport { AccessTokenType } from '@dxos/schema';\n\nimport { SCRIPT_PLUGIN } from '../meta';\n\n// TODO(wittjosiah): Factor out.\n// From https://stackoverflow.com/a/67243723/2804332\nconst kebabize = (str: string) => str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, ($, ofs) => (ofs ? '-' : '') + $.toLowerCase());\n\nexport type ScriptSettingsPanelProps = {\n script: ScriptType;\n};\n\nexport const ScriptSettingsPanel = ({ script }: ScriptSettingsPanelProps) => {\n const { t } = useTranslation(SCRIPT_PLUGIN);\n const { dispatchPromise: dispatch } = useIntentDispatcher();\n const client = useClient();\n const space = getSpace(script);\n const [fn] = useQuery(space, Filter.schema(FunctionType, { source: script }));\n const [githubToken] = useQuery(space, Filter.schema(AccessTokenType, { source: 'github.com' }));\n const gistKey = getMeta(script).keys.find(({ source }) => source === 'github.com');\n const [gistUrl, setGistUrl] = useState<string | undefined>();\n\n useEffect(() => {\n const token = githubToken?.token;\n const gistId = gistKey?.id;\n if (!token || !gistId) {\n setGistUrl(undefined);\n return;\n }\n\n const timeout = setTimeout(async () => {\n try {\n const octokit = new Octokit({ auth: githubToken.token });\n const response = await octokit.request('GET /gists/{gist_id}', {\n gist_id: gistId,\n });\n setGistUrl(response.data.html_url);\n } catch (err) {\n log.catch(err);\n setGistUrl(undefined);\n }\n });\n\n return () => clearTimeout(timeout);\n }, [githubToken, gistKey]);\n\n const [binding, setBinding] = useControlledState(fn?.binding ?? '');\n const handleBindingChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setBinding(event.target.value);\n },\n [setBinding],\n );\n const handleBindingBlur = useCallback(() => {\n fn.binding = binding;\n }, [fn, binding]);\n\n const functionPath = fn && getUserFunctionUrlInMetadata(getMeta(fn));\n const functionUrl =\n functionPath &&\n getInvocationUrl(functionPath, client.config.values.runtime?.services?.edge?.url ?? '', {\n spaceId: space?.id,\n });\n\n const handleOpenTokenManager = useCallback(\n () => dispatch(createIntent(SettingsAction.Open, { plugin: 'dxos.org/plugin/token-manager' })),\n [],\n );\n\n const [publishing, setPublishing] = useState(false);\n const handlePublish = useCallback(async () => {\n setPublishing(true);\n const octokit = new Octokit({ auth: githubToken.token });\n const source = await script.source.load();\n const filename = script.name ? kebabize(script.name) : 'composer-script';\n const files = { [`${filename}.ts`]: { content: source.content } };\n\n try {\n // TODO(wittjosiah): Factor out to intent.\n const meta = getMeta(script);\n const githubKey = meta.keys.find(({ source }) => source === 'github.com');\n const gistId = githubKey?.id;\n if (gistId) {\n await octokit.request('PATCH /gists/{gist_id}', {\n gist_id: gistId,\n files,\n });\n } else {\n const response = await octokit.request('POST /gists', {\n public: true,\n files,\n });\n if (response.data.id) {\n meta.keys.push({ source: 'github.com', id: response.data.id });\n }\n }\n } finally {\n setPublishing(false);\n }\n }, [script, githubToken]);\n\n return (\n <>\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('description label')}</Input.Label>\n <Input.TextInput\n placeholder={t('description placeholder')}\n value={script.description ?? ''}\n onChange={(event) => {\n script.description = event.target.value;\n }}\n />\n </div>\n </Input.Root>\n </div>\n {fn && functionUrl && (\n <>\n <Separator />\n <div role='form' className='flex flex-col w-full p-2 gap-4'>\n <h2>{t('remote function settings heading')}</h2>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function url label')}</Input.Label>\n <div role='none' className='flex gap-1'>\n <Input.TextInput\n disabled\n value={functionUrl}\n onChange={(event) => {\n fn.name = event.target.value;\n }}\n />\n <Clipboard.IconButton value={functionUrl} />\n </div>\n </div>\n </Input.Root>\n <Input.Root>\n <div role='none' className='flex flex-col gap-1'>\n <Input.Label>{t('function binding label')}</Input.Label>\n <Input.TextInput\n placeholder={t('function binding placeholder')}\n value={binding}\n onChange={handleBindingChange}\n onBlur={handleBindingBlur}\n />\n </div>\n </Input.Root>\n </div>\n </>\n )}\n <Separator />\n <div className='flex flex-col w-full p-2 gap-4'>\n <div>\n <h2>{t('script publish settings label')}</h2>\n <p className='text-description text-sm'>{t('script publish settings description')}</p>\n </div>\n {!githubToken && (\n <div className='flex flex-col items-center justify-center gap-2'>\n <span>{t('no github token label')}</span>\n <Button onClick={handleOpenTokenManager}>{t('open token manager label')}</Button>\n </div>\n )}\n {githubToken && (\n <div className='flex justify-end gap-2'>\n {gistUrl && <Clipboard.IconButton value={gistUrl} />}\n <Button disabled={publishing} onClick={handlePublish}>\n {t(publishing ? 'publishing label' : 'publish label')}\n </Button>\n </div>\n )}\n </div>\n </>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { lazy } from 'react';\n\nexport * from './ScriptSettings';\nexport * from './ScriptSettingsPanel';\n\nexport const AutomationPanel = lazy(() => import('./AutomationPanel'));\nexport const ScriptContainer = lazy(() => import('./ScriptContainer'));\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAAkB;AAGlB,0BAA0B;AAC1B,sBAA+C;AAC/C,6BAAuD;AACvD,2BAA6D;ACN7D,kBAAwB;AACxB,IAAAA,gBAA0E;AAE1E,2BAAkE;AAClE,uBAA8F;AAC9F,iBAAoB;AACpB,IAAAC,uBAA0B;AAC1B,kBAAoD;AACpD,IAAAC,mBAAwF;AACxF,oBAAgC;ACThC,IAAAF,gBAAqB;AFWd,IAAMG,iBAAiB,CAAC,EAAEC,SAAQ,MAAqC;AAC5E,QAAM,EAAEC,EAAC,QAAKC,gCAAeC,mCAAAA;AAC7B,QAAMC,aAASC,+BAAAA;AAGf,QAAMC,qBAAqB,YAAA;AACzB,UAAM,EAAEC,YAAW,IAAKH,OAAOI,KAAKC,SAASC,IAAG;AAChD,UAAMN,OAAOI,KAAKG,iBAAiB;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C0G,uBAAMnG,MAAI,MACTP,8BAAAA,QAAA,cAACuG,OAAAA;IAAIC,MAAK;IAAOC,WAAU;KACzBzG,8BAAAA,QAAA,cAAC0G,uBAAMC,OAAK,MAAE/H,EAAE,wBAAA,CAAA,GAChBoB,8BAAAA,QAAA,cAAC0G,uBAAME,WAAS;IACdhG,aAAahC,EAAE,8BAAA;IACf4B,OAAO2D;IACP2C,UAAUxC;IACV8C,QAAQ1C;UAOpB1E,8BAAAA,QAAA,cAAC+G,4BAAAA,IAAAA,GACD/G,8BAAAA,QAAA,cAACuG,OAAAA;IAAIE,WAAU;KACbzG,8BAAAA,QAAA,cAACuG,OAAAA,MACCvG,8BAAAA,QAAA,cAACgH,MAAAA,MAAIpI,EAAE,+BAAA,CAAA,GACPoB,8BAAAA,QAAA,cAACqH,KAAAA;IAAEZ,WAAU;KAA4B7H,EAAE,qCAAA,CAAA,CAAA,GAE5C,CAAC4D,eACAxC,8BAAAA,QAAA,cAACuG,OAAAA;IAAIE,WAAU;KACbzG,8BAAAA,QAAA,cAACsH,QAAAA,MAAM1I,EAAE,uBAAA,CAAA,GACToB,8BAAAA,QAAA,cAACI,iBAAAA,QAAAA;IAAOC,SAASiF;KAAyB1G,EAAE,0BAAA,CAAA,CAAA,GAG/C4D,eACCxC,8BAAAA,QAAA,cAACuG,OAAAA;IAAIE,WAAU;KACZ3D,WAAW9C,8BAAAA,QAAA,cAACkH,2BAAUC,YAAU;IAAC3G,OAAOsC;MACzC9C,8BAAAA,QAAA,cAACI,iBAAAA,QAAAA;IAAO6G,UAAUtB;IAAYtF,SAASwF;KACpCjH,EAAE+G,aAAa,qBAAqB,eAAA,CAAA,CAAA,CAAA,CAAA;AAOnD;AClLO,IAAM4B,sBAAkBC,oBAAK,MAAM,OAAO,gCAAA,CAAA;AAC1C,IAAMC,sBAAkBD,oBAAK,MAAM,OAAO,gCAAA,CAAA;",
6
- "names": ["import_react", "import_react_client", "import_react_ui", "ScriptSettings", "settings", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "handleAuthenticate", "identityKey", "halo", "identity", "get", "writeCredentials", "issuer", "issuanceDate", "Date", "subject", "id", "assertion", "serverName", "serverKey", "capabilities", "React", "DeprecatedFormContainer", "DeprecatedFormInput", "label", "Button", "onClick", "Select", "Root", "value", "editorInputMode", "onValueChange", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "EditorInputModes", "map", "mode", "Option", "key", "kebabize", "str", "replace", "$", "ofs", "toLowerCase", "ScriptSettingsPanel", "script", "dispatchPromise", "dispatch", "useIntentDispatcher", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "githubToken", "AccessTokenType", "gistKey", "getMeta", "keys", "find", "gistUrl", "setGistUrl", "useState", "useEffect", "token", "gistId", "undefined", "timeout", "setTimeout", "octokit", "Octokit", "auth", "response", "request", "gist_id", "data", "html_url", "err", "log", "catch", "clearTimeout", "binding", "setBinding", "useControlledValue", "handleBindingChange", "useCallback", "event", "target", "handleBindingBlur", "functionPath", "getUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "handleOpenTokenManager", "createIntent", "SettingsAction", "Open", "plugin", "publishing", "setPublishing", "handlePublish", "load", "filename", "name", "files", "content", "meta", "githubKey", "public", "push", "div", "role", "className", "Input", "Label", "TextInput", "description", "onChange", "Separator", "h2", "disabled", "Clipboard", "IconButton", "onBlur", "p", "span", "AutomationPanel", "lazy", "ScriptContainer"]
6
+ "names": ["import_react", "import_react_client", "import_react_ui", "ScriptSettings", "settings", "t", "useTranslation", "SCRIPT_PLUGIN", "client", "useClient", "handleAuthenticate", "identityKey", "halo", "identity", "get", "writeCredentials", "issuer", "issuanceDate", "Date", "subject", "id", "assertion", "serverName", "serverKey", "capabilities", "React", "DeprecatedFormContainer", "DeprecatedFormInput", "label", "Button", "onClick", "Select", "Root", "value", "editorInputMode", "onValueChange", "TriggerButton", "placeholder", "Portal", "Content", "Viewport", "EditorInputModes", "map", "mode", "Option", "key", "kebabize", "str", "replace", "$", "ofs", "toLowerCase", "ScriptSettingsPanel", "script", "dispatchPromise", "dispatch", "useIntentDispatcher", "space", "getSpace", "fn", "useQuery", "Filter", "schema", "FunctionType", "source", "githubToken", "AccessTokenType", "gistKey", "getMeta", "keys", "find", "gistUrl", "setGistUrl", "useState", "useEffect", "token", "gistId", "undefined", "timeout", "setTimeout", "octokit", "Octokit", "auth", "response", "request", "gist_id", "data", "html_url", "err", "log", "catch", "clearTimeout", "binding", "setBinding", "useControlledState", "handleBindingChange", "useCallback", "event", "target", "handleBindingBlur", "functionPath", "getUserFunctionUrlInMetadata", "functionUrl", "getInvocationUrl", "config", "values", "runtime", "services", "edge", "url", "spaceId", "handleOpenTokenManager", "createIntent", "SettingsAction", "Open", "plugin", "publishing", "setPublishing", "handlePublish", "load", "filename", "name", "files", "content", "meta", "githubKey", "public", "push", "div", "role", "className", "Input", "Label", "TextInput", "description", "onChange", "Separator", "h2", "disabled", "Clipboard", "IconButton", "onBlur", "p", "span", "AutomationPanel", "lazy", "ScriptContainer"]
7
7
  }
@@ -26,12 +26,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_DQRAVZM7_exports = {};
30
- __export(chunk_DQRAVZM7_exports, {
29
+ var chunk_IID7WUQS_exports = {};
30
+ __export(chunk_IID7WUQS_exports, {
31
31
  DebugPanel: () => DebugPanel
32
32
  });
33
- module.exports = __toCommonJS(chunk_DQRAVZM7_exports);
34
- var import_chunk_EFTZN5X7 = require("./chunk-EFTZN5X7.cjs");
33
+ module.exports = __toCommonJS(chunk_IID7WUQS_exports);
34
+ var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
35
35
  var import_react = __toESM(require("react"));
36
36
  var import_log = require("@dxos/log");
37
37
  var import_react_ui = require("@dxos/react-ui");
@@ -39,7 +39,7 @@ var import_react_ui_syntax_highlighter = require("@dxos/react-ui-syntax-highligh
39
39
  var import_react_ui_theme = require("@dxos/react-ui-theme");
40
40
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-script/src/components/DebugPanel/DebugPanel.tsx";
41
41
  var DebugPanel = ({ classNames, functionUrl }) => {
42
- const { t } = (0, import_react_ui.useTranslation)(import_chunk_EFTZN5X7.SCRIPT_PLUGIN);
42
+ const { t } = (0, import_react_ui.useTranslation)(import_chunk_5UH3F7TA.SCRIPT_PLUGIN);
43
43
  const inputRef = (0, import_react.useRef)(null);
44
44
  const [input, setInput] = (0, import_react.useState)("");
45
45
  const [result, setResult] = (0, import_react.useState)("");
@@ -266,4 +266,4 @@ var RobotAvatar = () => /* @__PURE__ */ import_react.default.createElement(impor
266
266
  0 && (module.exports = {
267
267
  DebugPanel
268
268
  });
269
- //# sourceMappingURL=chunk-DQRAVZM7.cjs.map
269
+ //# sourceMappingURL=chunk-IID7WUQS.cjs.map
@@ -26,16 +26,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var compiler_457ZR24G_exports = {};
30
- __export(compiler_457ZR24G_exports, {
29
+ var compiler_UIBLKJKG_exports = {};
30
+ __export(compiler_UIBLKJKG_exports, {
31
31
  default: () => compiler_default
32
32
  });
33
- module.exports = __toCommonJS(compiler_457ZR24G_exports);
34
- var import_chunk_T4TXCRN5 = require("./chunk-T4TXCRN5.cjs");
35
- var import_chunk_A2DI2G4D = require("./chunk-A2DI2G4D.cjs");
36
- var import_chunk_EFTZN5X7 = require("./chunk-EFTZN5X7.cjs");
33
+ module.exports = __toCommonJS(compiler_UIBLKJKG_exports);
34
+ var import_chunk_ALY3N6PW = require("./chunk-ALY3N6PW.cjs");
35
+ var import_chunk_5UH3F7TA = require("./chunk-5UH3F7TA.cjs");
37
36
  var import_esbuild = __toESM(require("esbuild-wasm/esbuild.wasm?url"));
38
37
  var import_app_framework = require("@dxos/app-framework");
38
+ var import_bundler = require("@dxos/functions/bundler");
39
39
  var import_vfs = require("@typescript/vfs");
40
40
  var import_typescript = __toESM(require("typescript"));
41
41
  var import_invariant = require("@dxos/invariant");
@@ -96,9 +96,9 @@ var compiler_default = async () => {
96
96
  export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;
97
97
  export const functionHandler = (handler: FunctionHandler) => handler;
98
98
  `);
99
- await (0, import_chunk_T4TXCRN5.initializeBundler)({
99
+ await (0, import_bundler.initializeBundler)({
100
100
  wasmUrl: import_esbuild.default
101
101
  });
102
- return (0, import_app_framework.contributes)(import_chunk_A2DI2G4D.ScriptCapabilities.Compiler, compiler);
102
+ return (0, import_app_framework.contributes)(import_chunk_ALY3N6PW.ScriptCapabilities.Compiler, compiler);
103
103
  };
104
- //# sourceMappingURL=compiler-457ZR24G.cjs.map
104
+ //# sourceMappingURL=compiler-UIBLKJKG.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/capabilities/compiler.ts", "../../../src/compiler/compiler.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n// @ts-ignore\nimport wasmUrl from 'esbuild-wasm/esbuild.wasm?url';\n\nimport { contributes } from '@dxos/app-framework';\nimport { initializeBundler } from '@dxos/functions/bundler';\n\nimport { ScriptCapabilities } from './capabilities';\nimport { Compiler } from '../compiler';\n\nexport default async () => {\n const compiler = new Compiler();\n\n await compiler.initialize();\n // TODO(wittjosiah): Fetch types for https modules.\n compiler.setFile('/src/typings.d.ts', \"declare module 'https://*';\");\n // TODO(wittjosiah): Proper function handler types.\n // TODO(wittjosiah): Remove.\n compiler.setFile(\n '/src/runtime.ts',\n `\n export const Filter: any = {};\n export type FunctionHandler = ({ event, context }: { event: any; context: any }) => Promise<Response>;\n export const functionHandler = (handler: FunctionHandler) => handler;\n `,\n );\n await initializeBundler({ wasmUrl });\n\n return contributes(ScriptCapabilities.Compiler, compiler);\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport {\n createDefaultMapFromCDN,\n createSystem,\n createVirtualTypeScriptEnvironment,\n type VirtualTypeScriptEnvironment,\n} from '@typescript/vfs';\nimport ts from 'typescript';\n\nimport { invariant } from '@dxos/invariant';\n\nconst defaultOptions: ts.CompilerOptions = {\n lib: ['DOM', 'es2022'],\n target: ts.ScriptTarget.ES2022,\n};\n\nexport class Compiler {\n private _env: VirtualTypeScriptEnvironment | undefined;\n private _fsMap: Map<string, string> | undefined;\n\n constructor(private readonly _options: ts.CompilerOptions = defaultOptions) {}\n\n async initialize() {\n if (this._env) {\n return;\n }\n\n // TODO(wittjosiah): Figure out how to get workers working in plugin packages.\n // https://github.com/val-town/codemirror-ts?tab=readme-ov-file#setup-worker\n this._fsMap = await createDefaultMapFromCDN(this._options, '5.5.4', true, ts);\n const system = createSystem(this._fsMap);\n this._env = createVirtualTypeScriptEnvironment(system, [], ts, this._options);\n }\n\n get environment() {\n invariant(this._env, 'Compiler environment not initialized.');\n return this._env;\n }\n\n setFile(fileName: string, content: string) {\n invariant(this._fsMap, 'File system map not initialized.');\n this.environment.createFile(fileName, content);\n }\n\n compile(fileName: string) {\n return this.environment.languageService.getEmitOutput(fileName);\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,qBAAoB;AAEpB,2BAA4B;AAC5B,qBAAkC;ACJlC,iBAKO;AACP,wBAAe;AAEf,uBAA0B;;AAE1B,IAAMA,iBAAqC;EACzCC,KAAK;IAAC;IAAO;;EACbC,QAAQC,kBAAAA,QAAGC,aAAaC;AAC1B;AAEO,IAAMC,WAAN,MAAMA;EAIXC,YAA6BC,WAA+BR,gBAAgB;SAA/CQ,WAAAA;EAAgD;EAE7E,MAAMC,aAAa;AACjB,QAAI,KAAKC,MAAM;AACb;IACF;AAIA,SAAKC,SAAS,UAAMC,oCAAwB,KAAKJ,UAAU,SAAS,MAAML,kBAAAA,OAAAA;AAC1E,UAAMU,aAASC,yBAAa,KAAKH,MAAM;AACvC,SAAKD,WAAOK,+CAAmCF,QAAQ,CAAA,GAAIV,kBAAAA,SAAI,KAAKK,QAAQ;EAC9E;EAEA,IAAIQ,cAAc;AAChBC,oCAAU,KAAKP,MAAM,yCAAA;;;;;;;;;AACrB,WAAO,KAAKA;EACd;EAEAQ,QAAQC,UAAkBC,SAAiB;AACzCH,oCAAU,KAAKN,QAAQ,oCAAA;;;;;;;;;AACvB,SAAKK,YAAYK,WAAWF,UAAUC,OAAAA;EACxC;EAEAE,QAAQH,UAAkB;AACxB,WAAO,KAAKH,YAAYO,gBAAgBC,cAAcL,QAAAA;EACxD;AACF;ADrCA,IAAA,mBAAe,YAAA;AACb,QAAMM,WAAW,IAAInB,SAAAA;AAErB,QAAMmB,SAAShB,WAAU;AAEzBgB,WAASP,QAAQ,qBAAqB,6BAAA;AAGtCO,WAASP,QACP,mBACA;;;;OAIG;AAEL,YAAMQ,kCAAkB;IAAEC,wBAAAA;EAAQ,CAAA;AAElC,aAAOC,kCAAYC,yCAAmBvB,UAAUmB,QAAAA;AAClD;",
6
+ "names": ["defaultOptions", "lib", "target", "ts", "ScriptTarget", "ES2022", "Compiler", "constructor", "_options", "initialize", "_env", "_fsMap", "createDefaultMapFromCDN", "system", "createSystem", "createVirtualTypeScriptEnvironment", "environment", "invariant", "setFile", "fileName", "content", "createFile", "compile", "languageService", "getEmitOutput", "compiler", "initializeBundler", "wasmUrl", "contributes", "ScriptCapabilities"]
7
+ }