@dxos/functions 0.8.2-main.2f9c567 → 0.8.2-main.36232bc

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 +3 -0
  2. package/dist/lib/browser/bundler/index.mjs.map +1 -1
  3. package/dist/lib/browser/chunk-2YE6S7XY.mjs +360 -0
  4. package/dist/lib/browser/chunk-2YE6S7XY.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-7CHDHCV3.mjs +482 -0
  6. package/dist/lib/browser/chunk-7CHDHCV3.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-LT4LR4VU.mjs +72 -0
  8. package/dist/lib/browser/chunk-LT4LR4VU.mjs.map +7 -0
  9. package/dist/lib/browser/chunk-XRCXIG74.mjs +12 -0
  10. package/dist/lib/browser/chunk-XRCXIG74.mjs.map +7 -0
  11. package/dist/lib/browser/edge/index.mjs +7 -63
  12. package/dist/lib/browser/edge/index.mjs.map +4 -4
  13. package/dist/lib/browser/index.mjs +99 -367
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/testing/index.mjs +670 -0
  17. package/dist/lib/browser/testing/index.mjs.map +7 -0
  18. package/dist/lib/browser/types/index.mjs +51 -0
  19. package/dist/lib/browser/types/index.mjs.map +7 -0
  20. package/dist/lib/node/bundler/index.cjs +1 -0
  21. package/dist/lib/node/bundler/index.cjs.map +1 -1
  22. package/dist/lib/node/chunk-FBIUZ7SD.cjs +496 -0
  23. package/dist/lib/node/chunk-FBIUZ7SD.cjs.map +7 -0
  24. package/dist/lib/node/chunk-JEQ2X3Z6.cjs +34 -0
  25. package/dist/lib/node/chunk-JEQ2X3Z6.cjs.map +7 -0
  26. package/dist/lib/node/chunk-NXZNXVT3.cjs +94 -0
  27. package/dist/lib/node/chunk-NXZNXVT3.cjs.map +7 -0
  28. package/dist/lib/node/chunk-SV5NRE5L.cjs +395 -0
  29. package/dist/lib/node/chunk-SV5NRE5L.cjs.map +7 -0
  30. package/dist/lib/node/edge/index.cjs +5 -65
  31. package/dist/lib/node/edge/index.cjs.map +4 -4
  32. package/dist/lib/node/index.cjs +94 -382
  33. package/dist/lib/node/index.cjs.map +4 -4
  34. package/dist/lib/node/meta.json +1 -1
  35. package/dist/lib/node/testing/index.cjs +687 -0
  36. package/dist/lib/node/testing/index.cjs.map +7 -0
  37. package/dist/lib/node/types/index.cjs +72 -0
  38. package/dist/lib/node/types/index.cjs.map +7 -0
  39. package/dist/lib/node-esm/bundler/index.mjs +1 -0
  40. package/dist/lib/node-esm/bundler/index.mjs.map +1 -1
  41. package/dist/lib/node-esm/chunk-3XMJFSID.mjs +360 -0
  42. package/dist/lib/node-esm/chunk-3XMJFSID.mjs.map +7 -0
  43. package/dist/lib/node-esm/chunk-C6YINTWG.mjs +482 -0
  44. package/dist/lib/node-esm/chunk-C6YINTWG.mjs.map +7 -0
  45. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs +12 -0
  46. package/dist/lib/node-esm/chunk-DHGBFXSZ.mjs.map +7 -0
  47. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs +72 -0
  48. package/dist/lib/node-esm/chunk-O2SXVYU5.mjs.map +7 -0
  49. package/dist/lib/node-esm/edge/index.mjs +6 -64
  50. package/dist/lib/node-esm/edge/index.mjs.map +4 -4
  51. package/dist/lib/node-esm/index.mjs +97 -367
  52. package/dist/lib/node-esm/index.mjs.map +4 -4
  53. package/dist/lib/node-esm/meta.json +1 -1
  54. package/dist/lib/node-esm/testing/index.mjs +670 -0
  55. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  56. package/dist/lib/node-esm/types/index.mjs +51 -0
  57. package/dist/lib/node-esm/types/index.mjs.map +7 -0
  58. package/dist/types/src/browser/index.d.ts +2 -0
  59. package/dist/types/src/browser/index.d.ts.map +1 -0
  60. package/dist/types/src/edge/index.d.ts.map +1 -1
  61. package/dist/types/src/function/function-registry.d.ts +25 -0
  62. package/dist/types/src/function/function-registry.d.ts.map +1 -0
  63. package/dist/types/src/function/function-registry.test.d.ts +2 -0
  64. package/dist/types/src/function/function-registry.test.d.ts.map +1 -0
  65. package/dist/types/src/function/index.d.ts +2 -0
  66. package/dist/types/src/function/index.d.ts.map +1 -0
  67. package/dist/types/src/handler.d.ts +61 -12
  68. package/dist/types/src/handler.d.ts.map +1 -1
  69. package/dist/types/src/index.d.ts +3 -3
  70. package/dist/types/src/index.d.ts.map +1 -1
  71. package/dist/types/src/runtime/dev-server.d.ts +52 -0
  72. package/dist/types/src/runtime/dev-server.d.ts.map +1 -0
  73. package/dist/types/src/runtime/dev-server.test.d.ts +2 -0
  74. package/dist/types/src/runtime/dev-server.test.d.ts.map +1 -0
  75. package/dist/types/src/runtime/index.d.ts +3 -0
  76. package/dist/types/src/runtime/index.d.ts.map +1 -0
  77. package/dist/types/src/runtime/scheduler.d.ts +34 -0
  78. package/dist/types/src/runtime/scheduler.d.ts.map +1 -0
  79. package/dist/types/src/runtime/scheduler.test.d.ts +2 -0
  80. package/dist/types/src/runtime/scheduler.test.d.ts.map +1 -0
  81. package/dist/types/src/testing/functions-integration.test.d.ts +2 -0
  82. package/dist/types/src/testing/functions-integration.test.d.ts.map +1 -0
  83. package/dist/types/src/testing/index.d.ts +5 -0
  84. package/dist/types/src/testing/index.d.ts.map +1 -0
  85. package/dist/types/src/testing/manifest.d.ts +3 -0
  86. package/dist/types/src/testing/manifest.d.ts.map +1 -0
  87. package/dist/types/src/testing/plugin-init.d.ts +6 -0
  88. package/dist/types/src/testing/plugin-init.d.ts.map +1 -0
  89. package/dist/types/src/testing/setup.d.ts +15 -0
  90. package/dist/types/src/testing/setup.d.ts.map +1 -0
  91. package/dist/types/src/testing/test/handler.d.ts +4 -0
  92. package/dist/types/src/testing/test/handler.d.ts.map +1 -0
  93. package/dist/types/src/testing/test/index.d.ts +3 -0
  94. package/dist/types/src/testing/test/index.d.ts.map +1 -0
  95. package/dist/types/src/testing/types.d.ts +10 -0
  96. package/dist/types/src/testing/types.d.ts.map +1 -0
  97. package/dist/types/src/testing/util.d.ts +5 -0
  98. package/dist/types/src/testing/util.d.ts.map +1 -0
  99. package/dist/types/src/trigger/index.d.ts +3 -0
  100. package/dist/types/src/trigger/index.d.ts.map +1 -0
  101. package/dist/types/src/trigger/trigger-registry.d.ts +38 -0
  102. package/dist/types/src/trigger/trigger-registry.d.ts.map +1 -0
  103. package/dist/types/src/trigger/trigger-registry.test.d.ts +2 -0
  104. package/dist/types/src/trigger/trigger-registry.test.d.ts.map +1 -0
  105. package/dist/types/src/trigger/type/index.d.ts +3 -0
  106. package/dist/types/src/trigger/type/index.d.ts.map +1 -0
  107. package/dist/types/src/trigger/type/subscription-trigger.d.ts +4 -0
  108. package/dist/types/src/trigger/type/subscription-trigger.d.ts.map +1 -0
  109. package/dist/types/src/trigger/type/timer-trigger.d.ts +4 -0
  110. package/dist/types/src/trigger/type/timer-trigger.d.ts.map +1 -0
  111. package/dist/types/src/trigger/type/webhook-trigger.d.ts +4 -0
  112. package/dist/types/src/trigger/type/webhook-trigger.d.ts.map +1 -0
  113. package/dist/types/src/types/index.d.ts +5 -0
  114. package/dist/types/src/types/index.d.ts.map +1 -0
  115. package/dist/types/src/types/schema.d.ts +53 -0
  116. package/dist/types/src/types/schema.d.ts.map +1 -0
  117. package/dist/types/src/types/trace.d.ts +146 -0
  118. package/dist/types/src/types/trace.d.ts.map +1 -0
  119. package/dist/types/src/{types.d.ts → types/types.d.ts} +49 -191
  120. package/dist/types/src/types/types.d.ts.map +1 -0
  121. package/dist/types/src/types/url.d.ts.map +1 -0
  122. package/dist/types/tools/schema.d.ts +2 -0
  123. package/dist/types/tools/schema.d.ts.map +1 -0
  124. package/package.json +36 -20
  125. package/schema/functions.json +211 -0
  126. package/src/browser/index.ts +5 -0
  127. package/src/edge/index.ts +0 -4
  128. package/src/function/function-registry.test.ts +118 -0
  129. package/src/function/function-registry.ts +104 -0
  130. package/src/function/index.ts +5 -0
  131. package/src/handler.ts +118 -14
  132. package/src/index.ts +5 -4
  133. package/src/runtime/dev-server.test.ts +79 -0
  134. package/src/runtime/dev-server.ts +240 -0
  135. package/src/runtime/index.ts +6 -0
  136. package/src/runtime/scheduler.test.ts +152 -0
  137. package/src/runtime/scheduler.ts +170 -0
  138. package/src/testing/functions-integration.test.ts +65 -0
  139. package/src/testing/index.ts +8 -0
  140. package/src/testing/manifest.ts +15 -0
  141. package/src/testing/plugin-init.ts +20 -0
  142. package/src/testing/setup.ts +109 -0
  143. package/src/testing/test/handler.ts +15 -0
  144. package/src/testing/test/index.ts +7 -0
  145. package/src/testing/types.ts +9 -0
  146. package/src/testing/util.ts +26 -0
  147. package/src/translations.ts +1 -1
  148. package/src/trigger/index.ts +6 -0
  149. package/src/trigger/trigger-registry.test.ts +278 -0
  150. package/src/trigger/trigger-registry.ts +218 -0
  151. package/src/trigger/type/index.ts +7 -0
  152. package/src/trigger/type/subscription-trigger.ts +84 -0
  153. package/src/trigger/type/timer-trigger.ts +48 -0
  154. package/src/trigger/type/webhook-trigger.ts +48 -0
  155. package/src/types/index.ts +8 -0
  156. package/src/types/schema.ts +46 -0
  157. package/src/{trace.ts → types/trace.ts} +31 -33
  158. package/src/types/types.ts +163 -0
  159. package/dist/types/src/schema.d.ts +0 -57
  160. package/dist/types/src/schema.d.ts.map +0 -1
  161. package/dist/types/src/trace.d.ts +0 -148
  162. package/dist/types/src/trace.d.ts.map +0 -1
  163. package/dist/types/src/types.d.ts.map +0 -1
  164. package/dist/types/src/url.d.ts.map +0 -1
  165. package/src/schema.ts +0 -53
  166. package/src/types.ts +0 -214
  167. /package/dist/types/src/{url.d.ts → types/url.d.ts} +0 -0
  168. /package/src/{url.ts → types/url.ts} +0 -0
