@dxos/functions 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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/README.md +4 -6
  2. package/dist/lib/neutral/Trace.mjs +38 -0
  3. package/dist/lib/neutral/Trace.mjs.map +7 -0
  4. package/dist/lib/neutral/chunk-5T7GOX2V.mjs +149 -0
  5. package/dist/lib/neutral/chunk-5T7GOX2V.mjs.map +7 -0
  6. package/dist/lib/neutral/chunk-IVDUS56O.mjs +49 -0
  7. package/dist/lib/neutral/chunk-IVDUS56O.mjs.map +7 -0
  8. package/dist/lib/neutral/chunk-J5LGTIGS.mjs +10 -0
  9. package/dist/lib/neutral/chunk-J5LGTIGS.mjs.map +7 -0
  10. package/dist/lib/neutral/fib-N45KAC7C.mjs +23 -0
  11. package/dist/lib/neutral/fib-N45KAC7C.mjs.map +7 -0
  12. package/dist/lib/neutral/index.mjs +1266 -0
  13. package/dist/lib/neutral/index.mjs.map +7 -0
  14. package/dist/lib/neutral/meta.json +1 -0
  15. package/dist/lib/neutral/reply-EUEPKNJF.mjs +19 -0
  16. package/dist/lib/neutral/reply-EUEPKNJF.mjs.map +7 -0
  17. package/dist/lib/neutral/sleep-PUK3D4FF.mjs +15 -0
  18. package/dist/lib/neutral/sleep-PUK3D4FF.mjs.map +7 -0
  19. package/dist/types/src/Trace.d.ts +155 -0
  20. package/dist/types/src/Trace.d.ts.map +1 -0
  21. package/dist/types/src/errors.d.ts +24 -32
  22. package/dist/types/src/errors.d.ts.map +1 -1
  23. package/dist/types/src/example/definitions.d.ts +11 -0
  24. package/dist/types/src/example/definitions.d.ts.map +1 -0
  25. package/dist/types/src/example/fib.d.ts +3 -2
  26. package/dist/types/src/example/fib.d.ts.map +1 -1
  27. package/dist/types/src/example/index.d.ts +3 -11
  28. package/dist/types/src/example/index.d.ts.map +1 -1
  29. package/dist/types/src/example/reply.d.ts +2 -1
  30. package/dist/types/src/example/reply.d.ts.map +1 -1
  31. package/dist/types/src/example/sleep.d.ts +3 -2
  32. package/dist/types/src/example/sleep.d.ts.map +1 -1
  33. package/dist/types/src/index.d.ts +4 -0
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/process/Process.d.ts +247 -0
  36. package/dist/types/src/process/Process.d.ts.map +1 -0
  37. package/dist/types/src/process/ServiceResolver.d.ts +74 -0
  38. package/dist/types/src/process/ServiceResolver.d.ts.map +1 -0
  39. package/dist/types/src/process/StorageService.d.ts +58 -0
  40. package/dist/types/src/process/StorageService.d.ts.map +1 -0
  41. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  42. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  43. package/dist/types/src/protocol/protocol.d.ts +2 -2
  44. package/dist/types/src/protocol/protocol.d.ts.map +1 -1
  45. package/dist/types/src/sdk.d.ts +4 -79
  46. package/dist/types/src/sdk.d.ts.map +1 -1
  47. package/dist/types/src/services/credentials.d.ts +6 -4
  48. package/dist/types/src/services/credentials.d.ts.map +1 -1
  49. package/dist/types/src/services/event-logger.d.ts +25 -31
  50. package/dist/types/src/services/event-logger.d.ts.map +1 -1
  51. package/dist/types/src/services/function-invocation-service.d.ts +9 -3
  52. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  53. package/dist/types/src/services/index.d.ts +0 -1
  54. package/dist/types/src/services/index.d.ts.map +1 -1
  55. package/dist/types/src/services/queues.d.ts +8 -5
  56. package/dist/types/src/services/queues.d.ts.map +1 -1
  57. package/dist/types/src/services/tracing.d.ts +61 -4
  58. package/dist/types/src/services/tracing.d.ts.map +1 -1
  59. package/dist/types/src/types/Script.d.ts +10 -16
  60. package/dist/types/src/types/Script.d.ts.map +1 -1
  61. package/dist/types/src/types/Trigger.d.ts +57 -76
  62. package/dist/types/src/types/Trigger.d.ts.map +1 -1
  63. package/dist/types/src/types/TriggerEvent.d.ts +44 -13
  64. package/dist/types/src/types/TriggerEvent.d.ts.map +1 -1
  65. package/dist/types/src/types/index.d.ts +0 -1
  66. package/dist/types/src/types/index.d.ts.map +1 -1
  67. package/dist/types/src/types/url.d.ts +6 -5
  68. package/dist/types/src/types/url.d.ts.map +1 -1
  69. package/dist/types/tsconfig.tsbuildinfo +1 -1
  70. package/package.json +29 -17
  71. package/src/Trace.ts +202 -0
  72. package/src/errors.ts +5 -5
  73. package/src/example/definitions.ts +49 -0
  74. package/src/example/fib.ts +15 -24
  75. package/src/example/forex-effect.ts +1 -1
  76. package/src/example/index.ts +7 -8
  77. package/src/example/reply.ts +11 -13
  78. package/src/example/sleep.ts +9 -16
  79. package/src/index.ts +4 -0
  80. package/src/process/Process.ts +486 -0
  81. package/src/process/ServiceResolver.ts +174 -0
  82. package/src/process/StorageService.ts +99 -0
  83. package/src/protocol/functions-ai-http-client.ts +67 -0
  84. package/src/protocol/protocol.test.ts +0 -1
  85. package/src/protocol/protocol.ts +206 -84
  86. package/src/sdk.ts +7 -194
  87. package/src/services/credentials.ts +31 -15
  88. package/src/services/event-logger.ts +2 -2
  89. package/src/services/function-invocation-service.ts +19 -3
  90. package/src/services/index.ts +0 -2
  91. package/src/services/queues.ts +15 -8
  92. package/src/services/tracing.ts +97 -5
  93. package/src/types/Script.ts +14 -9
  94. package/src/types/Trigger.ts +33 -18
  95. package/src/types/TriggerEvent.ts +29 -29
  96. package/src/types/index.ts +0 -1
  97. package/src/types/url.ts +6 -5
  98. package/dist/lib/browser/index.mjs +0 -927
  99. package/dist/lib/browser/index.mjs.map +0 -7
  100. package/dist/lib/browser/meta.json +0 -1
  101. package/dist/lib/node-esm/index.mjs +0 -928
  102. package/dist/lib/node-esm/index.mjs.map +0 -7
  103. package/dist/lib/node-esm/meta.json +0 -1
  104. package/dist/types/src/types/Function.d.ts +0 -58
  105. package/dist/types/src/types/Function.d.ts.map +0 -1
  106. package/src/types/Function.ts +0 -62
