@dxos/compute 0.8.4-main.ead640a → 0.8.4-main.effb148878

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 (180) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +36 -1
  3. package/dist/lib/neutral/StorageService.mjs +22 -0
  4. package/dist/lib/neutral/chunk-B5LUI4H6.mjs +21 -0
  5. package/dist/lib/neutral/chunk-B5LUI4H6.mjs.map +7 -0
  6. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  7. package/dist/lib/neutral/chunk-NVWB7432.mjs +25 -0
  8. package/dist/lib/neutral/chunk-NVWB7432.mjs.map +7 -0
  9. package/dist/lib/neutral/chunk-OIXBXJ6Y.mjs +239 -0
  10. package/dist/lib/neutral/chunk-OIXBXJ6Y.mjs.map +7 -0
  11. package/dist/lib/neutral/chunk-QBR5CRBN.mjs +171 -0
  12. package/dist/lib/neutral/chunk-QBR5CRBN.mjs.map +7 -0
  13. package/dist/lib/neutral/chunk-TC6ZBJQL.mjs +17 -0
  14. package/dist/lib/neutral/chunk-TC6ZBJQL.mjs.map +7 -0
  15. package/dist/lib/neutral/chunk-XEVFBI6S.mjs +62 -0
  16. package/dist/lib/neutral/chunk-XEVFBI6S.mjs.map +7 -0
  17. package/dist/lib/neutral/chunk-YOS36LKB.mjs +53 -0
  18. package/dist/lib/neutral/chunk-YOS36LKB.mjs.map +7 -0
  19. package/dist/lib/neutral/fib-IMDPAMDL.mjs +10 -0
  20. package/dist/lib/neutral/fib-IMDPAMDL.mjs.map +7 -0
  21. package/dist/lib/neutral/index.mjs +1211 -0
  22. package/dist/lib/neutral/index.mjs.map +7 -0
  23. package/dist/lib/neutral/meta.json +1 -0
  24. package/dist/lib/neutral/reply-RQQDQOZI.mjs +10 -0
  25. package/dist/lib/neutral/reply-RQQDQOZI.mjs.map +7 -0
  26. package/dist/lib/neutral/sleep-JEV3DDEJ.mjs +10 -0
  27. package/dist/lib/neutral/sleep-JEV3DDEJ.mjs.map +7 -0
  28. package/dist/lib/neutral/testing/index.mjs +32 -0
  29. package/dist/lib/neutral/testing/index.mjs.map +7 -0
  30. package/dist/types/src/Blueprint.d.ts +190 -0
  31. package/dist/types/src/Blueprint.d.ts.map +1 -0
  32. package/dist/types/src/Credential.d.ts +27 -0
  33. package/dist/types/src/Credential.d.ts.map +1 -0
  34. package/dist/types/src/LayerSpec.d.ts +56 -0
  35. package/dist/types/src/LayerSpec.d.ts.map +1 -0
  36. package/dist/types/src/McpServer.d.ts +26 -0
  37. package/dist/types/src/McpServer.d.ts.map +1 -0
  38. package/dist/types/src/Operation.d.ts +346 -0
  39. package/dist/types/src/Operation.d.ts.map +1 -0
  40. package/dist/types/src/OperationHandlerSet.d.ts +67 -0
  41. package/dist/types/src/OperationHandlerSet.d.ts.map +1 -0
  42. package/dist/types/src/OperationHandlerSet.test.d.ts +2 -0
  43. package/dist/types/src/OperationHandlerSet.test.d.ts.map +1 -0
  44. package/dist/types/src/OperationRegistry.d.ts +23 -0
  45. package/dist/types/src/OperationRegistry.d.ts.map +1 -0
  46. package/dist/types/src/Process.d.ts +247 -0
  47. package/dist/types/src/Process.d.ts.map +1 -0
  48. package/dist/types/src/Routine.d.ts +62 -0
  49. package/dist/types/src/Routine.d.ts.map +1 -0
  50. package/dist/types/src/Script.d.ts +21 -0
  51. package/dist/types/src/Script.d.ts.map +1 -0
  52. package/dist/types/src/ServiceResolver.d.ts +90 -0
  53. package/dist/types/src/ServiceResolver.d.ts.map +1 -0
  54. package/dist/types/src/StorageService.d.ts +58 -0
  55. package/dist/types/src/StorageService.d.ts.map +1 -0
  56. package/dist/types/src/Template.d.ts +61 -0
  57. package/dist/types/src/Template.d.ts.map +1 -0
  58. package/dist/types/src/Template.test.d.ts +2 -0
  59. package/dist/types/src/Template.test.d.ts.map +1 -0
  60. package/dist/types/src/Trace.d.ts +266 -0
  61. package/dist/types/src/Trace.d.ts.map +1 -0
  62. package/dist/types/src/Trigger.d.ts +192 -0
  63. package/dist/types/src/Trigger.d.ts.map +1 -0
  64. package/dist/types/src/TriggerEvent.d.ts +83 -0
  65. package/dist/types/src/TriggerEvent.d.ts.map +1 -0
  66. package/dist/types/src/errors.d.ts +308 -0
  67. package/dist/types/src/errors.d.ts.map +1 -0
  68. package/dist/types/src/index.d.ts +17 -5
  69. package/dist/types/src/index.d.ts.map +1 -1
  70. package/dist/types/src/testing/definitions.d.ts +11 -0
  71. package/dist/types/src/testing/definitions.d.ts.map +1 -0
  72. package/dist/types/src/testing/fib.d.ts +8 -0
  73. package/dist/types/src/testing/fib.d.ts.map +1 -0
  74. package/dist/types/src/testing/index.d.ts +6 -4
  75. package/dist/types/src/testing/index.d.ts.map +1 -1
  76. package/dist/types/src/testing/reply.d.ts +4 -0
  77. package/dist/types/src/testing/reply.d.ts.map +1 -0
  78. package/dist/types/src/testing/sleep.d.ts +6 -0
  79. package/dist/types/src/testing/sleep.d.ts.map +1 -0
  80. package/dist/types/src/umbrella.test.d.ts +2 -0
  81. package/dist/types/src/umbrella.test.d.ts.map +1 -0
  82. package/dist/types/tsconfig.tsbuildinfo +1 -1
  83. package/package.json +29 -40
  84. package/src/Blueprint.ts +294 -0
  85. package/src/Credential.ts +53 -0
  86. package/src/LayerSpec.ts +91 -0
  87. package/src/McpServer.ts +44 -0
  88. package/src/Operation.ts +603 -0
  89. package/src/OperationHandlerSet.test.ts +92 -0
  90. package/src/OperationHandlerSet.ts +174 -0
  91. package/src/OperationRegistry.ts +50 -0
  92. package/src/Process.ts +507 -0
  93. package/src/Routine.ts +71 -0
  94. package/src/Script.ts +36 -0
  95. package/src/ServiceResolver.ts +195 -0
  96. package/src/StorageService.ts +101 -0
  97. package/src/Template.test.ts +151 -0
  98. package/src/Template.ts +121 -0
  99. package/src/Trace.ts +365 -0
  100. package/src/Trigger.ts +195 -0
  101. package/src/TriggerEvent.ts +64 -0
  102. package/src/errors.ts +71 -0
  103. package/src/index.ts +18 -32
  104. package/src/testing/definitions.ts +49 -0
  105. package/src/testing/fib.ts +22 -0
  106. package/src/testing/index.ts +13 -5
  107. package/src/testing/reply.ts +18 -0
  108. package/src/testing/sleep.ts +16 -0
  109. package/src/umbrella.test.ts +51 -0
  110. package/dist/lib/browser/chunk-C7KLV2IU.mjs +0 -3144
  111. package/dist/lib/browser/chunk-C7KLV2IU.mjs.map +0 -7
  112. package/dist/lib/browser/index.mjs +0 -55
  113. package/dist/lib/browser/meta.json +0 -1
  114. package/dist/lib/browser/testing/index.mjs +0 -206
  115. package/dist/lib/browser/testing/index.mjs.map +0 -7
  116. package/dist/lib/node-esm/chunk-K37OSZ5O.mjs +0 -3146
  117. package/dist/lib/node-esm/chunk-K37OSZ5O.mjs.map +0 -7
  118. package/dist/lib/node-esm/index.mjs +0 -56
  119. package/dist/lib/node-esm/meta.json +0 -1
  120. package/dist/lib/node-esm/testing/index.mjs +0 -207
  121. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  122. package/dist/types/src/compute-graph-registry.d.ts +0 -37
  123. package/dist/types/src/compute-graph-registry.d.ts.map +0 -1
  124. package/dist/types/src/compute-graph-registry.test.d.ts +0 -2
  125. package/dist/types/src/compute-graph-registry.test.d.ts.map +0 -1
  126. package/dist/types/src/compute-graph.d.ts +0 -67
  127. package/dist/types/src/compute-graph.d.ts.map +0 -1
  128. package/dist/types/src/compute-graph.test.d.ts +0 -2
  129. package/dist/types/src/compute-graph.test.d.ts.map +0 -1
  130. package/dist/types/src/compute-node.d.ts +0 -24
  131. package/dist/types/src/compute-node.d.ts.map +0 -1
  132. package/dist/types/src/functions/async-function.d.ts +0 -68
  133. package/dist/types/src/functions/async-function.d.ts.map +0 -1
  134. package/dist/types/src/functions/edge-function.d.ts +0 -20
  135. package/dist/types/src/functions/edge-function.d.ts.map +0 -1
  136. package/dist/types/src/functions/function-defs.d.ts +0 -11
  137. package/dist/types/src/functions/function-defs.d.ts.map +0 -1
  138. package/dist/types/src/functions/index.d.ts +0 -4
  139. package/dist/types/src/functions/index.d.ts.map +0 -1
  140. package/dist/types/src/hyperformula.test.d.ts +0 -2
  141. package/dist/types/src/hyperformula.test.d.ts.map +0 -1
  142. package/dist/types/src/testing/test-builder.d.ts +0 -15
  143. package/dist/types/src/testing/test-builder.d.ts.map +0 -1
  144. package/dist/types/src/testing/test-plugin.d.ts +0 -35
  145. package/dist/types/src/testing/test-plugin.d.ts.map +0 -1
  146. package/dist/types/src/testing/test-runtime.d.ts +0 -10
  147. package/dist/types/src/testing/test-runtime.d.ts.map +0 -1
  148. package/dist/types/src/testing/util.d.ts +0 -2
  149. package/dist/types/src/testing/util.d.ts.map +0 -1
  150. package/dist/types/src/types/hyperformula.d.ts +0 -8
  151. package/dist/types/src/types/hyperformula.d.ts.map +0 -1
  152. package/dist/types/src/types/index.d.ts +0 -3
  153. package/dist/types/src/types/index.d.ts.map +0 -1
  154. package/dist/types/src/types/types.d.ts +0 -20
  155. package/dist/types/src/types/types.d.ts.map +0 -1
  156. package/dist/types/src/types/types.test.d.ts +0 -2
  157. package/dist/types/src/types/types.test.d.ts.map +0 -1
  158. package/dist/types/src/util.d.ts +0 -2
  159. package/dist/types/src/util.d.ts.map +0 -1
  160. package/src/compute-graph-registry.test.ts +0 -138
  161. package/src/compute-graph-registry.ts +0 -97
  162. package/src/compute-graph.test.ts +0 -88
  163. package/src/compute-graph.ts +0 -261
  164. package/src/compute-node.ts +0 -59
  165. package/src/functions/async-function.ts +0 -184
  166. package/src/functions/edge-function.ts +0 -114
  167. package/src/functions/function-defs.ts +0 -2427
  168. package/src/functions/index.ts +0 -7
  169. package/src/hyperformula.test.ts +0 -14
  170. package/src/testing/test-builder.ts +0 -60
  171. package/src/testing/test-plugin.ts +0 -98
  172. package/src/testing/test-runtime.ts +0 -38
  173. package/src/testing/util.ts +0 -9
  174. package/src/types/hyperformula.ts +0 -19
  175. package/src/types/index.ts +0 -6
  176. package/src/types/types.test.ts +0 -91
  177. package/src/types/types.ts +0 -80
  178. package/src/util.ts +0 -8
  179. /package/dist/lib/{browser/index.mjs.map → neutral/StorageService.mjs.map} +0 -0
  180. /package/dist/lib/{node-esm/index.mjs.map → neutral/chunk-J5LGTIGS.mjs.map} +0 -0