@@ -18,44 +18,48 @@ 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
- EmailTriggerOutput: () => EmailTriggerOutput,
22
- FUNCTIONS_PRESET_META_KEY: () => FUNCTIONS_PRESET_META_KEY,
23
- FUNCTION_TYPES: () => FUNCTION_TYPES,
24
- FunctionManifestSchema: () => FunctionManifestSchema,
25
- FunctionTrigger: () => FunctionTrigger,
26
- FunctionTriggerSchema: () => FunctionTriggerSchema,
27
- FunctionType: () => FunctionType,
28
- InvocationOutcome: () => InvocationOutcome,
29
- InvocationTraceEndEvent: () => InvocationTraceEndEvent,
30
- InvocationTraceEventType: () => InvocationTraceEventType,
31
- InvocationTraceStartEvent: () => InvocationTraceStartEvent,
32
- QueueTriggerOutput: () => QueueTriggerOutput,
33
- ScriptType: () => ScriptType,
34
- SubscriptionTriggerOutput: () => SubscriptionTriggerOutput,
35
- TimerTriggerOutput: () => TimerTriggerOutput,
36
- TraceEvent: () => TraceEvent,
37
- TraceEventException: () => TraceEventException,
38
- TraceEventLog: () => TraceEventLog,
39
- TriggerKind: () => TriggerKind,
40
- TriggerSchema: () => TriggerSchema,
41
- WebhookTriggerOutput: () => WebhookTriggerOutput,
42
- createInvocationSpans: () => createInvocationSpans,
21
+ FUNCTIONS_PRESET_META_KEY: () => import_chunk_SV5NRE5L.FUNCTIONS_PRESET_META_KEY,
22
+ FUNCTION_TYPES: () => import_chunk_SV5NRE5L.FUNCTION_TYPES,
23
+ FunctionDef: () => import_chunk_SV5NRE5L.FunctionDef,
24
+ FunctionManifestSchema: () => import_chunk_SV5NRE5L.FunctionManifestSchema,
25
+ FunctionRegistry: () => import_chunk_FBIUZ7SD.FunctionRegistry,
26
+ FunctionTrigger: () => import_chunk_SV5NRE5L.FunctionTrigger,
27
+ FunctionTriggerSchema: () => import_chunk_SV5NRE5L.FunctionTriggerSchema,
28
+ FunctionType: () => import_chunk_SV5NRE5L.FunctionType,
29
+ InvocationOutcome: () => import_chunk_SV5NRE5L.InvocationOutcome,
30
+ InvocationTraceEndEvent: () => import_chunk_SV5NRE5L.InvocationTraceEndEvent,
31
+ InvocationTraceEventType: () => import_chunk_SV5NRE5L.InvocationTraceEventType,
32
+ InvocationTraceStartEvent: () => import_chunk_SV5NRE5L.InvocationTraceStartEvent,
33
+ ScriptType: () => import_chunk_SV5NRE5L.ScriptType,
34
+ TraceEvent: () => import_chunk_SV5NRE5L.TraceEvent,
35
+ TraceEventException: () => import_chunk_SV5NRE5L.TraceEventException,
36
+ TraceEventLog: () => import_chunk_SV5NRE5L.TraceEventLog,
37
+ TriggerKind: () => import_chunk_SV5NRE5L.TriggerKind,
38
+ TriggerRegistry: () => import_chunk_FBIUZ7SD.TriggerRegistry,
39
+ TriggerSchema: () => import_chunk_SV5NRE5L.TriggerSchema,
40
+ createInvocationSpans: () => import_chunk_SV5NRE5L.createInvocationSpans,
41
+ createSubscriptionTrigger: () => import_chunk_FBIUZ7SD.createSubscriptionTrigger,
42
+ createTimerTrigger: () => import_chunk_FBIUZ7SD.createTimerTrigger,
43
43
  defineFunction: () => defineFunction,