@@ -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,17 @@ 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(burdon): Change to Feed.
28
+ // TODO(wittjosiah): Remove. Migrate to Subscription triggers once EDGE supports them for feed queries.
27
29
  export const QueueSpec = Schema.Struct({
28
30
  kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
29
31
 
30
- // TODO(dmaretskyi): Change to a reference.
32
+ // TODO(dmaretskyi): Rename to `feed` and change to a reference.
31
33
  queue: DXN.Schema,
32
- }).pipe(Schema.mutable);
34
+ });
33
35
  export type QueueSpec = Schema.Schema.Type<typeof QueueSpec>;
34
36
 
35
37
  /**
@@ -40,7 +42,7 @@ export const SubscriptionSpec = Schema.Struct({
40
42
  query: Schema.Struct({
41
43
  raw: Schema.optional(Schema.String.annotations({ title: 'Query' })),
42
44
  ast: QueryAST.Query,
43
- }).pipe(Schema.mutable),
45
+ }),
44
46
  options: Schema.optional(
45
47
  Schema.Struct({
46
48
  // Watch changes to object (not just creation).
@@ -49,7 +51,7 @@ export const SubscriptionSpec = Schema.Struct({
49
51
  delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
50
52
  }).annotations({ title: 'Options' }),
51
53
  ),
52
- }).pipe(Schema.mutable);
54
+ });
53
55
  export type SubscriptionSpec = Schema.Schema.Type<typeof SubscriptionSpec>;
54
56
 
55
57
  /**
@@ -61,7 +63,7 @@ export const TimerSpec = Schema.Struct({
61
63
  title: 'Cron',
62
64
  [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
63
65
  }),
64
- }).pipe(Schema.mutable);
66
+ });
65
67
  export type TimerSpec = Schema.Schema.Type<typeof TimerSpec>;
66
68
 
67
69
  /**
@@ -80,7 +82,7 @@ export const WebhookSpec = Schema.Struct({
80
82
  title: 'Port',
81
83
  }),
82
84
  ),
83
- }).pipe(Schema.mutable);
85
+ });
84
86
  export type WebhookSpec = Schema.Schema.Type<typeof WebhookSpec>;
85
87
 
86
88
  /**
@@ -96,12 +98,12 @@ export type Spec = Schema.Schema.Type<typeof Spec>;
96
98
  * Function is invoked with the `payload` passed as input data.
97
99
  * The event that triggers the function is available in the function context.
98
100
  */
