@dxos/functions 0.8.4-main.c85a9c8dae → 0.8.4-main.cb12b3f963

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 (73) hide show
  1. package/dist/lib/neutral/index.mjs +155 -920
  2. package/dist/lib/neutral/index.mjs.map +4 -4
  3. package/dist/lib/neutral/meta.json +1 -1
  4. package/dist/types/src/index.d.ts +0 -2
  5. package/dist/types/src/index.d.ts.map +1 -1
  6. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -1
  7. package/dist/types/src/protocol/protocol.d.ts +2 -2
  8. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  9. package/dist/types/src/sdk.d.ts +5 -112
  10. package/dist/types/src/sdk.d.ts.map +1 -1
  11. package/dist/types/src/services/credentials.d.ts +15 -38
  12. package/dist/types/src/services/credentials.d.ts.map +1 -1
  13. package/dist/types/src/services/function-invocation-service.d.ts +5 -6
  14. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  15. package/dist/types/src/services/index.d.ts +1 -4
  16. package/dist/types/src/services/index.d.ts.map +1 -1
  17. package/dist/types/src/services/queues.d.ts +1 -46
  18. package/dist/types/src/services/queues.d.ts.map +1 -1
  19. package/dist/types/src/services/tracing.d.ts +1 -84
  20. package/dist/types/src/services/tracing.d.ts.map +1 -1
  21. package/dist/types/src/types/index.d.ts +0 -4
  22. package/dist/types/src/types/index.d.ts.map +1 -1
  23. package/dist/types/src/types/url.d.ts +3 -3
  24. package/dist/types/src/types/url.d.ts.map +1 -1
  25. package/dist/types/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +17 -16
  27. package/src/index.ts +0 -2
  28. package/src/protocol/protocol.test.ts +9 -10
  29. package/src/protocol/protocol.ts +68 -34
  30. package/src/sdk.ts +10 -278
  31. package/src/services/credentials.ts +75 -118
  32. package/src/services/function-invocation-service.ts +6 -10
  33. package/src/services/index.ts +1 -4
  34. package/src/services/queues.ts +1 -78
  35. package/src/services/tracing.ts +0 -159
  36. package/src/types/index.ts +0 -4
  37. package/src/types/url.ts +3 -3
  38. package/dist/types/src/errors.d.ts +0 -121
  39. package/dist/types/src/errors.d.ts.map +0 -1
  40. package/dist/types/src/example/fib.d.ts +0 -7
  41. package/dist/types/src/example/fib.d.ts.map +0 -1
  42. package/dist/types/src/example/forex-effect.d.ts +0 -3
  43. package/dist/types/src/example/forex-effect.d.ts.map +0 -1
  44. package/dist/types/src/example/index.d.ts +0 -12
  45. package/dist/types/src/example/index.d.ts.map +0 -1
  46. package/dist/types/src/example/reply.d.ts +0 -3
  47. package/dist/types/src/example/reply.d.ts.map +0 -1
  48. package/dist/types/src/example/sleep.d.ts +0 -5
  49. package/dist/types/src/example/sleep.d.ts.map +0 -1
  50. package/dist/types/src/operation-compatibility.test.d.ts +0 -2
  51. package/dist/types/src/operation-compatibility.test.d.ts.map +0 -1
  52. package/dist/types/src/services/event-logger.d.ts +0 -81
  53. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  54. package/dist/types/src/types/Function.d.ts +0 -52
  55. package/dist/types/src/types/Function.d.ts.map +0 -1
  56. package/dist/types/src/types/Script.d.ts +0 -21
  57. package/dist/types/src/types/Script.d.ts.map +0 -1
  58. package/dist/types/src/types/Trigger.d.ts +0 -122
  59. package/dist/types/src/types/Trigger.d.ts.map +0 -1
  60. package/dist/types/src/types/TriggerEvent.d.ts +0 -75
  61. package/dist/types/src/types/TriggerEvent.d.ts.map +0 -1
  62. package/src/errors.ts +0 -21
  63. package/src/example/fib.ts +0 -32
  64. package/src/example/forex-effect.ts +0 -40
  65. package/src/example/index.ts +0 -13
  66. package/src/example/reply.ts +0 -21
  67. package/src/example/sleep.ts +0 -24
  68. package/src/operation-compatibility.test.ts +0 -185
  69. package/src/services/event-logger.ts +0 -127
  70. package/src/types/Function.ts +0 -83
  71. package/src/types/Script.ts +0 -34
  72. package/src/types/Trigger.ts +0 -153
  73. package/src/types/TriggerEvent.ts +0 -62
