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