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