@dxos/functions 0.8.1-main.ba2dec9 → 0.8.1-staging.5be625a

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 (57) hide show
  1. package/dist/lib/browser/{chunk-UMJKVIP4.mjs → chunk-B747D6L6.mjs} +5 -27
  2. package/dist/lib/browser/chunk-B747D6L6.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-RTBBW6RI.mjs → chunk-LHCAYQLL.mjs} +89 -17
  4. package/dist/lib/browser/chunk-LHCAYQLL.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-M7ZGVWUZ.mjs → chunk-OREUICVD.mjs} +2 -2
  6. package/dist/lib/browser/edge/index.mjs +1 -1
  7. package/dist/lib/browser/index.mjs +11 -5
  8. package/dist/lib/browser/index.mjs.map +2 -2
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/testing/index.mjs +2 -2
  11. package/dist/lib/browser/types/index.mjs +9 -3
  12. package/dist/lib/node/{chunk-UHTKCFWT.cjs → chunk-D4T2DS7U.cjs} +9 -31
  13. package/dist/lib/node/chunk-D4T2DS7U.cjs.map +7 -0
  14. package/dist/lib/node/{chunk-GX3ZLNHY.cjs → chunk-UQZH4J6S.cjs} +93 -18
  15. package/dist/lib/node/chunk-UQZH4J6S.cjs.map +7 -0
  16. package/dist/lib/node/{chunk-AOKUMNKK.cjs → chunk-ZSHBAXJA.cjs} +15 -15
  17. package/dist/lib/node/edge/index.cjs +4 -4
  18. package/dist/lib/node/edge/index.cjs.map +1 -1
  19. package/dist/lib/node/index.cjs +35 -29
  20. package/dist/lib/node/index.cjs.map +2 -2
  21. package/dist/lib/node/meta.json +1 -1
  22. package/dist/lib/node/testing/index.cjs +7 -7
  23. package/dist/lib/node/types/index.cjs +26 -20
  24. package/dist/lib/node/types/index.cjs.map +2 -2
  25. package/dist/lib/node-esm/{chunk-JDOIALGL.mjs → chunk-D43PP2YW.mjs} +5 -27
  26. package/dist/lib/node-esm/chunk-D43PP2YW.mjs.map +7 -0
  27. package/dist/lib/node-esm/{chunk-NALEEAQL.mjs → chunk-YCBKVXQU.mjs} +89 -17
  28. package/dist/lib/node-esm/chunk-YCBKVXQU.mjs.map +7 -0
  29. package/dist/lib/node-esm/{chunk-BYS52HOC.mjs → chunk-ZX523EY4.mjs} +2 -2
  30. package/dist/lib/node-esm/edge/index.mjs +1 -1
  31. package/dist/lib/node-esm/index.mjs +11 -5
  32. package/dist/lib/node-esm/index.mjs.map +2 -2
  33. package/dist/lib/node-esm/meta.json +1 -1
  34. package/dist/lib/node-esm/testing/index.mjs +2 -2
  35. package/dist/lib/node-esm/types/index.mjs +9 -3
  36. package/dist/types/src/edge/functions.d.ts.map +1 -1
  37. package/dist/types/src/handler.d.ts +1 -1
  38. package/dist/types/src/handler.d.ts.map +1 -1
  39. package/dist/types/src/types/schema.d.ts +20 -26
  40. package/dist/types/src/types/schema.d.ts.map +1 -1
  41. package/dist/types/src/types/trace.d.ts +100 -95
  42. package/dist/types/src/types/trace.d.ts.map +1 -1
  43. package/package.json +18 -18
  44. package/src/edge/functions.ts +2 -21
  45. package/src/handler.ts +2 -2
  46. package/src/runtime/scheduler.test.ts +2 -1
  47. package/src/types/schema.ts +8 -6
  48. package/src/types/trace.ts +94 -7
  49. package/dist/lib/browser/chunk-RTBBW6RI.mjs.map +0 -7
  50. package/dist/lib/browser/chunk-UMJKVIP4.mjs.map +0 -7
  51. package/dist/lib/node/chunk-GX3ZLNHY.cjs.map +0 -7
  52. package/dist/lib/node/chunk-UHTKCFWT.cjs.map +0 -7
  53. package/dist/lib/node-esm/chunk-JDOIALGL.mjs.map +0 -7
  54. package/dist/lib/node-esm/chunk-NALEEAQL.mjs.map +0 -7
  55. /package/dist/lib/browser/{chunk-M7ZGVWUZ.mjs.map → chunk-OREUICVD.mjs.map} +0 -0
  56. /package/dist/lib/node/{chunk-AOKUMNKK.cjs.map → chunk-ZSHBAXJA.cjs.map} +0 -0
  57. /package/dist/lib/node-esm/{chunk-BYS52HOC.mjs.map → chunk-ZX523EY4.mjs.map} +0 -0
@@ -8,17 +8,20 @@ import {
8
8
  FunctionTriggerSchema,
9
9
  FunctionType,
10
10
  InvocationOutcome,
11
- InvocationTraceEvent,
11
+ InvocationTraceEndEvent,
12
+ InvocationTraceEventType,
13
+ InvocationTraceStartEvent,
12
14
  ScriptType,
13
15
  TraceEvent,
14
16
  TraceEventException,
15
17
  TraceEventLog,
16
18
  TriggerKind,
17
19
  TriggerSchema,
20
+ createInvocationSpans,
18
21
  getInvocationUrl,
19
22
  getUserFunctionUrlInMetadata,
20
23
  setUserFunctionUrlInMetadata
21
- } from "../chunk-RTBBW6RI.mjs";
24
+ } from "../chunk-LHCAYQLL.mjs";
22
25
  import "../chunk-XRCXIG74.mjs";
