@dxos/functions 0.8.4-main.e098934 → 0.8.4-main.ead640a

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 (106) hide show
  1. package/dist/lib/browser/bundler/index.mjs +10 -6
  2. package/dist/lib/browser/bundler/index.mjs.map +3 -3
  3. package/dist/lib/browser/{chunk-D2XO7XXY.mjs → chunk-LKYT2SAL.mjs} +176 -122
  4. package/dist/lib/browser/chunk-LKYT2SAL.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +319 -199
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +11 -9
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/node-esm/bundler/index.mjs +10 -6
  11. package/dist/lib/node-esm/bundler/index.mjs.map +3 -3
  12. package/dist/lib/node-esm/{chunk-Z4CJ62WS.mjs → chunk-NAQIKLZB.mjs} +176 -122
  13. package/dist/lib/node-esm/chunk-NAQIKLZB.mjs.map +7 -0
  14. package/dist/lib/node-esm/index.mjs +319 -199
  15. package/dist/lib/node-esm/index.mjs.map +4 -4
  16. package/dist/lib/node-esm/meta.json +1 -1
  17. package/dist/lib/node-esm/testing/index.mjs +11 -9
  18. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  19. package/dist/types/src/bundler/bundler.d.ts.map +1 -1
  20. package/dist/types/src/errors.d.ts +16 -16
  21. package/dist/types/src/examples/fib.d.ts.map +1 -1
  22. package/dist/types/src/examples/reply.d.ts.map +1 -1
  23. package/dist/types/src/examples/sleep.d.ts.map +1 -1
  24. package/dist/types/src/executor/executor.d.ts +3 -0
  25. package/dist/types/src/executor/executor.d.ts.map +1 -1
  26. package/dist/types/src/handler.d.ts +19 -4
  27. package/dist/types/src/handler.d.ts.map +1 -1
  28. package/dist/types/src/schema.d.ts +5 -5
  29. package/dist/types/src/schema.d.ts.map +1 -1
  30. package/dist/types/src/services/credentials.d.ts +6 -2
  31. package/dist/types/src/services/credentials.d.ts.map +1 -1
  32. package/dist/types/src/services/database.d.ts +6 -2
  33. package/dist/types/src/services/database.d.ts.map +1 -1
  34. package/dist/types/src/services/event-logger.d.ts +4 -1
  35. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  36. package/dist/types/src/services/function-invocation-service.d.ts +28 -0
  37. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  38. package/dist/types/src/services/function-invocation-service.test.d.ts +2 -0
  39. package/dist/types/src/services/function-invocation-service.test.d.ts.map +1 -0
  40. package/dist/types/src/services/index.d.ts +4 -3
  41. package/dist/types/src/services/index.d.ts.map +1 -1
  42. package/dist/types/src/services/local-function-execution.d.ts +18 -9
  43. package/dist/types/src/services/local-function-execution.d.ts.map +1 -1
  44. package/dist/types/src/services/queues.d.ts +3 -1
  45. package/dist/types/src/services/queues.d.ts.map +1 -1
  46. package/dist/types/src/services/remote-function-execution-service.d.ts +11 -4
  47. package/dist/types/src/services/remote-function-execution-service.d.ts.map +1 -1
  48. package/dist/types/src/services/service-container.d.ts +2 -1
  49. package/dist/types/src/services/service-container.d.ts.map +1 -1
  50. package/dist/types/src/services/service-registry.d.ts +3 -1
  51. package/dist/types/src/services/service-registry.d.ts.map +1 -1
  52. package/dist/types/src/services/tracing.d.ts +5 -3
  53. package/dist/types/src/services/tracing.d.ts.map +1 -1
  54. package/dist/types/src/testing/layer.d.ts +6 -3
  55. package/dist/types/src/testing/layer.d.ts.map +1 -1
  56. package/dist/types/src/testing/logger.d.ts +1 -1
  57. package/dist/types/src/testing/logger.d.ts.map +1 -1
  58. package/dist/types/src/testing/services.d.ts +1 -1
  59. package/dist/types/src/testing/services.d.ts.map +1 -1
  60. package/dist/types/src/trace.d.ts +1 -1
  61. package/dist/types/src/trace.d.ts.map +1 -1
  62. package/dist/types/src/triggers/invocation-tracer.d.ts +3 -1
  63. package/dist/types/src/triggers/invocation-tracer.d.ts.map +1 -1
  64. package/dist/types/src/triggers/trigger-dispatcher.d.ts +7 -4
  65. package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +1 -1
  66. package/dist/types/src/triggers/trigger-state-store.d.ts +5 -4
  67. package/dist/types/src/triggers/trigger-state-store.d.ts.map +1 -1
  68. package/dist/types/src/types.d.ts +49 -30
  69. package/dist/types/src/types.d.ts.map +1 -1
  70. package/dist/types/src/url.d.ts +1 -1
  71. package/dist/types/src/url.d.ts.map +1 -1
  72. package/dist/types/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +27 -36
  74. package/src/bundler/bundler.ts +7 -3
  75. package/src/examples/fib.ts +4 -2
  76. package/src/examples/reply.ts +5 -2
  77. package/src/examples/sleep.ts +4 -2
  78. package/src/executor/executor.ts +5 -1
  79. package/src/handler.ts +33 -9
  80. package/src/schema.ts +5 -2
  81. package/src/services/credentials.ts +9 -2
  82. package/src/services/database.ts +6 -2
  83. package/src/services/event-logger.ts +4 -1
  84. package/src/services/function-invocation-service.test.ts +81 -0
  85. package/src/services/function-invocation-service.ts +84 -0
  86. package/src/services/index.ts +4 -3
  87. package/src/services/local-function-execution.ts +65 -26
  88. package/src/services/queues.ts +3 -1
  89. package/src/services/remote-function-execution-service.ts +38 -21
  90. package/src/services/service-container.ts +2 -1
  91. package/src/services/service-registry.test.ts +4 -1
  92. package/src/services/service-registry.ts +7 -3
  93. package/src/services/tracing.ts +17 -14
  94. package/src/testing/layer.ts +10 -7
  95. package/src/testing/logger.ts +2 -1
  96. package/src/testing/persist-database.test.ts +4 -4
  97. package/src/testing/services.ts +1 -1
  98. package/src/trace.ts +2 -2
  99. package/src/triggers/invocation-tracer.ts +3 -1
  100. package/src/triggers/trigger-dispatcher.test.ts +29 -16
  101. package/src/triggers/trigger-dispatcher.ts +29 -8
  102. package/src/triggers/trigger-state-store.ts +6 -5
  103. package/src/types.ts +30 -12
  104. package/src/url.ts +1 -1
  105. package/dist/lib/browser/chunk-D2XO7XXY.mjs.map +0 -7
  106. package/dist/lib/node-esm/chunk-Z4CJ62WS.mjs.map +0 -7
@@ -9,12 +9,16 @@ import {
9
9
  DatabaseService,
10
10
  FUNCTIONS_META_KEY,
11
11
  FUNCTIONS_PRESET_META_KEY,
12
+ FunctionError,
13
+ FunctionNotFoundError,
12
14
  MESSAGE_PROPERTY_TOOL_CALL_ID,
13
15
  QueueService,
14
16
  RemoteFunctionExecutionService,
15
17
  SERVICE_TAGS,
16
18
  ServiceContainer,
19
+ ServiceNotAvailableError,
17
20
  TracingService,
21
+ TriggerStateNotFoundError,
18
22
  createDefectLogger,
19
23
  createEventLogger,
20
24
  getInvocationUrl,
@@ -22,47 +26,21 @@ import {
22
26
  logCustomEvent,
23
27
  setUserFunctionIdInMetadata,
24
28
  withAuthorization
25
- } from "./chunk-Z4CJ62WS.mjs";
29
+ } from "./chunk-NAQIKLZB.mjs";
26
30
  import {
27
31
  __export
28
32
  } from "./chunk-HSLMI22Q.mjs";
