@dxos/functions 0.8.1 → 0.8.2-main.2f9c567

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 (168) hide show
  1. package/dist/lib/browser/bundler/index.mjs +0 -3
  2. package/dist/lib/browser/bundler/index.mjs.map +1 -1
  3. package/dist/lib/browser/edge/index.mjs +63 -7
  4. package/dist/lib/browser/edge/index.mjs.map +4 -4
  5. package/dist/lib/browser/index.mjs +368 -98
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/node/bundler/index.cjs +0 -1
  9. package/dist/lib/node/bundler/index.cjs.map +1 -1
  10. package/dist/lib/node/edge/index.cjs +65 -5
  11. package/dist/lib/node/edge/index.cjs.map +4 -4
  12. package/dist/lib/node/index.cjs +383 -93
  13. package/dist/lib/node/index.cjs.map +4 -4
  14. package/dist/lib/node/meta.json +1 -1
  15. package/dist/lib/node-esm/bundler/index.mjs +0 -1
  16. package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
  17. package/dist/lib/node-esm/edge/index.mjs +64 -6
  18. package/dist/lib/node-esm/edge/index.mjs.map +4 -4
  19. package/dist/lib/node-esm/index.mjs +368 -96
  20. package/dist/lib/node-esm/index.mjs.map +4 -4
  21. package/dist/lib/node-esm/meta.json +1 -1
  22. package/dist/types/src/edge/index.d.ts.map +1 -1
  23. package/dist/types/src/handler.d.ts +15 -63
  24. package/dist/types/src/handler.d.ts.map +1 -1
  25. package/dist/types/src/index.d.ts +3 -3
  26. package/dist/types/src/index.d.ts.map +1 -1
  27. package/dist/types/src/schema.d.ts +57 -0
  28. package/dist/types/src/schema.d.ts.map +1 -0
  29. package/dist/types/src/trace.d.ts +148 -0
  30. package/dist/types/src/trace.d.ts.map +1 -0
  31. package/dist/types/src/{types/types.d.ts → types.d.ts} +191 -49
  32. package/dist/types/src/types.d.ts.map +1 -0
  33. package/dist/types/src/{types/url.d.ts → url.d.ts} +6 -0
  34. package/dist/types/src/url.d.ts.map +1 -0
  35. package/package.json +20 -35
  36. package/src/edge/index.ts +4 -0
  37. package/src/handler.ts +17 -120
  38. package/src/index.ts +4 -5
  39. package/src/schema.ts +53 -0
  40. package/src/{types/trace.ts → trace.ts} +33 -31
  41. package/src/translations.ts +1 -1
  42. package/src/types.ts +214 -0
  43. package/src/{types/url.ts → url.ts} +5 -0
  44. package/dist/lib/browser/chunk-HI7YZO2K.mjs +0 -482
  45. package/dist/lib/browser/chunk-HI7YZO2K.mjs.map +0 -7
  46. package/dist/lib/browser/chunk-LT4LR4VU.mjs +0 -72
  47. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +0 -7
  48. package/dist/lib/browser/chunk-RVSG6WTL.mjs +0 -358
  49. package/dist/lib/browser/chunk-RVSG6WTL.mjs.map +0 -7
  50. package/dist/lib/browser/chunk-XRCXIG74.mjs +0 -12
  51. package/dist/lib/browser/chunk-XRCXIG74.mjs.map +0 -7
  52. package/dist/lib/browser/testing/index.mjs +0 -670
  53. package/dist/lib/browser/testing/index.mjs.map +0 -7
  54. package/dist/lib/browser/types/index.mjs +0 -49
  55. package/dist/lib/browser/types/index.mjs.map +0 -7
  56. package/dist/lib/node/chunk-DSUGRAAL.cjs +0 -392
  57. package/dist/lib/node/chunk-DSUGRAAL.cjs.map +0 -7
  58. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +0 -34
  59. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +0 -7
  60. package/dist/lib/node/chunk-NXZNXVT3.cjs +0 -94
  61. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +0 -7
  62. package/dist/lib/node/chunk-RXMCVAMJ.cjs +0 -496
  63. package/dist/lib/node/chunk-RXMCVAMJ.cjs.map +0 -7
  64. package/dist/lib/node/testing/index.cjs +0 -687
  65. package/dist/lib/node/testing/index.cjs.map +0 -7
  66. package/dist/lib/node/types/index.cjs +0 -70
  67. package/dist/lib/node/types/index.cjs.map +0 -7
  68. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +0 -12
  69. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-HBD2FZXO.mjs +0 -358
  71. package/dist/lib/node-esm/chunk-HBD2FZXO.mjs.map +0 -7
  72. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +0 -72
  73. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +0 -7
  74. package/dist/lib/node-esm/chunk-SQSJO5HI.mjs +0 -482
  75. package/dist/lib/node-esm/chunk-SQSJO5HI.mjs.map +0 -7
  76. package/dist/lib/node-esm/testing/index.mjs +0 -670
  77. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  78. package/dist/lib/node-esm/types/index.mjs +0 -49
  79. package/dist/lib/node-esm/types/index.mjs.map +0 -7
  80. package/dist/types/src/browser/index.d.ts +0 -2
  81. package/dist/types/src/browser/index.d.ts.map +0 -1
  82. package/dist/types/src/function/function-registry.d.ts +0 -25
  83. package/dist/types/src/function/function-registry.d.ts.map +0 -1
  84. package/dist/types/src/function/function-registry.test.d.ts +0 -2
  85. package/dist/types/src/function/function-registry.test.d.ts.map +0 -1
  86. package/dist/types/src/function/index.d.ts +0 -2
  87. package/dist/types/src/function/index.d.ts.map +0 -1
  88. package/dist/types/src/runtime/dev-server.d.ts +0 -52
  89. package/dist/types/src/runtime/dev-server.d.ts.map +0 -1
  90. package/dist/types/src/runtime/dev-server.test.d.ts +0 -2
  91. package/dist/types/src/runtime/dev-server.test.d.ts.map +0 -1
  92. package/dist/types/src/runtime/index.d.ts +0 -3
  93. package/dist/types/src/runtime/index.d.ts.map +0 -1
  94. package/dist/types/src/runtime/scheduler.d.ts +0 -34
  95. package/dist/types/src/runtime/scheduler.d.ts.map +0 -1
  96. package/dist/types/src/runtime/scheduler.test.d.ts +0 -2
  97. package/dist/types/src/runtime/scheduler.test.d.ts.map +0 -1
  98. package/dist/types/src/testing/functions-integration.test.d.ts +0 -2
  99. package/dist/types/src/testing/functions-integration.test.d.ts.map +0 -1
  100. package/dist/types/src/testing/index.d.ts +0 -5
  101. package/dist/types/src/testing/index.d.ts.map +0 -1
  102. package/dist/types/src/testing/manifest.d.ts +0 -3
  103. package/dist/types/src/testing/manifest.d.ts.map +0 -1
  104. package/dist/types/src/testing/plugin-init.d.ts +0 -6
  105. package/dist/types/src/testing/plugin-init.d.ts.map +0 -1
  106. package/dist/types/src/testing/setup.d.ts +0 -15
  107. package/dist/types/src/testing/setup.d.ts.map +0 -1
  108. package/dist/types/src/testing/test/handler.d.ts +0 -4
  109. package/dist/types/src/testing/test/handler.d.ts.map +0 -1
  110. package/dist/types/src/testing/test/index.d.ts +0 -3
  111. package/dist/types/src/testing/test/index.d.ts.map +0 -1
  112. package/dist/types/src/testing/types.d.ts +0 -10
  113. package/dist/types/src/testing/types.d.ts.map +0 -1
  114. package/dist/types/src/testing/util.d.ts +0 -5
  115. package/dist/types/src/testing/util.d.ts.map +0 -1
  116. package/dist/types/src/trigger/index.d.ts +0 -3
  117. package/dist/types/src/trigger/index.d.ts.map +0 -1
  118. package/dist/types/src/trigger/trigger-registry.d.ts +0 -38
  119. package/dist/types/src/trigger/trigger-registry.d.ts.map +0 -1
  120. package/dist/types/src/trigger/trigger-registry.test.d.ts +0 -2
  121. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +0 -1
  122. package/dist/types/src/trigger/type/index.d.ts +0 -3
  123. package/dist/types/src/trigger/type/index.d.ts.map +0 -1
  124. package/dist/types/src/trigger/type/subscription-trigger.d.ts +0 -4
  125. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +0 -1
  126. package/dist/types/src/trigger/type/timer-trigger.d.ts +0 -4
  127. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +0 -1
  128. package/dist/types/src/trigger/type/webhook-trigger.d.ts +0 -4
  129. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +0 -1
  130. package/dist/types/src/types/index.d.ts +0 -5
  131. package/dist/types/src/types/index.d.ts.map +0 -1
  132. package/dist/types/src/types/schema.d.ts +0 -53
  133. package/dist/types/src/types/schema.d.ts.map +0 -1
  134. package/dist/types/src/types/trace.d.ts +0 -146
  135. package/dist/types/src/types/trace.d.ts.map +0 -1
  136. package/dist/types/src/types/types.d.ts.map +0 -1
  137. package/dist/types/src/types/url.d.ts.map +0 -1
  138. package/dist/types/tools/schema.d.ts +0 -2
  139. package/dist/types/tools/schema.d.ts.map +0 -1
  140. package/schema/functions.json +0 -211
  141. package/src/browser/index.ts +0 -5
  142. package/src/function/function-registry.test.ts +0 -118
  143. package/src/function/function-registry.ts +0 -104
  144. package/src/function/index.ts +0 -5
  145. package/src/runtime/dev-server.test.ts +0 -79
  146. package/src/runtime/dev-server.ts +0 -240
  147. package/src/runtime/index.ts +0 -6
  148. package/src/runtime/scheduler.test.ts +0 -152
  149. package/src/runtime/scheduler.ts +0 -170
  150. package/src/testing/functions-integration.test.ts +0 -65
  151. package/src/testing/index.ts +0 -8
  152. package/src/testing/manifest.ts +0 -15
  153. package/src/testing/plugin-init.ts +0 -20
  154. package/src/testing/setup.ts +0 -109
  155. package/src/testing/test/handler.ts +0 -15
  156. package/src/testing/test/index.ts +0 -7
  157. package/src/testing/types.ts +0 -9
  158. package/src/testing/util.ts +0 -26
  159. package/src/trigger/index.ts +0 -6
  160. package/src/trigger/trigger-registry.test.ts +0 -278
  161. package/src/trigger/trigger-registry.ts +0 -218
  162. package/src/trigger/type/index.ts +0 -7
  163. package/src/trigger/type/subscription-trigger.ts +0 -84
  164. package/src/trigger/type/timer-trigger.ts +0 -48
  165. package/src/trigger/type/webhook-trigger.ts +0 -48
  166. package/src/types/index.ts +0 -8
  167. package/src/types/schema.ts +0 -46
  168. package/src/types/types.ts +0 -163