23
26
  export {
24
27
  FUNCTIONS_PRESET_META_KEY,
@@ -29,13 +32,16 @@ export {
29
32
  FunctionTriggerSchema,
30
33
  FunctionType,
31
34
  InvocationOutcome,
32
- InvocationTraceEvent,
35
+ InvocationTraceEndEvent,
36
+ InvocationTraceEventType,
37
+ InvocationTraceStartEvent,
33
38
  ScriptType,
34
39
  TraceEvent,
35
40
  TraceEventException,
36
41
  TraceEventLog,
37
42
  TriggerKind,
38
43
  TriggerSchema,
44
+ createInvocationSpans,
39
45
  getInvocationUrl,
40
46
  getUserFunctionUrlInMetadata,
41
47
  setUserFunctionUrlInMetadata
@@ -16,13 +16,14 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_UHTKCFWT_exports = {};
20
- __export(chunk_UHTKCFWT_exports, {
19
+ var chunk_D4T2DS7U_exports = {};
20
+ __export(chunk_D4T2DS7U_exports, {
21
21
  incrementSemverPatch: () => incrementSemverPatch,
22
22
  publicKeyToDid: () => publicKeyToDid,
23
23
  uploadWorkerFunction: () => uploadWorkerFunction
24
24
  });
25
- module.exports = __toCommonJS(chunk_UHTKCFWT_exports);
25
+ module.exports = __toCommonJS(chunk_D4T2DS7U_exports);
26
+ var import_edge = require("@dxos/client/edge");
26
27
  var import_edge_client = require("@dxos/edge-client");
27
28
  var import_invariant = require("@dxos/invariant");
28
29
  var import_log = require("@dxos/log");
@@ -31,7 +32,7 @@ var uploadWorkerFunction = async ({ client, name, version, source, spaceId, func
31
32
  const edgeUrl = client.config.values.runtime?.services?.edge?.url;
32
33
  (0, import_invariant.invariant)(edgeUrl, "Edge is not configured.", {
33
34
  F: __dxlog_file,
34
- L: 32,
35
+ L: 33,
35
36
  S: void 0,
36
37
  A: [
37
38
  "edgeUrl",
@@ -39,7 +40,7 @@ var uploadWorkerFunction = async ({ client, name, version, source, spaceId, func
39
40
  ]
40
41
  });
41
42
  const edgeClient = new import_edge_client.EdgeHttpClient(edgeUrl);
42
- const edgeIdentity = createEdgeIdentity(client);
43
+ const edgeIdentity = (0, import_edge.createEdgeIdentity)(client);
43
44
  edgeClient.setIdentity(edgeIdentity);
44
45
  const response = await edgeClient.uploadFunction({
45
46
  spaceId,
@@ -57,41 +58,18 @@ var uploadWorkerFunction = async ({ client, name, version, source, spaceId, func
57
58
  response
58
59
  }, {
59
60
  F: __dxlog_file,
60
- L: 38,
61
+ L: 39,
61
62
  S: void 0,
62
63
  C: (f, a) => f(...a)
63
64
  });
64
65
  return response;
65
66
  };
66
- var createEdgeIdentity = (client) => {
67
- const identity = client.halo.identity.get();
68
- const device = client.halo.device;
69
- if (!identity || !device) {
70
- throw new Error("Identity not available");
71
- }
72
- return {
73
- identityKey: identity.identityKey.toHex(),
74
- peerKey: device.deviceKey.toHex(),
75
- presentCredentials: async ({ challenge }) => {
76
- const identityService = client.services.services.IdentityService;
77
- const authCredential = await identityService.createAuthCredential();
78
- return identityService.signPresentation({
79
- presentation: {
80
- credentials: [
81
- authCredential
82
- ]
83
- },
84
- nonce: challenge
85
- });
86
- }
87
- };
88
- };
89
67
  var incrementSemverPatch = (version) => {
90
68
  const [major, minor, patch] = version.split(".");
91
69
  const patchNum = Number(patch);
92
70
  (0, import_invariant.invariant)(!Number.isNaN(patchNum), "Unexpected function version format.", {
93
71
  F: __dxlog_file,
94
- L: 72,
72
+ L: 53,
95
73
  S: void 0,
96
74
  A: [
97
75
  "!Number.isNaN(patchNum)",
@@ -113,4 +91,4 @@ var publicKeyToDid = (key) => {
113
91
  publicKeyToDid,
114
92
  uploadWorkerFunction
115
93
  });
116
- //# sourceMappingURL=chunk-UHTKCFWT.cjs.map
94
+ //# sourceMappingURL=chunk-D4T2DS7U.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/edge/functions.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { type DID } from 'iso-did/types';\n\nimport { type Client } from '@dxos/client';\nimport { createEdgeIdentity } from '@dxos/client/edge';\nimport { EdgeHttpClient } from '@dxos/edge-client';\nimport { invariant } from '@dxos/invariant';\nimport type { PublicKey, SpaceId } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\nexport type UploadWorkerArgs = {\n client: Client;\n name?: string;\n source: string;\n version: string;\n functionId?: string;\n spaceId: SpaceId;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n name,\n version,\n source,\n spaceId,\n functionId,\n}: UploadWorkerArgs): Promise<UploadFunctionResponseBody> => {\n const edgeUrl = client.config.values.runtime?.services?.edge?.url;\n invariant(edgeUrl, 'Edge is not configured.');\n const edgeClient = new EdgeHttpClient(edgeUrl);\n const edgeIdentity = createEdgeIdentity(client);\n edgeClient.setIdentity(edgeIdentity);\n const response = await edgeClient.uploadFunction({ spaceId, functionId }, { name, version, script: source });\n\n log('Uploaded', {\n functionId,\n source,\n name,\n identityKey: edgeIdentity.identityKey,\n response,\n });\n\n return response;\n};\n\nexport const incrementSemverPatch = (version: string): string => {\n const [major, minor, patch] = version.split('.');\n const patchNum = Number(patch);\n invariant(!Number.isNaN(patchNum), 'Unexpected function version format.');\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAOA,kBAAmC;AACnC,yBAA+B;AAC/B,uBAA0B;AAE1B,iBAAoB;;AAYb,IAAMA,uBAAuB,OAAO,EACzCC,QACAC,MACAC,SACAC,QACAC,SACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9DC,kCAAUP,SAAS,2BAAA;;;;;;;;;AACnB,QAAMQ,aAAa,IAAIC,kCAAeT,OAAAA;AACtC,QAAMU,mBAAeC,gCAAmBjB,MAAAA;AACxCc,aAAWI,YAAYF,YAAAA;AACvB,QAAMG,WAAW,MAAML,WAAWM,eAAe;IAAEhB;IAASC;EAAW,GAAG;IAAEJ;IAAMC;IAASmB,QAAQlB;EAAO,CAAA;AAE1GmB,sBAAI,YAAY;IACdjB;IACAF;IACAF;IACAsB,aAAaP,aAAaO;IAC1BJ;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMK,uBAAuB,CAACtB,YAAAA;AACnC,QAAM,CAACuB,OAAOC,OAAOC,KAAAA,IAASzB,QAAQ0B,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxBd,kCAAU,CAACiB,OAAOC,MAAMF,QAAAA,GAAW,uCAAA;;;;;;;;;AACnC,SAAO;IAACJ;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAEO,IAAMC,iBAAiB,CAACC,QAAAA;AAC7B,SAAO,WAAWA,IAAIC,MAAK,CAAA;AAC7B;",
6
+ "names": ["uploadWorkerFunction", "client", "name", "version", "source", "spaceId", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "invariant", "edgeClient", "EdgeHttpClient", "edgeIdentity", "createEdgeIdentity", "setIdentity", "response", "uploadFunction", "script", "log", "identityKey", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid", "key", "toHex"]
7
+ }
@@ -16,8 +16,8 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_GX3ZLNHY_exports = {};
20
- __export(chunk_GX3ZLNHY_exports, {
19
+ var chunk_UQZH4J6S_exports = {};
20
+ __export(chunk_UQZH4J6S_exports, {
21
21
  FUNCTIONS_PRESET_META_KEY: () => FUNCTIONS_PRESET_META_KEY,
22
22
  FUNCTION_TYPES: () => FUNCTION_TYPES,
23
23
  FunctionDef: () => FunctionDef,
@@ -26,34 +26,36 @@ __export(chunk_GX3ZLNHY_exports, {
26
26
  FunctionTriggerSchema: () => FunctionTriggerSchema,
27
27
  FunctionType: () => FunctionType,
28
28
  InvocationOutcome: () => InvocationOutcome,
29
- InvocationTraceEvent: () => InvocationTraceEvent,
29
+ InvocationTraceEndEvent: () => InvocationTraceEndEvent,
30
+ InvocationTraceEventType: () => InvocationTraceEventType,
31
+ InvocationTraceStartEvent: () => InvocationTraceStartEvent,
30
32
  ScriptType: () => ScriptType,
31
33
  TraceEvent: () => TraceEvent,
32
34
  TraceEventException: () => TraceEventException,
33
35
  TraceEventLog: () => TraceEventLog,
34
36
  TriggerKind: () => TriggerKind,
35
37
  TriggerSchema: () => TriggerSchema,
38
+ createInvocationSpans: () => createInvocationSpans,
36
39
  getInvocationUrl: () => getInvocationUrl,
37
40
  getUserFunctionUrlInMetadata: () => getUserFunctionUrlInMetadata,
38
41
  setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata
39
42
  });
40
- module.exports = __toCommonJS(chunk_GX3ZLNHY_exports);
43
+ module.exports = __toCommonJS(chunk_UQZH4J6S_exports);
41
44
  var import_echo_schema = require("@dxos/echo-schema");
42
45
  var import_schema = require("@dxos/schema");
43
46
  var import_echo_schema2 = require("@dxos/echo-schema");
44
47
  var import_echo_schema3 = require("@dxos/echo-schema");
45
- var ScriptType = class extends (0, import_echo_schema.TypedObject)({
46
- typename: "dxos.org/type/Script",
47
- version: "0.1.0"
48
- })({
48
+ var import_log = require("@dxos/log");
49
+ var ScriptType = import_echo_schema.S.Struct({
49
50
  name: import_echo_schema.S.optional(import_echo_schema.S.String),
50
51
  description: import_echo_schema.S.optional(import_echo_schema.S.String),
51
52
  // TODO(burdon): Change to hash of deployed content.
52
53
  // Whether source has changed since last deploy.
53
54
  changed: import_echo_schema.S.optional(import_echo_schema.S.Boolean),
54
55
  source: (0, import_echo_schema.Ref)(import_schema.TextType)
55
- }) {
56
- };
56
+ }).annotations({
57
+ [import_echo_schema.LabelAnnotationId]: "name"
58
+ }).pipe((0, import_echo_schema.EchoObject)("dxos.org/type/Script", "0.1.0"));
57
59
  var FunctionType = class extends (0, import_echo_schema.TypedObject)({
58
60
  typename: "dxos.org/type/Function",
59
61
  version: "0.1.0"
@@ -183,23 +185,41 @@ var FUNCTION_TYPES = [
183
185
  FunctionDef,
184
186
  FunctionTrigger
185
187
  ];
188
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/types/trace.ts";
186
189
  var InvocationOutcome;
187
190
  (function(InvocationOutcome2) {
188
191
  InvocationOutcome2["SUCCESS"] = "success";
189
192
  InvocationOutcome2["FAILURE"] = "failure";
190
193
  })(InvocationOutcome || (InvocationOutcome = {}));
194
+ var InvocationTraceEventType;
195
+ (function(InvocationTraceEventType2) {
196
+ InvocationTraceEventType2["START"] = "start";
197
+ InvocationTraceEventType2["END"] = "end";
198
+ })(InvocationTraceEventType || (InvocationTraceEventType = {}));
191
199
  var TraceEventException = import_echo_schema3.S.Struct({
192
200
  timestampMs: import_echo_schema3.S.Number,
193
201
  message: import_echo_schema3.S.String,
194
202
  name: import_echo_schema3.S.String,
195
203
  stack: import_echo_schema3.S.optional(import_echo_schema3.S.String)
196
204
  });
197
- var InvocationTraceEvent = import_echo_schema3.S.Struct({
205
+ var InvocationTraceStartEvent = import_echo_schema3.S.Struct({
206
+ /**
207
+ * Queue message id.
208
+ */
198
209
  id: import_echo_schema3.ObjectId,
210
+ type: import_echo_schema3.S.Literal("start"),
211
+ /**
212
+ * Invocation id, the same for invocation start and end events.
213
+ */
214
+ invocationId: import_echo_schema3.ObjectId,
215
+ /**
216
+ * Event generation time.
217
+ */
199
218
  timestampMs: import_echo_schema3.S.Number,
200
- outcome: import_echo_schema3.S.Enums(InvocationOutcome),
219
+ /**
220
+ * Data passed to function / workflow as an argument.
221
+ */
201
222
  input: import_echo_schema3.S.Object,
202
- durationMs: import_echo_schema3.S.Number,
203
223
  /**
204
224
  * Queue DXN for function/workflow invocation events.
205
225
  */
@@ -211,12 +231,25 @@ var InvocationTraceEvent = import_echo_schema3.S.Struct({
211
231
  /**
212
232
  * Present for automatic invocations.
213
233
  */
214
- trigger: import_echo_schema3.S.optional((0, import_echo_schema3.Ref)(FunctionTrigger)),
234
+ trigger: import_echo_schema3.S.optional((0, import_echo_schema3.Ref)(FunctionTrigger))
235
+ }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/InvocationTraceStart", "0.1.0"));
236
+ var InvocationTraceEndEvent = import_echo_schema3.S.Struct({
237
+ /**
238
+ * Trace event id.
239
+ */
240
+ id: import_echo_schema3.ObjectId,
241
+ type: import_echo_schema3.S.Literal("end"),
242
+ /**
243
+ * Invocation id, will be the same for invocation start and end.
244
+ */
245
+ invocationId: import_echo_schema3.ObjectId,
215
246
  /**
216
- * Present for outcome FAILURE.
247
+ * Event generation time.
217
248
  */
249
+ timestampMs: import_echo_schema3.S.Number,
250
+ outcome: import_echo_schema3.S.Enums(InvocationOutcome),
218
251
  exception: import_echo_schema3.S.optional(TraceEventException)
219
- }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/InvocationTrace", "0.1.0"));
252
+ }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/InvocationTraceEnd", "0.1.0"));
220
253
  var TraceEventLog = import_echo_schema3.S.Struct({
221
254
  timestampMs: import_echo_schema3.S.Number,
222
255
  level: import_echo_schema3.S.String,
@@ -234,6 +267,45 @@ var TraceEvent = import_echo_schema3.S.Struct({
234
267
  logs: import_echo_schema3.S.Array(TraceEventLog),
235
268
  exceptions: import_echo_schema3.S.Array(TraceEventException)
236
269
  }).pipe((0, import_echo_schema3.EchoObject)("dxos.org/type/TraceEvent", "0.1.0"));
270
+ var createInvocationSpans = (items) => {
271
+ if (!items) {
272
+ return [];
273
+ }
274
+ const startEvents = /* @__PURE__ */ new Map();
275
+ const result = [];
276
+ for (const item of items) {
277
+ if (item.type === "start") {
278
+ startEvents.set(item.invocationId, item);
279
+ } else if (item.type === "end") {
280
+ const matchingStart = startEvents.get(item.invocationId);
281
+ if (!matchingStart) {
282
+ import_log.log.warn("end event without matching start", {
283
+ item
284
+ }, {
285
+ F: __dxlog_file,
286
+ L: 133,
287
+ S: void 0,
288
+ C: (f, a) => f(...a)
289
+ });
290
+ continue;
291
+ }
292
+ result.push({
293
+ id: item.invocationId,
294
+ durationMs: item.timestampMs - matchingStart.timestampMs,
295
+ timestampMs: item.timestampMs,
296
+ outcome: item.outcome,
297
+ exception: item.exception,
298
+ trigger: matchingStart.trigger,
299
+ input: matchingStart.input,
300
+ invocationTraceQueue: matchingStart.invocationTraceQueue,
301
+ invocationTarget: matchingStart.invocationTarget
302
+ });
303
+ } else {
304
+ result.push(item);
305
+ }
306
+ }
307
+ return result;
308
+ };
237
309
  var FUNCTIONS_META_KEY = "dxos.org/service/function";
238
310
  var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
239
311
  var isSecure = (protocol) => {
@@ -274,15 +346,18 @@ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
274
346
  FunctionTriggerSchema,
275
347
  FunctionType,
276
348
  InvocationOutcome,
277
- InvocationTraceEvent,
349
+ InvocationTraceEndEvent,
350
+ InvocationTraceEventType,
351
+ InvocationTraceStartEvent,
278
352
  ScriptType,
279
353
  TraceEvent,
280
354
  TraceEventException,
281
355
  TraceEventLog,
282
356
  TriggerKind,
283
357
  TriggerSchema,
358
+ createInvocationSpans,
284
359
  getInvocationUrl,
285
360
  getUserFunctionUrlInMetadata,
286
361
  setUserFunctionUrlInMetadata
287
362
  });
288
- //# sourceMappingURL=chunk-GX3ZLNHY.cjs.map
363
+ //# sourceMappingURL=chunk-UQZH4J6S.cjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/types/schema.ts", "../../../src/types/types.ts", "../../../src/types/trace.ts", "../../../src/types/url.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, S, TypedObject } from '@dxos/echo-schema';\nimport { TextType } from '@dxos/schema';\n\n/**\n * Source script.\n */\nexport const ScriptType = S.Struct({\n name: S.optional(S.String),\n description: S.optional(S.String),\n // TODO(burdon): Change to hash of deployed content.\n // Whether source has changed since last deploy.\n changed: S.optional(S.Boolean),\n source: Ref(TextType),\n})\n .annotations({\n [LabelAnnotationId]: 'name',\n })\n .pipe(EchoObject('dxos.org/type/Script', '0.1.0'));\nexport type ScriptType = S.Schema.Type<typeof ScriptType>;\n\n/**\n * Function deployment.\n */\n// TODO(burdon): Move to core/functions.\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: S.NonEmptyString,\n version: S.String,\n\n description: S.optional(S.String),\n\n // Reference to a source script if it exists within ECHO.\n // TODO(burdon): Don't ref ScriptType directly (core).\n source: S.optional(Ref(ScriptType)),\n\n inputSchema: S.optional(JsonSchemaType),\n outputSchema: S.optional(JsonSchemaType),\n\n // Local binding to a function name.\n binding: S.optional(S.String),\n}) {}\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { AST, OptionsAnnotationId, RawObject, S, TypedObject, DXN } from '@dxos/echo-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 = { [AST.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 [AST.TitleAnnotationId]: 'Cron',\n [AST.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 [AST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: S.optional(\n S.Number.annotations({\n [AST.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({ [AST.TitleAnnotationId]: 'Type' })),\n props: S.optional(S.Record({ key: S.String, value: S.Any })),\n}).annotations({ [AST.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({ [AST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: S.optional(S.Number.annotations({ [AST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [AST.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 [AST.TitleAnnotationId]: 'Trigger',\n});\n\nexport type TriggerType = S.Schema.Type<typeof TriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport const FunctionTriggerSchema = S.Struct({\n // TODO(burdon): What type does this reference.\n // TODO(wittjosiah): This should probably be a Ref?\n function: S.optional(S.String.annotations({ [AST.TitleAnnotationId]: 'Function' })),\n\n enabled: S.optional(S.Boolean.annotations({ [AST.TitleAnnotationId]: 'Enabled' })),\n\n // TODO(burdon): Flatten entire schema.\n spec: S.optional(TriggerSchema),\n\n // TODO(burdon): Get meta from function.\n // The `meta` property is merged into the event data passed to the function.\n meta: 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/**\n * Function definition.\n * @deprecated (Use dxos.org/type/Function)\n */\n// TODO(burdon): Reconcile with FunctionType.\nexport class FunctionDef extends TypedObject({\n typename: 'dxos.org/type/FunctionDef',\n version: '0.1.0',\n})({\n uri: S.String,\n description: S.optional(S.String),\n route: S.String,\n handler: S.String,\n}) {}\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = S.Struct({\n functions: S.optional(S.mutable(S.Array(RawObject(FunctionDef)))),\n triggers: S.optional(S.mutable(S.Array(RawObject(FunctionTrigger)))),\n});\n\nexport type FunctionManifest = S.Schema.Type<typeof FunctionManifestSchema>;\n\nexport const FUNCTION_TYPES = [FunctionDef, FunctionTrigger];\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { EchoObject, Expando, ObjectId, Ref, S } 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}\n\nexport enum InvocationTraceEventType {\n START = 'start',\n END = 'end',\n}\n\nexport const TraceEventException = S.Struct({\n timestampMs: S.Number,\n message: S.String,\n name: S.String,\n stack: S.optional(S.String),\n});\nexport type TraceEventException = S.Schema.Type<typeof TraceEventException>;\n\nexport const InvocationTraceStartEvent = S.Struct({\n /**\n * Queue message id.\n */\n id: ObjectId,\n type: S.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: S.Number,\n /**\n * Data passed to function / workflow as an argument.\n */\n input: S.Object,\n /**\n * Queue DXN for function/workflow invocation events.\n */\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: S.optional(Ref(FunctionTrigger)),\n}).pipe(EchoObject('dxos.org/type/InvocationTraceStart', '0.1.0'));\n\nexport type InvocationTraceStartEvent = S.Schema.Type<typeof InvocationTraceStartEvent>;\n\nexport const InvocationTraceEndEvent = S.Struct({\n /**\n * Trace event id.\n */\n id: ObjectId,\n type: S.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 timestampMs: S.Number,\n outcome: S.Enums(InvocationOutcome),\n exception: S.optional(TraceEventException),\n}).pipe(EchoObject('dxos.org/type/InvocationTraceEnd', '0.1.0'));\n\nexport type InvocationTraceEndEvent = S.Schema.Type<typeof InvocationTraceEndEvent>;\n\nexport type InvocationTraceEvent = InvocationTraceStartEvent | InvocationTraceEndEvent;\n\nexport const TraceEventLog = S.Struct({\n timestampMs: S.Number,\n level: S.String,\n message: S.String,\n context: S.optional(S.Object),\n});\n\nexport const TraceEvent = S.Struct({\n id: ObjectId,\n outcome: S.String,\n truncated: S.Boolean,\n /**\n * Time when the event was persisted.\n */\n ingestionTimestampMs: S.Number,\n logs: S.Array(TraceEventLog),\n exceptions: S.Array(TraceEventException),\n}).pipe(EchoObject('dxos.org/type/TraceEvent', '0.1.0'));\n\nexport type TraceEvent = S.Schema.Type<typeof TraceEvent>;\n\n/**\n * TODO: remove\n * Deprecated InvocationTrace event format.\n */\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 const startEvents = new Map<ObjectId, InvocationTraceStartEvent>();\n const result: InvocationSpan[] = [];\n for (const item of items) {\n if (item.type === InvocationTraceEventType.START) {\n startEvents.set(item.invocationId, item);\n } else if (item.type === InvocationTraceEventType.END) {\n const matchingStart = startEvents.get(item.invocationId);\n if (!matchingStart) {\n log.warn('end event without matching start', { item });\n continue;\n }\n result.push({\n id: item.invocationId,\n durationMs: item.timestampMs - matchingStart.timestampMs,\n timestampMs: item.timestampMs,\n outcome: item.outcome,\n exception: item.exception,\n trigger: matchingStart.trigger,\n input: matchingStart.input,\n invocationTraceQueue: matchingStart.invocationTraceQueue,\n invocationTarget: matchingStart.invocationTarget,\n });\n } else {\n // TODO: remove, the deprecated InvocationTrace format is no longer produced by functions backend\n result.push(item as InvocationSpan);\n }\n }\n return result;\n};\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\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
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AAEO,IAAME,mBAAmB,CAACF,aAAqBG,SAAiB1E,UAA6B,CAAC,MAAC;AACpG,QAAM2E,UAAU,IAAIC,IAAI,cAAcF,OAAAA;AAGtC,QAAMG,cAAcN,YAAYO,QAAQ,OAAO,EAAA;AAC/C,QAAMC,MAAM,IAAIH,IAAI,KAAKC,WAAAA,IAAeF,QAAQK,SAAQ,CAAA;AACxDhF,UAAQiF,WAAWF,IAAIG,aAAa1B,IAAI,WAAWxD,QAAQiF,OAAO;AAClEjF,UAAQmF,aAAaJ,IAAIG,aAAa1B,IAAI,aAAaxD,QAAQmF,SAAS;AACxEJ,MAAIb,WAAWD,SAASc,IAAIb,QAAQ,IAAI,UAAU;AAClD,SAAOa,IAAIC,SAAQ;AACrB;",
6
+ "names": ["import_echo_schema", "ScriptType", "S", "Struct", "name", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "TextType", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "FunctionType", "TypedObject", "typename", "version", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "TriggerKind", "typeLiteralAnnotations", "AST", "TitleAnnotationId", "TimerTriggerSchema", "type", "Literal", "cron", "ExamplesAnnotationId", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "FunctionTriggerSchema", "function", "enabled", "spec", "meta", "FunctionTrigger", "fields", "FunctionDef", "uri", "route", "handler", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "timestampMs", "message", "stack", "InvocationTraceStartEvent", "id", "ObjectId", "invocationId", "input", "Object", "invocationTraceQueue", "Expando", "invocationTarget", "trigger", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "ingestionTimestampMs", "logs", "exceptions", "createInvocationSpans", "items", "startEvents", "Map", "result", "item", "set", "matchingStart", "get", "log", "warn", "push", "durationMs", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "keys", "find", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "getInvocationUrl", "edgeUrl", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "spaceId", "searchParams", "subjectId"]
7
+ }
@@ -16,15 +16,15 @@ var __copyProps = (to, from, except, desc) => {
16
16
  return to;
17
17
  };
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var chunk_AOKUMNKK_exports = {};
20
- __export(chunk_AOKUMNKK_exports, {
19
+ var chunk_ZSHBAXJA_exports = {};
20
+ __export(chunk_ZSHBAXJA_exports, {
21
21
  FunctionRegistry: () => FunctionRegistry,
22
22
  TriggerRegistry: () => TriggerRegistry,
23
23
  createSubscriptionTrigger: () => createSubscriptionTrigger,
24
24
  createTimerTrigger: () => createTimerTrigger
25
25
  });
26
- module.exports = __toCommonJS(chunk_AOKUMNKK_exports);
27
- var import_chunk_GX3ZLNHY = require("./chunk-GX3ZLNHY.cjs");
26
+ module.exports = __toCommonJS(chunk_ZSHBAXJA_exports);
27
+ var import_chunk_UQZH4J6S = require("./chunk-UQZH4J6S.cjs");
28
28
  var import_async = require("@dxos/async");
29
29
  var import_echo = require("@dxos/client/echo");
30
30
  var import_context = require("@dxos/context");
@@ -85,14 +85,14 @@ var FunctionRegistry = class extends import_context.Resource {
85
85
  if (!functions?.length) {
86
86
  return;
87
87
  }
88
- if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_GX3ZLNHY.FunctionDef)) {
88
+ if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_UQZH4J6S.FunctionDef)) {
89
89
  space.db.graph.schemaRegistry.addSchema([
90
- import_chunk_GX3ZLNHY.FunctionDef
90
+ import_chunk_UQZH4J6S.FunctionDef
91
91
  ]);
92
92
  }
93
- const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_GX3ZLNHY.FunctionDef)).run();
93
+ const { objects: existing } = await space.db.query(import_echo.Filter.schema(import_chunk_UQZH4J6S.FunctionDef)).run();
94
94
  const { added } = (0, import_util.diff)(existing, functions, (a, b) => a.uri === b.uri);
95
- added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_GX3ZLNHY.FunctionDef, def)));
95
+ added.forEach((def) => space.db.add((0, import_echo.create)(import_chunk_UQZH4J6S.FunctionDef, def)));
96
96
  if (added.length > 0) {
97
97
  await space.db.flush({
98
98
  indexes: true,
@@ -118,7 +118,7 @@ var FunctionRegistry = class extends import_context.Resource {
118
118
  if (this._ctx.disposed) {
119
119
  break;
120
120
  }
121
- this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_GX3ZLNHY.FunctionDef)).subscribe(({ objects }) => {
121
+ this._ctx.onDispose(space.db.query(import_echo.Filter.schema(import_chunk_UQZH4J6S.FunctionDef)).subscribe(({ objects }) => {
122
122
  const { added } = (0, import_util.diff)(registered, objects, (a, b) => a.uri === b.uri);
123
123
  if (added.length > 0) {
124
124
  registered.push(...added);
@@ -337,9 +337,9 @@ var TriggerRegistry = class extends import_context2.Resource {
337
337
  if (!manifest.triggers?.length) {
338
338
  return;
339
339
  }
340
- if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_GX3ZLNHY.FunctionTrigger)) {
340
+ if (!space.db.graph.schemaRegistry.hasSchema(import_chunk_UQZH4J6S.FunctionTrigger)) {
341
341
  space.db.graph.schemaRegistry.addSchema([
342
- import_chunk_GX3ZLNHY.FunctionTrigger
342
+ import_chunk_UQZH4J6S.FunctionTrigger
343
343
  ]);
344
344
  }
345
345
  const manifestTriggers = manifest.triggers.map((trigger) => {
@@ -353,11 +353,11 @@ var TriggerRegistry = class extends import_context2.Resource {
353
353
  ].join(":"))
354
354
  ];
355
355
  }
356
- return (0, import_echo3.create)(import_chunk_GX3ZLNHY.FunctionTrigger, trigger, {
356
+ return (0, import_echo3.create)(import_chunk_UQZH4J6S.FunctionTrigger, trigger, {
357
357
  keys
358
358
  });
359
359
  });
360
- const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_GX3ZLNHY.FunctionTrigger)).run();
360
+ const { objects: existing } = await space.db.query(import_echo3.Filter.schema(import_chunk_UQZH4J6S.FunctionTrigger)).run();
361
361
  const { added } = (0, import_util2.diff)(existing, manifestTriggers, import_echo3.compareForeignKeys);
362
362
  added.forEach((trigger) => {
363
363
  space.db.add(trigger);
@@ -392,7 +392,7 @@ var TriggerRegistry = class extends import_context2.Resource {
392
392
  if (this._ctx.disposed) {
393
393
  break;
394
394
  }
395
- this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_GX3ZLNHY.FunctionTrigger)).subscribe(async ({ objects: current }) => {
395
+ this._ctx.onDispose(space.db.query(import_echo3.Filter.schema(import_chunk_UQZH4J6S.FunctionTrigger)).subscribe(async ({ objects: current }) => {
396
396
  import_log4.log.info("update", {
397
397
  space: space.key,
398
398
  registered: registered.length,
@@ -493,4 +493,4 @@ var TriggerRegistry = class extends import_context2.Resource {
493
493
  createSubscriptionTrigger,
494
494
  createTimerTrigger
495
495
  });
496
- //# sourceMappingURL=chunk-AOKUMNKK.cjs.map
496
+ //# sourceMappingURL=chunk-ZSHBAXJA.cjs.map
@@ -18,12 +18,12 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var edge_exports = {};
20
20
  __export(edge_exports, {
21
- incrementSemverPatch: () => import_chunk_UHTKCFWT.incrementSemverPatch,
22
- publicKeyToDid: () => import_chunk_UHTKCFWT.publicKeyToDid,
23
- uploadWorkerFunction: () => import_chunk_UHTKCFWT.uploadWorkerFunction
21
+ incrementSemverPatch: () => import_chunk_D4T2DS7U.incrementSemverPatch,
22
+ publicKeyToDid: () => import_chunk_D4T2DS7U.publicKeyToDid,
23
+ uploadWorkerFunction: () => import_chunk_D4T2DS7U.uploadWorkerFunction
24
24
  });
25
25
  module.exports = __toCommonJS(edge_exports);
26
- var import_chunk_UHTKCFWT = require("../chunk-UHTKCFWT.cjs");
26
+ var import_chunk_D4T2DS7U = require("../chunk-D4T2DS7U.cjs");
27
27
  var import_chunk_JEQ2X3Z6 = require("../chunk-JEQ2X3Z6.cjs");
28
28
  // Annotate the CommonJS export names for ESM import in node:
29
29
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["index.cjs"],
4
- "sourcesContent": ["import {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n} from \"../chunk-UHTKCFWT.cjs\";\nimport \"../chunk-JEQ2X3Z6.cjs\";\nexport {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
4
+ "sourcesContent": ["import {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n} from \"../chunk-D4T2DS7U.cjs\";\nimport \"../chunk-JEQ2X3Z6.cjs\";\nexport {\n incrementSemverPatch,\n publicKeyToDid,\n uploadWorkerFunction\n};\n//# sourceMappingURL=index.cjs.map\n"],
5
5
  "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAIO;AACP,4BAAO;",
6
6
  "names": []
7
7
  }
@@ -18,38 +18,41 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
  var node_exports = {};
20
20
  __export(node_exports, {
21
- FUNCTIONS_PRESET_META_KEY: () => import_chunk_GX3ZLNHY.FUNCTIONS_PRESET_META_KEY,
22
- FUNCTION_TYPES: () => import_chunk_GX3ZLNHY.FUNCTION_TYPES,
23
- FunctionDef: () => import_chunk_GX3ZLNHY.FunctionDef,
24
- FunctionManifestSchema: () => import_chunk_GX3ZLNHY.FunctionManifestSchema,
25
- FunctionRegistry: () => import_chunk_AOKUMNKK.FunctionRegistry,
26
- FunctionTrigger: () => import_chunk_GX3ZLNHY.FunctionTrigger,
27
- FunctionTriggerSchema: () => import_chunk_GX3ZLNHY.FunctionTriggerSchema,
28
- FunctionType: () => import_chunk_GX3ZLNHY.FunctionType,
29
- InvocationOutcome: () => import_chunk_GX3ZLNHY.InvocationOutcome,
30
- InvocationTraceEvent: () => import_chunk_GX3ZLNHY.InvocationTraceEvent,
31
- ScriptType: () => import_chunk_GX3ZLNHY.ScriptType,
32
- TraceEvent: () => import_chunk_GX3ZLNHY.TraceEvent,
33
- TraceEventException: () => import_chunk_GX3ZLNHY.TraceEventException,
34
- TraceEventLog: () => import_chunk_GX3ZLNHY.TraceEventLog,
35
- TriggerKind: () => import_chunk_GX3ZLNHY.TriggerKind,
36
- TriggerRegistry: () => import_chunk_AOKUMNKK.TriggerRegistry,
37
- TriggerSchema: () => import_chunk_GX3ZLNHY.TriggerSchema,
38
- createSubscriptionTrigger: () => import_chunk_AOKUMNKK.createSubscriptionTrigger,
39
- createTimerTrigger: () => import_chunk_AOKUMNKK.createTimerTrigger,
21
+ FUNCTIONS_PRESET_META_KEY: () => import_chunk_UQZH4J6S.FUNCTIONS_PRESET_META_KEY,
22
+ FUNCTION_TYPES: () => import_chunk_UQZH4J6S.FUNCTION_TYPES,
23
+ FunctionDef: () => import_chunk_UQZH4J6S.FunctionDef,
24
+ FunctionManifestSchema: () => import_chunk_UQZH4J6S.FunctionManifestSchema,
25
+ FunctionRegistry: () => import_chunk_ZSHBAXJA.FunctionRegistry,
26
+ FunctionTrigger: () => import_chunk_UQZH4J6S.FunctionTrigger,
27
+ FunctionTriggerSchema: () => import_chunk_UQZH4J6S.FunctionTriggerSchema,
28
+ FunctionType: () => import_chunk_UQZH4J6S.FunctionType,
29
+ InvocationOutcome: () => import_chunk_UQZH4J6S.InvocationOutcome,
30
+ InvocationTraceEndEvent: () => import_chunk_UQZH4J6S.InvocationTraceEndEvent,
31
+ InvocationTraceEventType: () => import_chunk_UQZH4J6S.InvocationTraceEventType,
32
+ InvocationTraceStartEvent: () => import_chunk_UQZH4J6S.InvocationTraceStartEvent,
33
+ ScriptType: () => import_chunk_UQZH4J6S.ScriptType,
34
+ TraceEvent: () => import_chunk_UQZH4J6S.TraceEvent,
35
+ TraceEventException: () => import_chunk_UQZH4J6S.TraceEventException,
36
+ TraceEventLog: () => import_chunk_UQZH4J6S.TraceEventLog,
37
+ TriggerKind: () => import_chunk_UQZH4J6S.TriggerKind,
38
+ TriggerRegistry: () => import_chunk_ZSHBAXJA.TriggerRegistry,
39
+ TriggerSchema: () => import_chunk_UQZH4J6S.TriggerSchema,
40
+ createInvocationSpans: () => import_chunk_UQZH4J6S.createInvocationSpans,
41
+ createSubscriptionTrigger: () => import_chunk_ZSHBAXJA.createSubscriptionTrigger,
42
+ createTimerTrigger: () => import_chunk_ZSHBAXJA.createTimerTrigger,
40
43
  defineFunction: () => defineFunction,
41
- getInvocationUrl: () => import_chunk_GX3ZLNHY.getInvocationUrl,
42
- getUserFunctionUrlInMetadata: () => import_chunk_GX3ZLNHY.getUserFunctionUrlInMetadata,
43
- incrementSemverPatch: () => import_chunk_UHTKCFWT.incrementSemverPatch,
44
- publicKeyToDid: () => import_chunk_UHTKCFWT.publicKeyToDid,
45
- setUserFunctionUrlInMetadata: () => import_chunk_GX3ZLNHY.setUserFunctionUrlInMetadata,
44
+ getInvocationUrl: () => import_chunk_UQZH4J6S.getInvocationUrl,
45
+ getUserFunctionUrlInMetadata: () => import_chunk_UQZH4J6S.getUserFunctionUrlInMetadata,
46
+ incrementSemverPatch: () => import_chunk_D4T2DS7U.incrementSemverPatch,
47
+ publicKeyToDid: () => import_chunk_D4T2DS7U.publicKeyToDid,
48
+ setUserFunctionUrlInMetadata: () => import_chunk_UQZH4J6S.setUserFunctionUrlInMetadata,
46
49
  subscriptionHandler: () => subscriptionHandler,
47
- uploadWorkerFunction: () => import_chunk_UHTKCFWT.uploadWorkerFunction
50
+ uploadWorkerFunction: () => import_chunk_D4T2DS7U.uploadWorkerFunction
48
51
  });
49
52
  module.exports = __toCommonJS(node_exports);
50
- var import_chunk_UHTKCFWT = require("./chunk-UHTKCFWT.cjs");
51
- var import_chunk_AOKUMNKK = require("./chunk-AOKUMNKK.cjs");
52
- var import_chunk_GX3ZLNHY = require("./chunk-GX3ZLNHY.cjs");
53
+ var import_chunk_D4T2DS7U = require("./chunk-D4T2DS7U.cjs");
54
+ var import_chunk_ZSHBAXJA = require("./chunk-ZSHBAXJA.cjs");
55
+ var import_chunk_UQZH4J6S = require("./chunk-UQZH4J6S.cjs");
53
56
  var import_chunk_JEQ2X3Z6 = require("./chunk-JEQ2X3Z6.cjs");
54
57
  var import_effect = require("effect");
55
58
  var import_client = require("@dxos/client");
@@ -140,7 +143,9 @@ var registerTypes = (space, types = []) => {
140
143
  FunctionTriggerSchema,
141
144
  FunctionType,
142
145
  InvocationOutcome,
143
- InvocationTraceEvent,
146
+ InvocationTraceEndEvent,
147
+ InvocationTraceEventType,
148
+ InvocationTraceStartEvent,
144
149
  ScriptType,
145
150
  TraceEvent,
146
151
  TraceEventException,
@@ -148,6 +153,7 @@ var registerTypes = (space, types = []) => {
148
153
  TriggerKind,
149
154
  TriggerRegistry,
150
155
  TriggerSchema,
156
+ createInvocationSpans,
151
157
  createSubscriptionTrigger,
152
158
  createTimerTrigger,
153
159
  defineFunction,