@dxos/compute 0.8.4-main.72ec0f3 → 0.8.4-main.765dc60934

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