@@ -1,185 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Effect from 'effect/Effect';
6
- import * as Schema from 'effect/Schema';
7
- import { describe, expect, test } from 'vitest';
8
-
9
- import { FunctionDefinition, defineFunction } from './sdk';
10
-
11
- describe('Function/Operation Compatibility', () => {
12
- test('can convert FunctionDefinition to OperationDefinition', () => {
13
- const func = defineFunction({
14
- key: 'test.function',
15
- name: 'Test Function',
16
- description: 'A test function',
17
- inputSchema: Schema.Struct({ value: Schema.Number }),
18
- outputSchema: Schema.Struct({ result: Schema.String }),
19
- handler: async ({ data }) => {
20
- return { result: data.value.toString() };
21
- },
22
- });
23
-
24
- const op = FunctionDefinition.toOperation(func);
25
-
26
- expect(op.meta.key).toBe('test.function');
27
- expect(op.meta.name).toBe('Test Function');
28
- expect(op.meta.description).toBe('A test function');
29
- expect(Schema.isSchema(op.schema.input)).toBe(true);
30
- expect(Schema.isSchema(op.schema.output)).toBe(true);
31
- });
32
-
33
- test('converted operation has matching schemas', () => {
34
- const inputSchema = Schema.Struct({
35
- name: Schema.String,
36
- age: Schema.Number,
37
- });
38
- const outputSchema = Schema.Struct({
39
- greeting: Schema.String,
40
- });
41
-
42
- const func = defineFunction({
43
- key: 'test.greet',
44
- name: 'Greet',
45
- inputSchema,
46
- outputSchema,
47
- handler: async ({ data }) => {
48
- return { greeting: `Hello, ${data.name}!` };
49
- },
50
- });
51
-
52
- const op = FunctionDefinition.toOperation(func);
53
-
54
- // Verify schemas match
55
- const testInput = { name: 'Alice', age: 30 };
56
- const validatedInput = Schema.decodeSync(op.schema.input)(testInput);
57
- expect(validatedInput).toEqual(testInput);
58
-
59
- const testOutput = { greeting: 'Hello, Alice!' };
60
- const validatedOutput = Schema.decodeSync(op.schema.output)(testOutput);
61
- expect(validatedOutput).toEqual(testOutput);
62
- });
63
-
64
- test('converted operation preserves metadata', () => {
65
- const func = defineFunction({
66
- key: 'test.meta',
67
- name: 'Meta Test',
68
- description: 'Tests metadata preservation',
69
- inputSchema: Schema.Void,
70
- outputSchema: Schema.Void,
71
- handler: async () => {},
72
- });
73
-
74
- const op = FunctionDefinition.toOperation(func);
75
-
76
- expect(op.meta.key).toBe('test.meta');
77
- expect(op.meta.name).toBe('Meta Test');
78
- expect(op.meta.description).toBe('Tests metadata preservation');
79
- });
80
-
81
- test('converted operation is pipeable', () => {
82
- const func = defineFunction({
83
- key: 'test.pipe',
84
- name: 'Pipe Test',
85
- inputSchema: Schema.Void,
86
- outputSchema: Schema.Void,
87
- handler: async () => {},
88
- });
89
-
90
- const op = FunctionDefinition.toOperation(func);
91
-
92
- expect(typeof op.pipe).toBe('function');
93
- });
94
-
95
- test('handles functions without output schema', () => {
96
- const func = defineFunction({
97
- key: 'test.no-output',
98
- name: 'No Output',
99
- inputSchema: Schema.Struct({ value: Schema.Number }),
100
- handler: async ({ data }) => {
101
- return data.value * 2;
102
- },
103
- });
104
-
105
- const op = FunctionDefinition.toOperation(func);
106
-
107
- expect(op.meta.key).toBe('test.no-output');
108
- expect(Schema.isSchema(op.schema.output)).toBe(true);
109
- });
110
-
111
- test('converted operation includes handler', () => {
112
- const func = defineFunction({
113
- key: 'test.handler',
114
- name: 'Handler Test',
115
- inputSchema: Schema.Struct({ value: Schema.Number }),
116
- outputSchema: Schema.Struct({ doubled: Schema.Number }),
117
- handler: async ({ data }) => {
118
- return { doubled: data.value * 2 };
119
- },
120
- });
121
-
122
- const op = FunctionDefinition.toOperation(func);
123
-
124
- expect(op.handler).toBeDefined();
125
- expect(typeof op.handler).toBe('function');
126
- });
127
-
128
- test('converted operation has handler function', () => {
129
- const func = defineFunction({
130
- key: 'test.execute',
131
- name: 'Execute Test',
132
- inputSchema: Schema.Struct({ value: Schema.Number }),
133
- outputSchema: Schema.Struct({ result: Schema.Number }),
134
- handler: async ({ data }) => {
135
- return { result: data.value * 3 };
136
- },
137
- });
138
-
139
- const op = FunctionDefinition.toOperation(func);
140
-
141
- // Handler is present and is a function that returns an Effect
142
- expect(op.handler).toBeDefined();
143
- const effect = op.handler({ value: 5 });
144
- // Verify it returns an Effect-like object
145
- expect(effect).toHaveProperty('pipe');
146
- });
147
-
148
- test('converted operation works with Effect-based handlers', () => {
149
- const func = defineFunction({
150
- key: 'test.effect',
151
- name: 'Effect Test',
152
- inputSchema: Schema.Struct({ value: Schema.Number }),
153
- outputSchema: Schema.Struct({ result: Schema.Number }),
154
- handler: Effect.fn(function* ({ data }) {
155
- return { result: data.value * 4 };
156
- }),
157
- });
158
-
159
- const op = FunctionDefinition.toOperation(func);
160
-
161
- // Handler is present and produces an Effect
162
- expect(op.handler).toBeDefined();
163
- const effect = op.handler({ value: 3 });
164
- expect(effect).toHaveProperty('pipe');
165
- });
166
-
167
- test('converted operation works with synchronous handlers', () => {
168
- const func = defineFunction({
169
- key: 'test.sync',
170
- name: 'Sync Test',
171
- inputSchema: Schema.Struct({ value: Schema.Number }),
172
- outputSchema: Schema.Struct({ result: Schema.Number }),
173
- handler: ({ data }) => {
174
- return { result: data.value * 5 };
175
- },
176
- });
177
-
178
- const op = FunctionDefinition.toOperation(func);
179
-
180
- // Handler is present and produces an Effect
181
- expect(op.handler).toBeDefined();
182
- const effect = op.handler({ value: 2 });
183
- expect(effect).toHaveProperty('pipe');
184
- });
185
- });
@@ -1,127 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Context from 'effect/Context';
6
- import * as Effect from 'effect/Effect';
7
- import * as Layer from 'effect/Layer';
8
- import * as Schema from 'effect/Schema';
9
-
10
- import { Obj, Type } from '@dxos/echo';
11
- import { invariant } from '@dxos/invariant';
12
- import { LogLevel, log } from '@dxos/log';
13
-
14
- import { TracingService } from './tracing';
15
-
16
- export const ComputeEventPayload = Schema.Union(
17
- Schema.Struct({
18
- type: Schema.Literal('begin-compute'),
19
- nodeId: Schema.String,
20
- /**
21
- * Names of the inputs begin computed.
22
- */
23
- inputs: Schema.Array(Schema.String),
24
- }),
25
- Schema.Struct({
26
- type: Schema.Literal('end-compute'),
27
- nodeId: Schema.String,
28
- /**
29
- * Names of the outputs computed.
30
- */
31
- outputs: Schema.Array(Schema.String),
32
- }),
33
- Schema.Struct({
34
- type: Schema.Literal('compute-input'),
35
- nodeId: Schema.String,
36
- property: Schema.String,
37
- value: Schema.Any,
38
- }),
39
- Schema.Struct({
40
- type: Schema.Literal('compute-output'),
41
- nodeId: Schema.String,
42
- property: Schema.String,
43
- value: Schema.Any,
44
- }),
45
- Schema.Struct({
46
- type: Schema.Literal('custom'),
47
- nodeId: Schema.String,
48
- event: Schema.Any,
49
- }),
50
- );
51
- export type ComputeEventPayload = Schema.Schema.Type<typeof ComputeEventPayload>;
52
-
53
- export const ComputeEvent = Schema.Struct({
54
- payload: ComputeEventPayload,
55
- }).pipe(Type.object({ typename: 'dxos.org/type/ComputeEvent', version: '0.1.0' }));
56
-
57
- /**
58
- * Logs event for the compute workflows.
59
- */
60
- export class ComputeEventLogger extends Context.Tag('@dxos/functions/ComputeEventLogger')<
61
- ComputeEventLogger,
62
- { readonly log: (event: ComputeEventPayload) => void; readonly nodeId: string | undefined }
63
- >() {
64
- static noop: Context.Tag.Service<ComputeEventLogger> = {
65
- log: () => {},
66
- nodeId: undefined,
67
- };
68
-
69
- /**
70
- * Implements ComputeEventLogger using TracingService.
71
- */
72
- static layerFromTracing = Layer.effect(
73
- ComputeEventLogger,
74
- Effect.gen(function* () {
75
- const tracing = yield* TracingService;
76
- return {
77
- log: (event: ComputeEventPayload) => {
78
- tracing.write(Obj.make(ComputeEvent, { payload: event }), tracing.getTraceContext());
79
- },
80
- nodeId: undefined,
81
- };
82
- }),
83
- );
84
- }
85
-
86
- export const logCustomEvent = (data: any) =>
87
- Effect.gen(function* () {
88
- const logger = yield* ComputeEventLogger;
89
- if (!logger.nodeId) {
90
- throw new Error('logCustomEvent must be called within a node compute function');
91
- }
92
- logger.log({
93
- type: 'custom',
94
- nodeId: logger.nodeId,
95
- event: data,
96
- });
97
- });
98
-
99
- export const createDefectLogger = <A, E, R>(): ((self: Effect.Effect<A, E, R>) => Effect.Effect<A, E, R>) =>
100
- Effect.catchAll((error) =>
101
- Effect.gen(function* () {
102
- log.error('unhandled effect error', { error });
103
- throw error;
104
- }),
105
- );
106
-
107
- export const createEventLogger = (
108
- level: LogLevel,
109
- message: string = 'event',
110
- ): Context.Tag.Service<ComputeEventLogger> => {
111
- const logFunction = (
112
- {
113
- [LogLevel.WARN]: log.warn,
114
- [LogLevel.VERBOSE]: log.verbose,
115
- [LogLevel.DEBUG]: log.debug,
116
- [LogLevel.INFO]: log.info,
117
- [LogLevel.ERROR]: log.error,
118
- } as any
119
- )[level];
120
- invariant(logFunction);
121
- return {
122
- log: (event: ComputeEventPayload) => {
123
- logFunction(message, event);
124
- },
125
- nodeId: undefined,
126
- };
127
- };
@@ -1,83 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { Annotation, JsonSchema, Obj, Ref, Type } from '@dxos/echo';
8
- import { SystemTypeAnnotation } from '@dxos/echo/internal';
9
-
10
- import { Script } from './Script';
11
-
12
- /**
13
- * Function deployment.
14
- */
15
- export const Function = Schema.Struct({
16
- /**
17
- * Global registry ID.
18
- * NOTE: The `key` property refers to the original registry entry.
19
- */
20
- // TODO(burdon): Create Format type for DXN-like ids, such as this and schema type.
21
- // TODO(dmaretskyi): Consider making it part of ECHO meta.
22
- // TODO(dmaretskyi): Make required.
23
- key: Schema.optional(Schema.String).annotations({
24
- description: 'Unique registration key for the blueprint',
25
- }),
26
-
27
- name: Schema.NonEmptyString,
28
- version: Schema.String,
29
-
30
- description: Schema.optional(Schema.String),
31
-
32
- /**
33
- * ISO date string of the last deployment.
34
- */
35
- updated: Schema.optional(Schema.String),
36
-
37
- // Reference to a source script if it exists within ECHO.
38
- // TODO(burdon): Don't ref ScriptType directly (core).
39
- source: Schema.optional(Ref.Ref(Script)),
40
-
41
- inputSchema: Schema.optional(JsonSchema.JsonSchema),
42
- outputSchema: Schema.optional(JsonSchema.JsonSchema),
43
-
44
- /**
45
- * List of required services.
46
- * Match the Context.Tag keys of the FunctionServices variants.
47
- */
48
- services: Schema.optional(Schema.Array(Schema.String)),
49
-
50
- // Local binding to a function name.
51
- binding: Schema.optional(Schema.String),
52
- }).pipe(
53
- Type.object({
54
- typename: 'dxos.org/type/Function',
55
- version: '0.1.0',
56
- }),
57
- Annotation.LabelAnnotation.set(['name']),
58
- Annotation.IconAnnotation.set({ icon: 'ph--function--regular', hue: 'blue' }),
59
- SystemTypeAnnotation.set(true),
60
- );
61
-
62
- export interface Function extends Schema.Schema.Type<typeof Function> {}
63
-
64
- export const make = (props: Obj.MakeProps<typeof Function>) => Obj.make(Function, props);
65
-
66
- /**
67
- * Copies properties from source to target.
68
- * @param target - Target object to copy properties to.
69
- * @param source - Source object to copy properties from.
70
- */
71
- export const setFrom = (target: Function, source: Function) => {
72
- Obj.change(target, (t) => {
73
- t.key = source.key ?? target.key;
74
- t.name = source.name ?? target.name;
75
- t.version = source.version;
76
- t.description = source.description;
77
- t.updated = source.updated;
78
- // TODO(dmaretskyi): A workaround for an ECHO bug.
79
- t.inputSchema = source.inputSchema ? JSON.parse(JSON.stringify(source.inputSchema)) : undefined;
80
- t.outputSchema = source.outputSchema ? JSON.parse(JSON.stringify(source.outputSchema)) : undefined;
81
- Obj.getMeta(t).keys = JSON.parse(JSON.stringify(Obj.getMeta(source).keys));
82
- });
83
- };
@@ -1,34 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { Annotation, Obj, Ref, Type } from '@dxos/echo';
8
- import { FormInputAnnotation } from '@dxos/echo/internal';
9
- import { Text } from '@dxos/schema';
10
-
11
- /**
12
- * Source script.
13
- */
14
- export const Script = Schema.Struct({
15
- name: Schema.String.pipe(Schema.optional),
16
- description: Schema.String.pipe(Schema.optional),
17
- // TODO(burdon): Change to hash of deployed content.
18
- // Whether source has changed since last deploy.
19
- changed: Schema.Boolean.pipe(FormInputAnnotation.set(false), Schema.optional),
20
- source: Ref.Ref(Text.Text).pipe(FormInputAnnotation.set(false)),
21
- }).pipe(
22
- Type.object({
23
- typename: 'dxos.org/type/Script',
24
- version: '0.1.0',
25
- }),
26
- Annotation.LabelAnnotation.set(['name']),
27
- );
28
-
29
- export interface Script extends Schema.Schema.Type<typeof Script> {}
30
-
31
- type Props = Omit<Obj.MakeProps<typeof Script>, 'source'> & { source?: string };
32
-
33
- export const make = ({ source = '', ...props }: Props = {}): Script =>
34
- Obj.make(Script, { ...props, source: Ref.make(Text.make(source)) });
@@ -1,153 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
- import * as SchemaAST from 'effect/SchemaAST';
7
-
8
- import { Annotation, Obj, QueryAST, Ref, Type } from '@dxos/echo';
9
- import { OptionsAnnotationId, SystemTypeAnnotation } from '@dxos/echo/internal';
10
- import { DXN } from '@dxos/keys';
11
- import { Expando } from '@dxos/schema';
12
-
13
- /**
14
- * Type discriminator for TriggerType.
15
- * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
16
- * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
17
- */
18
- export const Kinds = ['email', 'queue', 'subscription', 'timer', 'webhook'] as const;
19
- export type Kind = (typeof Kinds)[number];
20
-
21
- const kindLiteralAnnotations = { title: 'Kind' };
22
-
23
- export const EmailSpec = Schema.Struct({
24
- kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
25
- });
26
- export type EmailSpec = Schema.Schema.Type<typeof EmailSpec>;
27
-
28
- export const QueueSpec = Schema.Struct({
29
- kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
30
-
31
- // TODO(dmaretskyi): Change to a reference.
32
- queue: DXN.Schema,
33
- });
34
- export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
35
-
36
- /**
37
- * Subscription.
38
- */
39
- export const SubscriptionSpec = Schema.Struct({
40
- kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
41
- query: Schema.Struct({
42
- raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
43
- ast: QueryAST.Query,
44
- }),
45
- options: Schema.optional(
46
- Schema.Struct({
47
- // Watch changes to object (not just creation).
48
- deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
49
- // Debounce changes (delay in ms).
50
- delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
51
- }).annotations({ title: 'Options' }),
52
- ),
53
- });
54
- export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
55
-
56
- /**
57
- * Cron timer.
58
- */
59
- export const TimerSpec = Schema.Struct({
60
- kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
61
- cron: Schema.String.annotations({
62
- title: 'Cron',
63
- [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
64
- }),
65
- });
66
- export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
67
-
68
- /**
69
- * Webhook.
70
- */
71
- export const WebhookSpec = Schema.Struct({
72
- kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
73
- method: Schema.optional(
74
- Schema.String.annotations({
75
- title: 'Method',
76
- [OptionsAnnotationId]: ['GET', 'POST'],
77
- }),
78
- ),
79
- port: Schema.optional(
80
- Schema.Number.annotations({
81
- title: 'Port',
82
- }),
83
- ),
84
- });
85
- export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
86
-
87
- /**
88
- * Trigger schema.
89
- */
90
- export const Spec = Schema.Union(EmailSpec, QueueSpec, SubscriptionSpec, TimerSpec, WebhookSpec).annotations({
91
- title: 'Trigger',
92
- });
93
- export type Spec = Schema.Schema.Type<typeof Spec>;
94
-
95
- /**
96
- * Function trigger.
97
- * Function is invoked with the `payload` passed as input data.
98
- * The event that triggers the function is available in the function context.
99
- */
100
- const TriggerSchema = Schema.Struct({
101
- /**
102
- * Function or workflow to invoke.
103
- */
104
- // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
105
- function: Schema.optional(Ref.Ref(Expando.Expando).annotations({ title: 'Function' })),
106
-
107
- /**
108
- * Only used for workflowSchema.
109
- * Specifies the input node in the circuit.
110
- * @deprecated Remove and enforce a single input node in all compute graphSchema.
111
- */
112
- inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
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.
116
- enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
117
-
118
- spec: Schema.optional(Spec),
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
-
129
- /**
130
- * Passed as the input data to the function.
131
- * Must match the function's input schema.
132
- *
133
- * @example
134
- * {
135
- * item: '{{$.trigger.event}}',
136
- * instructions: 'Summarize and perform entity-extraction'
137
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
138
- * }
139
- */
140
- input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
141
- }).pipe(
142
- Type.object({
143
- typename: 'dxos.org/type/Trigger',
144
- version: '0.1.0',
145
- }),
146
- Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
147
- SystemTypeAnnotation.set(true),
148
- );
149
-
150
- export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
151
- export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
152
-
153
- export const make = (props: Obj.MakeProps<typeof Trigger>) => Obj.make(Trigger, props);
@@ -1,62 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import * as Schema from 'effect/Schema';
6
-
7
- import { DXN, Obj, Ref } from '@dxos/echo';
8
-
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.
13
-
14
- // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
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
- });
22
- export type EmailEvent = Schema.Schema.Type<typeof EmailEvent>;
23
-
24
- export const QueueEvent = Schema.Struct({
25
- queue: DXN.Schema,
26
- item: Schema.Any,
27
- cursor: Schema.String,
28
- });
29
- export type QueueEvent = Schema.Schema.Type<typeof QueueEvent>;
30
-
31
- export const SubscriptionEvent = Schema.Struct({
32
- /**
33
- * Type of the mutation.
34
- */
35
- // TODO(dmaretskyi): Specify enum.
36
- type: Schema.String,
37
-
38
- /**
39
- * Reference to the object that was changed or created.
40
- */
41
- subject: Ref.Ref(Obj.Unknown),
42
-
43
- /**
44
- * @deprecated
45
- */
46
- changedObjectId: Schema.optional(Schema.String),
47
- });
48
- export type SubscriptionEvent = Schema.Schema.Type<typeof SubscriptionEvent>;
49
-
50
- export const TimerEvent = Schema.Struct({ tick: Schema.Number });
51
- export type TimerEvent = Schema.Schema.Type<typeof TimerEvent>;
52
-
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
- });
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>;