@dxos/functions 0.8.4-main.72ec0f3 → 0.8.4-main.7996785055

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 (84) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/chunk-GEM2K7BA.mjs +56 -0
  3. package/dist/lib/neutral/chunk-GEM2K7BA.mjs.map +7 -0
  4. package/dist/lib/neutral/fib-XBUKWUUS.mjs +22 -0
  5. package/dist/lib/neutral/fib-XBUKWUUS.mjs.map +7 -0
  6. package/dist/lib/neutral/index.mjs +960 -0
  7. package/dist/lib/neutral/index.mjs.map +7 -0
  8. package/dist/lib/neutral/meta.json +1 -0
  9. package/dist/lib/neutral/reply-XBQTXDLZ.mjs +18 -0
  10. package/dist/lib/neutral/reply-XBQTXDLZ.mjs.map +7 -0
  11. package/dist/lib/neutral/sleep-TLQKHAK2.mjs +14 -0
  12. package/dist/lib/neutral/sleep-TLQKHAK2.mjs.map +7 -0
  13. package/dist/types/src/errors.d.ts +24 -32
  14. package/dist/types/src/errors.d.ts.map +1 -1
  15. package/dist/types/src/example/definitions.d.ts +11 -0
  16. package/dist/types/src/example/definitions.d.ts.map +1 -0
  17. package/dist/types/src/example/fib.d.ts +3 -2
  18. package/dist/types/src/example/fib.d.ts.map +1 -1
  19. package/dist/types/src/example/index.d.ts +3 -11
  20. package/dist/types/src/example/index.d.ts.map +1 -1
  21. package/dist/types/src/example/reply.d.ts +2 -1
  22. package/dist/types/src/example/reply.d.ts.map +1 -1
  23. package/dist/types/src/example/sleep.d.ts +3 -2
  24. package/dist/types/src/example/sleep.d.ts.map +1 -1
  25. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  26. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  27. package/dist/types/src/protocol/protocol.d.ts +2 -2
  28. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  29. package/dist/types/src/sdk.d.ts +2 -79
  30. package/dist/types/src/sdk.d.ts.map +1 -1
  31. package/dist/types/src/services/credentials.d.ts +6 -4
  32. package/dist/types/src/services/credentials.d.ts.map +1 -1
  33. package/dist/types/src/services/event-logger.d.ts +25 -31
  34. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  35. package/dist/types/src/services/function-invocation-service.d.ts +9 -3
  36. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  37. package/dist/types/src/services/index.d.ts +0 -1
  38. package/dist/types/src/services/index.d.ts.map +1 -1
  39. package/dist/types/src/services/queues.d.ts +4 -4
  40. package/dist/types/src/services/queues.d.ts.map +1 -1
  41. package/dist/types/src/services/tracing.d.ts +38 -3
  42. package/dist/types/src/services/tracing.d.ts.map +1 -1
  43. package/dist/types/src/types/Script.d.ts +9 -16
  44. package/dist/types/src/types/Script.d.ts.map +1 -1
  45. package/dist/types/src/types/Trigger.d.ts +57 -76
  46. package/dist/types/src/types/Trigger.d.ts.map +1 -1
  47. package/dist/types/src/types/TriggerEvent.d.ts +44 -13
  48. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
  49. package/dist/types/src/types/index.d.ts +0 -1
  50. package/dist/types/src/types/index.d.ts.map +1 -1
  51. package/dist/types/src/types/url.d.ts +6 -5
  52. package/dist/types/src/types/url.d.ts.map +1 -1
  53. package/dist/types/tsconfig.tsbuildinfo +1 -1
  54. package/package.json +23 -17
  55. package/src/errors.ts +4 -4
  56. package/src/example/definitions.ts +48 -0
  57. package/src/example/fib.ts +14 -24
  58. package/src/example/forex-effect.ts +1 -1
  59. package/src/example/index.ts +7 -8
  60. package/src/example/reply.ts +10 -13
  61. package/src/example/sleep.ts +8 -17
  62. package/src/protocol/functions-ai-http-client.ts +67 -0
  63. package/src/protocol/protocol.ts +196 -84
  64. package/src/sdk.ts +4 -194
  65. package/src/services/credentials.ts +31 -15
  66. package/src/services/event-logger.ts +2 -2
  67. package/src/services/function-invocation-service.ts +18 -3
  68. package/src/services/index.ts +0 -2
  69. package/src/services/queues.ts +5 -7
  70. package/src/services/tracing.ts +64 -4
  71. package/src/types/Script.ts +13 -8
  72. package/src/types/Trigger.ts +31 -17
  73. package/src/types/TriggerEvent.ts +29 -29
  74. package/src/types/index.ts +0 -1
  75. package/src/types/url.ts +6 -5
  76. package/dist/lib/browser/index.mjs +0 -927
  77. package/dist/lib/browser/index.mjs.map +0 -7
  78. package/dist/lib/browser/meta.json +0 -1
  79. package/dist/lib/node-esm/index.mjs +0 -928
  80. package/dist/lib/node-esm/index.mjs.map +0 -7
  81. package/dist/lib/node-esm/meta.json +0 -1
  82. package/dist/types/src/types/Function.d.ts +0 -58
  83. package/dist/types/src/types/Function.d.ts.map +0 -1
  84. package/src/types/Function.ts +0 -62
