@dxos/compute 0.8.3 → 0.8.4-main.1c7ec43d41

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