44
- getInvocationUrl: () => getInvocationUrl,
45
- getUserFunctionUrlInMetadata: () => getUserFunctionUrlInMetadata,
46
- makeFunctionUrl: () => makeFunctionUrl,
47
- setUserFunctionUrlInMetadata: () => setUserFunctionUrlInMetadata
44
+ getInvocationUrl: () => import_chunk_SV5NRE5L.getInvocationUrl,
45
+ getUserFunctionUrlInMetadata: () => import_chunk_SV5NRE5L.getUserFunctionUrlInMetadata,
46
+ incrementSemverPatch: () => import_chunk_NXZNXVT3.incrementSemverPatch,
47
+ makeFunctionUrl: () => import_chunk_SV5NRE5L.makeFunctionUrl,
48
+ publicKeyToDid: () => import_chunk_NXZNXVT3.publicKeyToDid,
49
+ setUserFunctionUrlInMetadata: () => import_chunk_SV5NRE5L.setUserFunctionUrlInMetadata,
50
+ subscriptionHandler: () => subscriptionHandler,
51
+ uploadWorkerFunction: () => import_chunk_NXZNXVT3.uploadWorkerFunction
48
52
  });
49
53
  module.exports = __toCommonJS(node_exports);
54
+ var import_chunk_NXZNXVT3 = require("./chunk-NXZNXVT3.cjs");
55
+ var import_chunk_FBIUZ7SD = require("./chunk-FBIUZ7SD.cjs");
56
+ var import_chunk_SV5NRE5L = require("./chunk-SV5NRE5L.cjs");
57
+ var import_chunk_JEQ2X3Z6 = require("./chunk-JEQ2X3Z6.cjs");
50
58
  var import_effect = require("effect");