@@ -1,46 +1,7 @@
1
1
  import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
- import {
3
- incrementSemverPatch,
4
- publicKeyToDid,
5
- uploadWorkerFunction
6
- } from "./chunk-O2SXVYU5.mjs";
7
- import {
8
- FunctionRegistry,
9
- TriggerRegistry,
10
- createSubscriptionTrigger,
11
- createTimerTrigger
12
- } from "./chunk-SQSJO5HI.mjs";
13
- import {
14
- FUNCTIONS_PRESET_META_KEY,
15
- FUNCTION_TYPES,
16
- FunctionDef,
17
- FunctionManifestSchema,
18
- FunctionTrigger,
19
- FunctionTriggerSchema,
20
- FunctionType,
21
- InvocationOutcome,
22
- InvocationTraceEndEvent,
23
- InvocationTraceEventType,
24
- InvocationTraceStartEvent,
25
- ScriptType,
26
- TraceEvent,
27
- TraceEventException,
28
- TraceEventLog,
29
- TriggerKind,
30
- TriggerSchema,
31
- createInvocationSpans,
32
- getInvocationUrl,
33
- getUserFunctionUrlInMetadata,
34
- setUserFunctionUrlInMetadata
35
- } from "./chunk-HBD2FZXO.mjs";
36
- import "./chunk-DHGBFXSZ.mjs";
37
2
 
38
3
  // packages/core/functions/src/handler.ts
39
4
  import { Schema as S } from "effect";
