@dxos/functions 0.8.4-main.c4373fc → 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 (181) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/index.mjs +475 -0
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/index.d.ts +3 -9
  6. package/dist/types/src/index.d.ts.map +1 -1
  7. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  8. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  9. package/dist/types/src/protocol/index.d.ts +2 -0
  10. package/dist/types/src/protocol/index.d.ts.map +1 -0
  11. package/dist/types/src/protocol/protocol.d.ts +7 -0
  12. package/dist/types/src/protocol/protocol.d.ts.map +1 -0
  13. package/dist/types/src/protocol/protocol.test.d.ts +2 -0
  14. package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
  15. package/dist/types/src/sdk.d.ts +10 -0
  16. package/dist/types/src/sdk.d.ts.map +1 -0
  17. package/dist/types/src/services/credentials.d.ts +17 -38
  18. package/dist/types/src/services/credentials.d.ts.map +1 -1
  19. package/dist/types/src/services/function-invocation-service.d.ts +6 -19
  20. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -1
  21. package/dist/types/src/services/index.d.ts +1 -6
  22. package/dist/types/src/services/index.d.ts.map +1 -1
  23. package/dist/types/src/services/queues.d.ts +1 -46
  24. package/dist/types/src/services/queues.d.ts.map +1 -1
  25. package/dist/types/src/services/tracing.d.ts +2 -56
  26. package/dist/types/src/services/tracing.d.ts.map +1 -1
  27. package/dist/types/src/types/index.d.ts +2 -0
  28. package/dist/types/src/types/index.d.ts.map +1 -0
  29. package/dist/types/src/types/url.d.ts +13 -0
  30. package/dist/types/src/types/url.d.ts.map +1 -0
  31. package/dist/types/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +25 -63
  33. package/src/index.ts +3 -9
  34. package/src/protocol/functions-ai-http-client.ts +67 -0
  35. package/src/{executor → protocol}/index.ts +1 -1
  36. package/src/protocol/protocol.test.ts +58 -0
  37. package/src/protocol/protocol.ts +292 -0
  38. package/src/sdk.ts +29 -0
  39. package/src/services/credentials.ts +81 -109
  40. package/src/services/function-invocation-service.ts +19 -70
  41. package/src/services/index.ts +1 -6
  42. package/src/services/queues.ts +1 -80
  43. package/src/services/tracing.ts +1 -136
  44. package/src/types/index.ts +5 -0
  45. package/src/types/url.ts +32 -0
  46. package/dist/lib/browser/bundler/index.mjs +0 -269
  47. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  48. package/dist/lib/browser/chunk-J5LGTIGS.mjs +0 -10
  49. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +0 -7
  50. package/dist/lib/browser/chunk-LKYT2SAL.mjs +0 -665
  51. package/dist/lib/browser/chunk-LKYT2SAL.mjs.map +0 -7
  52. package/dist/lib/browser/edge/index.mjs +0 -83
  53. package/dist/lib/browser/edge/index.mjs.map +0 -7
  54. package/dist/lib/browser/index.mjs +0 -1395
  55. package/dist/lib/browser/index.mjs.map +0 -7
  56. package/dist/lib/browser/meta.json +0 -1
  57. package/dist/lib/browser/testing/index.mjs +0 -131
  58. package/dist/lib/browser/testing/index.mjs.map +0 -7
  59. package/dist/lib/node-esm/bundler/index.mjs +0 -270
  60. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  61. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +0 -11
  62. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +0 -7
  63. package/dist/lib/node-esm/chunk-NAQIKLZB.mjs +0 -667
  64. package/dist/lib/node-esm/chunk-NAQIKLZB.mjs.map +0 -7
  65. package/dist/lib/node-esm/edge/index.mjs +0 -84
  66. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  67. package/dist/lib/node-esm/index.mjs +0 -1396
  68. package/dist/lib/node-esm/index.mjs.map +0 -7
  69. package/dist/lib/node-esm/meta.json +0 -1
  70. package/dist/lib/node-esm/testing/index.mjs +0 -132
  71. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  72. package/dist/types/src/bundler/bundler.d.ts +0 -49
  73. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  74. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  75. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  76. package/dist/types/src/bundler/index.d.ts +0 -2
  77. package/dist/types/src/bundler/index.d.ts.map +0 -1
  78. package/dist/types/src/edge/functions.d.ts +0 -17
  79. package/dist/types/src/edge/functions.d.ts.map +0 -1
  80. package/dist/types/src/edge/index.d.ts +0 -2
  81. package/dist/types/src/edge/index.d.ts.map +0 -1
  82. package/dist/types/src/errors.d.ts +0 -137
  83. package/dist/types/src/errors.d.ts.map +0 -1
  84. package/dist/types/src/examples/fib.d.ts +0 -7
  85. package/dist/types/src/examples/fib.d.ts.map +0 -1
  86. package/dist/types/src/examples/index.d.ts +0 -4
  87. package/dist/types/src/examples/index.d.ts.map +0 -1
  88. package/dist/types/src/examples/reply.d.ts +0 -3
  89. package/dist/types/src/examples/reply.d.ts.map +0 -1
  90. package/dist/types/src/examples/sleep.d.ts +0 -5
  91. package/dist/types/src/examples/sleep.d.ts.map +0 -1
  92. package/dist/types/src/executor/executor.d.ts +0 -14
  93. package/dist/types/src/executor/executor.d.ts.map +0 -1
  94. package/dist/types/src/executor/index.d.ts +0 -2
  95. package/dist/types/src/executor/index.d.ts.map +0 -1
  96. package/dist/types/src/handler.d.ts +0 -109
  97. package/dist/types/src/handler.d.ts.map +0 -1
  98. package/dist/types/src/schema.d.ts +0 -43
  99. package/dist/types/src/schema.d.ts.map +0 -1
  100. package/dist/types/src/services/database.d.ts +0 -67
  101. package/dist/types/src/services/database.d.ts.map +0 -1
  102. package/dist/types/src/services/event-logger.d.ts +0 -75
  103. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  104. package/dist/types/src/services/function-invocation-service.test.d.ts +0 -2
  105. package/dist/types/src/services/function-invocation-service.test.d.ts.map +0 -1
  106. package/dist/types/src/services/local-function-execution.d.ts +0 -34
  107. package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
  108. package/dist/types/src/services/remote-function-execution-service.d.ts +0 -22
  109. package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
  110. package/dist/types/src/services/service-container.d.ts +0 -57
  111. package/dist/types/src/services/service-container.d.ts.map +0 -1
  112. package/dist/types/src/services/service-registry.d.ts +0 -31
  113. package/dist/types/src/services/service-registry.d.ts.map +0 -1
  114. package/dist/types/src/services/service-registry.test.d.ts +0 -2
  115. package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
  116. package/dist/types/src/testing/index.d.ts +0 -3
  117. package/dist/types/src/testing/index.d.ts.map +0 -1
  118. package/dist/types/src/testing/layer.d.ts +0 -18
  119. package/dist/types/src/testing/layer.d.ts.map +0 -1
  120. package/dist/types/src/testing/logger.d.ts +0 -5
  121. package/dist/types/src/testing/logger.d.ts.map +0 -1
  122. package/dist/types/src/testing/persist-database.test.d.ts +0 -2
  123. package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
  124. package/dist/types/src/testing/services.d.ts +0 -59
  125. package/dist/types/src/testing/services.d.ts.map +0 -1
  126. package/dist/types/src/trace.d.ts +0 -122
  127. package/dist/types/src/trace.d.ts.map +0 -1
  128. package/dist/types/src/translations.d.ts +0 -12
  129. package/dist/types/src/translations.d.ts.map +0 -1
  130. package/dist/types/src/triggers/index.d.ts +0 -4
  131. package/dist/types/src/triggers/index.d.ts.map +0 -1
  132. package/dist/types/src/triggers/input-builder.d.ts +0 -3
  133. package/dist/types/src/triggers/input-builder.d.ts.map +0 -1
  134. package/dist/types/src/triggers/invocation-tracer.d.ts +0 -37
  135. package/dist/types/src/triggers/invocation-tracer.d.ts.map +0 -1
  136. package/dist/types/src/triggers/trigger-dispatcher.d.ts +0 -78
  137. package/dist/types/src/triggers/trigger-dispatcher.d.ts.map +0 -1
  138. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts +0 -2
  139. package/dist/types/src/triggers/trigger-dispatcher.test.d.ts.map +0 -1
  140. package/dist/types/src/triggers/trigger-state-store.d.ts +0 -28
  141. package/dist/types/src/triggers/trigger-state-store.d.ts.map +0 -1
  142. package/dist/types/src/types.d.ts +0 -230
  143. package/dist/types/src/types.d.ts.map +0 -1
  144. package/dist/types/src/url.d.ts +0 -21
  145. package/dist/types/src/url.d.ts.map +0 -1
  146. package/src/bundler/bundler.test.ts +0 -58
  147. package/src/bundler/bundler.ts +0 -295
  148. package/src/bundler/index.ts +0 -5
  149. package/src/edge/functions.ts +0 -67
  150. package/src/edge/index.ts +0 -9
  151. package/src/errors.ts +0 -21
  152. package/src/examples/fib.ts +0 -32
  153. package/src/examples/index.ts +0 -7
  154. package/src/examples/reply.ts +0 -21
  155. package/src/examples/sleep.ts +0 -24
  156. package/src/executor/executor.ts +0 -58
  157. package/src/handler.ts +0 -225
  158. package/src/schema.ts +0 -71
  159. package/src/services/database.ts +0 -175
  160. package/src/services/event-logger.ts +0 -121
  161. package/src/services/function-invocation-service.test.ts +0 -81
  162. package/src/services/local-function-execution.ts +0 -153
  163. package/src/services/remote-function-execution-service.ts +0 -63
  164. package/src/services/service-container.ts +0 -115
  165. package/src/services/service-registry.test.ts +0 -45
  166. package/src/services/service-registry.ts +0 -63
  167. package/src/testing/index.ts +0 -6
  168. package/src/testing/layer.ts +0 -114
  169. package/src/testing/logger.ts +0 -17
  170. package/src/testing/persist-database.test.ts +0 -87
  171. package/src/testing/services.ts +0 -115
  172. package/src/trace.ts +0 -178
  173. package/src/translations.ts +0 -20
  174. package/src/triggers/index.ts +0 -7
  175. package/src/triggers/input-builder.ts +0 -35
  176. package/src/triggers/invocation-tracer.ts +0 -101
  177. package/src/triggers/trigger-dispatcher.test.ts +0 -665
  178. package/src/triggers/trigger-dispatcher.ts +0 -533
  179. package/src/triggers/trigger-state-store.ts +0 -61
  180. package/src/types.ts +0 -218
  181. package/src/url.ts +0 -55