@@ -3,21 +3,36 @@
3
3
  //
4
4
  import * as Context from 'effect/Context';
5
5
  import * as Effect from 'effect/Effect';
6
+ import * as Layer from 'effect/Layer';
6
7
 
7
- import { type FunctionDefinition, type InvocationServices } from '../sdk';
8
+ import type { FunctionNotFoundError } from '../errors';
9
+ import { type InvocationServices } from '../sdk';
10
+ import { Operation } from '@dxos/operation';
8
11
 
9
12
  export class FunctionInvocationService extends Context.Tag('@dxos/functions/FunctionInvocationService')<
10
13
  FunctionInvocationService,
11
14
  {
12
15
  invokeFunction<I, O>(
13
- functionDef: FunctionDefinition<I, O, any>,
16
+ functionDef: Operation.Definition<I, O, any>,
14
17
  input: I,
15
18
  ): Effect.Effect<O, never, InvocationServices>;
19
+
20
+ resolveFunction(key: string): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError>;
16
21
  }
17
22
  >() {
23
+ static layerNotAvailable = Layer.succeed(FunctionInvocationService, {
24
+ invokeFunction: () => Effect.die('FunctionInvocationService is not avaialble.'),
25
+ resolveFunction: () => Effect.die('FunctionInvocationService is not available.'),
26
+ });
27
+
18
28
  static invokeFunction = <I, O>(
19
- functionDef: FunctionDefinition<I, O, any>,
29
+ functionDef: Operation.Definition<I, O, any>,
20
30
  input: I,
21
31
  ): Effect.Effect<O, never, FunctionInvocationService | InvocationServices> =>
22
32
  Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.invokeFunction)(functionDef, input);
33
+
34
+ static resolveFunction = (
35
+ key: string,
36
+ ): Effect.Effect<Operation.Definition.Any, FunctionNotFoundError, FunctionInvocationService> =>
37
+ Effect.serviceFunctionEffect(FunctionInvocationService, (service) => service.resolveFunction)(key);
23
38
  }
@@ -2,8 +2,6 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export { DatabaseService } from '@dxos/echo-db';
6
-
7
5
  export * from './credentials';
8
6
  export { ConfiguredCredentialsService, type ServiceCredential } from './credentials';
9
7
  export * from './event-logger';
@@ -6,7 +6,7 @@ import * as Context from 'effect/Context';
6
6
  import * as Effect from 'effect/Effect';
7
7
  import * as Layer from 'effect/Layer';
8
8
 
9
- import type { Obj, Relation } from '@dxos/echo';
9
+ import type { Entity } from '@dxos/echo';
10
10
  import type { Queue, QueueAPI, QueueFactory } from '@dxos/echo-db';
11
11
  import type { DXN, QueueSubspaceTag } from '@dxos/keys';
12
12
 
@@ -53,22 +53,20 @@ export class QueueService extends Context.Tag('@dxos/functions/QueueService')<
53
53
  /**
54
54
  * Gets a queue by its DXN.
55
55
  */
56
- static getQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
56
+ static getQueue = <T extends Entity.Unknown = Entity.Unknown>(
57
57
  dxn: DXN,
58
58
  ): Effect.Effect<Queue<T>, never, QueueService> => QueueService.pipe(Effect.map(({ queues }) => queues.get<T>(dxn)));
59
59
 
60
60
  /**
61
61
  * Creates a new queue.
62
62
  */
