@dxos/compute 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc

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