package/src/types.ts DELETED
@@ -1,218 +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 { Obj, QueryAST, Type } from '@dxos/echo';
9
- import { Expando, OptionsAnnotationId, RawObject, Ref } from '@dxos/echo/internal';
10
- import { DXN } from '@dxos/keys';
11
-
12
- import { FunctionType } from './schema';
13
-
14
- /**
15
- * Type discriminator for TriggerType.
16
- * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.
17
- * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions
18
- */
19
- export const TriggerKinds = ['timer', 'webhook', 'subscription', 'email', 'queue'] as const;
20
- export type TriggerKind = (typeof TriggerKinds)[number];
21
-
22
- const kindLiteralAnnotations = { title: 'Kind' };
23
-
24
- /**
25
- * Cron timer.
26
- */
27
- const TimerTriggerSchema = Schema.Struct({
28
- kind: Schema.Literal('timer').annotations(kindLiteralAnnotations),
29
- cron: Schema.String.annotations({
30
- title: 'Cron',
31
- [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],
32
- }),
33
- }).pipe(Schema.mutable);
34
- export type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;
35
-
36
- const EmailTriggerSchema = Schema.Struct({
37
- kind: Schema.Literal('email').annotations(kindLiteralAnnotations),
38
- }).pipe(Schema.mutable);
39
- export type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;
40
-
41
- const QueueTriggerSchema = Schema.Struct({
42
- kind: Schema.Literal('queue').annotations(kindLiteralAnnotations),
43
-
44
- // TODO(dmaretskyi): Change to a reference.
45
- queue: DXN.Schema,
46
- }).pipe(Schema.mutable);
47
- export type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;
48
-
49
- /**
50
- * Webhook.
51
- */
52
- const WebhookTriggerSchema = Schema.Struct({
53
- kind: Schema.Literal('webhook').annotations(kindLiteralAnnotations),
54
- method: Schema.optional(
55
- Schema.String.annotations({
56
- title: 'Method',
57
- [OptionsAnnotationId]: ['GET', 'POST'],
58
- }),
59
- ),
60
- port: Schema.optional(
61
- Schema.Number.annotations({
62
- title: 'Port',
63
- }),
64
- ),
65
- }).pipe(Schema.mutable);
66
- export type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;
67
-
68
- /**
69
- * Subscription.
70
- */
71
- const SubscriptionTriggerSchema = Schema.Struct({
72
- kind: Schema.Literal('subscription').annotations(kindLiteralAnnotations),
73
- query: Schema.Struct({
74
- string: Schema.optional(Schema.String.annotations({ title: 'Query' })),
75
- ast: QueryAST.Query,
76
- }).pipe(Schema.mutable),
77
- options: Schema.optional(
78
- Schema.Struct({
79
- // Watch changes to object (not just creation).
80
- deep: Schema.optional(Schema.Boolean.annotations({ title: 'Nested' })),
81
- // Debounce changes (delay in ms).
82
- delay: Schema.optional(Schema.Number.annotations({ title: 'Delay' })),
83
- }).annotations({ title: 'Options' }),
84
- ),
85
- }).pipe(Schema.mutable);
86
- export type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;
87
-
88
- /**
89
- * Trigger schema (discriminated union).
90
- */
91
- export const TriggerSchema = Schema.Union(
92
- TimerTriggerSchema,
93
- WebhookTriggerSchema,
94
- SubscriptionTriggerSchema,
95
- EmailTriggerSchema,
96
- QueueTriggerSchema,
97
- ).annotations({
98
- title: 'Trigger',
99
- });
100
- export type TriggerType = Schema.Schema.Type<typeof TriggerSchema>;
101
-
102
- export type EventType =
103
- | EmailTriggerOutput
104
- | WebhookTriggerOutput
105
- | QueueTriggerOutput
106
- | SubscriptionTriggerOutput
107
- | TimerTriggerOutput;
108
-
109
- // TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).
110
- export const EmailTriggerOutput = Schema.mutable(
111
- Schema.Struct({
112
- from: Schema.String,
113
- to: Schema.String,
114
- subject: Schema.String,
115
- created: Schema.String,
116
- body: Schema.String,
117
- }),
118
- );
119
- export type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;
120
-
121
- export const WebhookTriggerOutput = Schema.mutable(
122
- Schema.Struct({
123
- url: Schema.String,
124
- method: Schema.Literal('GET', 'POST'),
125
- headers: Schema.Record({ key: Schema.String, value: Schema.String }),
126
- bodyText: Schema.String,
127
- }),
128
- );
129
- export type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;
130
-
131
- export const QueueTriggerOutput = Schema.mutable(
132
- Schema.Struct({
133
- queue: DXN.Schema,
134
- item: Schema.Any,
135
- cursor: Schema.String,
136
- }),
137
- );
138
- export type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;
139
-
140
- export const SubscriptionTriggerOutput = Schema.Struct({
141
- /**
142
- * Type of the mutation.
143
- */
144
- // TODO(dmaretskyi): Specify enum.
145
- type: Schema.String,
146
-
147
- /**
148
- * Reference to the object that was changed or created.
149
- */
150
- subject: Type.Ref(Obj.Any),
151
-
152
- /**
153
- * @deprecated
154
- */
155
- changedObjectId: Schema.optional(Schema.String),
156
- }).pipe(Schema.mutable);
157
- export type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;
158
-
159
- export const TimerTriggerOutput = Schema.mutable(Schema.Struct({ tick: Schema.Number }));
160
- export type TimerTriggerOutput = Schema.Schema.Type<typeof TimerTriggerOutput>;
161
-
162
- /**
163
- * Function trigger.
164
- * Function is invoked with the `payload` passed as input data.
165
- * The event that triggers the function is available in the function context.
166
- */
167
- const FunctionTrigger_ = Schema.Struct({
168
- /**
169
- * Function or workflow to invoke.
170
- */
171
- // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
172
- function: Schema.optional(Ref(Expando).annotations({ title: 'Function' })),
173
-
174
- /**
175
- * Only used for workflowSchema.
176
- * Specifies the input node in the circuit.
177
- * @deprecated Remove and enforce a single input node in all compute graphSchema.
178
- */
179
- inputNodeId: Schema.optional(Schema.String.annotations({ title: 'Input Node ID' })),
180
-
181
- enabled: Schema.optional(Schema.Boolean.annotations({ title: 'Enabled' })),
182
-
183
- spec: Schema.optional(TriggerSchema),
184
-
185
- /**
186
- * Passed as the input data to the function.
187
- * Must match the function's input schema.
188
- *
189
- * @example
190
- * {
191
- * item: '{{$.trigger.event}}',
192
- * instructions: 'Summarize and perform entity-extraction'
193
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
194
- * }
195
- */
196
- input: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),
197
- }).pipe(
198
- Type.Obj({
199
- typename: 'dxos.org/type/FunctionTrigger',
200
- version: '0.2.0',
201
- }),
202
- );
203
- export interface FunctionTrigger extends Schema.Schema.Type<typeof FunctionTrigger_> {}
204
- export interface FunctionTriggerEncoded extends Schema.Schema.Encoded<typeof FunctionTrigger_> {}
205
- export const FunctionTrigger: Schema.Schema<FunctionTrigger, FunctionTriggerEncoded> = FunctionTrigger_;
206
-
207
- // TODO(wittjosiah): Remove?
208
-
209
- /**
210
- * Function manifest file.
211
- */
212
- export const FunctionManifestSchema = Schema.Struct({
213
- functions: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionType)))),
214
- triggers: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionTrigger)))),
215
- });
216
- export type FunctionManifest = Schema.Schema.Type<typeof FunctionManifestSchema>;
217
-
218
- export const FUNCTION_TYPES = [FunctionType, FunctionTrigger];
package/src/url.ts DELETED
@@ -1,55 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type ObjectMeta } from '@dxos/echo/internal';
6
- import { type SpaceId } from '@dxos/keys';
7
-
8
- // TODO: use URL scheme for source?
9
- export const FUNCTIONS_META_KEY = 'dxos.org/service/function';
10
-
11
- export const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';
12
-
13
- const isSecure = (protocol: string) => {
14
- return protocol === 'https:' || protocol === 'wss:';
15
- };
16
-
17
- /**
18
- * NOTE: functionId is backend ID, not ECHO object id.
19
- */
20
- export const getUserFunctionIdInMetadata = (meta: ObjectMeta) => {
21
- return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
22
- };
23
-
24
- /**
25
- * NOTE: functionId is backend ID, not ECHO object id.
26
- */
27
- export const setUserFunctionIdInMetadata = (meta: ObjectMeta, functionId: string) => {
28
- const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);
29
- if (key) {
30
- if (key.id !== functionId) {
31
- throw new Error('Metadata mismatch');
32
- }
33
- } else {
34
- meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionId });
35
- }
36
- };
37
-
38
- /**
39
- * NOTE: functionId is backend ID, not ECHO object id.
40
- */
41
- export const getInvocationUrl = (functionId: string, edgeUrl: string, options: InvocationOptions = {}) => {
42
- const baseUrl = new URL('functions/', edgeUrl);
43
-
44
- // Leading slashes cause the URL to be treated as an absolute path.
45
- const url = new URL(`./${functionId}`, baseUrl.toString());
46
- options.spaceId && url.searchParams.set('spaceId', options.spaceId);
47
- options.subjectId && url.searchParams.set('subjectId', options.subjectId);
48
- url.protocol = isSecure(url.protocol) ? 'https' : 'http';
49
- return url.toString();
50
- };
51
-
52
- export type InvocationOptions = {
53
- spaceId?: SpaceId;
54
- subjectId?: string;
55
- };