63
- static createQueue = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(options?: {
63
+ static createQueue = <T extends Entity.Unknown = Entity.Unknown>(options?: {
64
64
  subspaceTag?: QueueSubspaceTag;
65
65
  }): Effect.Effect<Queue<T>, never, QueueService> =>
66
66
  QueueService.pipe(Effect.map(({ queues }) => queues.create<T>(options)));
67
67
 
68
- static append = <T extends Obj.Any | Relation.Any = Obj.Any | Relation.Any>(
69
- queue: Queue<T>,
70
- objects: T[],
71
- ): Effect.Effect<void> => Effect.promise(() => queue.append(objects));
68
+ static append = <T extends Entity.Unknown = Entity.Unknown>(queue: Queue<T>, objects: T[]): Effect.Effect<void> =>
69
+ Effect.promise(() => queue.append(objects));
72
70
  }
73
71
 
74
72
  /**
@@ -7,10 +7,12 @@ import * as Effect from 'effect/Effect';
7
7
  import * as Layer from 'effect/Layer';
8
8
 
9
9
  import { AgentStatus } from '@dxos/ai';
10
- import { Obj } from '@dxos/echo';
11
- import type { ObjectId } from '@dxos/echo/internal';
10
+ import { type DXN, Obj, Ref } from '@dxos/echo';
11
+ import { ObjectId } from '@dxos/keys';
12
12
  import { Message } from '@dxos/types';
13
13
 
14
+ import type { Trigger } from '../types';
15
+
14
16
  /**
15
17
  * Provides a way for compute primitives (functions, workflows, tools)
16
18
  * to emit an execution trace as a series of structured ECHO objects.
@@ -27,15 +29,35 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
27
29
  * Write an event to the tracing queue.
28
30
  * @param event - The event to write. Must be an a typed object.
29
31
  */
30
- write: (event: Obj.Any) => void;
32
+ write: (event: Obj.Unknown, traceContext: TracingService.TraceContext) => void;
33
+
34
+ traceInvocationStart({
35
+ payload,
36
+ target,
37
+ }: {
38
+ payload: TracingService.FunctionInvocationPayload;
39
+ target?: DXN;
40
+ }): Effect.Effect<TracingService.InvocationTraceData>;
41
+
42
+ traceInvocationEnd({
43
+ trace,
44
+ exception,
45
+ }: {
46
+ trace: TracingService.InvocationTraceData;
47
+ exception?: any;
48
+ }): Effect.Effect<void>;
31
49
  }
32
50
  >() {
33
51
  static noop: Context.Tag.Service<TracingService> = {
34
52
  getTraceContext: () => ({}),
35
53
  write: () => {},
54
+ traceInvocationStart: () =>
55
+ Effect.sync(() => ({ invocationId: ObjectId.random(), invocationTraceQueue: undefined })),
56
+ traceInvocationEnd: () => Effect.sync(() => {}),
36
57
  };
37
58
 
38
59
  static layerNoop: Layer.Layer<TracingService> = Layer.succeed(TracingService, TracingService.noop);
60
+
39
61
  /**
40
62
  * Creates a TracingService layer that emits events to the parent tracing service.
41
63
  */
@@ -46,12 +68,25 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
46
68
  const tracing = yield* TracingService;
47
69
  const context = mapContext(tracing.getTraceContext());
48
70
  return {
49
- write: (event) => tracing.write(event),
71
+ write: (event, context) => tracing.write(event, context),
50
72
  getTraceContext: () => context,
73
+ traceInvocationStart: () => Effect.die('Tracing invocation inside another invocation is not supported.'),
74
+ traceInvocationEnd: () => Effect.die('Tracing invocation inside another invocation is not supported.'),
51
75
  };
52
76
  }),
53
77
  );
54
78
 
79
+ /**
80
+ * Create sublayer to trace an invocation.
81
+ * @param data
82
+ * @returns
83
+ */
84
+ static layerInvocation = (data: TracingService.InvocationTraceData) =>
85
+ TracingService.layerSubframe((context) => ({
86
+ ...context,
87
+ currentInvocation: data,
88
+ }));
89
+
55
90
  /**
56
91
  * Emit the current human-readable execution status.
57
92
  */
@@ -66,6 +101,7 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
66
101
  created: new Date().toISOString(),
67
102
  ...data,
68
103
  }),
104
+ tracing.getTraceContext(),
69
105
  );
70
106
  });
71
107
 