@@ -0,0 +1,1211 @@
1
+ import {
2
+ StorageService_exports
3
+ } from "./chunk-XEVFBI6S.mjs";
4
+ import {
5
+ FunctionError,
6
+ FunctionNotFoundError,
7
+ FunctionsAiMemoizationMissError,
8
+ FunctionsAiUpstreamError,
9
+ InvalidOperationInputError,
10
+ InvalidOperationOutputError,
11
+ InvokerNotInitializedError,
12
+ NoHandlerError,
13
+ OperationHandlerProvider,
14
+ OperationHandlerSet_exports,
15
+ ServiceNotAvailableError,
16
+ TriggerStateNotFoundError,
17
+ getHandler,
18
+ getHandlerByKey
19
+ } from "./chunk-QBR5CRBN.mjs";
20
+ import {
21
+ Operation_exports,
22
+ PersistentOperation,
23
+ deserialize,
24
+ invoke
25
+ } from "./chunk-OIXBXJ6Y.mjs";
26
+ import {
27
+ __export
28
+ } from "./chunk-J5LGTIGS.mjs";
29
+
30
+ // src/Blueprint.ts
31
+ var Blueprint_exports = {};
32
+ __export(Blueprint_exports, {
33
+ Blueprint: () => Blueprint,
34
+ Blueprint_v0_1_0: () => Blueprint_v0_1_0,
35
+ NotFoundError: () => NotFoundError,
36
+ Registry: () => Registry,
37
+ RegistryService: () => RegistryService,
38
+ getKey: () => getKey,
39
+ getVersion: () => getVersion,
40
+ make: () => make2,
41
+ migrations: () => migrations,
42
+ resolve: () => resolve2,
43
+ toolDefinitions: () => toolDefinitions,
44
+ upsert: () => upsert
45
+ });
46
+ import * as Context2 from "effect/Context";
47
+ import * as Effect3 from "effect/Effect";
48
+ import * as Layer2 from "effect/Layer";
49
+ import * as Schema3 from "effect/Schema";
50
+ import { ToolId } from "@dxos/ai";
51
+ import { DXN, Annotation, Database as Database3, Filter as Filter2, Migration, Obj, Type } from "@dxos/echo";
52
+ import { BaseError } from "@dxos/errors";
53
+ import { log as log2 } from "@dxos/log";
54
+
55
+ // src/McpServer.ts
56
+ var McpServer_exports = {};
57
+ __export(McpServer_exports, {
58
+ McpServer: () => McpServer
59
+ });
60
+ import * as Schema from "effect/Schema";
61
+ var McpServer = Schema.Struct({
62
+ name: Schema.String.pipe(Schema.optional).annotations({
63
+ description: "Human-readable name of the MCP server"
64
+ }),
65
+ url: Schema.String.annotations({
66
+ description: "URL of the MCP server"
67
+ }),
68
+ /**
69
+ * Transport protocol. Prefer `'http'` (Streamable HTTP) for new servers; `'sse'` is
70
+ * kept for compatibility with servers that haven't migrated and is deprecated per
71
+ * the MCP SDK. Clients support both during the migration period.
72
+ */
73
+ protocol: Schema.Union(Schema.Literal("http"), Schema.Literal("sse")).annotations({
74
+ description: 'Transport protocol of the MCP server (prefer "http"; "sse" deprecated)'
75
+ }),
76
+ /**
77
+ * Optional API key sent with requests.
78
+ * Persisted in plaintext when stored on a space-replicated ECHO object — see the
79
+ * `@dxos/assistant-toolkit` `McpServer` type for security implications.
80
+ */
81
+ apiKey: Schema.optional(Schema.String).annotations({
82
+ description: "Optional API key sent with requests"
83
+ })
84
+ });
85
+
86
+ // src/Template.ts
87
+ var Template_exports = {};
88
+ __export(Template_exports, {
89
+ Input: () => Input,
90
+ InputKind: () => InputKind,
91
+ Template: () => Template,
92
+ make: () => make,
93
+ process: () => process,
94
+ processTemplate: () => processTemplate
95
+ });
96
+ import * as Effect2 from "effect/Effect";
97
+ import * as Schema2 from "effect/Schema";
98
+ import { Database as Database2, Ref } from "@dxos/echo";
99
+ import { invariant } from "@dxos/invariant";
100
+ import { log } from "@dxos/log";
101
+ import { Text } from "@dxos/schema";
102
+ import Handlebars from "@dxos/vendor-kbn-handlebars";
103
+
104
+ // src/OperationRegistry.ts
105
+ var OperationRegistry_exports = {};
106
+ __export(OperationRegistry_exports, {
107
+ Service: () => Service,
108
+ layer: () => layer,
109
+ resolve: () => resolve
110
+ });
111
+ import * as Context from "effect/Context";
112
+ import * as Effect from "effect/Effect";
113
+ import * as Layer from "effect/Layer";
114
+ import { Database, Filter, Query } from "@dxos/echo";
115
+ var Service = class extends Context.Tag("@dxos/operation/OperationRegistry")() {
116
+ };
117
+ var resolve = Effect.serviceFunctionEffect(Service, (service) => service.resolve);
118
+ var layer = Layer.effect(Service, Effect.gen(function* () {
119
+ const database = yield* Database.Service;
120
+ const handlerSet = yield* OperationHandlerProvider;
121
+ return {
122
+ resolve: (key) => Database.runQueryFirst(Query.select(Filter.and(Filter.type(PersistentOperation), Filter.key(key)))).pipe(Effect.flatten, Effect.map(deserialize), Effect.catchTag("NoSuchElementException", () => getHandlerByKey(handlerSet, key)), Effect.option).pipe(Effect.provideService(Database.Service, database))
123
+ };
124
+ }));
125
+
126
+ // src/Template.ts
127
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/compute/compute/src/Template.ts";
128
+ var InputKind = Schema2.Literal("value", "operation");
129
+ var Input = Schema2.Struct({
130
+ name: Schema2.String,
131
+ kind: InputKind,
132
+ default: Schema2.optional(Schema2.Any),
133
+ /**
134
+ * Operation key invoked when `kind === 'operation'`. The referenced operation must accept void input —
135
+ * template inputs have no mechanism for passing arguments.
136
+ */
137
+ operation: Schema2.optional(Schema2.String)
138
+ });
139
+ var Template = Schema2.Struct({
140
+ source: Ref.Ref(Text.Text).annotations({
141
+ description: "Markdown + Handlebars template."
142
+ }),
143
+ /**
144
+ * NOTE: We use an array rather than map so that updating variable names in the template doesn't disconnect existing inputs.
145
+ */
146
+ inputs: Schema2.optional(Schema2.Array(Input))
147
+ });
148
+ var make = ({ id, source, inputs = [] } = {}) => ({
149
+ source: Ref.make(Text.make({
150
+ id,
151
+ content: source
152
+ })),
153
+ inputs
154
+ });
155
+ var process = (source, variables = {}) => {
156
+ invariant(typeof source === "string", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 50, S: void 0, A: ["typeof source === 'string'", ""] });
157
+ let section = 0;
158
+ const handlebars = Handlebars.create();
159
+ handlebars.registerHelper("section", () => String(++section));
160
+ const template = handlebars.compileAST(source.trim());
161
+ const output = template(variables);
162
+ return output.trim().replace(/(\n\s*){3,}/g, "\n\n");
163
+ };
164
+ var processTemplate = (template) => Effect2.gen(function* () {
165
+ const entries = yield* Effect2.forEach(template.inputs ?? [], (input) => Effect2.gen(function* () {
166
+ switch (input.kind) {
167
+ case "value": {
168
+ return [
169
+ input.name,
170
+ input.default
171
+ ];
172
+ }
173
+ case "operation": {
174
+ invariant(input.operation, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 70, S: this, A: ["input.operation", ""] });
175
+ const fn = yield* resolve(input.operation).pipe(Effect2.flatten, Effect2.catchTag("NoSuchElementException", () => Effect2.fail(new FunctionNotFoundError(input.operation))));
176
+ const result = yield* invoke(fn, void 0).pipe(Effect2.orDie);
177
+ return [
178
+ input.name,
179
+ result
180
+ ];
181
+ }
182
+ default: {
183
+ return yield* Effect2.dieMessage(`Unsupported input kind: ${input.kind}`);
184
+ }
185
+ }
186
+ }));
187
+ const variables = Object.fromEntries(entries);
188
+ log("processTemplate", {
189
+ variables
190
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 86, S: this });
191
+ return process((yield* Database2.load(template.source)).content, variables);
192
+ });
193
+
194
+ // src/Blueprint.ts
195
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/compute/compute/src/Blueprint.ts";
196
+ var Blueprint = Schema3.Struct({
197
+ /**
198
+ * Human-readable name of the blueprint.
199
+ */
200
+ name: Schema3.String.annotations({
201
+ description: "Human-readable name of the blueprint"
202
+ }),
203
+ /**
204
+ * Description of the blueprint's purpose and functionality.
205
+ */
206
+ description: Schema3.optional(Schema3.String).annotations({
207
+ description: "Description of the blueprint's purpose and functionality"
208
+ }),
209
+ /**
210
+ * Instructions that guide the AI assistant's behavior and responses.
211
+ * These are system prompts or guidelines that the AI should follow.
212
+ */
213
+ instructions: Template.annotations({
214
+ description: "Instructions that guide the AI assistant's behavior and responses"
215
+ }),
216
+ /**
217
+ * Array of tools that the AI assistant can use when this blueprint is active.
218
+ */
219
+ tools: Schema3.Array(ToolId).annotations({
220
+ description: "Array of tools that the AI assistant can use when this blueprint is active"
221
+ }),
222
+ /**
223
+ * Whether an agent is allowed to auto-enable this blueprint in a conversation.
224
+ */
225
+ agentCanEnable: Schema3.optional(Schema3.Boolean).annotations({
226
+ description: "Whether an agent is allowed to auto-enable this blueprint in a conversation."
227
+ }),
228
+ /**
229
+ * Array of MCP servers that the AI assistant can use when this blueprint is active.
230
+ */
231
+ mcpServers: Schema3.optional(Schema3.Array(McpServer))
232
+ }).pipe(Annotation.LabelAnnotation.set([
233
+ "name"
234
+ ]), Annotation.IconAnnotation.set({
235
+ icon: "ph--blueprint--regular",
236
+ hue: "sky"
237
+ }), Type.makeObject(DXN.make("org.dxos.type.blueprint", "0.2.0")));
238
+ var make2 = ({ key, version, tools = [], instructions = make(), ...props }) => Obj.make(Blueprint, {
239
+ [Obj.Meta]: {
240
+ key,
241
+ version
242
+ },
243
+ tools,
244
+ instructions,
245
+ ...props
246
+ });
247
+ var getKey = (blueprint) => {
248
+ const key = Obj.getMeta(blueprint).key;
249
+ if (key === void 0) {
250
+ throw new Error("Blueprint is missing the meta key.");
251
+ }
252
+ return key;
253
+ };
254
+ var getVersion = (blueprint) => Obj.getMeta(blueprint).version;
255
+ var toolDefinitions = ({ tools = [], operations = [] }) => [
256
+ ...operations.map((op) => ToolId.make(op.meta.key)),
257
+ ...tools.map((tool) => ToolId.make(tool))
258
+ ];
259
+ var Registry = class {
260
+ _blueprints = [];
261
+ constructor(blueprints) {
262
+ const seen = /* @__PURE__ */ new Set();
263
+ blueprints.forEach((blueprint) => {
264
+ const key = getKey(blueprint);
265
+ if (seen.has(key)) {
266
+ log2.warn("duplicate blueprint", {
267
+ key
268
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 101, S: this });
269
+ } else {
270
+ seen.add(key);
271
+ this._blueprints.push(blueprint);
272
+ }
273
+ });
274
+ this._blueprints.sort(({ name: a }, { name: b }) => a.localeCompare(b));
275
+ }
276
+ get blueprints() {
277
+ return this._blueprints;
278
+ }
279
+ getByKey(key) {
280
+ return this._blueprints.find((blueprint) => Obj.getMeta(blueprint).key === key);
281
+ }
282
+ query() {
283
+ return this._blueprints;
284
+ }
285
+ updateBlueprints() {
286
+ return Effect3.gen(this, function* () {
287
+ const blueprints = yield* Database3.runQuery(Filter2.type(Blueprint));
288
+ for (const blueprint of blueprints) {
289
+ const blueprintKey = Obj.getMeta(blueprint).key;
290
+ if (!blueprintKey) {
291
+ continue;
292
+ }
293
+ const registryBlueprint = this.getByKey(blueprintKey);
294
+ if (!registryBlueprint) {
295
+ continue;
296
+ }
297
+ const source = Obj.clone(registryBlueprint, {
298
+ deep: true
299
+ });
300
+ Obj.update(blueprint, (blueprint2) => {
301
+ void Obj.updateFrom(blueprint2, source);
302
+ });
303
+ }
304
+ }).pipe(Effect3.orDie);
305
+ }
306
+ };
307
+ var RegistryService = class _RegistryService extends Context2.Tag("@dxos/blueprints/RegistryService")() {
308
+ static notAvailable = Layer2.succeed(_RegistryService, {
309
+ get blueprints() {
310
+ throw new Error("Blueprint registry not available");
311
+ },
312
+ getByKey(_key) {
313
+ throw new Error("Blueprint registry not available");
314
+ },
315
+ query() {
316
+ throw new Error("Blueprint registry not available");
317
+ },
318
+ updateBlueprints() {
319
+ throw new Error("Blueprint registry not available");
320
+ }
321
+ });
322
+ };
323
+ var resolve2 = (key) => Effect3.gen(function* () {
324
+ const registry = yield* RegistryService;
325
+ const blueprint = registry.getByKey(key);
326
+ if (!blueprint) {
327
+ return yield* Effect3.fail(new NotFoundError({
328
+ context: {
329
+ key
330
+ }
331
+ }));
332
+ }
333
+ return blueprint;
334
+ });
335
+ var upsert = (key) => Effect3.gen(function* () {
336
+ const local = yield* Database3.runQuery(Filter2.and(Filter2.type(Blueprint), Filter2.key(key)));
337
+ if (local.length > 0) {
338
+ return local[0];
339
+ }
340
+ return yield* Database3.add(Obj.clone(yield* resolve2(key), {
341
+ deep: true
342
+ }));
343
+ });
344
+ var NotFoundError = class extends BaseError.extend("BlueprintNotFound", "Blueprint not found") {
345
+ };
346
+ var Blueprint_v0_1_0 = Schema3.Struct({
347
+ /**
348
+ * Global registry ID.
349
+ * NOTE: The `key` property refers to the original registry entry.
350
+ */
351
+ key: Schema3.String.annotations({
352
+ description: "Unique registration key for the blueprint"
353
+ }),
354
+ name: Schema3.String.annotations({
355
+ description: "Human-readable name of the blueprint"
356
+ }),
357
+ description: Schema3.optional(Schema3.String),
358
+ instructions: Template,
359
+ tools: Schema3.Array(ToolId),
360
+ agentCanEnable: Schema3.optional(Schema3.Boolean),
361
+ mcpServers: Schema3.optional(Schema3.Array(McpServer))
362
+ }).pipe(Type.makeObject(DXN.make("org.dxos.type.blueprint", "0.1.0")));
363
+ var _migration = Migration.define({
364
+ from: Blueprint_v0_1_0,
365
+ to: Blueprint,
366
+ transform: async (from) => ({
367
+ [Obj.Meta]: {
368
+ key: from.key,
369
+ version: "0.1.0"
370
+ },
371
+ name: from.name,
372
+ description: from.description,
373
+ instructions: from.instructions,
374
+ tools: from.tools,
375
+ agentCanEnable: from.agentCanEnable,
376
+ mcpServers: from.mcpServers
377
+ })
378
+ });
379
+ var migrations = [
380
+ _migration
381
+ ];
382
+
383
+ // src/Credential.ts
384
+ var Credential_exports = {};
385
+ __export(Credential_exports, {
386
+ CredentialsService: () => CredentialsService
387
+ });
388
+ import * as Context3 from "effect/Context";
389
+ import * as Effect4 from "effect/Effect";
390
+ import * as Redacted from "effect/Redacted";
391
+ var CredentialsService = class _CredentialsService extends Context3.Tag("@dxos/functions/CredentialsService")() {
392
+ static getCredential = (query) => Effect4.gen(function* () {
393
+ const credentials = yield* _CredentialsService;
394
+ return yield* Effect4.promise(() => credentials.getCredential(query));
395
+ });
396
+ static getApiKey = (query) => Effect4.gen(function* () {
397
+ const credential = yield* _CredentialsService.getCredential(query);
398
+ if (!credential.apiKey) {
399
+ throw new Error(`API key not found for service: ${query.service}`);
400
+ }
401
+ return Redacted.make(credential.apiKey);
402
+ });
403
+ };
404
+
405
+ // src/LayerSpec.ts
406
+ var LayerSpec_exports = {};
407
+ __export(LayerSpec_exports, {
408
+ TypeId: () => TypeId,
409
+ make: () => make4
410
+ });
411
+ var TypeId = "~@dxos/functions/LayerSpec";
412
+ var make4 = (opts, make11) => {
413
+ return {
414
+ [TypeId]: TypeId,
415
+ affinity: opts.affinity,
416
+ requires: opts.requires,
417
+ provides: opts.provides,
418
+ make: make11
419
+ };
420
+ };
421
+
422
+ // src/Process.ts
423
+ var Process_exports = {};
424
+ __export(Process_exports, {
425
+ ExitedEvent: () => ExitedEvent,
426
+ ID: () => ID,
427
+ ProcessMonitorService: () => ProcessMonitorService,
428
+ ProcessTypeId: () => ProcessTypeId,
429
+ SpawnedEvent: () => SpawnedEvent,
430
+ State: () => State,
431
+ fromOperation: () => fromOperation,
432
+ isProcess: () => isProcess,
433
+ make: () => make5,
434
+ prettyProcessTree: () => prettyProcessTree
435
+ });
436
+ import * as Context5 from "effect/Context";
437
+ import * as Effect6 from "effect/Effect";
438
+ import * as Schema5 from "effect/Schema";
439
+ import { assertArgument } from "@dxos/invariant";
440
+ import { log as log4 } from "@dxos/log";
441
+
442
+ // src/Trace.ts
443
+ var Trace_exports = {};
444
+ __export(Trace_exports, {
445
+ CommonRuntimeName: () => CommonRuntimeName,
446
+ Event: () => Event,
447
+ EventType: () => EventType,
448
+ Message: () => Message,
449
+ MessageData: () => MessageData,
450
+ Meta: () => Meta,
451
+ OperationEnd: () => OperationEnd,
452
+ OperationInput: () => OperationInput,
453
+ OperationOutput: () => OperationOutput,
454
+ OperationStart: () => OperationStart,
455
+ RuntimeName: () => RuntimeName,
456
+ StatusUpdate: () => StatusUpdate,
457
+ TraceService: () => TraceService,
458
+ TraceSink: () => TraceSink,
459
+ emitStatus: () => emitStatus,
460
+ flatten: () => flatten3,
461
+ isEdgeRuntime: () => isEdgeRuntime,
462
+ isOfType: () => isOfType,
463
+ layerConsole: () => layerConsole,
464
+ layerNoop: () => layerNoop,
465
+ mergeSinks: () => mergeSinks,
466
+ noopSink: () => noopSink,
467
+ noopWriter: () => noopWriter,
468
+ testTraceService: () => testTraceService,
469
+ write: () => write,
470
+ writerLayerNoop: () => writerLayerNoop
471
+ });
472
+ import * as Context4 from "effect/Context";
473
+ import * as Effect5 from "effect/Effect";
474
+ import * as Layer3 from "effect/Layer";
475
+ import * as Schema4 from "effect/Schema";
476
+ import { DXN as DXN2, Annotation as Annotation2, Obj as Obj2, Type as Type2 } from "@dxos/echo";
477
+ import { log as log3 } from "@dxos/log";
478
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/compute/compute/src/Trace.ts";
479
+ var TraceService = class extends Context4.Tag("@dxos/functions/TraceService")() {
480
+ };
481
+ function write(eventType, payload) {
482
+ return Effect5.gen(function* () {
483
+ log3("trace write", {
484
+ key: eventType.key,
485
+ isEphemeral: eventType.isEphemeral
486
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file3, L: 20, S: this });
487
+ const writer = yield* TraceService;
488
+ writer.write(eventType, payload);
489
+ });
490
+ }
491
+ var EventType = (key, opts) => {
492
+ return {
493
+ key,
494
+ schema: opts.schema,
495
+ isEphemeral: opts.isEphemeral
496
+ };
497
+ };
498
+ var Event = Schema4.Struct({
499
+ timestamp: Schema4.Number,
500
+ type: Schema4.String,
501
+ data: Schema4.Unknown
502
+ });
503
+ var isOfType = (eventType, event) => {
504
+ return event.type === eventType.key;
505
+ };
506
+ var RuntimeName = Schema4.String.pipe(Schema4.brand("@dxos/compute/Trace/RuntimeName"));
507
+ var CommonRuntimeName = {
508
+ /**
509
+ * Web app / CLI / Desktop app / Mobile app.
510
+ */
511
+ local: RuntimeName.make("local"),
512
+ edgeIntrinsic: RuntimeName.make("edge-intrinsic"),
513
+ edgeWorkerLoader: RuntimeName.make("edge-worker-loader"),
514
+ edgeWorkerForPlatforms: RuntimeName.make("edge-worker-for-platforms")
515
+ };
516
+ var Meta = Schema4.Struct({
517
+ pid: Schema4.optional(Schema4.String),
518
+ parentPid: Schema4.optional(Schema4.String),
519
+ processName: Schema4.optional(Schema4.String),
520
+ /**
521
+ * Space the message was produced in.
522
+ * Stored as a string to avoid circular dependency on `@dxos/keys`.
523
+ */
524
+ space: Schema4.optional(Schema4.String),
525
+ /**
526
+ * ID of the conversation feed object if present.
527
+ */
528
+ conversationId: Schema4.optional(Obj2.ID),
529
+ /**
530
+ * ID of the trigger object if invocation resulted from a trigger.
531
+ */
532
+ triggerId: Schema4.optional(Obj2.ID),
533
+ /**
534
+ * ID of the tool call that created the current process.
535
+ */
536
+ toolCallId: Schema4.optional(Schema4.String),
537
+ /**
538
+ * Extensible name informing which runtime executed the code that produced the event.
539
+ */
540
+ runtimeName: Schema4.optional(RuntimeName)
541
+ });
542
+ var isEdgeRuntime = (name) => name === CommonRuntimeName.edgeIntrinsic || name === CommonRuntimeName.edgeWorkerLoader || name === CommonRuntimeName.edgeWorkerForPlatforms;
543
+ var MessageData = Schema4.Struct({
544
+ meta: Meta,
545
+ isEphemeral: Schema4.Boolean,
546
+ events: Schema4.Array(Event)
547
+ });
548
+ var Message = MessageData.pipe(Annotation2.IconAnnotation.set({
549
+ icon: "ph--note--regular",
550
+ hue: "rose"
551
+ }), Type2.makeObject(DXN2.make("org.dxos.type.traceMessage", "0.1.0")));
552
+ var flatten3 = (message) => {
553
+ return message.events.map((event) => ({
554
+ ...event,
555
+ meta: message.meta,
556
+ isEphemeral: message.isEphemeral
557
+ }));
558
+ };
559
+ var TraceSink = class extends Context4.Tag("@dxos/functions/TraceSink")() {
560
+ };
561
+ var noopWriter = {
562
+ write: () => {
563
+ }
564
+ };
565
+ var writerLayerNoop = Layer3.succeed(TraceService, noopWriter);
566
+ var noopSink = {
567
+ write: () => {
568
+ }
569
+ };
570
+ var layerNoop = Layer3.succeed(TraceSink, noopSink);
571
+ var layerConsole = Layer3.succeed(TraceSink, {
572
+ write: (message) => {
573
+ console.log(message);
574
+ }
575
+ });
576
+ var mergeSinks = (sinks) => {
577
+ if (sinks.length === 0) {
578
+ return noopSink;
579
+ }
580
+ return {
581
+ write: (message) => {
582
+ for (const sink of sinks) {
583
+ try {
584
+ sink.write(message);
585
+ } catch (err) {
586
+ console.error("[trace] sink.write threw", err);
587
+ }
588
+ }
589
+ }
590
+ };
591
+ };
592
+ var testTraceService = (opts = {}) => Layer3.effect(TraceService, Effect5.gen(function* () {
593
+ const sink = yield* TraceSink;
594
+ const clock = opts.clock ?? Date.now;
595
+ return {
596
+ write: (event, data) => {
597
+ sink.write(Obj2.make(Message, {
598
+ meta: opts.meta ?? {},
599
+ isEphemeral: event.isEphemeral,
600
+ events: [
601
+ {
602
+ type: event.key,
603
+ timestamp: clock(),
604
+ data
605
+ }
606
+ ]
607
+ }));
608
+ }
609
+ };
610
+ }));
611
+ var OperationStart = EventType("operation.start", {
612
+ schema: Schema4.Struct({
613
+ /** Operation key. */
614
+ key: Schema4.String,
615
+ /** Human-readable operation name. */
616
+ name: Schema4.optional(Schema4.String),
617
+ /** Phosphor icon identifier in `ph--<name>--<variant>` format. */
618
+ icon: Schema4.optional(Schema4.String)
619
+ }),
620
+ isEphemeral: false
621
+ });
622
+ var OperationEnd = EventType("operation.end", {
623
+ schema: Schema4.Struct({
624
+ /** Operation key. */
625
+ key: Schema4.String,
626
+ /** Human-readable operation name. */
627
+ name: Schema4.optional(Schema4.String),
628
+ /** Phosphor icon identifier in `ph--<name>--<variant>` format. */
629
+ icon: Schema4.optional(Schema4.String),
630
+ /** Outcome of the operation. */
631
+ outcome: Schema4.Literal("success", "failure"),
632
+ /** Error message if the operation failed. */
633
+ error: Schema4.optional(Schema4.String)
634
+ }),
635
+ isEphemeral: false
636
+ });
637
+ var OperationInput = EventType("operation.input", {
638
+ schema: Schema4.Struct({
639
+ /** Operation key. */
640
+ key: Schema4.String,
641
+ /** Human-readable operation name. */
642
+ name: Schema4.optional(Schema4.String),
643
+ /** Raw operation input. Shape determined by the operation definition. */
644
+ input: Schema4.Unknown
645
+ }),
646
+ isEphemeral: true
647
+ });
648
+ var OperationOutput = EventType("operation.output", {
649
+ schema: Schema4.Struct({
650
+ /** Operation key. */
651
+ key: Schema4.String,
652
+ /** Human-readable operation name. */
653
+ name: Schema4.optional(Schema4.String),
654
+ /** Raw operation output. Shape determined by the operation definition. */
655
+ output: Schema4.Unknown
656
+ }),
657
+ isEphemeral: true
658
+ });
659
+ var StatusUpdate = EventType("status.update", {
660
+ schema: Schema4.Struct({
661
+ /** Human-readable status message. */
662
+ message: Schema4.String
663
+ }),
664
+ isEphemeral: true
665
+ });
666
+ var emitStatus = (message) => write(StatusUpdate, {
667
+ message
668
+ });
669
+
670
+ // src/Process.ts
671
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/core/compute/compute/src/Process.ts";
672
+ var ID = Schema5.String.pipe(Schema5.brand("ProcessId"));
673
+ var ProcessTypeId = "~@dxos/functions/Process";
674
+ var isProcess = (executable) => typeof executable === "object" && executable !== null && ProcessTypeId in executable;
675
+ var make5 = (opts, create) => {
676
+ assertArgument(/^[a-z0-9]([a-z0-9.\-/]*[a-z0-9])?$/i.test(opts.key), "key", "Invalid key");
677
+ return {
678
+ [ProcessTypeId]: {},
679
+ ...opts,
680
+ create: (ctx) => create(ctx).pipe(Effect6.map((partial) => ({
681
+ onSpawn: () => Effect6.void,
682
+ onInput: () => Effect6.void,
683
+ onAlarm: () => Effect6.void,
684
+ onChildEvent: () => Effect6.void,
685
+ ...partial
686
+ })))
687
+ };
688
+ };
689
+ var fromOperation = (op, handler) => make5({
690
+ key: op.meta.key,
691
+ input: op.input,
692
+ output: op.output,
693
+ services: op.services
694
+ }, (ctx) => Effect6.gen(function* () {
695
+ const semaphore = yield* Effect6.makeSemaphore(1);
696
+ return {
697
+ onInput: (input) => Effect6.gen(function* () {
698
+ log4("operation process invoking", {
699
+ key: op.meta.key,
700
+ name: op.meta.name
701
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 45, S: this });
702
+ yield* write(OperationStart, {
703
+ key: op.meta.key,
704
+ name: op.meta.name,
705
+ icon: op.meta.icon
706
+ });
707
+ yield* write(OperationInput, {
708
+ key: op.meta.key,
709
+ name: op.meta.name,
710
+ input
711
+ });
712
+ const opHandler = yield* getHandler(handler, op).pipe(Effect6.orDie);
713
+ const output = yield* opHandler.handler(input).pipe(Effect6.orDie, Effect6.withSpan(op.meta.key));
714
+ ctx.submitOutput(output);
715
+ ctx.succeed();
716
+ yield* write(OperationOutput, {
717
+ key: op.meta.key,
718
+ name: op.meta.name,
719
+ output
720
+ });
721
+ yield* write(OperationEnd, {
722
+ key: op.meta.key,
723
+ name: op.meta.name,
724
+ icon: op.meta.icon,
725
+ outcome: "success"
726
+ });
727
+ }).pipe(Effect6.catchAllDefect((defect) => Effect6.gen(function* () {
728
+ const errorMessage = defect instanceof Error ? defect.message : String(defect);
729
+ yield* write(OperationEnd, {
730
+ key: op.meta.key,
731
+ name: op.meta.name,
732
+ icon: op.meta.icon,
733
+ outcome: "failure",
734
+ error: errorMessage
735
+ });
736
+ return yield* Effect6.die(defect);
737
+ })), semaphore.withPermits(1))
738
+ };
739
+ }));
740
+ var State = /* @__PURE__ */ (function(State2) {
741
+ State2["RUNNING"] = "RUNNING";
742
+ State2["HYBERNATING"] = "HYBERNATING";
743
+ State2["IDLE"] = "IDLE";
744
+ State2["TERMINATING"] = "TERMINATING";
745
+ State2["TERMINATED"] = "TERMINATED";
746
+ State2["SUCCEEDED"] = "SUCCEEDED";
747
+ State2["FAILED"] = "FAILED";
748
+ return State2;
749
+ })({});
750
+ var ProcessMonitorService = class extends Context5.Tag("@dxos/functions/ProcessMonitorService")() {
751
+ };
752
+ var SpawnedEvent = EventType("process.spawned", {
753
+ schema: Schema5.Void,
754
+ isEphemeral: false
755
+ });
756
+ var ExitedEvent = EventType("process.exited", {
757
+ schema: Schema5.Struct({
758
+ outcome: Schema5.Literal("succeeded", "failed", "terminated")
759
+ }),
760
+ isEphemeral: false
761
+ });
762
+ var prettyProcessTree = (tree) => {
763
+ if (tree.length === 0) {
764
+ return "";
765
+ }
766
+ const pidSet = new Set(tree.map((node) => node.pid));
767
+ const childrenByParent = /* @__PURE__ */ new Map();
768
+ const roots = [];
769
+ for (const node of tree) {
770
+ const parent = node.parentPid;
771
+ if (parent === null || !pidSet.has(parent)) {
772
+ roots.push(node);
773
+ continue;
774
+ }
775
+ const key = String(parent);
776
+ const siblings = childrenByParent.get(key) ?? [];
777
+ siblings.push(node);
778
+ childrenByParent.set(key, siblings);
779
+ }
780
+ const byPid = (a, b) => String(a.pid).localeCompare(String(b.pid));
781
+ roots.sort(byPid);
782
+ for (const siblings of childrenByParent.values()) {
783
+ siblings.sort(byPid);
784
+ }
785
+ const formatLabel = (node) => {
786
+ const idShort = String(node.pid).slice(0, 6);
787
+ const parts = [
788
+ idShort,
789
+ node.state
790
+ ];
791
+ if (node.params.name != null && node.params.name !== "") {
792
+ parts.push(node.params.name);
793
+ }
794
+ if (node.error != null) {
795
+ parts.push(`(${node.error})`);
796
+ }
797
+ const { inputCount, outputCount, wallTime } = node.metrics;
798
+ parts.push(`[in:${inputCount} out:${outputCount} wall:${Math.round(wallTime)}ms]`);
799
+ return parts.join(" ");
800
+ };
801
+ const lines = [];
802
+ const walk = (node, prefix, isLast, isRoot) => {
803
+ if (isRoot) {
804
+ lines.push(`- ${formatLabel(node)}`);
805
+ } else {
806
+ const branch = isLast ? "\u2514\u2500\u2500 " : "\u251C\u2500\u2500 ";
807
+ lines.push(`${prefix}${branch}${formatLabel(node)}`);
808
+ }
809
+ const children = childrenByParent.get(String(node.pid)) ?? [];
810
+ const nextPrefix = isRoot ? " " : `${prefix}${isLast ? " " : "\u2502 "}`;
811
+ children.forEach((child, index) => {
812
+ walk(child, nextPrefix, index === children.length - 1, false);
813
+ });
814
+ };
815
+ for (const root of roots) {
816
+ walk(root, "", true, true);
817
+ }
818
+ return lines.join("\n");
819
+ };
820
+
821
+ // src/Routine.ts
822
+ var Routine_exports = {};
823
+ __export(Routine_exports, {
824
+ Routine: () => Routine,
825
+ make: () => make6
826
+ });
827
+ import * as Schema6 from "effect/Schema";
828
+ import { DXN as DXN3, Annotation as Annotation3, JsonSchema, Obj as Obj3, Ref as Ref2, Type as Type3 } from "@dxos/echo";
829
+ var Routine = Schema6.Struct({
830
+ name: Schema6.optional(Schema6.String),
831
+ description: Schema6.optional(Schema6.String),
832
+ input: JsonSchema.JsonSchema.pipe(Annotation3.FormInputAnnotation.set(false)).annotations({
833
+ description: "Input schema"
834
+ }),
835
+ output: JsonSchema.JsonSchema.pipe(Annotation3.FormInputAnnotation.set(false)).annotations({
836
+ description: "Output schema"
837
+ }),
838
+ // TODO(burdon): Form editor.
839
+ instructions: Template.pipe(Annotation3.FormInputAnnotation.set(false)).annotations({
840
+ description: "Agent instructions"
841
+ }),
842
+ blueprints: Schema6.Array(Ref2.Ref(Blueprint)),
843
+ // TODO(burdon): Change to map?
844
+ context: Schema6.Array(Schema6.Any).pipe(Annotation3.FormInputAnnotation.set(false))
845
+ }).pipe(Annotation3.LabelAnnotation.set([
846
+ "name"
847
+ ]), Annotation3.IconAnnotation.set({
848
+ icon: "ph--scroll--regular",
849
+ hue: "sky"
850
+ }), Type3.makeObject(DXN3.make("org.dxos.type.routine", "0.1.0")));
851
+ var make6 = ({ name, description, input, output, instructions, blueprints = [], context = [] }) => Obj3.make(Routine, {
852
+ name,
853
+ description,
854
+ input: JsonSchema.toJsonSchema(input ?? Schema6.Void),
855
+ output: JsonSchema.toJsonSchema(output ?? Schema6.Void),
856
+ instructions: make({
857
+ source: instructions
858
+ }),
859
+ blueprints,
860
+ context
861
+ });
862
+
863
+ // src/Script.ts
864
+ var Script_exports = {};
865
+ __export(Script_exports, {
866
+ Script: () => Script,
867
+ make: () => make7
868
+ });
869
+ import * as Schema7 from "effect/Schema";
870
+ import { DXN as DXN4, Annotation as Annotation4, Obj as Obj4, Ref as Ref3, Type as Type4 } from "@dxos/echo";
871
+ import { FormInputAnnotation } from "@dxos/echo/internal";
872
+ import { Text as Text2 } from "@dxos/schema";
873
+ var Script = Schema7.Struct({
874
+ name: Schema7.String.pipe(Schema7.optional),
875
+ description: Schema7.String.pipe(Schema7.optional),
876
+ // TODO(burdon): Change to hash of deployed content.
877
+ // Whether source has changed since last deploy.
878
+ changed: Schema7.Boolean.pipe(FormInputAnnotation.set(false), Schema7.optional),
879
+ source: Ref3.Ref(Text2.Text).pipe(FormInputAnnotation.set(false))
880
+ }).pipe(Annotation4.LabelAnnotation.set([
881
+ "name"
882
+ ]), Annotation4.IconAnnotation.set({
883
+ icon: "ph--code--regular",
884
+ hue: "sky"
885
+ }), Type4.makeObject(DXN4.make("org.dxos.type.script", "0.1.0")));
886
+ var make7 = ({ source = "", ...props } = {}) => Obj4.make(Script, {
887
+ ...props,
888
+ source: Ref3.make(Text2.make({
889
+ content: source
890
+ }))
891
+ });
892
+
893
+ // src/ServiceResolver.ts
894
+ var ServiceResolver_exports = {};
895
+ __export(ServiceResolver_exports, {
896
+ ServiceResolver: () => ServiceResolver,
897
+ compose: () => compose,
898
+ empty: () => empty2,
899
+ fromContext: () => fromContext,
900
+ fromRequirements: () => fromRequirements,
901
+ layerRequirements: () => layerRequirements,
902
+ make: () => make9,
903
+ provide: () => provide,
904
+ resolve: () => resolve3,
905
+ resolveAll: () => resolveAll,
906
+ succeed: () => succeed3
907
+ });
908
+ import * as Context6 from "effect/Context";
909
+ import * as Effect7 from "effect/Effect";
910
+ import * as Either from "effect/Either";
911
+ import * as Layer4 from "effect/Layer";
912
+ import * as Option from "effect/Option";
913
+ var ServiceResolverTypeId = "~@dxos/functions/ServiceResolver";
914
+ var ServiceResolver = Context6.GenericTag("@dxos/functions/ServiceResolver");
915
+ var resolve3 = Effect7.serviceFunctionEffect(ServiceResolver, (_) => _.resolve);
916
+ var resolveAll = (tags, context) => Effect7.gen(function* () {
917
+ const services = yield* Effect7.forEach(tags, (tag) => resolve3(tag, context).pipe(Effect7.map((service) => Context6.make(tag, service))));
918
+ return Context6.mergeAll(...services);
919
+ });
920
+ var succeed3 = (tag, getService) => {
921
+ return make9((tag1, context) => {
922
+ if (tag1.key !== tag.key) {
923
+ return Effect7.fail(new ServiceNotAvailableError(`Service not available: ${String(tag.key ?? tag)}`));
924
+ }
925
+ const service = getService(context);
926
+ return service;
927
+ });
928
+ };
929
+ var make9 = (resolveFn) => ({
930
+ [ServiceResolverTypeId]: ServiceResolverTypeId,
931
+ resolve: resolveFn
932
+ });
933
+ var fromContext = (ctx) => make9((tag, context) => Effect7.gen(function* () {
934
+ const service = Context6.getOption(ctx, tag);
935
+ if (Option.isNone(service)) {
936
+ return yield* Effect7.fail(new ServiceNotAvailableError(String(tag.key ?? tag)));
937
+ }
938
+ return service.value;
939
+ }));
940
+ var fromRequirements = (...tags) => Effect7.contextWith((parentCtx) => {
941
+ const available = new Set(tags.map((tag) => tag.key));
942
+ return make9((tag, context) => Effect7.gen(function* () {
943
+ let result = Context6.empty();
944
+ if (!available.has(tag.key)) {
945
+ return yield* Effect7.fail(new ServiceNotAvailableError(String(tag.key ?? tag)));
946
+ }
947
+ const service = Context6.getOption(parentCtx, tag);
948
+ if (Option.isNone(service)) {
949
+ return yield* Effect7.fail(new ServiceNotAvailableError(String(tag.key ?? tag)));
950
+ }
951
+ return service.value;
952
+ }));
953
+ });
954
+ var layerRequirements = (...tags) => Layer4.effect(ServiceResolver, fromRequirements(...tags));
955
+ var provide = (context, ...tags) => Layer4.scopedContext(resolveAll(tags, context));
956
+ var compose = (...resolvers) => make9((tag, context) => Effect7.gen(function* () {
957
+ for (const resolver of resolvers) {
958
+ const single = yield* resolver.resolve(tag, context).pipe(Effect7.either);
959
+ if (Either.isRight(single)) {
960
+ return single.right;
961
+ }
962
+ }
963
+ return yield* Effect7.fail(new ServiceNotAvailableError(String(tag.key ?? tag)));
964
+ }));
965
+ var empty2 = make9((tag, context) => {
966
+ return Effect7.fail(new ServiceNotAvailableError(String(tag.key ?? tag)));
967
+ });
968
+
969
+ // src/Trigger.ts
970
+ var Trigger_exports = {};
971
+ __export(Trigger_exports, {
972
+ EmailSpec: () => EmailSpec,
973
+ FeedSpec: () => FeedSpec,
974
+ Kinds: () => Kinds,
975
+ Spec: () => Spec,
976
+ SubscriptionSpec: () => SubscriptionSpec,
977
+ TimerSpec: () => TimerSpec,
978
+ Trigger: () => Trigger,
979
+ WebhookSpec: () => WebhookSpec,
980
+ make: () => make10,
981
+ specEmail: () => specEmail,
982
+ specFeed: () => specFeed,
983
+ specSubscription: () => specSubscription,
984
+ specTimer: () => specTimer,
985
+ specWebhook: () => specWebhook
986
+ });
987
+ import * as Schema8 from "effect/Schema";
988
+ import * as SchemaAST from "effect/SchemaAST";
989
+ import { DXN as DXN5, Annotation as Annotation5, Feed, Obj as Obj5, QueryAST, Ref as Ref4, Type as Type5 } from "@dxos/echo";
990
+ import { OptionsAnnotationId, SystemTypeAnnotation } from "@dxos/echo/internal";
991
+ var Kinds = [
992
+ "email",
993
+ "feed",
994
+ "subscription",
995
+ "timer",
996
+ "webhook"
997
+ ];
998
+ var kindLiteralAnnotations = {
999
+ title: "Kind"
1000
+ };
1001
+ var EmailSpec = Schema8.Struct({
1002
+ kind: Schema8.Literal("email").annotations(kindLiteralAnnotations)
1003
+ });
1004
+ var specEmail = () => ({
1005
+ kind: "email"
1006
+ });
1007
+ var FeedSpec = Schema8.Struct({
1008
+ kind: Schema8.Literal("feed").annotations(kindLiteralAnnotations),
1009
+ feed: Schema8.optional(Ref4.Ref(Feed.Feed).annotations({
1010
+ title: "Feed"
1011
+ }))
1012
+ });
1013
+ var specFeed = (feed) => ({
1014
+ kind: "feed",
1015
+ feed: Ref4.make(feed)
1016
+ });
1017
+ var SubscriptionSpec = Schema8.Struct({
1018
+ kind: Schema8.Literal("subscription").annotations(kindLiteralAnnotations),
1019
+ query: Schema8.Struct({
1020
+ raw: Schema8.optional(Schema8.String.annotations({
1021
+ title: "Query"
1022
+ })),
1023
+ ast: QueryAST.Query
1024
+ }),
1025
+ options: Schema8.optional(Schema8.Struct({
1026
+ // Watch changes to object (not just creation).
1027
+ deep: Schema8.optional(Schema8.Boolean.annotations({
1028
+ title: "Nested"
1029
+ })),
1030
+ // Debounce changes (delay in ms).
1031
+ delay: Schema8.optional(Schema8.Number.annotations({
1032
+ title: "Delay"
1033
+ }))
1034
+ }).annotations({
1035
+ title: "Options"
1036
+ }))
1037
+ });
1038
+ var specSubscription = (query, options) => ({
1039
+ kind: "subscription",
1040
+ query: {
1041
+ ast: query.ast
1042
+ },
1043
+ options: options ? {
1044
+ deep: options.deep,
1045
+ delay: options.delay
1046
+ } : void 0
1047
+ });
1048
+ var TimerSpec = Schema8.Struct({
1049
+ kind: Schema8.Literal("timer").annotations(kindLiteralAnnotations),
1050
+ cron: Schema8.String.annotations({
1051
+ title: "Cron",
1052
+ [SchemaAST.ExamplesAnnotationId]: [
1053
+ "0 0 * * *"
1054
+ ]
1055
+ })
1056
+ });
1057
+ var specTimer = (cron) => ({
1058
+ kind: "timer",
1059
+ cron
1060
+ });
1061
+ var WebhookSpec = Schema8.Struct({
1062
+ kind: Schema8.Literal("webhook").annotations(kindLiteralAnnotations),
1063
+ method: Schema8.optional(Schema8.String.annotations({
1064
+ title: "Method",
1065
+ [OptionsAnnotationId]: [
1066
+ "GET",
1067
+ "POST"
1068
+ ]
1069
+ })),
1070
+ port: Schema8.optional(Schema8.Number.annotations({
1071
+ title: "Port"
1072
+ }))
1073
+ });
1074
+ var specWebhook = (opts) => ({
1075
+ kind: "webhook",
1076
+ method: opts?.method,
1077
+ port: opts?.port
1078
+ });
1079
+ var Spec = Schema8.Union(EmailSpec, FeedSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
1080
+ title: "Trigger"
1081
+ });
1082
+ var TriggerSchema = Schema8.Struct({
1083
+ /**
1084
+ * Function or workflow to invoke.
1085
+ */
1086
+ // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
1087
+ function: Schema8.optional(Ref4.Ref(Obj5.Unknown).annotations({
1088
+ title: "Function"
1089
+ })),
1090
+ /**
1091
+ * Only used for workflowSchema.
1092
+ * Specifies the input node in the circuit.
1093
+ * @deprecated Remove and enforce a single input node in all compute graphSchema.
1094
+ */
1095
+ inputNodeId: Schema8.optional(Schema8.String.annotations({
1096
+ title: "Input Node ID"
1097
+ })),
1098
+ // TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
1099
+ // Need lint rule; or agent rule to require PR review for "boolean" key word.
1100
+ enabled: Schema8.optional(Schema8.Boolean.annotations({
1101
+ title: "Enabled"
1102
+ })),
1103
+ spec: Schema8.optional(Spec),
1104
+ concurrency: Schema8.optional(Schema8.Number.annotations({
1105
+ title: "Concurrency",
1106
+ default: 1,
1107
+ description: "Maximum number of concurrent invocations of the trigger. For Feed triggers, this will process Feed items in parallel."
1108
+ })),
1109
+ /**
1110
+ * Passed as the input data to the function.
1111
+ * Must match the function's input schema.
1112
+ *
1113
+ * @example
1114
+ * {
1115
+ * item: '{{event.item}}',
1116
+ * instructions: 'Summarize and perform entity-extraction'
1117
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
1118
+ * }
1119
+ */
1120
+ input: Schema8.optional(Schema8.Record({
1121
+ key: Schema8.String,
1122
+ value: Schema8.Any
1123
+ }))
1124
+ }).pipe(Annotation5.IconAnnotation.set({
1125
+ icon: "ph--lightning--regular",
1126
+ hue: "yellow"
1127
+ }), SystemTypeAnnotation.set(true), Type5.makeObject(DXN5.make("org.dxos.type.trigger", "0.1.0")));
1128
+ var Trigger = TriggerSchema;
1129
+ var make10 = (props) => Obj5.make(Trigger, props);
1130
+
1131
+ // src/TriggerEvent.ts
1132
+ var TriggerEvent_exports = {};
1133
+ __export(TriggerEvent_exports, {
1134
+ EmailEvent: () => EmailEvent,
1135
+ FeedEvent: () => FeedEvent,
1136
+ SubscriptionEvent: () => SubscriptionEvent,
1137
+ TimerEvent: () => TimerEvent,
1138
+ TriggerEvent: () => TriggerEvent,
1139
+ WebhookEvent: () => WebhookEvent
1140
+ });
1141
+ import * as Schema9 from "effect/Schema";
1142
+ import { Feed as Feed2, Obj as Obj6, Ref as Ref5 } from "@dxos/echo";
1143
+ var EmailEvent = Schema9.Struct({
1144
+ from: Schema9.String,
1145
+ to: Schema9.String,
1146
+ subject: Schema9.String,
1147
+ created: Schema9.String,
1148
+ body: Schema9.String
1149
+ });
1150
+ var FeedEvent = Schema9.Struct({
1151
+ feed: Ref5.Ref(Feed2.Feed),
1152
+ item: Schema9.Any,
1153
+ cursor: Schema9.String
1154
+ });
1155
+ var SubscriptionEvent = Schema9.Struct({
1156
+ /**
1157
+ * Type of the mutation.
1158
+ */
1159
+ // TODO(dmaretskyi): Specify enum.
1160
+ type: Schema9.String,
1161
+ /**
1162
+ * Reference to the object that was changed or created.
1163
+ */
1164
+ subject: Ref5.Ref(Obj6.Unknown),
1165
+ /**
1166
+ * @deprecated
1167
+ */
1168
+ changedObjectId: Schema9.optional(Schema9.String)
1169
+ });
1170
+ var TimerEvent = Schema9.Struct({
1171
+ tick: Schema9.Number
1172
+ });
1173
+ var WebhookEvent = Schema9.Struct({
1174
+ url: Schema9.String,
1175
+ method: Schema9.Literal("GET", "POST"),
1176
+ headers: Schema9.Record({
1177
+ key: Schema9.String,
1178
+ value: Schema9.String
1179
+ }),
1180
+ bodyText: Schema9.String
1181
+ });
1182
+ var TriggerEvent = Schema9.Union(EmailEvent, FeedEvent, SubscriptionEvent, TimerEvent, WebhookEvent);
1183
+ export {
1184
+ Blueprint_exports as Blueprint,
1185
+ Credential_exports as Credential,
1186
+ FunctionError,
1187
+ FunctionNotFoundError,
1188
+ FunctionsAiMemoizationMissError,
1189
+ FunctionsAiUpstreamError,
1190
+ InvalidOperationInputError,
1191
+ InvalidOperationOutputError,
1192
+ InvokerNotInitializedError,
1193
+ LayerSpec_exports as LayerSpec,
1194
+ McpServer_exports as McpServer,
1195
+ NoHandlerError,
1196
+ Operation_exports as Operation,
1197
+ OperationHandlerSet_exports as OperationHandlerSet,
1198
+ OperationRegistry_exports as OperationRegistry,
1199
+ Process_exports as Process,
1200
+ Routine_exports as Routine,
1201
+ Script_exports as Script,
1202
+ ServiceNotAvailableError,
1203
+ ServiceResolver_exports as ServiceResolver,
1204
+ StorageService_exports as StorageService,
1205
+ Template_exports as Template,
1206
+ Trace_exports as Trace,
1207
+ Trigger_exports as Trigger,
1208
+ TriggerEvent_exports as TriggerEvent,
1209
+ TriggerStateNotFoundError
1210
+ };
1211
+ //# sourceMappingURL=index.mjs.map