@dxos/compute 0.8.4-main.406dc2a → 0.8.4-main.43cb759274

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