51
- var import_effect2 = require("effect");
52
- var import_echo_schema = require("@dxos/echo-schema");
53
- var import_schema = require("@dxos/schema");
54
- var import_effect3 = require("effect");
55
- var import_echo_schema2 = require("@dxos/echo-schema");
59
+ var import_client = require("@dxos/client");
56
60
  var import_log = require("@dxos/log");
57
- var import_effect4 = require("effect");
58
- var import_echo_schema3 = require("@dxos/echo-schema");
61
+ var import_util = require("@dxos/util");
62
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/handler.ts";
59
63
  var defineFunction = (params) => {
60
64
  if (!import_effect.Schema.isSchema(params.inputSchema)) {
61
65
  throw new Error("Input schema must be a valid schema");
@@ -70,367 +74,72 @@ var defineFunction = (params) => {
70
74
  handler: params.handler
71
75
  };
72
76
  };
73
- var ScriptType = import_effect2.Schema.Struct({
74
- name: import_effect2.Schema.optional(import_effect2.Schema.String),
75
- description: import_effect2.Schema.optional(import_effect2.Schema.String),
76
- // TODO(burdon): Change to hash of deployed content.
77
- // Whether source has changed since last deploy.
78
- changed: import_effect2.Schema.optional(import_effect2.Schema.Boolean),
79
- source: (0, import_echo_schema.Ref)(import_schema.DataType.Text)
80
- }).annotations({
81
- [import_echo_schema.LabelAnnotationId]: "name"
82
- }).pipe((0, import_echo_schema.EchoObject)({
83
- typename: "dxos.org/type/Script",
84
- version: "0.1.0"
85
- }));
86
- var FunctionType = class extends (0, import_echo_schema.TypedObject)({
87
- typename: "dxos.org/type/Function",
88
- version: "0.1.0"
89
- })({
90
- // TODO(burdon): Rename to id/uri?
91
- name: import_effect2.Schema.NonEmptyString,
92
- version: import_effect2.Schema.String,
93
- description: import_effect2.Schema.optional(import_effect2.Schema.String),
94
- // Reference to a source script if it exists within ECHO.
95
- // TODO(burdon): Don't ref ScriptType directly (core).
96
- source: import_effect2.Schema.optional((0, import_echo_schema.Ref)(ScriptType)),
97
- inputSchema: import_effect2.Schema.optional(import_echo_schema.JsonSchemaType),
98
- outputSchema: import_effect2.Schema.optional(import_echo_schema.JsonSchemaType),
99
- // Local binding to a function name.
100
- binding: import_effect2.Schema.optional(import_effect2.Schema.String)
101
- }) {
102
- };
103
- var TriggerKind;
104
- (function(TriggerKind2) {
105
- TriggerKind2["Timer"] = "timer";
106
- TriggerKind2["Webhook"] = "webhook";
107
- TriggerKind2["Subscription"] = "subscription";
108
- TriggerKind2["Email"] = "email";
109
- TriggerKind2["Queue"] = "queue";
110
- })(TriggerKind || (TriggerKind = {}));
111
- var typeLiteralAnnotations = {
112
- [import_effect4.SchemaAST.TitleAnnotationId]: "Type"
113
- };
114
- var TimerTriggerSchema = import_effect4.Schema.Struct({
115
- type: import_effect4.Schema.Literal("timer").annotations(typeLiteralAnnotations),
116
- cron: import_effect4.Schema.String.annotations({
117
- [import_effect4.SchemaAST.TitleAnnotationId]: "Cron",
118
- [import_effect4.SchemaAST.ExamplesAnnotationId]: [
119
- "0 0 * * *"
120
- ]
121
- })
122
- }).pipe(import_effect4.Schema.mutable);
123
- var EmailTriggerSchema = import_effect4.Schema.Struct({
124
- type: import_effect4.Schema.Literal("email").annotations(typeLiteralAnnotations)
125
- }).pipe(import_effect4.Schema.mutable);
126
- var QueueTriggerSchema = import_effect4.Schema.Struct({
127
- type: import_effect4.Schema.Literal("queue").annotations(typeLiteralAnnotations),
128
- queue: import_echo_schema3.DXN
129
- }).pipe(import_effect4.Schema.mutable);
130
- var WebhookTriggerSchema = import_effect4.Schema.Struct({
131
- type: import_effect4.Schema.Literal("webhook").annotations(typeLiteralAnnotations),
132
- method: import_effect4.Schema.optional(import_effect4.Schema.String.annotations({
133
- [import_effect4.SchemaAST.TitleAnnotationId]: "Method",
134
- [import_echo_schema3.OptionsAnnotationId]: [
135
- "GET",
136
- "POST"
137
- ]
138
- })),
139
- port: import_effect4.Schema.optional(import_effect4.Schema.Number.annotations({
140
- [import_effect4.SchemaAST.TitleAnnotationId]: "Port"
141
- }))
142
- }).pipe(import_effect4.Schema.mutable);
143
- var QuerySchema = import_effect4.Schema.Struct({
144
- type: import_effect4.Schema.optional(import_effect4.Schema.String.annotations({
145
- [import_effect4.SchemaAST.TitleAnnotationId]: "Type"
146
- })),
147
- props: import_effect4.Schema.optional(import_effect4.Schema.Record({
148
- key: import_effect4.Schema.String,
149
- value: import_effect4.Schema.Any
150
- }))
151
- }).annotations({
152
- [import_effect4.SchemaAST.TitleAnnotationId]: "Query"
153
- });
154
- var SubscriptionTriggerSchema = import_effect4.Schema.Struct({
155
- type: import_effect4.Schema.Literal("subscription").annotations(typeLiteralAnnotations),
156
- // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
157
- filter: QuerySchema,
158
- options: import_effect4.Schema.optional(import_effect4.Schema.Struct({
159
- // Watch changes to object (not just creation).
160
- deep: import_effect4.Schema.optional(import_effect4.Schema.Boolean.annotations({
161
- [import_effect4.SchemaAST.TitleAnnotationId]: "Nested"
162
- })),
163
- // Debounce changes (delay in ms).
164
- delay: import_effect4.Schema.optional(import_effect4.Schema.Number.annotations({
165
- [import_effect4.SchemaAST.TitleAnnotationId]: "Delay"
166
- }))
167
- }).annotations({
168
- [import_effect4.SchemaAST.TitleAnnotationId]: "Options"
169
- }))
170
- }).pipe(import_effect4.Schema.mutable);
171
- var TriggerSchema = import_effect4.Schema.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
172
- [import_effect4.SchemaAST.TitleAnnotationId]: "Trigger"
173
- });
174
- var EmailTriggerOutput = import_effect4.Schema.mutable(import_effect4.Schema.Struct({
175
- from: import_effect4.Schema.String,
176
- to: import_effect4.Schema.String,
177
- subject: import_effect4.Schema.String,
178
- created: import_effect4.Schema.String,
179
- body: import_effect4.Schema.String
180
- }));
181
- var WebhookTriggerOutput = import_effect4.Schema.mutable(import_effect4.Schema.Struct({
182
- url: import_effect4.Schema.String,
183
- method: import_effect4.Schema.Literal("GET", "POST"),
184
- headers: import_effect4.Schema.Record({
185
- key: import_effect4.Schema.String,
186
- value: import_effect4.Schema.String
187
- }),
188
- bodyText: import_effect4.Schema.String
189
- }));
190
- var QueueTriggerOutput = import_effect4.Schema.mutable(import_effect4.Schema.Struct({
191
- queue: import_echo_schema3.DXN,
192
- item: import_effect4.Schema.Any,
193
- cursor: import_effect4.Schema.String
194
- }));
195
- var SubscriptionTriggerOutput = import_effect4.Schema.mutable(import_effect4.Schema.Struct({
196
- type: import_effect4.Schema.String,
197
- changedObjectId: import_effect4.Schema.String
198
- }));
199
- var TimerTriggerOutput = import_effect4.Schema.mutable(import_effect4.Schema.Struct({
200
- tick: import_effect4.Schema.Number
201
- }));
202
- var FunctionTriggerSchema = import_effect4.Schema.Struct({
203
- /**
204
- * Function or workflow to invoke.
205
- */
206
- // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
207
- function: import_effect4.Schema.optional((0, import_echo_schema3.Ref)(import_echo_schema3.Expando).annotations({
208
- [import_effect4.SchemaAST.TitleAnnotationId]: "Function"
209
- })),
210
- /**
211
- * Only used for workflows.
212
- * Specifies the input node in the circuit.
213
- * @deprecated Remove and enforce a single input node in all compute graphs.
214
- */
215
- inputNodeId: import_effect4.Schema.optional(import_effect4.Schema.String.annotations({
216
- [import_effect4.SchemaAST.TitleAnnotationId]: "Input Node ID"
217
- })),
218
- enabled: import_effect4.Schema.optional(import_effect4.Schema.Boolean.annotations({
219
- [import_effect4.SchemaAST.TitleAnnotationId]: "Enabled"
220
- })),
221
- spec: import_effect4.Schema.optional(TriggerSchema),
222
- /**
223
- * Passed as the input data to the function.
224
- * Must match the function's input schema.
225
- *
226
- * @example
227
- * {
228
- * item: '{{$.trigger.event}}',
229
- * instructions: 'Summarize and perform entity-extraction'
230
- * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
231
- * }
232
- */
233
- input: import_effect4.Schema.optional(import_effect4.Schema.mutable(import_effect4.Schema.Record({
234
- key: import_effect4.Schema.String,
235
- value: import_effect4.Schema.Any
236
- })))
237
- });
238
- var FunctionTrigger = class extends (0, import_echo_schema3.TypedObject)({
239
- typename: "dxos.org/type/FunctionTrigger",
240
- version: "0.1.0"
241
- })(FunctionTriggerSchema.fields) {
242
- };
243
- var FunctionManifestSchema = import_effect4.Schema.Struct({
244
- functions: import_effect4.Schema.optional(import_effect4.Schema.mutable(import_effect4.Schema.Array((0, import_echo_schema3.RawObject)(FunctionType)))),
245
- triggers: import_effect4.Schema.optional(import_effect4.Schema.mutable(import_effect4.Schema.Array((0, import_echo_schema3.RawObject)(FunctionTrigger))))
246
- });
247
- var FUNCTION_TYPES = [
248
- FunctionType,
249
- FunctionTrigger
250
- ];
251
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/trace.ts";
252
- var InvocationOutcome;
253
- (function(InvocationOutcome2) {
254
- InvocationOutcome2["SUCCESS"] = "success";
255
- InvocationOutcome2["FAILURE"] = "failure";
256
- InvocationOutcome2["PENDING"] = "pending";
257
- })(InvocationOutcome || (InvocationOutcome = {}));
258
- var InvocationTraceEventType;
259
- (function(InvocationTraceEventType2) {
260
- InvocationTraceEventType2["START"] = "start";
261
- InvocationTraceEventType2["END"] = "end";
262
- })(InvocationTraceEventType || (InvocationTraceEventType = {}));
263
- var TraceEventException = import_effect3.Schema.Struct({
264
- timestampMs: import_effect3.Schema.Number,
265
- message: import_effect3.Schema.String,
266
- name: import_effect3.Schema.String,
267
- stack: import_effect3.Schema.optional(import_effect3.Schema.String)
268
- });
269
- var InvocationTraceStartEvent = import_effect3.Schema.Struct({
270
- /**
271
- * Queue message id.
272
- */
273
- id: import_echo_schema2.ObjectId,
274
- type: import_effect3.Schema.Literal("start"),
275
- /**
276
- * Invocation id, the same for invocation start and end events.
277
- */
278
- invocationId: import_echo_schema2.ObjectId,
279
- /**
280
- * Event generation time.
281
- */
282
- timestampMs: import_effect3.Schema.Number,
283
- /**
284
- * Data passed to function / workflow as an argument.
285
- */
286
- // TODO(burdon): Input schema?
287
- input: import_effect3.Schema.Object,
288
- /**
289
- * Queue DXN for function/workflow invocation events.
290
- */
291
- // TODO(burdon): Need reference type for queue. vs. string?
292
- invocationTraceQueue: (0, import_echo_schema2.Ref)(import_echo_schema2.Expando),
293
- /**
294
- * DXN of the invoked function/workflow.
295
- */
296
- invocationTarget: (0, import_echo_schema2.Ref)(import_echo_schema2.Expando),
297
- /**
298
- * Present for automatic invocations.
299
- */
300
- trigger: import_effect3.Schema.optional((0, import_echo_schema2.Ref)(FunctionTrigger))
301
- }).pipe((0, import_echo_schema2.EchoObject)({
302
- typename: "dxos.org/type/InvocationTraceStart",
303
- version: "0.1.0"
304
- }));
305
- var InvocationTraceEndEvent = import_effect3.Schema.Struct({
306
- /**
307
- * Trace event id.
308
- */
309
- id: import_echo_schema2.ObjectId,
310
- type: import_effect3.Schema.Literal("end"),
311
- /**
312
- * Invocation id, will be the same for invocation start and end.
313
- */
314
- invocationId: import_echo_schema2.ObjectId,
315
- /**
316
- * Event generation time.
317
- */
318
- // TODO(burdon): Remove ms suffix.
319
- timestampMs: import_effect3.Schema.Number,
320
- outcome: import_effect3.Schema.Enums(InvocationOutcome),
321
- exception: import_effect3.Schema.optional(TraceEventException)
322
- }).pipe((0, import_echo_schema2.EchoObject)({
323
- typename: "dxos.org/type/InvocationTraceEnd",
324
- version: "0.1.0"
325
- }));
326
- var TraceEventLog = import_effect3.Schema.Struct({
327
- timestampMs: import_effect3.Schema.Number,
328
- level: import_effect3.Schema.String,
329
- message: import_effect3.Schema.String,
330
- context: import_effect3.Schema.optional(import_effect3.Schema.Object)
331
- });
332
- var TraceEvent = import_effect3.Schema.Struct({
333
- id: import_echo_schema2.ObjectId,
334
- // TODO(burdon): Need enum/numeric result (not string).
335
- outcome: import_effect3.Schema.String,
336
- truncated: import_effect3.Schema.Boolean,
337
- /**
338
- * Time when the event was persisted.
339
- */
340
- ingestionTimestampMs: import_effect3.Schema.Number,
341
- logs: import_effect3.Schema.Array(TraceEventLog),
342
- exceptions: import_effect3.Schema.Array(TraceEventException)
343
- }).pipe((0, import_echo_schema2.EchoObject)({
344
- typename: "dxos.org/type/TraceEvent",
345
- version: "0.1.0"
346
- }));
347
- var createInvocationSpans = (items) => {
348
- if (!items) {
349
- return [];
350
- }
351
- const eventsByInvocationId = /* @__PURE__ */ new Map();
352
- for (const event of items) {
353
- if (!("invocationId" in event)) {
354
- continue;
355
- }
356
- const invocationId = event.invocationId;
357
- const entry = eventsByInvocationId.get(invocationId) || {
358
- start: void 0,
359
- end: void 0
360
- };
361
- if (event.type === "start") {
362
- entry.start = event;
363
- } else if (event.type === "end") {
364
- entry.end = event;
77
+ var subscriptionHandler = (handler, types) => {
78
+ return async ({ event: { data }, context, response, ...rest }) => {
79
+ const { client } = context;
80
+ const space = data.spaceKey ? client.spaces.get(import_client.PublicKey.from(data.spaceKey)) : void 0;
81
+ if (!space) {
82
+ import_log.log.error("Invalid space", void 0, {
83
+ F: __dxlog_file,
84
+ L: 181,
85
+ S: void 0,
86
+ C: (f, a) => f(...a)
87
+ });
88
+ return response.status(500);
365
89
  }
366
- eventsByInvocationId.set(invocationId, entry);
367
- }
368
- const now = Date.now();
369
- const result = [];
370
- for (const [invocationId, { start, end }] of eventsByInvocationId.entries()) {
371
- if (!start) {
372
- import_log.log.warn("found end event without matching start", {
373
- invocationId
90
+ registerTypes(space, types);
91
+ const objects = space ? data.objects?.map((id) => space.db.getObjectById(id)).filter(import_util.isNonNullable) : [];
92
+ if (!!data.spaceKey && !space) {
93
+ import_log.log.warn("invalid space", {
94
+ data
95
+ }, {
96
+ F: __dxlog_file,
97
+ L: 193,
98
+ S: void 0,
99
+ C: (f, a) => f(...a)
100
+ });
101
+ } else {
102
+ import_log.log.info("handler", {
103
+ space: space?.key.truncate(),
104
+ objects: objects?.length
374
105
  }, {
375
106
  F: __dxlog_file,
376
- L: 160,
107
+ L: 195,
377
108
  S: void 0,
378
109
  C: (f, a) => f(...a)
379
110
  });
380
- continue;
381
111
  }
382
- const isInProgress = end === void 0;
383
- result.push({
384
- id: invocationId,
385
- timestampMs: start.timestampMs,
386
- durationMs: isInProgress ? now - start.timestampMs : end.timestampMs - start.timestampMs,
387
- outcome: end?.outcome ?? "pending",
388
- exception: end?.exception,
389
- input: start.input,
390
- invocationTraceQueue: start.invocationTraceQueue,
391
- invocationTarget: start.invocationTarget,
392
- trigger: start.trigger
112
+ return handler({
113
+ event: {
114
+ data: {
115
+ ...data,
116
+ space,
117
+ objects
118
+ }
119
+ },
120
+ context,
121
+ response,
122
+ ...rest
393
123
  });
394
- }
395
- return result;
396
- };
397
- var FUNCTIONS_META_KEY = "dxos.org/service/function";
398
- var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
399
- var isSecure = (protocol) => {
400
- return protocol === "https:" || protocol === "wss:";
401
- };
402
- var getUserFunctionUrlInMetadata = (meta) => {
403
- return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
124
+ };
404
125
  };
405
- var setUserFunctionUrlInMetadata = (meta, functionUrl) => {
406
- const key = meta.keys.find((key2) => key2.source === FUNCTIONS_META_KEY);
407
- if (key) {
408
- if (key.id !== functionUrl) {
409
- throw new Error("Metadata mismatch");
126
+ var registerTypes = (space, types = []) => {
127
+ const registry = space.db.graph.schemaRegistry;
128
+ for (const type of types) {
129
+ if (!registry.hasSchema(type)) {
130
+ registry.addSchema([
131
+ type
132
+ ]);
410
133
  }
411
- } else {
412
- meta.keys.push({
413
- source: FUNCTIONS_META_KEY,
414
- id: functionUrl
415
- });
416
134
  }
417
135
  };
418
- var makeFunctionUrl = (spaceId, fn) => `/${spaceId}/${fn.functionId}`;
419
- var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
420
- const baseUrl = new URL("functions/", edgeUrl);
421
- const relativeUrl = functionUrl.replace(/^\//, "");
422
- const url = new URL(`./${relativeUrl}`, baseUrl.toString());
423
- options.spaceId && url.searchParams.set("spaceId", options.spaceId);
424
- options.subjectId && url.searchParams.set("subjectId", options.subjectId);
425
- url.protocol = isSecure(url.protocol) ? "https" : "http";
426
- return url.toString();
427
- };
428
136
  // Annotate the CommonJS export names for ESM import in node:
429
137
  0 && (module.exports = {
430
- EmailTriggerOutput,
431
138
  FUNCTIONS_PRESET_META_KEY,
432
139
  FUNCTION_TYPES,
140
+ FunctionDef,
433
141
  FunctionManifestSchema,
142
+ FunctionRegistry,
434
143
  FunctionTrigger,
435
144
  FunctionTriggerSchema,
436
145
  FunctionType,
@@ -438,21 +147,24 @@ var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
438
147
  InvocationTraceEndEvent,
439
148
  InvocationTraceEventType,
440
149
  InvocationTraceStartEvent,
441
- QueueTriggerOutput,
442
150
  ScriptType,
443
- SubscriptionTriggerOutput,
444
- TimerTriggerOutput,
445
151
  TraceEvent,
446
152
  TraceEventException,
447
153
  TraceEventLog,
448
154
  TriggerKind,
155
+ TriggerRegistry,
449
156
  TriggerSchema,
450
- WebhookTriggerOutput,
451
157
  createInvocationSpans,
158
+ createSubscriptionTrigger,
159
+ createTimerTrigger,
452
160
  defineFunction,
453
161
  getInvocationUrl,
454
162
  getUserFunctionUrlInMetadata,
163
+ incrementSemverPatch,
455
164
  makeFunctionUrl,
456
- setUserFunctionUrlInMetadata
165
+ publicKeyToDid,
166
+ setUserFunctionUrlInMetadata,
167
+ subscriptionHandler,
168
+ uploadWorkerFunction
457
169
  });
458
170
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,oBAA4B;ACA5B,IAAAA,iBAAuB;AAEvB,yBAAgF;AAChF,oBAAyB;ACHzB,IAAAA,iBAAuB;AAEvB,IAAAC,sBAAmD;AACnD,iBAAoB;ACHpB,IAAAD,iBAAuC;AAEvC,IAAAC,sBAA+E;AHqFxE,IAAMC,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,cAAAA,OAAEC,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,cAAAA,OAAEO;IACvCH,SAASL,OAAOK;EAClB;AACF;AC7FO,IAAMI,aAAaC,sBAAOC,OAAO;EACtCC,MAAMF,sBAAOG,SAASH,sBAAOI,MAAM;EACnCR,aAAaI,sBAAOG,SAASH,sBAAOI,MAAM;;;EAG1CC,SAASL,sBAAOG,SAASH,sBAAOM,OAAO;EACvCC,YAAQC,wBAAIC,uBAASC,IAAI;AAC3B,CAAA,EACGC,YAAY;EAAE,CAACC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,QAAQ8F,OAAO;AAClE9F,UAAQyG,aAAa7F,IAAI4F,aAAa/B,IAAI,aAAazE,QAAQyG,SAAS;AACxE7F,MAAI0E,WAAWD,SAASzE,IAAI0E,QAAQ,IAAI,UAAU;AAClD,SAAO1E,IAAI2F,SAAQ;AACrB;",
6
- "names": ["import_effect", "import_echo_schema", "defineFunction", "params", "S", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "ScriptType", "Schema", "Struct", "name", "optional", "String", "changed", "Boolean", "source", "Ref", "DataType", "Text", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "typename", "version", "FunctionType", "TypedObject", "NonEmptyString", "JsonSchemaType", "binding", "TriggerKind", "typeLiteralAnnotations", "SchemaAST", "TitleAnnotationId", "TimerTriggerSchema", "type", "Literal", "cron", "ExamplesAnnotationId", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "SubscriptionTriggerSchema", "filter", "options", "deep", "delay", "TriggerSchema", "Union", "EmailTriggerOutput", "from", "to", "subject", "created", "body", "WebhookTriggerOutput", "url", "headers", "bodyText", "QueueTriggerOutput", "item", "cursor", "SubscriptionTriggerOutput", "changedObjectId", "TimerTriggerOutput", "tick", "FunctionTriggerSchema", "function", "Expando", "inputNodeId", "enabled", "spec", "input", "FunctionTrigger", "fields", "FunctionManifestSchema", "functions", "Array", "RawObject", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "timestampMs", "message", "stack", "InvocationTraceStartEvent", "id", "ObjectId", "invocationId", "Object", "invocationTraceQueue", "invocationTarget", "trigger", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "ingestionTimestampMs", "logs", "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", "setUserFunctionUrlInMetadata", "functionUrl", "makeFunctionUrl", "spaceId", "fn", "functionId", "getInvocationUrl", "edgeUrl", "baseUrl", "URL", "relativeUrl", "replace", "toString", "searchParams", "subjectId"]
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 AIServiceClient } from '@dxos/assistant';\nimport { type Client, PublicKey } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport type { CoreDatabase, EchoDatabase, ReactiveEchoObject } from '@dxos/echo-db';\nimport { type HasId } from '@dxos/echo-schema';\nimport { type SpaceId, 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: AIServiceClient;\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,oBAA4B;AAI5B,oBAAuC;AAKvC,iBAAoB;AAEpB,kBAA8B;;AAoHvB,IAAMA,iBAAiB,CAAOC,WAAAA;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P,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": ["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"]
7
7
  }