29
33
 
30
- // src/errors.ts
31
- import { BaseError } from "@dxos/errors";
32
- var ServiceNotAvailableError = class extends BaseError.extend("SERVICE_NOT_AVAILABLE", "Service not available") {
33
- constructor(service, options) {
34
- super({
35
- context: {
36
- service
37
- },
38
- ...options
39
- });
40
- }
41
- };
42
- var FunctionNotFoundError = class extends BaseError.extend("FUNCTION_NOT_FOUND", "Function not found") {
43
- constructor(functionKey, options) {
44
- super({
45
- context: {
46
- function: functionKey
47
- },
48
- ...options
49
- });
50
- }
51
- };
52
- var FunctionError = class extends BaseError.extend("FUNCTION_ERROR", "Function invocation error") {
53
- };
54
- var TriggerStateNotFoundError = class extends BaseError.extend("TRIGGER_STATE_NOT_FOUND", "Trigger state not found") {
55
- };
56
-
57
34
  // src/handler.ts
58
- import { Effect, Schema as Schema2 } from "effect";
35
+ import * as Effect from "effect/Effect";
36
+ import * as Schema2 from "effect/Schema";
59
37
  import { Obj, Type as Type2 } from "@dxos/echo";
60
38
  import { assertArgument } from "@dxos/invariant";
61
39
 
62
40
  // src/schema.ts
63
- import { Schema } from "effect";
41
+ import * as Schema from "effect/Schema";
64
42
  import { Type } from "@dxos/echo";
65
- import { JsonSchemaType, LabelAnnotation, Ref } from "@dxos/echo-schema";
43
+ import { JsonSchemaType, LabelAnnotation, Ref } from "@dxos/echo/internal";
66
44
  import { DataType } from "@dxos/schema";