@@ -82,12 +118,15 @@ export class TracingService extends Context.Tag('@dxos/functions/TracingService'
82
118
  ...data.properties,
83
119
  },
84
120
  }),
121
+ tracing.getTraceContext(),
85
122
  );
86
123
  });
87
124
  }
88
125
 
89
126
  export namespace TracingService {
90
127
  export interface TraceContext {
128
+ currentInvocation?: InvocationTraceData;
129
+
91
130
  /**
92
131
  * If this thread sprung from a tool call, this is the ID of the message containing the tool call.
93
132
  */
@@ -100,6 +139,27 @@ export namespace TracingService {
100
139
 
101
140
  debugInfo?: unknown;
102
141
  }
142
+
143
+ /**
144
+ * Trace data for a function/trigger invocation.
145
+ */
146
+ export interface InvocationTraceData {
147
+ invocationId: ObjectId;
148
+ invocationTraceQueue?: DXN.String;
149
+ }
150
+
151
+ /**
152
+ * Payload for a function/trigger invocation.
153
+ */
154
+ export interface FunctionInvocationPayload {
155
+ data?: any;
156
+ inputNodeId?: string;
157
+ trigger?: {
158
+ id: string;
159
+ kind: Trigger.Kind;
160
+ };
161
+ chat?: Ref.Ref<Obj.Unknown>;
162
+ }
103
163
  }
104
164
 
105
165
  /**
@@ -4,8 +4,8 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { Obj, Ref, Type } from '@dxos/echo';
8
- import { FormAnnotation, LabelAnnotation } from '@dxos/echo/internal';
7
+ import { Annotation, Obj, Ref, Type } from '@dxos/echo';
8
+ import { FormInputAnnotation } from '@dxos/echo/internal';
9
9
  import { Text } from '@dxos/schema';
10
10
 
11
11
  /**
@@ -16,18 +16,23 @@ export const Script = Schema.Struct({
16
16
  description: Schema.String.pipe(Schema.optional),
17
17
  // TODO(burdon): Change to hash of deployed content.
18
18
  // Whether source has changed since last deploy.
19
- changed: Schema.Boolean.pipe(FormAnnotation.set(false), Schema.optional),
20
- source: Type.Ref(Text.Text).pipe(FormAnnotation.set(false)),
19
+ changed: Schema.Boolean.pipe(FormInputAnnotation.set(false), Schema.optional),
20
+ source: Ref.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
21
21
  }).pipe(
22
- Type.Obj({
23
- typename: 'dxos.org/type/Script',
22
+ Type.object({
23
+ typename: 'org.dxos.type.script',
24
24
  version: '0.1.0',
25
25
  }),
26
- LabelAnnotation.set(['name']),
26
+ Annotation.LabelAnnotation.set(['name']),
27
+ Annotation.IconAnnotation.set({
28
+ icon: 'ph--code--regular',
29
+ hue: 'sky',
30
+ }),
27
31
  );
32
+
28
33
  export interface Script extends Schema.Schema.Type<typeof Script> {}
29
34
 
30
35
  type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
31
36
 
32
- export const make = ({ source = '', ...props }: Props = {}) =>
37
+ export const make = ({ source = '', ...props }: Props = {}): Script =>
33
38
  Obj.make(Script, { ...props, source: Ref.make(Text.make(source)) });
@@ -5,8 +5,8 @@
5
5
  import * as Schema from 'effect/Schema';
6
6
  import * as SchemaAST from 'effect/SchemaAST';
7
7
 
8
- import { Obj, QueryAST, Type } from '@dxos/echo';
9
- import { Expando, OptionsAnnotationId, Ref } from '@dxos/echo/internal';
8
+ import { Annotation, Obj, QueryAST, Ref, Type } from '@dxos/echo';
9
+ import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
10
10
  import { DXN } from '@dxos/keys';
11
11
 
12
12
  /**
@@ -21,15 +21,16 @@ const kindLiteralAnnotations = { title: 'Kind' };
21
21
 
22
22
  export const EmailSpec = Schema.Struct({
23
23
  kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
24
- }).pipe(Schema.mutable);
24
+ });
25
25
  export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
26
26
 
27
+ // TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
27
28
  export const QueueSpec = Schema.Struct({
28
29
  kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
29
30
 
30
31
  // TODO(dmaretskyi): Change to a reference.
31
32
  queue: DXN.Schema,
32
- }).pipe(Schema.mutable);
33
+ });
33
34
  export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
34
35
 
35
36
  /**
@@ -40,7 +41,7 @@ export const SubscriptionSpec = Schema.Struct({
40
41
  query: Schema.Struct({
41
42
  raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
42
43
  ast: QueryAST.Query,
43
- }).pipe(Schema.mutable),
44
+ }),
44
45
  options: Schema.optional(
45
46
  Schema.Struct({
46
47
  // Watch changes to object (not just creation).
@@ -49,7 +50,7 @@ export const SubscriptionSpec = Schema.Struct({
49
50
  delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
50
51
  }).annotations({ title: 'Options' }),
51
52
  ),
52
- }).pipe(Schema.mutable);
53
+ });
53
54
  export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
54
55
 
55
56
  /**
@@ -61,7 +62,7 @@ export const TimerSpec = Schema.Struct({
61
62
  title: 'Cron',
62
63
  [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
63
64
  }),
64
- }).pipe(Schema.mutable);
65
+ });
65
66
  export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
66
67
 
67
68
  /**
@@ -80,7 +81,7 @@ export const WebhookSpec = Schema.Struct({
80
81
  title: 'Port',
81
82
  }),
82
83
  ),
83
- }).pipe(Schema.mutable);
84
+ });
84
85
  export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
85
86
 
86
87
  /**
@@ -96,12 +97,12 @@ export type Spec = Schema.Schema.Type<typeof Spec>;
96
97
  * Function is invoked with the `payload` passed as input data.
97
98
  * The event that triggers the function is available in the function context.
98
99
  */
99
- const Trigger_ = Schema.Struct({
100
+ const TriggerSchema = Schema.Struct({
100
101
  /**
101
102
  * Function or workflow to invoke.
102
103
  */
103
104
  // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
104
- function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
105
+ function: Schema.optional(Ref.Ref(Obj.Unknown).annotations({ title: 'Function' })),
105
106
 
106
107
  /**
107
108
  * Only used for workflowSchema.
@@ -110,30 +111,43 @@ const Trigger_ = Schema.Struct({
110
111
  */
111
112
  inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
112
113
 
114
+ // TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
115
+ // Need lint rule; or agent rule to require PR review for "boolean" key word.
113
116
  enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
114
117
 
115
118
  spec: Schema.optional(Spec),
116
119
 
120
+ concurrency: Schema.optional(
121
+ Schema.Number.annotations({
122
+ title: 'Concurrency',
123
+ default: 1,
124
+ description:
125
+ 'Maximum number of concurrent invocations of the trigger. For queue triggers, this will process queue items in parallel.',
126
+ }),
127
+ ),
128
+
117
129
  /**
118
130
  * Passed as the input data to the function.
119
131
  * Must match the function's input schema.
120
132
  *
121
133
  * @example
122
134
  * {
123
- * item: '{{$.trigger.event}}',
135
+ * item: '{{event.item}}',
124
136
  * instructions: 'Summarize and perform entity-extraction'
125
137
  * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
126
138
  * }
127
139
  */
128
- input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
140
+ input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
129
141
  }).pipe(
130
- Type.Obj({
131
- typename: 'dxos.org/type/Trigger',
142
+ Type.object({
143
+ typename: 'org.dxos.type.trigger',
132
144
  version: '0.1.0',
133
145
  }),
146
+ Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
147
+ SystemTypeAnnotation.set(true),
134
148
  );
135
- export interface Trigger extends Schema.Schema.Type<typeof Trigger_> {}
136
- export interface TriggerEncoded extends Schema.Schema.Encoded<typeof Trigger_> {}
137
- export const Trigger: Schema.Schema<Trigger, TriggerEncoded> = Trigger_;
149
+
150
+ export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
151
+ export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
138
152
 
139
153
  export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
@@ -4,29 +4,28 @@
4
4
 
5
5
  import * as Schema from 'effect/Schema';
6
6
 
7
- import { DXN, Obj, Type } from '@dxos/echo';
7
+ import { DXN, Obj, Ref } from '@dxos/echo';
8
8
 
9
- export type TriggerEvent = EmailEvent | QueueEvent | SubscriptionEvent | TimerEvent | WebhookEvent;
9
+ // TODO(wittjosiah): Review this type.
10
+ // - Should be discriminated union.
11
+ // - Should be more consistent (e.g. subject vs item).
12
+ // - Should re-use schemas if possible.
10
13
 
11
14
  // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
12
- export const EmailEvent = Schema.mutable(
13
- Schema.Struct({
14
- from: Schema.String,
15
- to: Schema.String,
16
- subject: Schema.String,
17
- created: Schema.String,
18
- body: Schema.String,
19
- }),
20
- );
15
+ export const EmailEvent = Schema.Struct({
16
+ from: Schema.String,
17
+ to: Schema.String,
18
+ subject: Schema.String,
19
+ created: Schema.String,
20
+ body: Schema.String,
21
+ });
21
22
  export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
22
23
 
23
- export const QueueEvent = Schema.mutable(
24
- Schema.Struct({
25
- queue: DXN.Schema,
26
- item: Schema.Any,
27
- cursor: Schema.String,
28
- }),
29
- );
24
+ export const QueueEvent = Schema.Struct({
25
+ queue: DXN.Schema,
26
+ item: Schema.Any,
27
+ cursor: Schema.String,
28
+ });
30
29
  export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
31
30
 
32
31
  export const SubscriptionEvent = Schema.Struct({
@@ -39,24 +38,25 @@ export const SubscriptionEvent = Schema.Struct({
39
38
  /**
40
39
  * Reference to the object that was changed or created.
41
40
  */
42
- subject: Type.Ref(Obj.Any),
41
+ subject: Ref.Ref(Obj.Unknown),
43
42
 
44
43
  /**
45
44
  * @deprecated
46
45
  */
47
46
  changedObjectId: Schema.optional(Schema.String),
48
- }).pipe(Schema.mutable);
47
+ });
49
48
  export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
50
49
 
51
- export const TimerEvent = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
50
+ export const TimerEvent = Schema.Struct({ tick: Schema.Number });
52
51
  export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
53
52
 
54
- export const WebhookEvent = Schema.mutable(
55
- Schema.Struct({
56
- url: Schema.String,
57
- method: Schema.Literal('GET', 'POST'),
58
- headers: Schema.Record({ key: Schema.String, value: Schema.String }),
59
- bodyText: Schema.String,
60
- }),
61
- );
53
+ export const WebhookEvent = Schema.Struct({
54
+ url: Schema.String,
55
+ method: Schema.Literal('GET', 'POST'),
56
+ headers: Schema.Record({ key: Schema.String, value: Schema.String }),
57
+ bodyText: Schema.String,
58
+ });
62
59
  export type WebhookEvent = Schema.Schema.Type<typeof WebhookEvent>;
60
+
61
+ export const TriggerEvent = Schema.Union(EmailEvent, QueueEvent, SubscriptionEvent, TimerEvent, WebhookEvent);
62
+ export type TriggerEvent = Schema.Schema.Type<typeof TriggerEvent>;
@@ -2,7 +2,6 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * as Function from './Function';
6
5
  export * as Script from './Script';
7
6
  export * as Trigger from './Trigger';
8
7
  export * as TriggerEvent from './TriggerEvent';
package/src/types/url.ts CHANGED
@@ -2,24 +2,25 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type ObjectMeta } from '@dxos/echo/internal';
5
+ import { type Obj } from '@dxos/echo';
6
6
 
7
7
  // TODO: use URL scheme for source?
8
- export const FUNCTIONS_META_KEY = 'dxos.org/service/function';
8
+ export const FUNCTIONS_META_KEY = 'org.dxos.service.function';
9
9
 
10
- export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
10
+ export const FUNCTIONS_PRESET_META_KEY = 'org.dxos.service.function-preset';
11
11
 
12
12
  /**
13
13
  * NOTE: functionId is backend ID, not ECHO object id.
14
14
  */
15
- export const getUserFunctionIdInMetadata = (meta: ObjectMeta) => {
15
+ export const getUserFunctionIdInMetadata = (meta: Obj.ReadonlyMeta) => {
16
16
  return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
17
17
  };
18
18
 
19
19
  /**
20
20
  * NOTE: functionId is backend ID, not ECHO object id.
21
+ * Must be called inside Obj.changeMeta() since it mutates the meta.
21
22
  */
22
- export const setUserFunctionIdInMetadata = (meta: ObjectMeta, functionId: string) => {
23
+ export const setUserFunctionIdInMetadata = (meta: Obj.Meta, functionId: string) => {
23
24
  const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
24
25
  if (key) {
25
26
  if (key.id !== functionId) {