99
- const Trigger_ = Schema.Struct({
101
+ const TriggerSchema = Schema.Struct({
100
102
  /**
101
103
  * Function or workflow to invoke.
102
104
  */
103
105
  // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
104
- function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
106
+ function: Schema.optional(Ref.Ref(Obj.Unknown).annotations({ title: 'Function' })),
105
107
 
106
108
  /**
107
109
  * Only used for workflowSchema.
@@ -110,30 +112,43 @@ const Trigger_ = Schema.Struct({
110
112
  */
111
113
  inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
112
114
 
115
+ // TODO(burdon): NO BOOLEAN PROPERTIES (enabld/disabled/paused, etc.)
116
+ // Need lint rule; or agent rule to require PR review for "boolean" key word.
113
117
  enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
114
118
 
115
119
  spec: Schema.optional(Spec),
116
120
 
121
+ concurrency: Schema.optional(
122
+ Schema.Number.annotations({
123
+ title: 'Concurrency',
124
+ default: 1,
125
+ description:
126
+ 'Maximum number of concurrent invocations of the trigger. For Feed triggers, this will process Feed items in parallel.',
127
+ }),
128
+ ),
129
+
117
130
  /**
118
131
  * Passed as the input data to the function.
119
132
  * Must match the function's input schema.
120
133
  *
121
134
  * @example
122
135
  * {
123
- * item: '{{$.trigger.event}}',
136
+ * item: '{{event.item}}',
124
137
  * instructions: 'Summarize and perform entity-extraction'
125
138
  * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
126
139
  * }
127
140
  */
128
- input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
141
+ input: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),
129
142
  }).pipe(
130
- Type.Obj({
131
- typename: 'dxos.org/type/Trigger',
143
+ Type.object({
144
+ typename: 'org.dxos.type.trigger',
132
145
  version: '0.1.0',
133
146
  }),
147
+ Annotation.IconAnnotation.set({ icon: 'ph--lightning--regular', hue: 'yellow' }),
148
+ SystemTypeAnnotation.set(true),
134
149
  );
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_;
150
+
151
+ export interface Trigger extends Schema.Schema.Type<typeof TriggerSchema> {}
152
+ export const Trigger: Type.Obj<Trigger> = TriggerSchema as any;
138
153
 
139
154
  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) {