@dxos/functions 0.8.2-main.2f9c567 → 0.8.2-main.30e4dbb

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.
@@ -4,11 +4,11 @@ import { EdgeHttpClient } from "@dxos/edge-client";
4
4
  import { invariant } from "@dxos/invariant";
5
5
  import { log } from "@dxos/log";
6
6
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/edge/functions.ts";
7
- var uploadWorkerFunction = async ({ client, spaceId, version, source, name, functionId }) => {
7
+ var uploadWorkerFunction = async ({ client, version, source, name, functionId }) => {
8
8
  const edgeUrl = client.config.values.runtime?.services?.edge?.url;
9
9
  invariant(edgeUrl, "Edge is not configured.", {
10
10
  F: __dxlog_file,
11
- L: 33,
11
+ L: 31,
12
12
  S: void 0,
13
13
  A: [
14
14
  "edgeUrl",
@@ -19,7 +19,6 @@ var uploadWorkerFunction = async ({ client, spaceId, version, source, name, func
19
19
  const edgeIdentity = createEdgeIdentity(client);
20
20
  edgeClient.setIdentity(edgeIdentity);
21
21
  const response = await edgeClient.uploadFunction({
22
- spaceId,
23
22
  functionId
24
23
  }, {
25
24
  name,
@@ -34,7 +33,7 @@ var uploadWorkerFunction = async ({ client, spaceId, version, source, name, func
34
33
  response
35
34
  }, {
36
35
  F: __dxlog_file,
37
- L: 40,
36
+ L: 38,
38
37
  S: void 0,
39
38
  C: (f, a) => f(...a)
40
39
  });
@@ -45,7 +44,7 @@ var incrementSemverPatch = (version) => {
45
44
  const patchNum = Number(patch);
46
45
  invariant(!Number.isNaN(patchNum), `Unexpected function version format: ${version}`, {
47
46
  F: __dxlog_file,
48
- L: 54,
47
+ L: 52,
49
48
  S: void 0,
50
49
  A: [
51
50
  "!Number.isNaN(patchNum)",
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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 spaceId: SpaceId;\n source: string;\n version: string;\n name?: string;\n functionId?: string;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n spaceId,\n version,\n source,\n name,\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 // TODO(burdon): Edge service log.\n log.info('Uploaded', {\n identityKey: edgeIdentity.identityKey,\n functionId,\n name,\n source: source.length,\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: ${version}`);\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\n// TODO(burdon): Factor out.\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
5
- "mappings": ";AAOA,SAASA,0BAA0B;AACnC,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;AAE1B,SAASC,WAAW;;AAYb,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,SACAC,SACAC,QACAC,MACAC,WAAU,MACO;AACjB,QAAMC,UAAUN,OAAOO,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9Df,YAAUS,SAAS,2BAAA;;;;;;;;;AACnB,QAAMO,aAAa,IAAIjB,eAAeU,OAAAA;AACtC,QAAMQ,eAAenB,mBAAmBK,MAAAA;AACxCa,aAAWE,YAAYD,YAAAA;AACvB,QAAME,WAAW,MAAMH,WAAWI,eAAe;IAAEhB;IAASI;EAAW,GAAG;IAAED;IAAMF;IAASgB,QAAQf;EAAO,CAAA;AAG1GL,MAAIqB,KAAK,YAAY;IACnBC,aAAaN,aAAaM;IAC1Bf;IACAD;IACAD,QAAQA,OAAOkB;IACfL;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMM,uBAAuB,CAACpB,YAAAA;AACnC,QAAM,CAACqB,OAAOC,OAAOC,KAAAA,IAASvB,QAAQwB,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxB5B,YAAU,CAAC+B,OAAOC,MAAMF,QAAAA,GAAW,uCAAuCzB,OAAAA,IAAS;;;;;;;;;AACnF,SAAO;IAACqB;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAGO,IAAMC,iBAAiB,CAACC,QAAAA;AAC7B,SAAO,WAAWA,IAAIC,MAAK,CAAA;AAC7B;",
6
- "names": ["createEdgeIdentity", "EdgeHttpClient", "invariant", "log", "uploadWorkerFunction", "client", "spaceId", "version", "source", "name", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "edgeClient", "edgeIdentity", "setIdentity", "response", "uploadFunction", "script", "info", "identityKey", "length", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid", "key", "toHex"]
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 } from '@dxos/keys';\nimport { log } from '@dxos/log';\nimport { type UploadFunctionResponseBody } from '@dxos/protocols';\n\nexport type UploadWorkerArgs = {\n client: Client;\n source: string;\n version: string;\n name?: string;\n functionId?: string;\n};\n\nexport const uploadWorkerFunction = async ({\n client,\n version,\n source,\n name,\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({ functionId }, { name, version, script: source });\n\n // TODO(burdon): Edge service log.\n log.info('Uploaded', {\n identityKey: edgeIdentity.identityKey,\n functionId,\n name,\n source: source.length,\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: ${version}`);\n return [major, minor, String(patchNum + 1)].join('.');\n};\n\n// TODO(burdon): Factor out.\nexport const publicKeyToDid = (key: PublicKey): DID => {\n return `did:key:${key.toHex()}`;\n};\n"],
5
+ "mappings": ";AAOA,SAASA,0BAA0B;AACnC,SAASC,sBAAsB;AAC/B,SAASC,iBAAiB;AAE1B,SAASC,WAAW;;AAWb,IAAMC,uBAAuB,OAAO,EACzCC,QACAC,SACAC,QACAC,MACAC,WAAU,MACO;AACjB,QAAMC,UAAUL,OAAOM,OAAOC,OAAOC,SAASC,UAAUC,MAAMC;AAC9Dd,YAAUQ,SAAS,2BAAA;;;;;;;;;AACnB,QAAMO,aAAa,IAAIhB,eAAeS,OAAAA;AACtC,QAAMQ,eAAelB,mBAAmBK,MAAAA;AACxCY,aAAWE,YAAYD,YAAAA;AACvB,QAAME,WAAW,MAAMH,WAAWI,eAAe;IAAEZ;EAAW,GAAG;IAAED;IAAMF;IAASgB,QAAQf;EAAO,CAAA;AAGjGJ,MAAIoB,KAAK,YAAY;IACnBC,aAAaN,aAAaM;IAC1Bf;IACAD;IACAD,QAAQA,OAAOkB;IACfL;EACF,GAAA;;;;;;AAEA,SAAOA;AACT;AAEO,IAAMM,uBAAuB,CAACpB,YAAAA;AACnC,QAAM,CAACqB,OAAOC,OAAOC,KAAAA,IAASvB,QAAQwB,MAAM,GAAA;AAC5C,QAAMC,WAAWC,OAAOH,KAAAA;AACxB3B,YAAU,CAAC8B,OAAOC,MAAMF,QAAAA,GAAW,uCAAuCzB,OAAAA,IAAS;;;;;;;;;AACnF,SAAO;IAACqB;IAAOC;IAAOM,OAAOH,WAAW,CAAA;IAAII,KAAK,GAAA;AACnD;AAGO,IAAMC,iBAAiB,CAACC,QAAAA;AAC7B,SAAO,WAAWA,IAAIC,MAAK,CAAA;AAC7B;",
6
+ "names": ["createEdgeIdentity", "EdgeHttpClient", "invariant", "log", "uploadWorkerFunction", "client", "version", "source", "name", "functionId", "edgeUrl", "config", "values", "runtime", "services", "edge", "url", "edgeClient", "edgeIdentity", "setIdentity", "response", "uploadFunction", "script", "info", "identityKey", "length", "incrementSemverPatch", "major", "minor", "patch", "split", "patchNum", "Number", "isNaN", "String", "join", "publicKeyToDid", "key", "toHex"]
7
7
  }
@@ -1,7 +1,7 @@
1
1
  // packages/core/functions/src/handler.ts
2
- import { Schema as S } from "effect";
2
+ import { Schema } from "effect";
3
3
  var defineFunction = (params) => {
4
- if (!S.isSchema(params.inputSchema)) {
4
+ if (!Schema.isSchema(params.inputSchema)) {
5
5
  throw new Error("Input schema must be a valid schema");
6
6
  }
7
7
  if (typeof params.handler !== "function") {
@@ -10,21 +10,21 @@ var defineFunction = (params) => {
10
10
  return {
11
11
  description: params.description,
12
12
  inputSchema: params.inputSchema,
13
- outputSchema: params.outputSchema ?? S.Any,
13
+ outputSchema: params.outputSchema ?? Schema.Any,
14
14
  handler: params.handler
15
15
  };
16
16
  };
17
17
 
18
18
  // packages/core/functions/src/schema.ts
19
- import { Schema } from "effect";
19
+ import { Schema as Schema2 } from "effect";
20
20
  import { EchoObject, JsonSchemaType, LabelAnnotationId, Ref, TypedObject } from "@dxos/echo-schema";
21
21
  import { DataType } from "@dxos/schema";
22
- var ScriptType = Schema.Struct({
23
- name: Schema.optional(Schema.String),
24
- description: Schema.optional(Schema.String),
22
+ var ScriptType = Schema2.Struct({
23
+ name: Schema2.optional(Schema2.String),
24
+ description: Schema2.optional(Schema2.String),
25
25
  // TODO(burdon): Change to hash of deployed content.
26
26
  // Whether source has changed since last deploy.
27
- changed: Schema.optional(Schema.Boolean),
27
+ changed: Schema2.optional(Schema2.Boolean),
28
28
  source: Ref(DataType.Text)
29
29
  }).annotations({
30
30
  [LabelAnnotationId]: "name"
@@ -37,26 +37,26 @@ var FunctionType = class extends TypedObject({
37
37
  version: "0.1.0"
38
38
  })({
39
39
  // TODO(burdon): Rename to id/uri?
40
- name: Schema.NonEmptyString,
41
- version: Schema.String,
42
- description: Schema.optional(Schema.String),
40
+ name: Schema2.NonEmptyString,
41
+ version: Schema2.String,
42
+ description: Schema2.optional(Schema2.String),
43
43
  // Reference to a source script if it exists within ECHO.
44
44
  // TODO(burdon): Don't ref ScriptType directly (core).
45
- source: Schema.optional(Ref(ScriptType)),
46
- inputSchema: Schema.optional(JsonSchemaType),
47
- outputSchema: Schema.optional(JsonSchemaType),
45
+ source: Schema2.optional(Ref(ScriptType)),
46
+ inputSchema: Schema2.optional(JsonSchemaType),
47
+ outputSchema: Schema2.optional(JsonSchemaType),
48
48
  // Local binding to a function name.
49
- binding: Schema.optional(Schema.String)
49
+ binding: Schema2.optional(Schema2.String)
50
50
  }) {
51
51
  };
52
52
 
53
53
  // packages/core/functions/src/trace.ts
54
- import { Schema as Schema2 } from "effect";
54
+ import { Schema as Schema4 } from "effect";
55
55
  import { EchoObject as EchoObject2, Expando as Expando2, ObjectId, Ref as Ref3 } from "@dxos/echo-schema";
56
56
  import { log } from "@dxos/log";
57
57
 
58
58
  // packages/core/functions/src/types.ts
59
- import { Schema as S2, SchemaAST } from "effect";
59
+ import { Schema as Schema3, SchemaAST } from "effect";
60
60
  import { Expando, OptionsAnnotationId, TypedObject as TypedObject2, DXN, Ref as Ref2, RawObject } from "@dxos/echo-schema";
61
61
  var TriggerKind;
62
62
  (function(TriggerKind2) {
@@ -66,117 +66,117 @@ var TriggerKind;
66
66
  TriggerKind2["Email"] = "email";
67
67
  TriggerKind2["Queue"] = "queue";
68
68
  })(TriggerKind || (TriggerKind = {}));
69
- var typeLiteralAnnotations = {
70
- [SchemaAST.TitleAnnotationId]: "Type"
69
+ var kindLiteralAnnotations = {
70
+ [SchemaAST.TitleAnnotationId]: "Kind"
71
71
  };
72
- var TimerTriggerSchema = S2.Struct({
73
- type: S2.Literal("timer").annotations(typeLiteralAnnotations),
74
- cron: S2.String.annotations({
72
+ var TimerTriggerSchema = Schema3.Struct({
73
+ kind: Schema3.Literal("timer").annotations(kindLiteralAnnotations),
74
+ cron: Schema3.String.annotations({
75
75
  [SchemaAST.TitleAnnotationId]: "Cron",
76
76
  [SchemaAST.ExamplesAnnotationId]: [
77
77
  "0 0 * * *"
78
78
  ]
79
79
  })
80
- }).pipe(S2.mutable);
81
- var EmailTriggerSchema = S2.Struct({
82
- type: S2.Literal("email").annotations(typeLiteralAnnotations)
83
- }).pipe(S2.mutable);
84
- var QueueTriggerSchema = S2.Struct({
85
- type: S2.Literal("queue").annotations(typeLiteralAnnotations),
80
+ }).pipe(Schema3.mutable);
81
+ var EmailTriggerSchema = Schema3.Struct({
82
+ kind: Schema3.Literal("email").annotations(kindLiteralAnnotations)
83
+ }).pipe(Schema3.mutable);
84
+ var QueueTriggerSchema = Schema3.Struct({
85
+ kind: Schema3.Literal("queue").annotations(kindLiteralAnnotations),
86
86
  queue: DXN
87
- }).pipe(S2.mutable);
88
- var WebhookTriggerSchema = S2.Struct({
89
- type: S2.Literal("webhook").annotations(typeLiteralAnnotations),
90
- method: S2.optional(S2.String.annotations({
87
+ }).pipe(Schema3.mutable);
88
+ var WebhookTriggerSchema = Schema3.Struct({
89
+ kind: Schema3.Literal("webhook").annotations(kindLiteralAnnotations),
90
+ method: Schema3.optional(Schema3.String.annotations({
91
91
  [SchemaAST.TitleAnnotationId]: "Method",
92
92
  [OptionsAnnotationId]: [
93
93
  "GET",
94
94
  "POST"
95
95
  ]
96
96
  })),
97
- port: S2.optional(S2.Number.annotations({
97
+ port: Schema3.optional(Schema3.Number.annotations({
98
98
  [SchemaAST.TitleAnnotationId]: "Port"
99
99
  }))
100
- }).pipe(S2.mutable);
101
- var QuerySchema = S2.Struct({
102
- type: S2.optional(S2.String.annotations({
100
+ }).pipe(Schema3.mutable);
101
+ var QuerySchema = Schema3.Struct({
102
+ type: Schema3.optional(Schema3.String.annotations({
103
103
  [SchemaAST.TitleAnnotationId]: "Type"
104
104
  })),
105
- props: S2.optional(S2.Record({
106
- key: S2.String,
107
- value: S2.Any
105
+ props: Schema3.optional(Schema3.Record({
106
+ key: Schema3.String,
107
+ value: Schema3.Any
108
108
  }))
109
109
  }).annotations({
110
110
  [SchemaAST.TitleAnnotationId]: "Query"
111
111
  });
112
- var SubscriptionTriggerSchema = S2.Struct({
113
- type: S2.Literal("subscription").annotations(typeLiteralAnnotations),
112
+ var SubscriptionTriggerSchema = Schema3.Struct({
113
+ kind: Schema3.Literal("subscription").annotations(kindLiteralAnnotations),
114
114
  // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.
115
115
  filter: QuerySchema,
116
- options: S2.optional(S2.Struct({
116
+ options: Schema3.optional(Schema3.Struct({
117
117
  // Watch changes to object (not just creation).
118
- deep: S2.optional(S2.Boolean.annotations({
118
+ deep: Schema3.optional(Schema3.Boolean.annotations({
119
119
  [SchemaAST.TitleAnnotationId]: "Nested"
120
120
  })),
121
121
  // Debounce changes (delay in ms).
122
- delay: S2.optional(S2.Number.annotations({
122
+ delay: Schema3.optional(Schema3.Number.annotations({
123
123
  [SchemaAST.TitleAnnotationId]: "Delay"
124
124
  }))
125
125
  }).annotations({
126
126
  [SchemaAST.TitleAnnotationId]: "Options"
127
127
  }))
128
- }).pipe(S2.mutable);
129
- var TriggerSchema = S2.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
128
+ }).pipe(Schema3.mutable);
129
+ var TriggerSchema = Schema3.Union(TimerTriggerSchema, WebhookTriggerSchema, SubscriptionTriggerSchema, EmailTriggerSchema, QueueTriggerSchema).annotations({
130
130
  [SchemaAST.TitleAnnotationId]: "Trigger"
131
131
  });
132
- var EmailTriggerOutput = S2.mutable(S2.Struct({
133
- from: S2.String,
134
- to: S2.String,
135
- subject: S2.String,
136
- created: S2.String,
137
- body: S2.String
132
+ var EmailTriggerOutput = Schema3.mutable(Schema3.Struct({
133
+ from: Schema3.String,
134
+ to: Schema3.String,
135
+ subject: Schema3.String,
136
+ created: Schema3.String,
137
+ body: Schema3.String
138
138
  }));
139
- var WebhookTriggerOutput = S2.mutable(S2.Struct({
140
- url: S2.String,
141
- method: S2.Literal("GET", "POST"),
142
- headers: S2.Record({
143
- key: S2.String,
144
- value: S2.String
139
+ var WebhookTriggerOutput = Schema3.mutable(Schema3.Struct({
140
+ url: Schema3.String,
141
+ method: Schema3.Literal("GET", "POST"),
142
+ headers: Schema3.Record({
143
+ key: Schema3.String,
144
+ value: Schema3.String
145
145
  }),
146
- bodyText: S2.String
146
+ bodyText: Schema3.String
147
147
  }));
148
- var QueueTriggerOutput = S2.mutable(S2.Struct({
148
+ var QueueTriggerOutput = Schema3.mutable(Schema3.Struct({
149
149
  queue: DXN,
150
- item: S2.Any,
151
- cursor: S2.String
150
+ item: Schema3.Any,
151
+ cursor: Schema3.String
152
152
  }));
153
- var SubscriptionTriggerOutput = S2.mutable(S2.Struct({
154
- type: S2.String,
155
- changedObjectId: S2.String
153
+ var SubscriptionTriggerOutput = Schema3.mutable(Schema3.Struct({
154
+ type: Schema3.String,
155
+ changedObjectId: Schema3.String
156
156
  }));
157
- var TimerTriggerOutput = S2.mutable(S2.Struct({
158
- tick: S2.Number
157
+ var TimerTriggerOutput = Schema3.mutable(Schema3.Struct({
158
+ tick: Schema3.Number
159
159
  }));
160
- var FunctionTriggerSchema = S2.Struct({
160
+ var FunctionTriggerSchema = Schema3.Struct({
161
161
  /**
162
162
  * Function or workflow to invoke.
163
163
  */
164
164
  // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).
165
- function: S2.optional(Ref2(Expando).annotations({
165
+ function: Schema3.optional(Ref2(Expando).annotations({
166
166
  [SchemaAST.TitleAnnotationId]: "Function"
167
167
  })),
168
168
  /**
169
- * Only used for workflows.
169
+ * Only used for workflowSchema.
170
170
  * Specifies the input node in the circuit.
171
- * @deprecated Remove and enforce a single input node in all compute graphs.
171
+ * @deprecated Remove and enforce a single input node in all compute graphSchema.
172
172
  */
173
- inputNodeId: S2.optional(S2.String.annotations({
173
+ inputNodeId: Schema3.optional(Schema3.String.annotations({
174
174
  [SchemaAST.TitleAnnotationId]: "Input Node ID"
175
175
  })),
176
- enabled: S2.optional(S2.Boolean.annotations({
176
+ enabled: Schema3.optional(Schema3.Boolean.annotations({
177
177
  [SchemaAST.TitleAnnotationId]: "Enabled"
178
178
  })),
179
- spec: S2.optional(TriggerSchema),
179
+ spec: Schema3.optional(TriggerSchema),
180
180
  /**
181
181
  * Passed as the input data to the function.
182
182
  * Must match the function's input schema.
@@ -188,19 +188,19 @@ var FunctionTriggerSchema = S2.Struct({
188
188
  * mailbox: { '/': 'dxn:echo:AAA:ZZZ' }
189
189
  * }
190
190
  */
191
- input: S2.optional(S2.mutable(S2.Record({
192
- key: S2.String,
193
- value: S2.Any
191
+ input: Schema3.optional(Schema3.mutable(Schema3.Record({
192
+ key: Schema3.String,
193
+ value: Schema3.Any
194
194
  })))
195
195
  });
196
196
  var FunctionTrigger = class extends TypedObject2({
197
197
  typename: "dxos.org/type/FunctionTrigger",
198
- version: "0.1.0"
198
+ version: "0.2.0"
199
199
  })(FunctionTriggerSchema.fields) {
200
200
  };
201
- var FunctionManifestSchema = S2.Struct({
202
- functions: S2.optional(S2.mutable(S2.Array(RawObject(FunctionType)))),
203
- triggers: S2.optional(S2.mutable(S2.Array(RawObject(FunctionTrigger))))
201
+ var FunctionManifestSchema = Schema3.Struct({
202
+ functions: Schema3.optional(Schema3.mutable(Schema3.Array(RawObject(FunctionType)))),
203
+ triggers: Schema3.optional(Schema3.mutable(Schema3.Array(RawObject(FunctionTrigger))))
204
204
  });
205
205
  var FUNCTION_TYPES = [
206
206
  FunctionType,
@@ -220,18 +220,18 @@ var InvocationTraceEventType;
220
220
  InvocationTraceEventType2["START"] = "start";
221
221
  InvocationTraceEventType2["END"] = "end";
222
222
  })(InvocationTraceEventType || (InvocationTraceEventType = {}));
223
- var TraceEventException = Schema2.Struct({
224
- timestampMs: Schema2.Number,
225
- message: Schema2.String,
226
- name: Schema2.String,
227
- stack: Schema2.optional(Schema2.String)
223
+ var TraceEventException = Schema4.Struct({
224
+ timestampMs: Schema4.Number,
225
+ message: Schema4.String,
226
+ name: Schema4.String,
227
+ stack: Schema4.optional(Schema4.String)
228
228
  });
229
- var InvocationTraceStartEvent = Schema2.Struct({
229
+ var InvocationTraceStartEvent = Schema4.Struct({
230
230
  /**
231
231
  * Queue message id.
232
232
  */
233
233
  id: ObjectId,
234
- type: Schema2.Literal("start"),
234
+ type: Schema4.Literal("start"),
235
235
  /**
236
236
  * Invocation id, the same for invocation start and end events.
237
237
  */
@@ -239,12 +239,12 @@ var InvocationTraceStartEvent = Schema2.Struct({
239
239
  /**
240
240
  * Event generation time.
241
241
  */
242
- timestampMs: Schema2.Number,
242
+ timestampMs: Schema4.Number,
243
243
  /**
244
244
  * Data passed to function / workflow as an argument.
245
245
  */
246
246
  // TODO(burdon): Input schema?
247
- input: Schema2.Object,
247
+ input: Schema4.Object,
248
248
  /**
249
249
  * Queue DXN for function/workflow invocation events.
250
250
  */
@@ -257,17 +257,17 @@ var InvocationTraceStartEvent = Schema2.Struct({
257
257
  /**
258
258
  * Present for automatic invocations.
259
259
  */
260
- trigger: Schema2.optional(Ref3(FunctionTrigger))
260
+ trigger: Schema4.optional(Ref3(FunctionTrigger))
261
261
  }).pipe(EchoObject2({
262
262
  typename: "dxos.org/type/InvocationTraceStart",
263
263
  version: "0.1.0"
264
264
  }));
265
- var InvocationTraceEndEvent = Schema2.Struct({
265
+ var InvocationTraceEndEvent = Schema4.Struct({
266
266
  /**
267
267
  * Trace event id.
268
268
  */
269
269
  id: ObjectId,
270
- type: Schema2.Literal("end"),
270
+ type: Schema4.Literal("end"),
271
271
  /**
272
272
  * Invocation id, will be the same for invocation start and end.
273
273
  */
@@ -276,30 +276,30 @@ var InvocationTraceEndEvent = Schema2.Struct({
276
276
  * Event generation time.
277
277
  */
278
278
  // TODO(burdon): Remove ms suffix.
279
- timestampMs: Schema2.Number,
280
- outcome: Schema2.Enums(InvocationOutcome),
281
- exception: Schema2.optional(TraceEventException)
279
+ timestampMs: Schema4.Number,
280
+ outcome: Schema4.Enums(InvocationOutcome),
281
+ exception: Schema4.optional(TraceEventException)
282
282
  }).pipe(EchoObject2({
283
283
  typename: "dxos.org/type/InvocationTraceEnd",
284
284
  version: "0.1.0"
285
285
  }));
286
- var TraceEventLog = Schema2.Struct({
287
- timestampMs: Schema2.Number,
288
- level: Schema2.String,
289
- message: Schema2.String,
290
- context: Schema2.optional(Schema2.Object)
286
+ var TraceEventLog = Schema4.Struct({
287
+ timestampMs: Schema4.Number,
288
+ level: Schema4.String,
289
+ message: Schema4.String,
290
+ context: Schema4.optional(Schema4.Object)
291
291
  });
292
- var TraceEvent = Schema2.Struct({
292
+ var TraceEvent = Schema4.Struct({
293
293
  id: ObjectId,
294
294
  // TODO(burdon): Need enum/numeric result (not string).
295
- outcome: Schema2.String,
296
- truncated: Schema2.Boolean,
295
+ outcome: Schema4.String,
296
+ truncated: Schema4.Boolean,
297
297
  /**
298
298
  * Time when the event was persisted.
299
299
  */
300
- ingestionTimestampMs: Schema2.Number,
301
- logs: Schema2.Array(TraceEventLog),
302
- exceptions: Schema2.Array(TraceEventException)
300
+ ingestionTimestampMs: Schema4.Number,
301
+ logs: Schema4.Array(TraceEventLog),
302
+ exceptions: Schema4.Array(TraceEventException)
303
303
  }).pipe(EchoObject2({
304
304
  typename: "dxos.org/type/TraceEvent",
305
305
  version: "0.1.0"
@@ -377,7 +377,7 @@ var setUserFunctionUrlInMetadata = (meta, functionUrl) => {
377
377
  });
378
378
  }
379
379
  };
380
- var makeFunctionUrl = (spaceId, fn) => `/${spaceId}/${fn.functionId}`;
380
+ var makeFunctionUrl = (fn) => `/${fn.functionId}`;
381
381
  var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
382
382
  const baseUrl = new URL("functions/", edgeUrl);
383
383
  const relativeUrl = functionUrl.replace(/^\//, "");
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
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,SAASA,UAAUC,SAAS;AAuFrB,IAAMC,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,EAAEC,SAASF,OAAOG,WAAW,GAAG;AACnC,UAAM,IAAIC,MAA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B;IACjB,CAAA;EACF;AAEA,SAAOiC;AACT;;;AE3KA,IAAMO,qBAAqB;AAEpB,IAAMC,4BAA4B;AAEzC,IAAMC,WAAW,CAACC,aAAAA;AAChB,SAAOA,aAAa,YAAYA,aAAa;AAC/C;AAEO,IAAMC,+BAA+B,CAACC,SAAAA;AAC3C,SAAOA,KAAKC,KAAKC,KAAK,CAACC,QAAQA,IAAIC,WAAWT,kBAAAA,GAAqBU;AACrE;AAEO,IAAMC,+BAA+B,CAACN,MAAkBO,gBAAAA;AAC7D,QAAMJ,MAAMH,KAAKC,KAAKC,KAAK,CAACC,SAAQA,KAAIC,WAAWT,kBAAAA;AACnD,MAAIQ,KAAK;AACP,QAAIA,IAAIE,OAAOE,aAAa;AAC1B,YAAM,IAAIC,MAAM,mBAAA;IAClB;EACF,OAAO;AACLR,SAAKC,KAAKQ,KAAK;MAAEL,QAAQT;MAAoBU,IAAIE;IAAY,CAAA;EAC/D;AACF;AAKO,IAAMG,kBAAkB,CAACC,SAAkBC,OAA+B,IAAID,OAAAA,IAAWC,GAAGC,UAAU;AAEtG,IAAMC,mBAAmB,CAACP,aAAqBQ,SAAiBC,UAA6B,CAAC,MAAC;AACpG,QAAMC,UAAU,IAAIC,IAAI,cAAcH,OAAAA;AAGtC,QAAMI,cAAcZ,YAAYa,QAAQ,OAAO,EAAA;AAC/C,QAAMC,MAAM,IAAIH,IAAI,KAAKC,WAAAA,IAAeF,QAAQK,SAAQ,CAAA;AACxDN,UAAQL,WAAWU,IAAIE,aAAaC,IAAI,WAAWR,QAAQL,OAAO;AAClEK,UAAQS,aAAaJ,IAAIE,aAAaC,IAAI,aAAaR,QAAQS,SAAS;AACxEJ,MAAIvB,WAAWD,SAASwB,IAAIvB,QAAQ,IAAI,UAAU;AAClD,SAAOuB,IAAIC,SAAQ;AACrB;",
6
- "names": ["Schema", "S", "defineFunction", "params", "S", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "Schema", "EchoObject", "JsonSchemaType", "LabelAnnotationId", "Ref", "TypedObject", "DataType", "ScriptType", "Schema", "Struct", "name", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "DataType", "Text", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "typename", "version", "FunctionType", "TypedObject", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "Schema", "EchoObject", "Expando", "ObjectId", "Ref", "log", "Schema", "S", "SchemaAST", "Expando", "OptionsAnnotationId", "TypedObject", "DXN", "Ref", "RawObject", "TriggerKind", "typeLiteralAnnotations", "SchemaAST", "TitleAnnotationId", "TimerTriggerSchema", "S", "Struct", "type", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "EmailTriggerOutput", "from", "to", "subject", "created", "body", "WebhookTriggerOutput", "url", "headers", "bodyText", "QueueTriggerOutput", "item", "cursor", "SubscriptionTriggerOutput", "changedObjectId", "TimerTriggerOutput", "tick", "FunctionTriggerSchema", "function", "Ref", "Expando", "inputNodeId", "enabled", "spec", "input", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionManifestSchema", "functions", "Array", "RawObject", "FunctionType", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "Schema", "Struct", "timestampMs", "Number", "message", "String", "name", "stack", "optional", "InvocationTraceStartEvent", "id", "ObjectId", "type", "Literal", "invocationId", "input", "Object", "invocationTraceQueue", "Ref", "Expando", "invocationTarget", "trigger", "FunctionTrigger", "pipe", "EchoObject", "typename", "version", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "Boolean", "ingestionTimestampMs", "logs", "Array", "exceptions", "createInvocationSpans", "items", "eventsByInvocationId", "Map", "event", "entry", "get", "start", "undefined", "end", "set", "now", "Date", "result", "entries", "log", "warn", "isInProgress", "push", "durationMs", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "source", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "makeFunctionUrl", "spaceId", "fn", "functionId", "getInvocationUrl", "edgeUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "searchParams", "set", "subjectId"]
4
+ "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { Schema } from 'effect';\nimport { type Effect } from 'effect';\n\nimport { type AIServiceClient } from '@dxos/assistant';\n// import { type Space } from '@dxos/client/echo';\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\n// TODO(wittjosiah): Queues are incompatible.\nconst __assertFunctionSpaceIsCompatibleWithTheClientSpace = () => {\n // const _: SpaceAPI = {} as Space;\n};\n\nexport type FunctionDefinition<T = {}, O = any> = {\n description?: string;\n inputSchema: Schema.Schema<T, any>;\n outputSchema?: Schema.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 (!Schema.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 ?? Schema.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, 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\nconst kindLiteralAnnotations = { [SchemaAST.TitleAnnotationId]: 'Kind' };\n\n/**\n * Cron timer.\n */\nconst TimerTriggerSchema = Schema.Struct({\n kind: Schema.Literal(TriggerKind.Timer).annotations(kindLiteralAnnotations),\n cron: Schema.String.annotations({\n [SchemaAST.TitleAnnotationId]: 'Cron',\n [SchemaAST.ExamplesAnnotationId]: ['0 0 * * *'],\n }),\n}).pipe(Schema.mutable);\nexport type TimerTrigger = Schema.Schema.Type<typeof TimerTriggerSchema>;\n\nconst EmailTriggerSchema = Schema.Struct({\n kind: Schema.Literal(TriggerKind.Email).annotations(kindLiteralAnnotations),\n}).pipe(Schema.mutable);\nexport type EmailTrigger = Schema.Schema.Type<typeof EmailTriggerSchema>;\n\nconst QueueTriggerSchema = Schema.Struct({\n kind: Schema.Literal(TriggerKind.Queue).annotations(kindLiteralAnnotations),\n queue: DXN,\n}).pipe(Schema.mutable);\nexport type QueueTrigger = Schema.Schema.Type<typeof QueueTriggerSchema>;\n\n/**\n * Webhook.\n */\nconst WebhookTriggerSchema = Schema.Struct({\n kind: Schema.Literal(TriggerKind.Webhook).annotations(kindLiteralAnnotations),\n method: Schema.optional(\n Schema.String.annotations({\n [SchemaAST.TitleAnnotationId]: 'Method',\n [OptionsAnnotationId]: ['GET', 'POST'],\n }),\n ),\n port: Schema.optional(\n Schema.Number.annotations({\n [SchemaAST.TitleAnnotationId]: 'Port',\n }),\n ),\n}).pipe(Schema.mutable);\nexport type WebhookTrigger = Schema.Schema.Type<typeof WebhookTriggerSchema>;\n\n// TODO(burdon): Use ECHO definition (from https://github.com/dxos/dxos/pull/8233).\nconst QuerySchema = Schema.Struct({\n type: Schema.optional(Schema.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Type' })),\n props: Schema.optional(Schema.Record({ key: Schema.String, value: Schema.Any })),\n}).annotations({ [SchemaAST.TitleAnnotationId]: 'Query' });\n\n/**\n * Subscription.\n */\nconst SubscriptionTriggerSchema = Schema.Struct({\n kind: Schema.Literal(TriggerKind.Subscription).annotations(kindLiteralAnnotations),\n // TODO(burdon): Define query DSL (from ECHO). Reconcile with Table.Query.\n filter: QuerySchema,\n options: Schema.optional(\n Schema.Struct({\n // Watch changes to object (not just creation).\n deep: Schema.optional(Schema.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Nested' })),\n // Debounce changes (delay in ms).\n delay: Schema.optional(Schema.Number.annotations({ [SchemaAST.TitleAnnotationId]: 'Delay' })),\n }).annotations({ [SchemaAST.TitleAnnotationId]: 'Options' }),\n ),\n}).pipe(Schema.mutable);\nexport type SubscriptionTrigger = Schema.Schema.Type<typeof SubscriptionTriggerSchema>;\n\n/**\n * Trigger schema (discriminated union).\n */\nexport const TriggerSchema = Schema.Union(\n TimerTriggerSchema,\n WebhookTriggerSchema,\n SubscriptionTriggerSchema,\n EmailTriggerSchema,\n QueueTriggerSchema,\n).annotations({\n [SchemaAST.TitleAnnotationId]: 'Trigger',\n});\nexport type TriggerType = Schema.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 = Schema.mutable(\n Schema.Struct({\n from: Schema.String,\n to: Schema.String,\n subject: Schema.String,\n created: Schema.String,\n body: Schema.String,\n }),\n);\nexport type EmailTriggerOutput = Schema.Schema.Type<typeof EmailTriggerOutput>;\n\nexport const WebhookTriggerOutput = Schema.mutable(\n Schema.Struct({\n url: Schema.String,\n method: Schema.Literal('GET', 'POST'),\n headers: Schema.Record({ key: Schema.String, value: Schema.String }),\n bodyText: Schema.String,\n }),\n);\nexport type WebhookTriggerOutput = Schema.Schema.Type<typeof WebhookTriggerOutput>;\n\nexport const QueueTriggerOutput = Schema.mutable(\n Schema.Struct({\n queue: DXN,\n item: Schema.Any,\n cursor: Schema.String,\n }),\n);\nexport type QueueTriggerOutput = Schema.Schema.Type<typeof QueueTriggerOutput>;\n\nexport const SubscriptionTriggerOutput = Schema.mutable(\n Schema.Struct({ type: Schema.String, changedObjectId: Schema.String }),\n);\nexport type SubscriptionTriggerOutput = Schema.Schema.Type<typeof SubscriptionTriggerOutput>;\n\nexport const TimerTriggerOutput = Schema.mutable(Schema.Struct({ tick: Schema.Number }));\nexport type TimerTriggerOutput = Schema.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 = Schema.Struct({\n /**\n * Function or workflow to invoke.\n */\n // TODO(dmaretskyi): Can be a Ref(FunctionType) or Ref(ComputeGraphType).\n function: Schema.optional(Ref(Expando).annotations({ [SchemaAST.TitleAnnotationId]: 'Function' })),\n\n /**\n * Only used for workflowSchema.\n * Specifies the input node in the circuit.\n * @deprecated Remove and enforce a single input node in all compute graphSchema.\n */\n inputNodeId: Schema.optional(Schema.String.annotations({ [SchemaAST.TitleAnnotationId]: 'Input Node ID' })),\n\n enabled: Schema.optional(Schema.Boolean.annotations({ [SchemaAST.TitleAnnotationId]: 'Enabled' })),\n\n spec: Schema.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: Schema.optional(Schema.mutable(Schema.Record({ key: Schema.String, value: Schema.Any }))),\n});\n\nexport type FunctionTriggerType = Schema.Schema.Type<typeof FunctionTriggerSchema>;\n\n/**\n * Function trigger.\n */\nexport class FunctionTrigger extends TypedObject({\n typename: 'dxos.org/type/FunctionTrigger',\n version: '0.2.0',\n})(FunctionTriggerSchema.fields) {}\n\n// TODO(wittjosiah): Remove?\n\n/**\n * Function manifest file.\n */\nexport const FunctionManifestSchema = Schema.Struct({\n functions: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionType)))),\n triggers: Schema.optional(Schema.mutable(Schema.Array(RawObject(FunctionTrigger)))),\n});\nexport type FunctionManifest = Schema.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 = (fn: { functionId: string }) => `/${fn.functionId}`;\n\nexport const getInvocationUrl = (functionUrl: string, edgeUrl: string, options: InvocationOptions = {}) => {\n const baseUrl = new URL('functions/', edgeUrl);\n\n // Leading slashes cause the URL to be treated as an absolute path.\n const relativeUrl = functionUrl.replace(/^\\//, '');\n const url = new URL(`./${relativeUrl}`, baseUrl.toString());\n options.spaceId && url.searchParams.set('spaceId', options.spaceId);\n options.subjectId && url.searchParams.set('subjectId', options.subjectId);\n url.protocol = isSecure(url.protocol) ? 'https' : 'http';\n return url.toString();\n};\n\nexport type InvocationOptions = {\n spaceId?: SpaceId;\n subjectId?: string;\n};\n"],
5
+ "mappings": ";AAIA,SAASA,cAAc;AAyFhB,IAAMC,iBAAiB,CAAOC,WAAAA;AACnC,MAAI,CAACC,OAAOC,SAASF,OAAOG,WAAW,GAAG;AACxC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B;MAC5BG,kBAAkB4B,MAAM5B;MACxBC,SAAS2B,MAAM3B;IACjB,CAAA;EACF;AAEA,SAAOiC;AACT;;;AE3KA,IAAMO,qBAAqB;AAEpB,IAAMC,4BAA4B;AAEzC,IAAMC,WAAW,CAACC,aAAAA;AAChB,SAAOA,aAAa,YAAYA,aAAa;AAC/C;AAEO,IAAMC,+BAA+B,CAACC,SAAAA;AAC3C,SAAOA,KAAKC,KAAKC,KAAK,CAACC,QAAQA,IAAIC,WAAWT,kBAAAA,GAAqBU;AACrE;AAEO,IAAMC,+BAA+B,CAACN,MAAkBO,gBAAAA;AAC7D,QAAMJ,MAAMH,KAAKC,KAAKC,KAAK,CAACC,SAAQA,KAAIC,WAAWT,kBAAAA;AACnD,MAAIQ,KAAK;AACP,QAAIA,IAAIE,OAAOE,aAAa;AAC1B,YAAM,IAAIC,MAAM,mBAAA;IAClB;EACF,OAAO;AACLR,SAAKC,KAAKQ,KAAK;MAAEL,QAAQT;MAAoBU,IAAIE;IAAY,CAAA;EAC/D;AACF;AAKO,IAAMG,kBAAkB,CAACC,OAA+B,IAAIA,GAAGC,UAAU;AAEzE,IAAMC,mBAAmB,CAACN,aAAqBO,SAAiBC,UAA6B,CAAC,MAAC;AACpG,QAAMC,UAAU,IAAIC,IAAI,cAAcH,OAAAA;AAGtC,QAAMI,cAAcX,YAAYY,QAAQ,OAAO,EAAA;AAC/C,QAAMC,MAAM,IAAIH,IAAI,KAAKC,WAAAA,IAAeF,QAAQK,SAAQ,CAAA;AACxDN,UAAQO,WAAWF,IAAIG,aAAaC,IAAI,WAAWT,QAAQO,OAAO;AAClEP,UAAQU,aAAaL,IAAIG,aAAaC,IAAI,aAAaT,QAAQU,SAAS;AACxEL,MAAItB,WAAWD,SAASuB,IAAItB,QAAQ,IAAI,UAAU;AAClD,SAAOsB,IAAIC,SAAQ;AACrB;",
6
+ "names": ["Schema", "defineFunction", "params", "Schema", "isSchema", "inputSchema", "Error", "handler", "description", "outputSchema", "Any", "Schema", "EchoObject", "JsonSchemaType", "LabelAnnotationId", "Ref", "TypedObject", "DataType", "ScriptType", "Schema", "Struct", "name", "optional", "String", "description", "changed", "Boolean", "source", "Ref", "DataType", "Text", "annotations", "LabelAnnotationId", "pipe", "EchoObject", "typename", "version", "FunctionType", "TypedObject", "NonEmptyString", "inputSchema", "JsonSchemaType", "outputSchema", "binding", "Schema", "EchoObject", "Expando", "ObjectId", "Ref", "log", "Schema", "SchemaAST", "Expando", "OptionsAnnotationId", "TypedObject", "DXN", "Ref", "RawObject", "TriggerKind", "kindLiteralAnnotations", "SchemaAST", "TitleAnnotationId", "TimerTriggerSchema", "Schema", "Struct", "kind", "Literal", "annotations", "cron", "String", "ExamplesAnnotationId", "pipe", "mutable", "EmailTriggerSchema", "QueueTriggerSchema", "queue", "DXN", "WebhookTriggerSchema", "method", "optional", "OptionsAnnotationId", "port", "Number", "QuerySchema", "type", "props", "Record", "key", "value", "Any", "SubscriptionTriggerSchema", "filter", "options", "deep", "Boolean", "delay", "TriggerSchema", "Union", "EmailTriggerOutput", "from", "to", "subject", "created", "body", "WebhookTriggerOutput", "url", "headers", "bodyText", "QueueTriggerOutput", "item", "cursor", "SubscriptionTriggerOutput", "changedObjectId", "TimerTriggerOutput", "tick", "FunctionTriggerSchema", "function", "Ref", "Expando", "inputNodeId", "enabled", "spec", "input", "FunctionTrigger", "TypedObject", "typename", "version", "fields", "FunctionManifestSchema", "functions", "Array", "RawObject", "FunctionType", "triggers", "FUNCTION_TYPES", "InvocationOutcome", "InvocationTraceEventType", "TraceEventException", "Schema", "Struct", "timestampMs", "Number", "message", "String", "name", "stack", "optional", "InvocationTraceStartEvent", "id", "ObjectId", "type", "Literal", "invocationId", "input", "Object", "invocationTraceQueue", "Ref", "Expando", "invocationTarget", "trigger", "FunctionTrigger", "pipe", "EchoObject", "typename", "version", "InvocationTraceEndEvent", "outcome", "Enums", "exception", "TraceEventLog", "level", "context", "TraceEvent", "truncated", "Boolean", "ingestionTimestampMs", "logs", "Array", "exceptions", "createInvocationSpans", "items", "eventsByInvocationId", "Map", "event", "entry", "get", "start", "undefined", "end", "set", "now", "Date", "result", "entries", "log", "warn", "isInProgress", "push", "durationMs", "FUNCTIONS_META_KEY", "FUNCTIONS_PRESET_META_KEY", "isSecure", "protocol", "getUserFunctionUrlInMetadata", "meta", "keys", "find", "key", "source", "id", "setUserFunctionUrlInMetadata", "functionUrl", "Error", "push", "makeFunctionUrl", "fn", "functionId", "getInvocationUrl", "edgeUrl", "options", "baseUrl", "URL", "relativeUrl", "replace", "url", "toString", "spaceId", "searchParams", "set", "subjectId"]
7
7
  }