40
- import { PublicKey } from "@dxos/client";
41
- import { log } from "@dxos/log";
42
- import { isNonNullable } from "@dxos/util";
43
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
44
5
  var defineFunction = (params) => {
45
6
  if (!S.isSchema(params.inputSchema)) {
46
7
  throw new Error("Input schema must be a valid schema");
@@ -55,71 +16,384 @@ var defineFunction = (params) => {
55
16
  handler: params.handler
56
17
  };
57
18
  };
58
- var subscriptionHandler = (handler, types) => {
59
- return async ({ event: { data }, context, response, ...rest }) => {
60
- const { client } = context;
61
- const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : void 0;
62
- if (!space) {
63
- log.error("Invalid space", void 0, {
64
- F: __dxlog_file,
65
- L: 180,
66
- S: void 0,
67
- C: (f, a) => f(...a)
68
- });
69
- return response.status(500);
19
+
20
+ // packages/core/functions/src/schema.ts
21
+ import { Schema } from "effect";
22
+ import { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, TypedObject } from "@dxos/echo-schema";
23
+ import { DataType } from "@dxos/schema";
24
+ var ScriptType = Schema.Struct({
25
+ name: Schema.optional(Schema.String),
26
+ description: Schema.optional(Schema.String),
27
+ // TODO(burdon): Change to hash of deployed content.
28
+ // Whether source has changed since last deploy.
29
+ changed: Schema.optional(Schema.Boolean),
30
+ source: Ref(DataType.Text)
31
+ }).annotations({
32
+ [LabelAnnotationId]: "name"
33
+ }).pipe(EchoObject({
34
+ typename: "dxos.org/type/Script",
35
+ version: "0.1.0"
36
+ }));
37
+ var FunctionType = class extends TypedObject({
38
+ typename: "dxos.org/type/Function",
39
+ version: "0.1.0"
40
+ })({
41
+ // TODO(burdon): Rename to id/uri?
42
+ name: Schema.NonEmptyString,
43
+ version: Schema.String,
44
+ description: Schema.optional(Schema.String),
45
+ // Reference to a source script if it exists within ECHO.
46
+ // TODO(burdon): Don't ref ScriptType directly (core).
47
+ source: Schema.optional(Ref(ScriptType)),
48
+ inputSchema: Schema.optional(JsonSchemaType),
49
+ outputSchema: Schema.optional(JsonSchemaType),
50
+ // Local binding to a function name.
51
+ binding: Schema.optional(Schema.String)
52
+ }) {
53
+ };
54
+
55
+ // packages/core/functions/src/trace.ts
56
+ import { Schema as Schema2 } from "effect";
57
+ import { EchoObject as EchoObject2, Expando as Expando2, ObjectId, Ref as Ref3 } from "@dxos/echo-schema";
58
+ import { log } from "@dxos/log";
59
+
60
+ // packages/core/functions/src/types.ts
61
+ import { Schema as S2, SchemaAST } from "effect";
62
+ import { Expando, OptionsAnnotationId, TypedObject as TypedObject2, DXN, Ref as Ref2, RawObject } from "@dxos/echo-schema";
63
+ var TriggerKind;
64
+ (function(TriggerKind2) {
65
+ TriggerKind2["Timer"] = "timer";
66
+ TriggerKind2["Webhook"] = "webhook";
67
+ TriggerKind2["Subscription"] = "subscription";
68
+ TriggerKind2["Email"] = "email";
69
+ TriggerKind2["Queue"] = "queue";
70
+ })(TriggerKind || (TriggerKind = {}));
71
+ var typeLiteralAnnotations = {
72
+ [SchemaAST.TitleAnnotationId]: "Type"
73
+ };
74
+ var TimerTriggerSchema = S2.Struct({
75
+ type: S2.Literal("timer").annotations(typeLiteralAnnotations),
76
+ cron: S2.String.annotations({
77
+ [SchemaAST.TitleAnnotationId]: "Cron",
78
+ [SchemaAST.ExamplesAnnotationId]: [
79
+ "0 0 * * *"
80
+ ]
81
+ })
82
+ }).pipe(S2.mutable);
83
+ var EmailTriggerSchema = S2.Struct({
84
+ type: S2.Literal("email").annotations(typeLiteralAnnotations)
85
+ }).pipe(S2.mutable);
86
+ var QueueTriggerSchema = S2.Struct({
87
+ type: S2.Literal("queue").annotations(typeLiteralAnnotations),
88
+ queue: DXN
89
+ }).pipe(S2.mutable);
90
+ var WebhookTriggerSchema = S2.Struct({
91
+ type: S2.Literal("webhook").annotations(typeLiteralAnnotations),
92
+ method: S2.optional(S2.String.annotations({
93
+ [SchemaAST.TitleAnnotationId]: "Method",
94
+ [OptionsAnnotationId]: [
95
+ "GET",
96
+ "POST"
97
+ ]
98
+ })),
99
+ port: S2.optional(S2.Number.annotations({
100
+ [SchemaAST.TitleAnnotationId]: "Port"
101
+ }))
102
+ }).pipe(S2.mutable);
103
+ var QuerySchema = S2.Struct({
104
+ type: S2.optional(S2.String.annotations({
105
+ [SchemaAST.TitleAnnotationId]: "Type"
106
+ })),
107
+ props: S2.optional(S2.Record({
108
+ key: S2.String,
109
+ value: S2.Any
110
+ }))
111
+ }).annotations({
112
+ [SchemaAST.TitleAnnotationId]: "Query"
113
+ });
114
+ var SubscriptionTriggerSchema = S2.Struct({
115
+ type: S2.Literal("subscription").annotations(typeLiteralAnnotations),
116
+ // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
117
+ filter: QuerySchema,
118
+ options: S2.optional(S2.Struct({
119
+ // Watch changes to object (not just creation).
120
+ deep: S2.optional(S2.Boolean.annotations({
121
+ [SchemaAST.TitleAnnotationId]: "Nested"
122
+ })),
123
+ // Debounce changes (delay in ms).
124
+ delay: S2.optional(S2.Number.annotations({
125
+ [SchemaAST.TitleAnnotationId]: "Delay"
126
+ }))
127
+ }).annotations({
128
+ [SchemaAST.TitleAnnotationId]: "Options"
129
+ }))
130
+ }).pipe(S2.mutable);
131
+ var TriggerSchema = S2.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
132
+ [SchemaAST.TitleAnnotationId]: "Trigger"
133
+ });
134
+ var EmailTriggerOutput = S2.mutable(S2.Struct({
135
+ from: S2.String,
136
+ to: S2.String,
137
+ subject: S2.String,
138
+ created: S2.String,
139
+ body: S2.String
140
+ }));
141
+ var WebhookTriggerOutput = S2.mutable(S2.Struct({
142
+ url: S2.String,
143
+ method: S2.Literal("GET", "POST"),
144
+ headers: S2.Record({
145
+ key: S2.String,
146
+ value: S2.String
147
+ }),
148
+ bodyText: S2.String
149
+ }));
150
+ var QueueTriggerOutput = S2.mutable(S2.Struct({
151
+ queue: DXN,
152
+ item: S2.Any,
153
+ cursor: S2.String
154
+ }));
155
+ var SubscriptionTriggerOutput = S2.mutable(S2.Struct({
156
+ type: S2.String,
157
+ changedObjectId: S2.String
158
+ }));
159
+ var TimerTriggerOutput = S2.mutable(S2.Struct({
160
+ tick: S2.Number
161
+ }));
162
+ var FunctionTriggerSchema = S2.Struct({
163
+ /**
164
+ * Function or workflow to invoke.
165
+ */
166
+ // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
167
+ function: S2.optional(Ref2(Expando).annotations({
168
+ [SchemaAST.TitleAnnotationId]: "Function"
169
+ })),
170
+ /**
171
+ * Only used for workflows.
172
+ * Specifies the input node in the circuit.
173
+ * @deprecated Remove and enforce a single input node in all compute graphs.
174
+ */
175
+ inputNodeId: S2.optional(S2.String.annotations({
176
+ [SchemaAST.TitleAnnotationId]: "Input Node ID"
177
+ })),
178
+ enabled: S2.optional(S2.Boolean.annotations({
179
+ [SchemaAST.TitleAnnotationId]: "Enabled"
180
+ })),
181
+ spec: S2.optional(TriggerSchema),
182
+ /**
183
+ * Passed as the input data to the function.
184
+ * Must match the function's input schema.
185
+ *
186
+ * @example
187
+ * {
188
+ * item: '{{$.trigger.event}}',
189
+ * instructions: 'Summarize and perform entity-extraction'
190
+ * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
191
+ * }
192
+ */
193
+ input: S2.optional(S2.mutable(S2.Record({
194
+ key: S2.String,
195
+ value: S2.Any
196
+ })))
197
+ });
198
+ var FunctionTrigger = class extends TypedObject2({
199
+ typename: "dxos.org/type/FunctionTrigger",
200
+ version: "0.1.0"
201
+ })(FunctionTriggerSchema.fields) {
202
+ };
203
+ var FunctionManifestSchema = S2.Struct({
204
+ functions: S2.optional(S2.mutable(S2.Array(RawObject(FunctionType)))),
205
+ triggers: S2.optional(S2.mutable(S2.Array(RawObject(FunctionTrigger))))
206
+ });
207
+ var FUNCTION_TYPES = [
208
+ FunctionType,
209
+ FunctionTrigger
210
+ ];
211
+
212
+ // packages/core/functions/src/trace.ts
213
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/trace.ts";
214
+ var InvocationOutcome;
215
+ (function(InvocationOutcome2) {
216
+ InvocationOutcome2["SUCCESS"] = "success";
217
+ InvocationOutcome2["FAILURE"] = "failure";
218
+ InvocationOutcome2["PENDING"] = "pending";
219
+ })(InvocationOutcome || (InvocationOutcome = {}));
220
+ var InvocationTraceEventType;
221
+ (function(InvocationTraceEventType2) {
222
+ InvocationTraceEventType2["START"] = "start";
223
+ InvocationTraceEventType2["END"] = "end";
224
+ })(InvocationTraceEventType || (InvocationTraceEventType = {}));
225
+ var TraceEventException = Schema2.Struct({
226
+ timestampMs: Schema2.Number,
227
+ message: Schema2.String,
228
+ name: Schema2.String,
229
+ stack: Schema2.optional(Schema2.String)
230
+ });
231
+ var InvocationTraceStartEvent = Schema2.Struct({
232
+ /**
233
+ * Queue message id.
234
+ */
235
+ id: ObjectId,
236
+ type: Schema2.Literal("start"),
237
+ /**
238
+ * Invocation id, the same for invocation start and end events.
239
+ */
240
+ invocationId: ObjectId,
241
+ /**
242
+ * Event generation time.
243
+ */
244
+ timestampMs: Schema2.Number,
245
+ /**
246
+ * Data passed to function / workflow as an argument.
247
+ */
248
+ // TODO(burdon): Input schema?
249
+ input: Schema2.Object,
250
+ /**
251
+ * Queue DXN for function/workflow invocation events.
252
+ */
253
+ // TODO(burdon): Need reference type for queue. vs. string?
254
+ invocationTraceQueue: Ref3(Expando2),
255
+ /**
256
+ * DXN of the invoked function/workflow.
257
+ */
258
+ invocationTarget: Ref3(Expando2),
259
+ /**
260
+ * Present for automatic invocations.
261
+ */
262
+ trigger: Schema2.optional(Ref3(FunctionTrigger))
263
+ }).pipe(EchoObject2({
264
+ typename: "dxos.org/type/InvocationTraceStart",
265
+ version: "0.1.0"
266
+ }));
267
+ var InvocationTraceEndEvent = Schema2.Struct({
268
+ /**
269
+ * Trace event id.
270
+ */
271
+ id: ObjectId,
272
+ type: Schema2.Literal("end"),
273
+ /**
274
+ * Invocation id, will be the same for invocation start and end.
275
+ */
276
+ invocationId: ObjectId,
277
+ /**
278
+ * Event generation time.
279
+ */
280
+ // TODO(burdon): Remove ms suffix.
281
+ timestampMs: Schema2.Number,
282
+ outcome: Schema2.Enums(InvocationOutcome),
283
+ exception: Schema2.optional(TraceEventException)
284
+ }).pipe(EchoObject2({
285
+ typename: "dxos.org/type/InvocationTraceEnd",
286
+ version: "0.1.0"
287
+ }));
288
+ var TraceEventLog = Schema2.Struct({
289
+ timestampMs: Schema2.Number,
290
+ level: Schema2.String,
291
+ message: Schema2.String,
292
+ context: Schema2.optional(Schema2.Object)
293
+ });
294
+ var TraceEvent = Schema2.Struct({
295
+ id: ObjectId,
296
+ // TODO(burdon): Need enum/numeric result (not string).
297
+ outcome: Schema2.String,
298
+ truncated: Schema2.Boolean,
299
+ /**
300
+ * Time when the event was persisted.
301
+ */
302
+ ingestionTimestampMs: Schema2.Number,
303
+ logs: Schema2.Array(TraceEventLog),
304
+ exceptions: Schema2.Array(TraceEventException)
305
+ }).pipe(EchoObject2({
306
+ typename: "dxos.org/type/TraceEvent",
307
+ version: "0.1.0"
308
+ }));
309
+ var createInvocationSpans = (items) => {
310
+ if (!items) {
311
+ return [];
312
+ }
313
+ const eventsByInvocationId = /* @__PURE__ */ new Map();
314
+ for (const event of items) {
315
+ if (!("invocationId" in event)) {
316
+ continue;
70
317
  }
71
- registerTypes(space, types);
72
- const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(isNonNullable) : [];
73
- if (!!data.spaceKey && !space) {
74
- log.warn("invalid space", {
75
- data
76
- }, {
77
- F: __dxlog_file,
78
- L: 192,
79
- S: void 0,
80
- C: (f, a) => f(...a)
81
- });
82
- } else {
83
- log.info("handler", {
84
- space: space?.key.truncate(),
85
- objects: objects?.length
318
+ const invocationId = event.invocationId;
319
+ const entry = eventsByInvocationId.get(invocationId) || {
320
+ start: void 0,
321
+ end: void 0
322
+ };
323
+ if (event.type === "start") {
324
+ entry.start = event;
325
+ } else if (event.type === "end") {
326
+ entry.end = event;
327
+ }
328
+ eventsByInvocationId.set(invocationId, entry);
329
+ }
330
+ const now = Date.now();
331
+ const result = [];
332
+ for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
333
+ if (!start) {
334
+ log.warn("found end event without matching start", {
335
+ invocationId
86
336
  }, {
87
337
  F: __dxlog_file,
88
- L: 194,
338
+ L: 160,
89
339
  S: void 0,
90
340
  C: (f, a) => f(...a)
91
341
  });
342
+ continue;
92
343
  }
93
- return handler({
94
- event: {
95
- data: {
96
- ...data,
97
- space,
98
- objects
99
- }
100
- },
101
- context,
102
- response,
103
- ...rest
344
+ const isInProgress = end === void 0;
345
+ result.push({
346
+ id: invocationId,
347
+ timestampMs: start.timestampMs,
348
+ durationMs: isInProgress ? now - start.timestampMs : end.timestampMs - start.timestampMs,
349
+ outcome: end?.outcome ?? "pending",
350
+ exception: end?.exception,
351
+ input: start.input,
352
+ invocationTraceQueue: start.invocationTraceQueue,
353
+ invocationTarget: start.invocationTarget,
354
+ trigger: start.trigger
104
355
  });
105
- };
356
+ }
357
+ return result;
106
358
  };
107
- var registerTypes = (space, types = []) => {
108
- const registry = space.db.graph.schemaRegistry;
109
- for (const type of types) {
110
- if (!registry.hasSchema(type)) {
111
- registry.addSchema([
112
- type
113
- ]);
359
+
360
+ // packages/core/functions/src/url.ts
361
+ var FUNCTIONS_META_KEY = "dxos.org/service/function";
362
+ var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
363
+ var isSecure = (protocol) => {
364
+ return protocol === "https:" || protocol === "wss:";
365
+ };
366
+ var getUserFunctionUrlInMetadata = (meta) => {
367
+ return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
368
+ };
369
+ var setUserFunctionUrlInMetadata = (meta, functionUrl) => {
370
+ const key = meta.keys.find((key2) => key2.source === FUNCTIONS_META_KEY);
371
+ if (key) {
372
+ if (key.id !== functionUrl) {
373
+ throw new Error("Metadata mismatch");
114
374
  }
375
+ } else {
376
+ meta.keys.push({
377
+ source: FUNCTIONS_META_KEY,
378
+ id: functionUrl
379
+ });
115
380
  }
116
381
  };
382
+ var makeFunctionUrl = (spaceId, fn) => `/${spaceId}/${fn.functionId}`;
383
+ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
384
+ const baseUrl = new URL("functions/", edgeUrl);
385
+ const relativeUrl = functionUrl.replace(/^\//, "");
386
+ const url = new URL(`./${relativeUrl}`, baseUrl.toString());
387
+ options.spaceId && url.searchParams.set("spaceId", options.spaceId);
388
+ options.subjectId && url.searchParams.set("subjectId", options.subjectId);
389
+ url.protocol = isSecure(url.protocol) ? "https" : "http";
390
+ return url.toString();
391
+ };
117
392
  export {
393
+ EmailTriggerOutput,
118
394
  FUNCTIONS_PRESET_META_KEY,
119
395
  FUNCTION_TYPES,
120
- FunctionDef,
121
396
  FunctionManifestSchema,
122
- FunctionRegistry,
123
397
  FunctionTrigger,
124
398
  FunctionTriggerSchema,
125
399
  FunctionType,
@@ -127,23 +401,21 @@ export {
127
401
  InvocationTraceEndEvent,
128
402
  InvocationTraceEventType,
129
403
  InvocationTraceStartEvent,
404
+ QueueTriggerOutput,
130
405
  ScriptType,
406
+ SubscriptionTriggerOutput,
407
+ TimerTriggerOutput,
131
408
  TraceEvent,
132
409
  TraceEventException,
133
410
  TraceEventLog,
134
411
  TriggerKind,
135
- TriggerRegistry,
136
412
  TriggerSchema,
413
+ WebhookTriggerOutput,
137
414
  createInvocationSpans,
138
- createSubscriptionTrigger,
139
- createTimerTrigger,
140
415
  defineFunction,
141
416
  getInvocationUrl,
142
417
  getUserFunctionUrlInMetadata,
143
- incrementSemverPatch,
144
- publicKeyToDid,
145
- setUserFunctionUrlInMetadata,
146
- subscriptionHandler,
147
- uploadWorkerFunction
418
+ makeFunctionUrl,
419
+ setUserFunctionUrlInMetadata
148
420
  };
149
421
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/handler.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema as S } from 'effect';\nimport { type Effect } from 'effect';\n\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space, type SpaceId } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';\nimport { type HasId } from '@dxos/echo-schema';\nimport { type DXN } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type QueryResult } from '@dxos/protocols';\nimport { isNonNullable } from '@dxos/util';\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n\n/**\n * Function handler.\n */\nexport type FunctionHandler<TData = {}, TMeta = {}, TOutput = any> = (params: {\n context: FunctionContext;\n event: FunctionEvent<TData, TMeta>;\n /**\n * @deprecated\n */\n response: FunctionResponse;\n}) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;\n\n/**\n * Function context.\n */\nexport interface FunctionContext {\n getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;\n\n /**\n * Space from which the function was invoked.\n */\n space: SpaceAPI | undefined;\n\n ai: FunctionContextAi;\n\n /**\n * @deprecated\n */\n // TODO(burdon): Limit access to individual space.\n client: Client;\n /**\n * @deprecated\n */\n // TODO(burdon): Replace with storage service abstraction.\n dataDir?: string;\n}\n\nexport interface FunctionContextAi {\n // TODO(dmaretskyi): Refer to cloudflare AI docs for more comprehensive typedefs.\n run(model: string, inputs: any, options?: any): Promise<any>;\n}\n\n/**\n * Event payload.\n */\n// TODO(dmaretskyi): Update type definitions to match the actual payload.\nexport type FunctionEvent<TData = {}, TMeta = {}> = {\n data: FunctionEventMeta<TMeta> & TData;\n};\n\n/**\n * Metadata from trigger.\n */\nexport type FunctionEventMeta<TMeta = {}> = {\n meta: TMeta;\n};\n\n/**\n * Function response.\n */\nexport type FunctionResponse = {\n status(code: number): FunctionResponse;\n};\n\n//\n// API.\n//\n\n// TODO(dmaretskyi): Temporary API to get the queues working.\n// TODO(dmaretskyi): To be replaced with integrating queues into echo.\nexport interface QueuesAPI {\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;\n}\n\n/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n /**\n * @deprecated\n */\n get crud(): CoreDatabase;\n get db(): EchoDatabase;\n // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);\n get queues(): QueuesAPI;\n}\n\n// TODO(wittjosiah): Fix this.\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // const _: SpaceAPI = {} as Space;\n};\n\nexport type FunctionDefinition = {\n description?: string;\n inputSchema: S.Schema.AnyNoContext;\n outputSchema?: S.Schema.AnyNoContext;\n handler: FunctionHandler<any>;\n};\n\nexport type DefineFunctionParams<T, O = any> = {\n description?: string;\n inputSchema: S.Schema<T, any>;\n outputSchema?: S.Schema<O, any>;\n handler: FunctionHandler<T, any, O>;\n};\n\n// TODO(dmaretskyi): Bind input type to function handler.\nexport const defineFunction = <T, O>(params: DefineFunctionParams<T, O>): FunctionDefinition => {\n if (!S.isSchema(params.inputSchema)) {\n throw new Error('Input schema must be a valid schema');\n }\n if (typeof params.handler !== 'function') {\n throw new Error('Handler must be a function');\n }\n\n return {\n description: params.description,\n inputSchema: params.inputSchema,\n outputSchema: params.outputSchema ?? S.Any,\n handler: params.handler,\n };\n};\n\n//\n// Subscription utils.\n//\n\nexport type RawSubscriptionData = {\n spaceKey?: string;\n objects?: string[];\n};\n\nexport type SubscriptionData = {\n space?: Space;\n objects?: ReactiveEchoObject<any>[];\n};\n\n/**\n * Handler wrapper for subscription events; extracts space and objects.\n *\n * To test:\n * ```\n * curl -s -X POST -H \"Content-Type: application/json\" --data '{\"space\": \"0446...1cbb\"}' http://localhost:7100/dev/email-extractor\n * ```\n *\n * NOTE: Get space key from devtools or `dx space list --json`\n */\n// TODO(burdon): Evolve into plugin definition like Composer.\nexport const subscriptionHandler = <TMeta>(\n handler: FunctionHandler<SubscriptionData, TMeta>,\n types?: S.Schema.AnyNoContext[],\n): FunctionHandler<RawSubscriptionData, TMeta> => {\n return async ({ event: { data }, context, response, ...rest }) => {\n const { client } = context;\n const space = data.spaceKey ? client.spaces.get(PublicKey.from(data.spaceKey)) : undefined;\n if (!space) {\n log.error('Invalid space');\n return response.status(500);\n }\n\n registerTypes(space, types);\n const objects = space\n ? data.objects\n ?.map<ReactiveEchoObject<any> | undefined>((id) => space!.db.getObjectById(id))\n .filter(isNonNullable)\n : [];\n\n if (!!data.spaceKey && !space) {\n log.warn('invalid space', { data });\n } else {\n log.info('handler', { space: space?.key.truncate(), objects: objects?.length });\n }\n\n return handler({ event: { data: { ...data, space, objects } }, context, response, ...rest });\n };\n};\n\n// TODO(burdon): Evolve types as part of function metadata.\nconst registerTypes = (space: Space, types: S.Schema.AnyNoContext[] = []) => {\n const registry = space.db.graph.schemaRegistry;\n for (const type of types) {\n if (!registry.hasSchema(type)) {\n registry.addSchema([type]);\n }\n }\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,SAASA,UAAUC,SAAS;AAG5B,SAAsBC,iBAAiB;AAKvC,SAASC,WAAW;AAEpB,SAASC,qBAAqB;;AAoHvB,IAAMC,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,EAAEC,SAASF,OAAOG,WAAW,GAAG;AACnC,UAAM,IAAIC,MAAM,qCAAA;EAClB;AACA,MAAI,OAAOJ,OAAOK,YAAY,YAAY;AACxC,UAAM,IAAID,MAAM,4BAAA;EAClB;AAEA,SAAO;IACLE,aAAaN,OAAOM;IACpBH,aAAaH,OAAOG;IACpBI,cAAcP,OAAOO,gBAAgBN,EAAEO;IACvCH,SAASL,OAAOK;EAClB;AACF;AA2BO,IAAMI,sBAAsB,CACjCJ,SACAK,UAAAA;AAEA,SAAO,OAAO,EAAEC,OAAO,EAAEC,KAAI,GAAIC,SAASC,UAAU,GAAGC,KAAAA,MAAM;AAC3D,UAAM,EAAEC,OAAM,IAAKH;AACnB,UAAMI,QAAQL,KAAKM,WAAWF,OAAOG,OAAOC,IAAIC,UAAUC,KAAKV,KAAKM,QAAQ,CAAA,IAAKK;AACjF,QAAI,CAACN,OAAO;AACVO,UAAIC,MAAM,iBAAA,QAAA;;;;;;AACV,aAAOX,SAASY,OAAO,GAAA;IACzB;AAEAC,kBAAcV,OAAOP,KAAAA;AACrB,UAAMkB,UAAUX,QACZL,KAAKgB,SACDC,IAAyC,CAACC,OAAOb,MAAOc,GAAGC,cAAcF,EAAAA,CAAAA,EAC1EG,OAAOC,aAAAA,IACV,CAAA;AAEJ,QAAI,CAAC,CAACtB,KAAKM,YAAY,CAACD,OAAO;AAC7BO,UAAIW,KAAK,iBAAiB;QAAEvB;MAAK,GAAA;;;;;;IACnC,OAAO;AACLY,UAAIY,KAAK,WAAW;QAAEnB,OAAOA,OAAOoB,IAAIC,SAAAA;QAAYV,SAASA,SAASW;MAAO,GAAA;;;;;;IAC/E;AAEA,WAAOlC,QAAQ;MAAEM,OAAO;QAAEC,MAAM;UAAE,GAAGA;UAAMK;UAAOW;QAAQ;MAAE;MAAGf;MAASC;MAAU,GAAGC;IAAK,CAAA;EAC5F;AACF;AAGA,IAAMY,gBAAgB,CAACV,OAAcP,QAAiC,CAAA,MAAE;AACtE,QAAM8B,WAAWvB,MAAMc,GAAGU,MAAMC;AAChC,aAAWC,QAAQjC,OAAO;AACxB,QAAI,CAAC8B,SAASI,UAAUD,IAAAA,GAAO;AAC7BH,eAASK,UAAU;QAACF;OAAK;IAC3B;EACF;AACF;",
6
- "names": ["Schema", "S", "PublicKey", "log", "isNonNullable", "defineFunction", "params", "S", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "subscriptionHandler", "types", "event", "data", "context", "response", "rest", "client", "space", "spaceKey", "spaces", "get", "PublicKey", "from", "undefined", "log", "error", "status", "registerTypes", "objects", "map", "id", "db", "getObjectById", "filter", "isNonNullable", "warn", "info", "key", "truncate", "length", "registry", "graph", "schemaRegistry", "type", "hasSchema", "addSchema"]
3
+ "sources": ["../../../src/handler.ts", "../../../src/schema.ts", "../../../src/trace.ts", "../../../src/types.ts", "../../../src/url.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema as S } from 'effect';\nimport { type Effect } from 'effect';\n\nimport { type AIServiceClient } from '@dxos/assistant';\nimport type { CoreDatabase, EchoDatabase } from '@dxos/echo-db';\nimport { type HasId } from '@dxos/echo-schema';\nimport { type SpaceId, type DXN } from '@dxos/keys';\nimport { type QueryResult } from '@dxos/protocols';\n\n// TODO(burdon): Model after http request. Ref Lambda/OpenFaaS.\n// https://docs.aws.amazon.com/lambda/latest/dg/typescript-handler.html\n// https://www.serverless.com/framework/docs/providers/aws/guide/serverless.yml/#functions\n// https://www.npmjs.com/package/aws-lambda\n\n/**\n * Function handler.\n */\nexport type FunctionHandler<TData = {}, TOutput = any> = (params: {\n /**\n * Services and context available to the function.\n */\n context: FunctionContext;\n\n /**\n * Data passed as the input to the function.\n * Must match the function's input schema.\n * This will be the payload from the trigger or other data passed into the function in a workflow.\n */\n data: TData;\n}) => TOutput | Promise<TOutput> | Effect.Effect<TOutput, any>;\n\n/**\n * Function context.\n */\nexport interface FunctionContext {\n getSpace: (spaceId: SpaceId) => Promise<SpaceAPI>;\n\n /**\n * Space from which the function was invoked.\n */\n space: SpaceAPI | undefined;\n\n ai: AIServiceClient;\n}\n\nexport interface FunctionContextAi {\n // TODO(dmaretskyi): Refer to cloudflare AI docs for more comprehensive typedefs.\n run(model: string, inputs: any, options?: any): Promise<any>;\n}\n\n//\n// API.\n//\n\n// TODO(dmaretskyi): Temporary API to get the queues working.\n// TODO(dmaretskyi): To be replaced with integrating queues into echo.\nexport interface QueuesAPI {\n queryQueue(queue: DXN, options?: {}): Promise<QueryResult>;\n insertIntoQueue(queue: DXN, objects: HasId[]): Promise<void>;\n}\n\n/**\n * Space interface available to functions.\n */\nexport interface SpaceAPI {\n get id(): SpaceId;\n /**\n * @deprecated\n */\n get crud(): CoreDatabase;\n get db(): EchoDatabase;\n // TODO(dmaretskyi): Align with echo api --- queues.get(id).append(items);\n get queues(): QueuesAPI;\n}\n\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n const _: SpaceAPI = {} as SpaceAPI;\n};\n\nexport type FunctionDefinition<T = {}, O = any> = {\n description?: string;\n inputSchema: S.Schema<T, any>;\n outputSchema?: S.Schema<O, any>;\n handler: FunctionHandler<T, O>;\n};\n\n// TODO(dmaretskyi): Bind input type to function handler.\nexport const defineFunction = <T, O>(params: FunctionDefinition<T, O>): FunctionDefinition<T, O> => {\n if (!S.isSchema(params.inputSchema)) {\n throw new Error('Input schema must be a valid schema');\n }\n if (typeof params.handler !== 'function') {\n throw new Error('Handler must be a function');\n }\n\n return {\n description: params.description,\n inputSchema: params.inputSchema,\n outputSchema: params.outputSchema ?? S.Any,\n handler: params.handler,\n };\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, TypedObject } from '@dxos/echo-schema';\nimport { DataType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport const ScriptType = Schema.Struct({\n name: Schema.optional(Schema.String),\n description: Schema.optional(Schema.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: Schema.optional(Schema.Boolean),\n source: Ref(DataType.Text),\n})\n .annotations({ [LabelAnnotationId]: 'name' })\n .pipe(\n EchoObject({\n typename: 'dxos.org/type/Script',\n version: '0.1.0',\n }),\n );\n\nexport type ScriptType = Schema.Schema.Type<typeof ScriptType>;\n\n/**\n * Function deployment.\n */\nexport class FunctionType extends TypedObject({\n typename: 'dxos.org/type/Function',\n version: '0.1.0',\n})({\n // TODO(burdon): Rename to id/uri?\n name: Schema.NonEmptyString,\n version: Schema.String,\n\n description: Schema.optional(Schema.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: Schema.optional(Ref(ScriptType)),\n\n inputSchema: Schema.optional(JsonSchemaType),\n outputSchema: Schema.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: Schema.optional(Schema.String),\n}) {}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Schema } from 'effect';\n\nimport { EchoObject, Expando, ObjectId, Ref } from '@dxos/echo-schema';\nimport { log } from '@dxos/log';\n\nimport { FunctionTrigger, type FunctionTriggerType } from './types';\n\nexport enum InvocationOutcome {\n SUCCESS = 'success',\n FAILURE = 'failure',\n PENDING = 'pending',\n}\n\n// TODO(burdon): Convert to extensible discriminated union of EDGE events.\nexport enum InvocationTraceEventType {\n START = 'start',\n END = 'end',\n}\n\nexport const TraceEventException = Schema.Struct({\n timestampMs: Schema.Number,\n message: Schema.String,\n name: Schema.String,\n stack: Schema.optional(Schema.String),\n});\nexport type TraceEventException = Schema.Schema.Type<typeof TraceEventException>;\n\nexport const InvocationTraceStartEvent = Schema.Struct({\n /**\n * Queue message id.\n */\n id: ObjectId,\n type: Schema.Literal(InvocationTraceEventType.START),\n /**\n * Invocation id, the same for invocation start and end events.\n */\n invocationId: ObjectId,\n /**\n * Event generation time.\n */\n timestampMs: Schema.Number,\n /**\n * Data passed to function / workflow as an argument.\n */\n // TODO(burdon): Input schema?\n input: Schema.Object,\n /**\n * Queue DXN for function/workflow invocation events.\n */\n // TODO(burdon): Need reference type for queue. vs. string?\n invocationTraceQueue: Ref(Expando),\n /**\n * DXN of the invoked function/workflow.\n */\n invocationTarget: Ref(Expando),\n /**\n * Present for automatic invocations.\n */\n trigger: Schema.optional(Ref(FunctionTrigger)),\n}).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceStart', version: '0.1.0' }));\n\nexport type InvocationTraceStartEvent = Schema.Schema.Type<typeof InvocationTraceStartEvent>;\n\nexport const InvocationTraceEndEvent = Schema.Struct({\n /**\n * Trace event id.\n */\n id: ObjectId,\n type: Schema.Literal(InvocationTraceEventType.END),\n /**\n * Invocation id, will be the same for invocation start and end.\n */\n invocationId: ObjectId,\n /**\n * Event generation time.\n */\n // TODO(burdon): Remove ms suffix.\n timestampMs: Schema.Number,\n outcome: Schema.Enums(InvocationOutcome),\n exception: Schema.optional(TraceEventException),\n}).pipe(EchoObject({ typename: 'dxos.org/type/InvocationTraceEnd', version: '0.1.0' }));\n\nexport type InvocationTraceEndEvent = Schema.Schema.Type<typeof InvocationTraceEndEvent>;\n\nexport type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;\n\nexport const TraceEventLog = Schema.Struct({\n timestampMs: Schema.Number,\n level: Schema.String,\n message: Schema.String,\n context: Schema.optional(Schema.Object),\n});\n\nexport const TraceEvent = Schema.Struct({\n id: ObjectId,\n // TODO(burdon): Need enum/numeric result (not string).\n outcome: Schema.String,\n truncated: Schema.Boolean,\n /**\n * Time when the event was persisted.\n */\n ingestionTimestampMs: Schema.Number,\n logs: Schema.Array(TraceEventLog),\n exceptions: Schema.Array(TraceEventException),\n}).pipe(EchoObject({ typename: 'dxos.org/type/TraceEvent', version: '0.1.0' }));\n\nexport type TraceEvent = Schema.Schema.Type<typeof TraceEvent>;\n\n/**\n * Deprecated InvocationTrace event format.\n * @deprecated\n */\n// TODO(burdon): Remove.\nexport type InvocationSpan = {\n id: string;\n timestampMs: number;\n outcome: InvocationOutcome;\n input: object;\n durationMs: number;\n invocationTraceQueue: Ref<Expando>;\n invocationTarget: Ref<Expando>;\n trigger?: Ref<FunctionTriggerType>;\n exception?: TraceEventException;\n};\n\nexport const createInvocationSpans = (items?: InvocationTraceEvent[]): InvocationSpan[] => {\n if (!items) {\n return [];\n }\n\n const eventsByInvocationId = new Map<string, { start?: InvocationTraceStartEvent; end?: InvocationTraceEndEvent }>();\n for (const event of items) {\n if (!('invocationId' in event)) {\n // Skip legacy format entries.\n continue;\n }\n\n const invocationId = event.invocationId;\n const entry = eventsByInvocationId.get(invocationId) || { start: undefined, end: undefined };\n if (event.type === InvocationTraceEventType.START) {\n entry.start = event as InvocationTraceStartEvent;\n } else if (event.type === InvocationTraceEventType.END) {\n entry.end = event as InvocationTraceEndEvent;\n }\n\n eventsByInvocationId.set(invocationId, entry);\n }\n\n const now = Date.now();\n const result: InvocationSpan[] = [];\n\n // Create spans for each invocation\n for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {\n if (!start) {\n // No start event, can't create a meaningful span\n log.warn('found end event without matching start', { invocationId });\n continue;\n }\n\n const isInProgress = end === undefined;\n\n result.push({\n id: invocationId,\n timestampMs: start.timestampMs,\n durationMs: isInProgress ? now - start.timestampMs : end!.timestampMs - start.timestampMs,\n outcome: end?.outcome ?? InvocationOutcome.PENDING,\n exception: end?.exception,\n input: start.input,\n invocationTraceQueue: start.invocationTraceQueue,\n invocationTarget: start.invocationTarget,\n trigger: start.trigger,\n });\n }\n\n return result;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema as S, SchemaAST } from 'effect';\n\nimport { Expando, OptionsAnnotationId, TypedObject, DXN, Ref, RawObject } from '@dxos/echo-schema';\n\nimport { FunctionType } from './schema';\n\n/**\n * Type discriminator for TriggerType.\n * Every spec has a type field of type TriggerKind that we can use to understand which type we're working with.\n * https://www.typescriptlang.org/docs/handbook/2/narrowing.html#discriminated-unions\n */\nexport enum TriggerKind {\n Timer = 'timer',\n Webhook = 'webhook',\n Subscription = 'subscription',\n Email = 'email',\n Queue = 'queue',\n}\n\n// TODO(burdon): Rename prop kind.\nconst typeLiteralAnnotations = { [SchemaAST.TitleAnnotationId]: 'Type' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Timer).annotations(typeLiteralAnnotations),\n cron: S.String.annotations({\n [SchemaAST.TitleAnnotationId]: 'Cron',\n [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(S.mutable);\n\nexport type TimerTrigger = S.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Email).annotations(typeLiteralAnnotations),\n}).pipe(S.mutable);\n\nexport type EmailTrigger = S.Schema.Type<typeof EmailTriggerSchema>;\n\nconst QueueTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Queue).annotations(typeLiteralAnnotations),\n queue: DXN,\n}).pipe(S.mutable);\n\nexport type QueueTrigger = S.Schema.Type<typeof QueueTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Webhook).annotations(typeLiteralAnnotations),\n method: S.optional(\n S.String.annotations({\n [SchemaAST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [SchemaAST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(S.mutable);\n\nexport type WebhookTrigger = S.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = S.Struct({\n type: S.optional(S.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [SchemaAST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = S.Struct({\n type: S.Literal(TriggerKind.Subscription).annotations(typeLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: S.optional(\n S.Struct({\n // Watch changes to object (not just creation).\n deep: S.optional(S.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [SchemaAST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [SchemaAST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(S.mutable);\n\nexport type SubscriptionTrigger = S.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = S.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n QueueTriggerSchema,\n).annotations({\n [SchemaAST.TitleAnnotationId]: 'Trigger',\n});\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\nexport type EventType =\n | EmailTriggerOutput\n | WebhookTriggerOutput\n | QueueTriggerOutput\n | SubscriptionTriggerOutput\n | TimerTriggerOutput;\n\n// TODO(burdon): Reuse trigger schema from @dxos/functions (TriggerType).\nexport const EmailTriggerOutput = S.mutable(\n S.Struct({\n from: S.String,\n to: S.String,\n subject: S.String,\n created: S.String,\n body: S.String,\n }),\n);\nexport type EmailTriggerOutput = S.Schema.Type<typeof EmailTriggerOutput>;\n\nexport const WebhookTriggerOutput = S.mutable(\n S.Struct({\n url: S.String,\n method: S.Literal('GET', 'POST'),\n headers: S.Record({ key: S.String, value: S.String }),\n bodyText: S.String,\n }),\n);\nexport type WebhookTriggerOutput = S.Schema.Type<typeof WebhookTriggerOutput>;\n\nexport const QueueTriggerOutput = S.mutable(\n S.Struct({\n queue: DXN,\n item: S.Any,\n cursor: S.String,\n }),\n);\nexport type QueueTriggerOutput = S.Schema.Type<typeof QueueTriggerOutput>;\n\nexport const SubscriptionTriggerOutput = S.mutable(S.Struct({ type: S.String, changedObjectId: S.String }));\nexport type SubscriptionTriggerOutput = S.Schema.Type<typeof SubscriptionTriggerOutput>;\n\nexport const TimerTriggerOutput = S.mutable(S.Struct({ tick: S.Number }));\nexport type TimerTriggerOutput = S.Schema.Type<typeof TimerTriggerOutput>;\n\n/**\n * Function trigger.\n * Function is invoked with the `payload` passed as input data.\n * The event that triggers the function is available in the function context.\n */\nexport const FunctionTriggerSchema = S.Struct({\n /**\n * Function or workflow to invoke.\n */\n // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).\n function: S.optional(Ref(Expando).annotations({ [SchemaAST.TitleAnnotationId]: 'Function' })),\n\n /**\n * Only used for workflows.\n * Specifies the input node in the circuit.\n * @deprecated Remove and enforce a single input node in all compute graphs.\n */\n inputNodeId: S.optional(S.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Input Node ID' })),\n\n enabled: S.optional(S.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Enabled' })),\n\n spec: S.optional(TriggerSchema),\n\n /**\n * Passed as the input data to the function.\n * Must match the function's input schema.\n *\n * @example\n * {\n * item: '{{$.trigger.event}}',\n * instructions: 'Summarize and perform entity-extraction'\n * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }\n * }\n */\n input: S.optional(S.mutable(S.Record({ key: S.String, value: S.Any }))),\n});\n\nexport type FunctionTriggerType = S.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.1.0',\n})(FunctionTriggerSchema.fields) {}\n\n// TODO(wittjosiah): Remove?\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionType)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionType, FunctionTrigger];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type ObjectMeta } from '@dxos/echo-schema';\nimport { type SpaceId } from '@dxos/keys';\n\n// TODO: use URL scheme for source?\nconst FUNCTIONS_META_KEY = 'dxos.org/service/function';\n\nexport const FUNCTIONS_PRESET_META_KEY = 'dxos.org/service/function-preset';\n\nconst isSecure = (protocol: string) => {\n return protocol === 'https:' || protocol === 'wss:';\n};\n\nexport const getUserFunctionUrlInMetadata = (meta: ObjectMeta) => {\n return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;\n};\n\nexport const setUserFunctionUrlInMetadata = (meta: ObjectMeta, functionUrl: string) => {\n const key = meta.keys.find((key) => key.source === FUNCTIONS_META_KEY);\n if (key) {\n if (key.id !== functionUrl) {\n throw new Error('Metadata mismatch');\n }\n } else {\n meta.keys.push({ source: FUNCTIONS_META_KEY, id: functionUrl });\n }\n};\n\n/**\n * NOTE: functionId is backend ID, not ECHO object id.\n */\nexport const makeFunctionUrl = (spaceId: SpaceId, fn: { functionId: string }) => `/${spaceId}/${fn.functionId}`;\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = isSecure(url.protocol) ? 'https' : 'http';\n return url.toString();\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
5
+ "mappings": ";;;AAIA,SAASA,UAAUC,SAAS;AAuFrB,IAAMC,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,EAAEC,SAASF,OAAOG,WAAW,GAAG;AACnC,UAAM,IAAIC,MAAM,qCAAA;EAClB;AACA,MAAI,OAAOJ,OAAOK,YAAY,YAAY;AACxC,UAAM,IAAID,MAAM,4BAAA;EAClB;AAEA,SAAO;IACLE,aAAaN,OAAOM;IACpBH,aAAaH,OAAOG;IACpBI,cAAcP,OAAOO,gBAAgBN,EAAEO;IACvCH,SAASL,OAAOK;EAClB;AACF;;;ACrGA,SAASI,cAAc;AAEvB,SAASC,YAAYC,gBAAgBC,mBAAmBC,KAAKC,mBAAmB;AAChF,SAASC,gBAAgB;AAKlB,IAAMC,aAAaC,OAAOC,OAAO;EACtCC,MAAMF,OAAOG,SAASH,OAAOI,MAAM;EACnCC,aAAaL,OAAOG,SAASH,OAAOI,MAAM;;;EAG1CE,SAASN,OAAOG,SAASH,OAAOO,OAAO;EACvCC,QAAQC,IAAIC,SAASC,IAAI;AAC3B,CAAA,EACGC,YAAY;EAAE,CAACC,iBAAAA,GAAoB;AAAO,CAAA,EAC1CC,KACCC,WAAW;EACTC,UAAU;EACVC,SAAS;AACX,CAAA,CAAA;AAQG,IAAMC,eAAN,cAA2BC,YAAY;EAC5CH,UAAU;EACVC,SAAS;AACX,CAAA,EAAG;;EAEDf,MAAMF,OAAOoB;EACbH,SAASjB,OAAOI;EAEhBC,aAAaL,OAAOG,SAASH,OAAOI,MAAM;;;EAI1CI,QAAQR,OAAOG,SAASM,IAAIV,UAAAA,CAAAA;EAE5BsB,aAAarB,OAAOG,SAASmB,cAAAA;EAC7BC,cAAcvB,OAAOG,SAASmB,cAAAA;;E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AIE,aAAaC,IAAI,WAAWR,QAAQL,OAAO;AAClEK,UAAQS,aAAaJ,IAAIE,aAAaC,IAAI,aAAaR,QAAQS,SAAS;AACxEJ,MAAIvB,WAAWD,SAASwB,IAAIvB,QAAQ,IAAI,UAAU;AAClD,SAAOuB,IAAIC,SAAQ;AACrB;",
6
+ "names": ["Schema", "S", "defineFunction", "params", "S", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "Schema", "EchoObject", "JsonSchemaType", "LabelAnnotationId", "Ref", "TypedObject", "DataType", "ScriptType", "Schema", "Struct", "name", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "DataType", "Text", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "typename", "version", "FunctionType", "TypedObject", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "Schema", "EchoObject", "Expando", "ObjectId", "Ref", "log", "Schema", "S", "SchemaAST", "Expando", "OptionsAnnotationId", "TypedObject", "DXN", "Ref", "RawObject", "TriggerKind", "typeLiteralAnnotations", "SchemaAST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "EmailTriggerOutput", "from", "to", "subject", "created", "body", "WebhookTriggerOutput", "url", "headers", "bodyText", "QueueTriggerOutput", "item", "cursor", "SubscriptionTriggerOutput", "changedObjectId", "TimerTriggerOutput", "tick", "FunctionTriggerSchema", "function", "Ref", "Expando", "inputNodeId", "enabled", "spec", "input", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionManifestSchema", "functions", "Array", "RawObject", "FunctionType", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "Schema", "Struct", "timestampMs", "Number", "message", "String", "name", "stack", "optional", "InvocationTraceStartEvent", "id", "ObjectId", "type", "Literal", "invocationId", "input", "Object", "invocationTraceQueue", "Ref", "Expando", "invocationTarget", "trigger", "FunctionTrigger", "pipe", "EchoObject", "typename", "version", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "Boolean", "ingestionTimestampMs", "logs", "Array", "exceptions", "createInvocationSpans", "items", "eventsByInvocationId", "Map", "event", "entry", "get", "start", "undefined", "end", "set", "now", "Date", "result", "entries", "log", "warn", "isInProgress", "push", "durationMs", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "source", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "makeFunctionUrl", "spaceId", "fn", "functionId", "getInvocationUrl", "edgeUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "searchParams", "set", "subjectId"]
7
7
  }