67
45
  var ScriptType = Schema.Struct({
68
46
  name: Schema.optional(Schema.String),
@@ -143,7 +121,7 @@ var defineFunction = ({ key, name, description, inputSchema, outputSchema = Sche
143
121
  };
144
122
  return {
145
123
  [typeId]: true,
146
- key: key ?? name,
124
+ key,
147
125
  name,
148
126
  description,
149
127
  inputSchema,
@@ -165,14 +143,20 @@ var FunctionDefinition = {
165
143
  return deserializeFunction(functionObj);
166
144
  }
167
145
  };
168
- var serializeFunction = (functionDef) => Obj.make(FunctionType, {
169
- key: functionDef.name,
170
- name: functionDef.name,
171
- version: "0.1.0",
172
- description: functionDef.description,
173
- inputSchema: Type2.toJsonSchema(functionDef.inputSchema),
174
- outputSchema: !functionDef.outputSchema ? void 0 : Type2.toJsonSchema(functionDef.outputSchema)
175
- });
146
+ var serializeFunction = (functionDef) => {
147
+ const fn6 = Obj.make(FunctionType, {
148
+ key: functionDef.key,
149
+ name: functionDef.name,
150
+ version: "0.1.0",
151
+ description: functionDef.description,
152
+ inputSchema: Type2.toJsonSchema(functionDef.inputSchema),
153
+ outputSchema: !functionDef.outputSchema ? void 0 : Type2.toJsonSchema(functionDef.outputSchema)
154
+ });
155
+ if (functionDef.meta?.deployedFunctionId) {
156
+ setUserFunctionIdInMetadata(Obj.getMeta(fn6), functionDef.meta.deployedFunctionId);
157
+ }
158
+ return fn6;
159
+ };
176
160
  var deserializeFunction = (functionObj) => {
177
161
  return {
178
162
  [typeId]: true,
@@ -182,22 +166,27 @@ var deserializeFunction = (functionObj) => {
182
166
  description: functionObj.description,
183
167
  inputSchema: !functionObj.inputSchema ? Schema2.Unknown : Type2.toEffectSchema(functionObj.inputSchema),
184
168
  outputSchema: !functionObj.outputSchema ? void 0 : Type2.toEffectSchema(functionObj.outputSchema),
169
+ // TODO(dmaretskyi): This should throw error.
185
170
  handler: () => {
171
+ },
172
+ meta: {
173
+ deployedFunctionId: getUserFunctionIdInMetadata(Obj.getMeta(functionObj))
186
174
  }
187
175
  };
188
176
  };
189
177
 
190
178
  // src/trace.ts
191
- import { Schema as Schema4 } from "effect";
179
+ import * as Schema4 from "effect/Schema";
192
180
  import { Type as Type4 } from "@dxos/echo";
181
+ import { ObjectId } from "@dxos/echo/internal";
193
182
  import { Queue } from "@dxos/echo-db";
194
- import { ObjectId } from "@dxos/echo-schema";
195
183
  import { log } from "@dxos/log";
196
184
 
197
185
  // src/types.ts
198
- import { Schema as Schema3, SchemaAST } from "effect";
199
- import { QueryAST, Type as Type3 } from "@dxos/echo";
200
- import { Expando, OptionsAnnotationId, RawObject, Ref as Ref2 } from "@dxos/echo-schema";
186
+ import * as Schema3 from "effect/Schema";
187
+ import * as SchemaAST from "effect/SchemaAST";
188
+ import { Obj as Obj2, QueryAST, Type as Type3 } from "@dxos/echo";
189
+ import { Expando, OptionsAnnotationId, RawObject, Ref as Ref2 } from "@dxos/echo/internal";
201
190
  import { DXN } from "@dxos/keys";
202
191
  var TriggerKinds = [
203
192
  "timer",
@@ -241,9 +230,12 @@ var WebhookTriggerSchema = Schema3.Struct({
241
230
  }).pipe(Schema3.mutable);
242
231
  var SubscriptionTriggerSchema = Schema3.Struct({
243
232
  kind: Schema3.Literal("subscription").annotations(kindLiteralAnnotations),
244
- query: QueryAST.Query.annotations({
245
- title: "Query"
246
- }),
233
+ query: Schema3.Struct({
234
+ raw: Schema3.optional(Schema3.String.annotations({
235
+ title: "Query"
236
+ })),
237
+ ast: QueryAST.Query
238
+ }).pipe(Schema3.mutable),
247
239
  options: Schema3.optional(Schema3.Struct({
248
240
  // Watch changes to object (not just creation).
249
241
  deep: Schema3.optional(Schema3.Boolean.annotations({
@@ -257,7 +249,7 @@ var SubscriptionTriggerSchema = Schema3.Struct({
257
249
  title: "Options"
258
250
  }))
259
251
  }).pipe(Schema3.mutable);
260
- var TriggerSchema = Schema3.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
252
+ var TriggerSchema = Schema3.Union(EmailTriggerSchema, QueueTriggerSchema, SubscriptionTriggerSchema, TimerTriggerSchema, WebhookTriggerSchema).annotations({
261
253
  title: "Trigger"
262
254
  });
263
255
  var EmailTriggerOutput = Schema3.mutable(Schema3.Struct({
@@ -281,10 +273,21 @@ var QueueTriggerOutput = Schema3.mutable(Schema3.Struct({
281
273
  item: Schema3.Any,
282
274
  cursor: Schema3.String
283
275
  }));
284
- var SubscriptionTriggerOutput = Schema3.mutable(Schema3.Struct({
276
+ var SubscriptionTriggerOutput = Schema3.Struct({
277
+ /**
278
+ * Type of the mutation.
279
+ */
280
+ // TODO(dmaretskyi): Specify enum.
285
281
  type: Schema3.String,
286
- changedObjectId: Schema3.String
287
- }));
282
+ /**
283
+ * Reference to the object that was changed or created.
284
+ */
285
+ subject: Type3.Ref(Obj2.Any),
286
+ /**
287
+ * @deprecated
288
+ */
289
+ changedObjectId: Schema3.optional(Schema3.String)
290
+ }).pipe(Schema3.mutable);
288
291
  var TimerTriggerOutput = Schema3.mutable(Schema3.Struct({
289
292
  tick: Schema3.Number
290
293
  }));
@@ -339,17 +342,17 @@ var FUNCTION_TYPES = [
339
342
 
340
343
  // src/trace.ts
341
344
  var __dxlog_file = "/__w/dxos/dxos/packages/core/functions/src/trace.ts";
342
- var InvocationOutcome = /* @__PURE__ */ function(InvocationOutcome2) {
345
+ var InvocationOutcome = /* @__PURE__ */ (function(InvocationOutcome2) {
343
346
  InvocationOutcome2["SUCCESS"] = "success";
344
347
  InvocationOutcome2["FAILURE"] = "failure";
345
348
  InvocationOutcome2["PENDING"] = "pending";
346
349
  return InvocationOutcome2;
347
- }({});
348
- var InvocationTraceEventType = /* @__PURE__ */ function(InvocationTraceEventType2) {
350
+ })({});
351
+ var InvocationTraceEventType = /* @__PURE__ */ (function(InvocationTraceEventType2) {
349
352
  InvocationTraceEventType2["START"] = "start";
350
353
  InvocationTraceEventType2["END"] = "end";
351
354
  return InvocationTraceEventType2;
352
- }({});
355
+ })({});
353
356
  var TraceEventException = Schema4.Struct({
354
357
  timestamp: Schema4.Number,
355
358
  message: Schema4.String,
@@ -483,13 +486,26 @@ var createInvocationSpans = (items) => {
483
486
  };
484
487
 
485
488
  // src/triggers/invocation-tracer.ts
486
- import { Context as Context2, Effect as Effect3, Layer as Layer2 } from "effect";
487
- import { Obj as Obj2, Ref as Ref3 } from "@dxos/echo";
489
+ import * as Context3 from "effect/Context";
490
+ import * as Effect4 from "effect/Effect";
491
+ import * as Layer3 from "effect/Layer";
492
+ import { Obj as Obj3, Ref as Ref3 } from "@dxos/echo";
488
493
  import { DXN as DXN2, ObjectId as ObjectId2 } from "@dxos/keys";
489
494
 
495
+ // src/services/function-invocation-service.ts
496
+ import * as Context2 from "effect/Context";
497
+ import * as Effect3 from "effect/Effect";
498
+ import * as Layer2 from "effect/Layer";
499
+ import { AiService as AiService2 } from "@dxos/ai";
500
+
490
501
  // src/services/local-function-execution.ts
491
- import { Context, Effect as Effect2, Layer, Schema as Schema5 } from "effect";
502
+ import * as Context from "effect/Context";
503
+ import * as Effect2 from "effect/Effect";
504
+ import * as Layer from "effect/Layer";
505
+ import * as Schema5 from "effect/Schema";
506
+ import { AiService } from "@dxos/ai";
492
507
  import { todo } from "@dxos/debug";
508
+ import { log as log2 } from "@dxos/log";
493
509
  function _define_property(obj, key, value) {
494
510
  if (key in obj) {
495
511
  Object.defineProperty(obj, key, {
@@ -503,25 +519,40 @@ function _define_property(obj, key, value) {
503
519
  }
504
520
  return obj;
505
521
  }
522
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions/src/services/local-function-execution.ts";
506
523
  var _Context_Tag;
507
524
  var LocalFunctionExecutionService = class extends (_Context_Tag = Context.Tag("@dxos/functions/LocalFunctionExecutionService")()) {
508
525
  };
509
- _define_property(LocalFunctionExecutionService, "layer", Layer.succeed(LocalFunctionExecutionService, {
510
- invokeFunction: (functionDef, input) => invokeFunction(functionDef, input)
511
- }));
512
526
  _define_property(LocalFunctionExecutionService, "layerLive", Layer.effect(LocalFunctionExecutionService, Effect2.gen(function* () {
513
527
  const resolver = yield* FunctionImplementationResolver;
528
+ const ai = yield* AiService.AiService;
529
+ const credentials = yield* CredentialsService;
530
+ const database = yield* DatabaseService;
531
+ const queues = yield* QueueService;
532
+ const functionCallService = yield* RemoteFunctionExecutionService;
514
533
  return {
515
- invokeFunction: Effect2.fn("invokeFunction")(function* (functionDef, input) {
534
+ // TODO(dmaretskyi): Better error types.
535
+ invokeFunction: (functionDef, input) => Effect2.gen(function* () {
516
536
  const resolved = yield* resolver.resolveFunctionImplementation(functionDef).pipe(Effect2.orDie);
517
- return yield* invokeFunction(resolved, input);
518
- })
537
+ const output = yield* invokeFunction(resolved, input);
538
+ return output;
539
+ }).pipe(Effect2.provideService(AiService.AiService, ai), Effect2.provideService(CredentialsService, credentials), Effect2.provideService(DatabaseService, database), Effect2.provideService(QueueService, queues), Effect2.provideService(RemoteFunctionExecutionService, functionCallService))
519
540
  };
520
541
  })));
521
542
  _define_property(LocalFunctionExecutionService, "invokeFunction", Effect2.serviceFunctionEffect(LocalFunctionExecutionService, (_) => _.invokeFunction));
522
543
  var invokeFunction = (functionDef, input) => Effect2.gen(function* () {
523
- const assertInput = functionDef.inputSchema.pipe(Schema5.asserts);
524
- assertInput(input);
544
+ try {
545
+ const assertInput = functionDef.inputSchema.pipe(Schema5.asserts);
546
+ assertInput(input);
547
+ } catch (e) {
548
+ throw new FunctionError({
549
+ message: "Invalid function input",
550
+ context: {
551
+ name: functionDef.name
552
+ },
553
+ cause: e
554
+ });
555
+ }
525
556
  const context = {
526
557
  space: void 0,
527
558
  getService: () => todo(),
@@ -529,6 +560,15 @@ var invokeFunction = (functionDef, input) => Effect2.gen(function* () {
529
560
  throw new Error("Not available. Use the database service instead.");
530
561
  }
531
562
  };
563
+ log2.info("invoking function", {
564
+ name: functionDef.name,
565
+ input
566
+ }, {
567
+ F: __dxlog_file2,
568
+ L: 98,
569
+ S: this,
570
+ C: (f, a) => f(...a)
571
+ });
532
572
  const data = yield* Effect2.gen(function* () {
533
573
  const result = functionDef.handler({
534
574
  context,
@@ -547,8 +587,28 @@ var invokeFunction = (functionDef, input) => Effect2.gen(function* () {
547
587
  },
548
588
  cause: defect
549
589
  }))));
550
- const assertOutput = functionDef.outputSchema?.pipe(Schema5.asserts);
551
- assertOutput(data);
590
+ log2.info("completed", {
591
+ function: functionDef.name,
592
+ input,
593
+ data
594
+ }, {
595
+ F: __dxlog_file2,
596
+ L: 122,
597
+ S: this,
598
+ C: (f, a) => f(...a)
599
+ });
600
+ try {
601
+ const assertOutput = functionDef.outputSchema?.pipe(Schema5.asserts);
602
+ assertOutput(data);
603
+ } catch (e) {
604
+ throw new FunctionError({
605
+ message: "Invalid function output",
606
+ context: {
607
+ name: functionDef.name
608
+ },
609
+ cause: e
610
+ });
611
+ }
552
612
  return data;
553
613
  }).pipe(Effect2.withSpan("invokeFunction", {
554
614
  attributes: {
@@ -560,7 +620,7 @@ var FunctionImplementationResolver = class extends (_Context_Tag1 = Context.Tag(
560
620
  };
561
621
  _define_property(FunctionImplementationResolver, "layerTest", ({ functions }) => Layer.succeed(FunctionImplementationResolver, {
562
622
  resolveFunctionImplementation: (functionDef) => {
563
- const resolved = functions.find((f) => f.name === functionDef.name);
623
+ const resolved = functions.find((f) => f.key === functionDef.key);
564
624
  if (!resolved) {
565
625
  return Effect2.fail(new FunctionNotFoundError(functionDef.name));
566
626
  }
@@ -568,7 +628,7 @@ _define_property(FunctionImplementationResolver, "layerTest", ({ functions }) =>
568
628
  }
569
629
  }));
570
630
 
571
- // src/triggers/invocation-tracer.ts
631
+ // src/services/function-invocation-service.ts
572
632
  function _define_property2(obj, key, value) {
573
633
  if (key in obj) {
574
634
  Object.defineProperty(obj, key, {
@@ -583,17 +643,54 @@ function _define_property2(obj, key, value) {
583
643
  return obj;
584
644
  }
585
645
  var _Context_Tag2;
586
- var InvocationTracer = class extends (_Context_Tag2 = Context2.Tag("@dxos/functions/InvocationTracer")()) {
646
+ var FunctionInvocationService = class extends (_Context_Tag2 = Context2.Tag("@dxos/functions/FunctionInvocationService")()) {
647
+ };
648
+ _define_property2(FunctionInvocationService, "invokeFunction", Effect3.serviceFunctionEffect(FunctionInvocationService, (_) => _.invokeFunction));
649
+ _define_property2(FunctionInvocationService, "layer", Layer2.effect(FunctionInvocationService, Effect3.gen(function* () {
650
+ const localExecutioner = yield* LocalFunctionExecutionService;
651
+ const remoteExecutioner = yield* RemoteFunctionExecutionService;
652
+ return {
653
+ invokeFunction: (functionDef, input) => Effect3.gen(function* () {
654
+ if (functionDef.meta?.deployedFunctionId) {
655
+ return yield* remoteExecutioner.callFunction(functionDef.meta.deployedFunctionId, input);
656
+ }
657
+ return yield* localExecutioner.invokeFunction(functionDef, input);
658
+ })
659
+ };
660
+ })));
661
+ _define_property2(FunctionInvocationService, "layerTest", ({ functions = [] } = {}) => FunctionInvocationService.layer.pipe(Layer2.provide(LocalFunctionExecutionService.layerLive), Layer2.provide(FunctionImplementationResolver.layerTest({
662
+ functions
663
+ })), Layer2.provide(RemoteFunctionExecutionService.layerMock)));
664
+ _define_property2(FunctionInvocationService, "layerTestMocked", ({ functions }) => FunctionInvocationService.layerTest({
665
+ functions
666
+ }).pipe(Layer2.provide(AiService2.notAvailable), Layer2.provide(CredentialsService.configuredLayer([])), Layer2.provide(DatabaseService.notAvailable), Layer2.provide(QueueService.notAvailable)));
667
+
668
+ // src/triggers/invocation-tracer.ts
669
+ function _define_property3(obj, key, value) {
670
+ if (key in obj) {
671
+ Object.defineProperty(obj, key, {
672
+ value,
673
+ enumerable: true,
674
+ configurable: true,
675
+ writable: true
676
+ });
677
+ } else {
678
+ obj[key] = value;
679
+ }
680
+ return obj;
681
+ }
682
+ var _Context_Tag3;
683
+ var InvocationTracer = class extends (_Context_Tag3 = Context3.Tag("@dxos/functions/InvocationTracer")()) {
587
684
  };
588
- _define_property2(InvocationTracer, "layerLive", (opts) => Layer2.effect(InvocationTracer, Effect3.gen(function* () {
685
+ _define_property3(InvocationTracer, "layerLive", (opts) => Layer3.effect(InvocationTracer, Effect4.gen(function* () {
589
686
  return {
590
- traceInvocationStart: Effect3.fn("traceInvocationStart")(function* ({ payload, target }) {
687
+ traceInvocationStart: Effect4.fn("traceInvocationStart")(function* ({ payload, target }) {
591
688
  const invocationId = ObjectId2.random();
592
689
  const invocationTraceQueue = yield* QueueService.createQueue({
593
690
  subspaceTag: "trace"
594
691
  });
595
692
  const now = Date.now();
596
- const traceEvent = Obj2.make(InvocationTraceStartEvent, {
693
+ const traceEvent = Obj3.make(InvocationTraceStartEvent, {
597
694
  type: InvocationTraceEventType.START,
598
695
  invocationId,
599
696
  timestamp: now,
@@ -611,9 +708,9 @@ _define_property2(InvocationTracer, "layerLive", (opts) => Layer2.effect(Invocat
611
708
  invocationTraceQueue
612
709
  };
613
710
  }),
614
- traceInvocationEnd: Effect3.fn("traceInvocationEnd")(function* ({ trace, exception }) {
711
+ traceInvocationEnd: Effect4.fn("traceInvocationEnd")(function* ({ trace, exception }) {
615
712
  const now = Date.now();
616
- const traceEvent = Obj2.make(InvocationTraceEndEvent, {
713
+ const traceEvent = Obj3.make(InvocationTraceEndEvent, {
617
714
  type: InvocationTraceEventType.END,
618
715
  invocationId: trace.invocationId,
619
716
  timestamp: now,
@@ -631,7 +728,7 @@ _define_property2(InvocationTracer, "layerLive", (opts) => Layer2.effect(Invocat
631
728
  })
632
729
  };
633
730
  })));
634
- _define_property2(InvocationTracer, "layerTest", Layer2.unwrapEffect(Effect3.gen(function* () {
731
+ _define_property3(InvocationTracer, "layerTest", Layer3.unwrapEffect(Effect4.gen(function* () {
635
732
  const queue = yield* QueueService.createQueue({
636
733
  subspaceTag: "trace"
637
734
  });
@@ -641,11 +738,22 @@ _define_property2(InvocationTracer, "layerTest", Layer2.unwrapEffect(Effect3.gen
641
738
  })));
642
739
 
643
740
  // src/triggers/trigger-dispatcher.ts
644
- import { Cause, Context as Context4, Cron, Duration, Effect as Effect5, Either, Exit, Fiber, Layer as Layer4, Option as Option2, Record, Schedule } from "effect";
645
- import { DXN as DXN3, Filter, Obj as Obj3, Query } from "@dxos/echo";
741
+ import * as Cause from "effect/Cause";
742
+ import * as Context5 from "effect/Context";
743
+ import * as Cron from "effect/Cron";
744
+ import * as Duration from "effect/Duration";
745
+ import * as Effect6 from "effect/Effect";
746
+ import * as Either from "effect/Either";
747
+ import * as Exit from "effect/Exit";
748
+ import * as Fiber from "effect/Fiber";
749
+ import * as Layer5 from "effect/Layer";
750
+ import * as Option2 from "effect/Option";
751
+ import * as Record3 from "effect/Record";
752
+ import * as Schedule from "effect/Schedule";
753
+ import { DXN as DXN3, Filter, Obj as Obj4, Query } from "@dxos/echo";
646
754
  import { causeToError } from "@dxos/effect";
647
755
  import { invariant } from "@dxos/invariant";
648
- import { log as log2 } from "@dxos/log";
756
+ import { log as log3 } from "@dxos/log";
649
757
  import { KEY_QUEUE_POSITION } from "@dxos/protocols";
650
758
 
651
759
  // src/triggers/input-builder.ts
@@ -672,13 +780,14 @@ var createInvocationPayload = (trigger, event) => {
672
780
  };
673
781
 
674
782
  // src/triggers/trigger-state-store.ts
675
- import { KeyValueStore } from "@effect/platform";
676
- import { Context as Context3 } from "effect";
677
- import { Schema as Schema6 } from "effect";
678
- import { Effect as Effect4, Layer as Layer3 } from "effect";
679
- import { Option } from "effect";
783
+ import * as KeyValueStore from "@effect/platform/KeyValueStore";
784
+ import * as Context4 from "effect/Context";
785
+ import * as Effect5 from "effect/Effect";
786
+ import * as Layer4 from "effect/Layer";
787
+ import * as Option from "effect/Option";
788
+ import * as Schema6 from "effect/Schema";
680
789
  import { ObjectId as ObjectId3 } from "@dxos/keys";
681
- function _define_property3(obj, key, value) {
790
+ function _define_property4(obj, key, value) {
682
791
  if (key in obj) {
683
792
  Object.defineProperty(obj, key, {
684
793
  value,
@@ -701,32 +810,32 @@ var TriggerState = Schema6.Struct({
701
810
  })
702
811
  })))
703
812
  });
704
- var _Context_Tag3;
705
- var TriggerStateStore = class extends (_Context_Tag3 = Context3.Tag("@dxos/functions/TriggerStateStore")()) {
813
+ var _Context_Tag4;
814
+ var TriggerStateStore = class extends (_Context_Tag4 = Context4.Tag("@dxos/functions/TriggerStateStore")()) {
706
815
  };
707
- _define_property3(TriggerStateStore, "getState", Effect4.serviceFunctionEffect(TriggerStateStore, (_) => _.getState));
708
- _define_property3(TriggerStateStore, "saveState", Effect4.serviceFunctionEffect(TriggerStateStore, (_) => _.saveState));
709
- _define_property3(TriggerStateStore, "layerKv", Layer3.effect(TriggerStateStore, Effect4.gen(function* () {
816
+ _define_property4(TriggerStateStore, "getState", Effect5.serviceFunctionEffect(TriggerStateStore, (_) => _.getState));
817
+ _define_property4(TriggerStateStore, "saveState", Effect5.serviceFunctionEffect(TriggerStateStore, (_) => _.saveState));
818
+ _define_property4(TriggerStateStore, "layerKv", Layer4.effect(TriggerStateStore, Effect5.gen(function* () {
710
819
  const kv = yield* KeyValueStore.KeyValueStore;
711
820
  const schemaStore = kv.forSchema(Schema6.parseJson(TriggerState));
712
821
  const store = {
713
- getState: Effect4.fn("TriggerStateStore.getState")(function* (triggerId) {
714
- const valueOption = yield* schemaStore.get(triggerId).pipe(Effect4.orDie);
822
+ getState: Effect5.fn("TriggerStateStore.getState")(function* (triggerId) {
823
+ const valueOption = yield* schemaStore.get(triggerId).pipe(Effect5.orDie);
715
824
  if (Option.isNone(valueOption)) {
716
- return yield* Effect4.fail(new TriggerStateNotFoundError());
825
+ return yield* Effect5.fail(new TriggerStateNotFoundError());
717
826
  }
718
827
  return valueOption.value;
719
828
  }),
720
- saveState: Effect4.fn("TriggerStateStore.saveState")(function* (state) {
721
- yield* schemaStore.set(state.triggerId, state).pipe(Effect4.orDie);
829
+ saveState: Effect5.fn("TriggerStateStore.saveState")(function* (state) {
830
+ yield* schemaStore.set(state.triggerId, state).pipe(Effect5.orDie);
722
831
  })
723
832
  };
724
833
  return store;
725
834
  })));
726
- _define_property3(TriggerStateStore, "layerMemory", TriggerStateStore.layerKv.pipe(Layer3.provide(KeyValueStore.layerMemory)));
835
+ _define_property4(TriggerStateStore, "layerMemory", TriggerStateStore.layerKv.pipe(Layer4.provide(KeyValueStore.layerMemory)));
727
836
 
728
837
  // src/triggers/trigger-dispatcher.ts
729
- function _define_property4(obj, key, value) {
838
+ function _define_property5(obj, key, value) {
730
839
  if (key in obj) {
731
840
  Object.defineProperty(obj, key, {
732
841
  value,
@@ -739,11 +848,11 @@ function _define_property4(obj, key, value) {
739
848
  }
740
849
  return obj;
741
850
  }
742
- var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions/src/triggers/trigger-dispatcher.ts";
743
- var _Context_Tag4;
744
- var TriggerDispatcher = class extends (_Context_Tag4 = Context4.Tag("@dxos/functions/TriggerDispatcher")()) {
851
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions/src/triggers/trigger-dispatcher.ts";
852
+ var _Context_Tag5;
853
+ var TriggerDispatcher = class extends (_Context_Tag5 = Context5.Tag("@dxos/functions/TriggerDispatcher")()) {
745
854
  };
746
- _define_property4(TriggerDispatcher, "layer", (options) => Layer4.effect(TriggerDispatcher, Effect5.gen(function* () {
855
+ _define_property5(TriggerDispatcher, "layer", (options) => Layer5.effect(TriggerDispatcher, Effect6.gen(function* () {
747
856
  return new TriggerDispatcherImpl(options);
748
857
  })));
749
858
  var TriggerDispatcherImpl = class {
@@ -751,44 +860,44 @@ var TriggerDispatcherImpl = class {
751
860
  return this._running;
752
861
  }
753
862
  constructor(options) {
754
- _define_property4(this, "livePollInterval", void 0);
755
- _define_property4(this, "timeControl", void 0);
756
- _define_property4(this, "_running", false);
757
- _define_property4(this, "_internalTime", void 0);
758
- _define_property4(this, "_timerFiber", void 0);
759
- _define_property4(this, "_scheduledTriggers", /* @__PURE__ */ new Map());
760
- _define_property4(this, "start", () => Effect5.gen(this, function* () {
863
+ _define_property5(this, "livePollInterval", void 0);
864
+ _define_property5(this, "timeControl", void 0);
865
+ _define_property5(this, "_running", false);
866
+ _define_property5(this, "_internalTime", void 0);
867
+ _define_property5(this, "_timerFiber", void 0);
868
+ _define_property5(this, "_scheduledTriggers", /* @__PURE__ */ new Map());
869
+ _define_property5(this, "start", () => Effect6.gen(this, function* () {
761
870
  if (this._running) {
762
871
  return;
763
872
  }
764
873
  this._running = true;
765
874
  if (this.timeControl === "natural") {
766
- this._timerFiber = yield* this._startNaturalTimeProcessing().pipe(Effect5.tapErrorCause((cause) => {
875
+ this._timerFiber = yield* this._startNaturalTimeProcessing().pipe(Effect6.tapErrorCause((cause) => {
767
876
  const error = causeToError(cause);
768
- log2.error("trigger dispatcher error", {
877
+ log3.error("trigger dispatcher error", {
769
878
  error
770
879
  }, {
771
- F: __dxlog_file2,
772
- L: 170,
880
+ F: __dxlog_file3,
881
+ L: 187,
773
882
  S: this,
774
883
  C: (f, a) => f(...a)
775
884
  });
776
885
  this._running = false;
777
- return Effect5.void;
778
- }), Effect5.forkDaemon);
886
+ return Effect6.void;
887
+ }), Effect6.forkDaemon);
779
888
  } else {
780
- return yield* Effect5.dieMessage("TriggerDispatcher started in manual time control mode");
889
+ return yield* Effect6.dieMessage("TriggerDispatcher started in manual time control mode");
781
890
  }
782
- log2.info("TriggerDispatcher started", {
891
+ log3.info("TriggerDispatcher started", {
783
892
  timeControl: this.timeControl
784
893
  }, {
785
- F: __dxlog_file2,
786
- L: 180,
894
+ F: __dxlog_file3,
895
+ L: 197,
787
896
  S: this,
788
897
  C: (f, a) => f(...a)
789
898
  });
790
899
  }));
791
- _define_property4(this, "stop", () => Effect5.gen(this, function* () {
900
+ _define_property5(this, "stop", () => Effect6.gen(this, function* () {
792
901
  if (!this._running) {
793
902
  return;
794
903
  }
@@ -798,22 +907,22 @@ var TriggerDispatcherImpl = class {
798
907
  this._timerFiber = void 0;
799
908
  }
800
909
  this._scheduledTriggers.clear();
801
- log2.info("TriggerDispatcher stopped", void 0, {
802
- F: __dxlog_file2,
803
- L: 200,
910
+ log3.info("TriggerDispatcher stopped", void 0, {
911
+ F: __dxlog_file3,
912
+ L: 217,
804
913
  S: this,
805
914
  C: (f, a) => f(...a)
806
915
  });
807
916
  }));
808
- _define_property4(this, "invokeTrigger", (options2) => Effect5.gen(this, function* () {
917
+ _define_property5(this, "invokeTrigger", (options2) => Effect6.gen(this, function* () {
809
918
  const { trigger, event } = options2;
810
- log2.info("running trigger", {
919
+ log3.info("running trigger", {
811
920
  triggerId: trigger.id,
812
921
  spec: trigger.spec,
813
922
  event
814
923
  }, {
815
- F: __dxlog_file2,
816
- L: 208,
924
+ F: __dxlog_file3,
925
+ L: 225,
817
926
  S: this,
818
927
  C: (f, a) => f(...a)
819
928
  });
@@ -829,17 +938,17 @@ var TriggerDispatcherImpl = class {
829
938
  data: event
830
939
  }
831
940
  });
832
- const result = yield* Effect5.gen(this, function* () {
941
+ const result = yield* Effect6.gen(this, function* () {
833
942
  if (!trigger.enabled) {
834
- return yield* Effect5.dieMessage("Attempting to invoke disabled trigger");
943
+ return yield* Effect6.dieMessage("Attempting to invoke disabled trigger");
835
944
  }
836
945
  if (!trigger.function) {
837
- return yield* Effect5.dieMessage("Trigger has no function reference");
946
+ return yield* Effect6.dieMessage("Trigger has no function reference");
838
947
  }
839
- const serialiedFunction = yield* DatabaseService.load(trigger.function).pipe(Effect5.orDie);
840
- invariant(Obj3.instanceOf(FunctionType, serialiedFunction), void 0, {
841
- F: __dxlog_file2,
842
- L: 235,
948
+ const serialiedFunction = yield* DatabaseService.load(trigger.function).pipe(Effect6.orDie);
949
+ invariant(Obj4.instanceOf(FunctionType, serialiedFunction), void 0, {
950
+ F: __dxlog_file3,
951
+ L: 252,
843
952
  S: this,
844
953
  A: [
845
954
  "Obj.instanceOf(FunctionType, serialiedFunction)",
@@ -848,27 +957,27 @@ var TriggerDispatcherImpl = class {
848
957
  });
849
958
  const functionDef = deserializeFunction(serialiedFunction);
850
959
  const inputData = this._prepareInputData(trigger, event);
851
- return yield* LocalFunctionExecutionService.invokeFunction(functionDef, inputData).pipe(Effect5.provide(ComputeEventLogger.layerFromTracing.pipe(Layer4.provideMerge(TracingService.layerQueue(trace.invocationTraceQueue)))));
852
- }).pipe(Effect5.exit);
960
+ return yield* FunctionInvocationService.invokeFunction(functionDef, inputData).pipe(Effect6.provide(ComputeEventLogger.layerFromTracing.pipe(Layer5.provideMerge(TracingService.layerQueue(trace.invocationTraceQueue)))));
961
+ }).pipe(Effect6.exit);
853
962
  const triggerExecutionResult = {
854
963
  triggerId: trigger.id,
855
964
  result
856
965
  };
857
966
  if (Exit.isSuccess(result)) {
858
- log2.info("trigger execution success", {
967
+ log3.info("trigger execution success", {
859
968
  triggerId: trigger.id
860
969
  }, {
861
- F: __dxlog_file2,
862
- L: 256,
970
+ F: __dxlog_file3,
971
+ L: 273,
863
972
  S: this,
864
973
  C: (f, a) => f(...a)
865
974
  });
866
975
  } else {
867
- log2.error("trigger execution failure", {
976
+ log3.error("trigger execution failure", {
868
977
  error: causeToError(result.cause)
869
978
  }, {
870
- F: __dxlog_file2,
871
- L: 260,
979
+ F: __dxlog_file3,
980
+ L: 277,
872
981
  S: this,
873
982
  C: (f, a) => f(...a)
874
983
  });
@@ -880,11 +989,11 @@ var TriggerDispatcherImpl = class {
880
989
  });
881
990
  return triggerExecutionResult;
882
991
  }));
883
- _define_property4(this, "invokeScheduledTriggers", ({ kinds = [
992
+ _define_property5(this, "invokeScheduledTriggers", ({ kinds = [
884
993
  "timer",
885
994
  "queue",
886
995
  "subscription"
887
- ] } = {}) => Effect5.gen(this, function* () {
996
+ ] } = {}) => Effect6.gen(this, function* () {
888
997
  const invocations = [];
889
998
  for (const kind of kinds) {
890
999
  switch (kind) {
@@ -899,7 +1008,7 @@ var TriggerDispatcherImpl = class {
899
1008
  scheduledTrigger.nextExecution = Cron.next(scheduledTrigger.cron, now);
900
1009
  }
901
1010
  }
902
- invocations.push(...yield* Effect5.forEach(triggersToInvoke, (trigger) => this.invokeTrigger({
1011
+ invocations.push(...yield* Effect6.forEach(triggersToInvoke, (trigger) => this.invokeTrigger({
903
1012
  trigger,
904
1013
  event: {
905
1014
  tick: now.getTime()
@@ -916,11 +1025,11 @@ var TriggerDispatcherImpl = class {
916
1025
  if (spec?.kind !== "queue") {
917
1026
  continue;
918
1027
  }
919
- const cursor = Obj3.getKeys(trigger, KEY_QUEUE_CURSOR).at(0)?.id;
1028
+ const cursor = Obj4.getKeys(trigger, KEY_QUEUE_CURSOR).at(0)?.id;
920
1029
  const queue = yield* QueueService.getQueue(DXN3.parse(spec.queue));
921
- const objects = yield* Effect5.promise(() => queue.queryObjects());
1030
+ const objects = yield* Effect6.promise(() => queue.queryObjects());
922
1031
  for (const object of objects) {
923
- const objectPos = Obj3.getKeys(object, KEY_QUEUE_POSITION).at(0)?.id;
1032
+ const objectPos = Obj4.getKeys(object, KEY_QUEUE_POSITION).at(0)?.id;
924
1033
  if (!objectPos || cursor && parseInt(cursor) >= parseInt(objectPos)) {
925
1034
  continue;
926
1035
  }
@@ -932,8 +1041,8 @@ var TriggerDispatcherImpl = class {
932
1041
  cursor: objectPos
933
1042
  }
934
1043
  }));
935
- Obj3.deleteKeys(trigger, KEY_QUEUE_CURSOR);
936
- Obj3.getMeta(trigger).keys.push({
1044
+ Obj4.deleteKeys(trigger, KEY_QUEUE_CURSOR);
1045
+ Obj4.getMeta(trigger).keys.push({
937
1046
  source: KEY_QUEUE_CURSOR,
938
1047
  id: objectPos
939
1048
  });
@@ -946,12 +1055,12 @@ var TriggerDispatcherImpl = class {
946
1055
  case "subscription": {
947
1056
  const triggers = yield* this._fetchTriggers();
948
1057
  for (const trigger of triggers) {
949
- const spec = Obj3.getSnapshot(trigger).spec;
1058
+ const spec = Obj4.getSnapshot(trigger).spec;
950
1059
  if (spec?.kind !== "subscription") {
951
1060
  continue;
952
1061
  }
953
- const { objects } = yield* DatabaseService.runQuery(Query.fromAst(spec.query));
954
- const state = yield* TriggerStateStore.getState(trigger.id).pipe(Effect5.catchTag("TRIGGER_STATE_NOT_FOUND", () => Effect5.succeed({
1062
+ const { objects } = yield* DatabaseService.runQuery(Query.fromAst(spec.query.ast));
1063
+ const state = yield* TriggerStateStore.getState(trigger.id).pipe(Effect6.catchTag("TRIGGER_STATE_NOT_FOUND", () => Effect6.succeed({
955
1064
  version: "1",
956
1065
  triggerId: trigger.id,
957
1066
  state: {
@@ -960,8 +1069,8 @@ var TriggerDispatcherImpl = class {
960
1069
  }
961
1070
  })));
962
1071
  invariant(state.state?._tag === "subscription", void 0, {
963
- F: __dxlog_file2,
964
- L: 373,
1072
+ F: __dxlog_file3,
1073
+ L: 390,
965
1074
  S: this,
966
1075
  A: [
967
1076
  "state.state?._tag === 'subscription'",
@@ -970,21 +1079,23 @@ var TriggerDispatcherImpl = class {
970
1079
  });
971
1080
  let updated = false;
972
1081
  for (const object of objects) {
973
- const existingVersion = Record.get(state.state.processedVersions, object.id).pipe(Option2.map(Obj3.decodeVersion));
974
- const currentVersion = Obj3.version(object);
975
- const run = Option2.isNone(existingVersion) || Obj3.compareVersions(currentVersion, existingVersion.value) === "different";
1082
+ const existingVersion = Record3.get(state.state.processedVersions, object.id).pipe(Option2.map(Obj4.decodeVersion));
1083
+ const currentVersion = Obj4.version(object);
1084
+ const run = Option2.isNone(existingVersion) || Obj4.compareVersions(currentVersion, existingVersion.value) === "different";
976
1085
  if (!run) {
977
1086
  continue;
978
1087
  }
1088
+ const { db } = yield* DatabaseService;
979
1089
  invocations.push(yield* this.invokeTrigger({
980
1090
  trigger,
981
1091
  event: {
982
1092
  // TODO(dmaretskyi): Change type not supported.
983
1093
  type: "unknown",
1094
+ subject: db.ref(Obj4.getDXN(object)),
984
1095
  changedObjectId: object.id
985
1096
  }
986
1097
  }));
987
- state.state.processedVersions[object.id] = Obj3.encodeVersion(currentVersion);
1098
+ state.state.processedVersions[object.id] = Obj4.encodeVersion(currentVersion);
988
1099
  updated = true;
989
1100
  }
990
1101
  if (updated) {
@@ -994,36 +1105,36 @@ var TriggerDispatcherImpl = class {
994
1105
  break;
995
1106
  }
996
1107
  default: {
997
- return yield* Effect5.dieMessage(`Unknown trigger kind: ${kind}`);
1108
+ return yield* Effect6.dieMessage(`Unknown trigger kind: ${kind}`);
998
1109
  }
999
1110
  }
1000
1111
  }
1001
1112
  return invocations;
1002
1113
  }));
1003
- _define_property4(this, "advanceTime", (duration) => Effect5.gen(this, function* () {
1114
+ _define_property5(this, "advanceTime", (duration) => Effect6.gen(this, function* () {
1004
1115
  if (this.timeControl !== "manual") {
1005
- return yield* Effect5.dieMessage("advanceTime can only be used in manual time control mode");
1116
+ return yield* Effect6.dieMessage("advanceTime can only be used in manual time control mode");
1006
1117
  }
1007
1118
  const millis = Duration.toMillis(duration);
1008
1119
  this._internalTime = new Date(this._internalTime.getTime() + millis);
1009
- log2("Advanced internal time", {
1120
+ log3("Advanced internal time", {
1010
1121
  newTime: this._internalTime,
1011
1122
  advancedBy: Duration.format(duration)
1012
1123
  }, {
1013
- F: __dxlog_file2,
1014
- L: 426,
1124
+ F: __dxlog_file3,
1125
+ L: 447,
1015
1126
  S: this,
1016
1127
  C: (f, a) => f(...a)
1017
1128
  });
1018
- }).pipe(Effect5.orDie));
1019
- _define_property4(this, "getCurrentTime", () => {
1129
+ }).pipe(Effect6.orDie));
1130
+ _define_property5(this, "getCurrentTime", () => {
1020
1131
  if (this.timeControl === "natural") {
1021
1132
  return /* @__PURE__ */ new Date();
1022
1133
  } else {
1023
1134
  return new Date(this._internalTime);
1024
1135
  }
1025
1136
  });
1026
- _define_property4(this, "refreshTriggers", () => Effect5.gen(this, function* () {
1137
+ _define_property5(this, "refreshTriggers", () => Effect6.gen(this, function* () {
1027
1138
  const triggers = yield* this._fetchTriggers();
1028
1139
  const currentTriggerIds = new Set(triggers.map((t) => t.id));
1029
1140
  for (const triggerId of this._scheduledTriggers.keys()) {
@@ -1040,14 +1151,14 @@ var TriggerDispatcherImpl = class {
1040
1151
  const existing = this._scheduledTriggers.get(trigger.id);
1041
1152
  const now = this.getCurrentTime();
1042
1153
  const nextExecution = existing?.nextExecution ?? Cron.next(cron, now);
1043
- log2("Updated scheduled trigger", {
1154
+ log3("Updated scheduled trigger", {
1044
1155
  triggerId: trigger.id,
1045
1156
  cron: timerSpec.cron,
1046
1157
  nextExecution,
1047
1158
  now
1048
1159
  }, {
1049
- F: __dxlog_file2,
1050
- L: 466,
1160
+ F: __dxlog_file3,
1161
+ L: 487,
1051
1162
  S: this,
1052
1163
  C: (f, a) => f(...a)
1053
1164
  });
@@ -1057,36 +1168,36 @@ var TriggerDispatcherImpl = class {
1057
1168
  nextExecution
1058
1169
  });
1059
1170
  } else {
1060
- log2.error("Invalid cron expression", {
1171
+ log3.error("Invalid cron expression", {
1061
1172
  triggerId: trigger.id,
1062
1173
  cron: timerSpec.cron,
1063
1174
  error: cronEither.left.message
1064
1175
  }, {
1065
- F: __dxlog_file2,
1066
- L: 478,
1176
+ F: __dxlog_file3,
1177
+ L: 499,
1067
1178
  S: this,
1068
1179
  C: (f, a) => f(...a)
1069
1180
  });
1070
1181
  }
1071
1182
  }
1072
1183
  }
1073
- log2("Updated scheduled triggers", {
1184
+ log3("Updated scheduled triggers", {
1074
1185
  count: this._scheduledTriggers.size
1075
1186
  }, {
1076
- F: __dxlog_file2,
1077
- L: 487,
1187
+ F: __dxlog_file3,
1188
+ L: 508,
1078
1189
  S: this,
1079
1190
  C: (f, a) => f(...a)
1080
1191
  });
1081
- }).pipe(Effect5.withSpan("TriggerDispatcher.refreshTriggers")));
1082
- _define_property4(this, "_fetchTriggers", () => Effect5.gen(this, function* () {
1192
+ }).pipe(Effect6.withSpan("TriggerDispatcher.refreshTriggers")));
1193
+ _define_property5(this, "_fetchTriggers", () => Effect6.gen(this, function* () {
1083
1194
  const { objects } = yield* DatabaseService.runQuery(Filter.type(FunctionTrigger));
1084
1195
  return objects;
1085
- }).pipe(Effect5.withSpan("TriggerDispatcher.fetchTriggers")));
1086
- _define_property4(this, "_startNaturalTimeProcessing", () => Effect5.gen(this, function* () {
1196
+ }).pipe(Effect6.withSpan("TriggerDispatcher.fetchTriggers")));
1197
+ _define_property5(this, "_startNaturalTimeProcessing", () => Effect6.gen(this, function* () {
1087
1198
  yield* this.invokeScheduledTriggers();
1088
- }).pipe(Effect5.repeat(Schedule.fixed(this.livePollInterval)), Effect5.asVoid));
1089
- _define_property4(this, "_prepareInputData", (trigger, event) => {
1199
+ }).pipe(Effect6.repeat(Schedule.fixed(this.livePollInterval)), Effect6.asVoid));
1200
+ _define_property5(this, "_prepareInputData", (trigger, event) => {
1090
1201
  return createInvocationPayload(trigger, event);
1091
1202
  });
1092
1203
  this.timeControl = options.timeControl;
@@ -1097,9 +1208,10 @@ var TriggerDispatcherImpl = class {
1097
1208
  var KEY_QUEUE_CURSOR = "dxos.org/key/local-trigger-dispatcher/queue-cursor";
1098
1209
 
1099
1210
  // src/executor/executor.ts
1100
- import { Effect as Effect6, Schema as Schema7 } from "effect";
1211
+ import * as Effect7 from "effect/Effect";
1212
+ import * as Schema7 from "effect/Schema";
1101
1213
  import { runAndForwardErrors } from "@dxos/effect";
1102
- function _define_property5(obj, key, value) {
1214
+ function _define_property6(obj, key, value) {
1103
1215
  if (key in obj) {
1104
1216
  Object.defineProperty(obj, key, {
1105
1217
  value,
@@ -1132,8 +1244,8 @@ var FunctionExecutor = class {
1132
1244
  data: input
1133
1245
  });
1134
1246
  let data;
1135
- if (Effect6.isEffect(result)) {
1136
- data = await result.pipe(Effect6.provide(this._services.createLayer()), runAndForwardErrors);
1247
+ if (Effect7.isEffect(result)) {
1248
+ data = await result.pipe(Effect7.provide(this._services.createLayer()), runAndForwardErrors);
1137
1249
  } else {
1138
1250
  data = await result;
1139
1251
  }
@@ -1142,7 +1254,7 @@ var FunctionExecutor = class {
1142
1254
  return data;
1143
1255
  }
1144
1256
  constructor(_services) {
1145
- _define_property5(this, "_services", void 0);
1257
+ _define_property6(this, "_services", void 0);
1146
1258
  this._services = _services;
1147
1259
  }
1148
1260
  };
@@ -1156,9 +1268,11 @@ __export(examples_exports, {
1156
1268
  });
1157
1269
 
1158
1270
  // src/examples/fib.ts
1159
- import { Effect as Effect7, Schema as Schema8 } from "effect";
1271
+ import * as Effect8 from "effect/Effect";
1272
+ import * as Schema8 from "effect/Schema";
1160
1273
  var fib_default = defineFunction({
1161
- name: "example.org/function/fib",
1274
+ key: "example.org/function/fib",
1275
+ name: "Fibonacci",
1162
1276
  description: "Function that calculates a Fibonacci number",
1163
1277
  inputSchema: Schema8.Struct({
1164
1278
  iterations: Schema8.optional(Schema8.Number).annotations({
@@ -1169,7 +1283,7 @@ var fib_default = defineFunction({
1169
1283
  outputSchema: Schema8.Struct({
1170
1284
  result: Schema8.String
1171
1285
  }),
1172
- handler: Effect7.fn(function* ({ data: { iterations = 1e5 } }) {
1286
+ handler: Effect8.fn(function* ({ data: { iterations = 1e5 } }) {
1173
1287
  let a = 0n;
1174
1288
  let b = 1n;
1175
1289
  for (let i = 0; i < iterations; i++) {
@@ -1183,13 +1297,16 @@ var fib_default = defineFunction({
1183
1297
  });
1184
1298
 
1185
1299
  // src/examples/reply.ts
1186
- import { Console, Effect as Effect8, Schema as Schema9 } from "effect";
1300
+ import * as Console from "effect/Console";
1301
+ import * as Effect9 from "effect/Effect";
1302
+ import * as Schema9 from "effect/Schema";
1187
1303
  var reply_default = defineFunction({
1188
- name: "example.org/function/reply",
1304
+ key: "example.org/function/reply",
1305
+ name: "Reply",
1189
1306
  description: "Function that echoes the input",
1190
1307
  inputSchema: Schema9.Any,
1191
1308
  outputSchema: Schema9.Any,
1192
- handler: Effect8.fn(function* ({ data }) {
1309
+ handler: Effect9.fn(function* ({ data }) {
1193
1310
  yield* Console.log("reply", {
1194
1311
  data
1195
1312
  });
@@ -1198,9 +1315,11 @@ var reply_default = defineFunction({
1198
1315
  });
1199
1316
 
1200
1317
  // src/examples/sleep.ts
1201
- import { Effect as Effect9, Schema as Schema10 } from "effect";
1318
+ import * as Effect10 from "effect/Effect";
1319
+ import * as Schema10 from "effect/Schema";
1202
1320
  var sleep_default = defineFunction({
1203
- name: "example.org/function/sleep",
1321
+ key: "example.org/function/sleep",
1322
+ name: "Sleep",
1204
1323
  description: "Function that sleeps for a given amount of time",
1205
1324
  inputSchema: Schema10.Struct({
1206
1325
  duration: Schema10.optional(Schema10.Number).annotations({
@@ -1209,8 +1328,8 @@ var sleep_default = defineFunction({
1209
1328
  })
1210
1329
  }),
1211
1330
  outputSchema: Schema10.Void,
1212
- handler: Effect9.fn(function* ({ data: { duration = 1e5 } }) {
1213
- yield* Effect9.sleep(duration);
1331
+ handler: Effect10.fn(function* ({ data: { duration = 1e5 } }) {
1332
+ yield* Effect10.sleep(duration);
1214
1333
  })
1215
1334
  });
1216
1335
  export {
@@ -1229,6 +1348,7 @@ export {
1229
1348
  FunctionError,
1230
1349
  FunctionExecutor,
1231
1350
  FunctionImplementationResolver,
1351
+ FunctionInvocationService,
1232
1352
  FunctionManifestSchema,
1233
1353
  FunctionNotFoundError,
1234
1354
  FunctionTrigger,