@dxos/functions 0.8.3 → 0.8.4-main.03d5cd7b56

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 (142) hide show
  1. package/README.md +4 -6
  2. package/dist/lib/neutral/index.mjs +593 -0
  3. package/dist/lib/neutral/index.mjs.map +7 -0
  4. package/dist/lib/neutral/meta.json +1 -0
  5. package/dist/types/src/index.d.ts +3 -6
  6. package/dist/types/src/index.d.ts.map +1 -1
  7. package/dist/types/src/protocol/functions-ai-http-client.d.ts +12 -0
  8. package/dist/types/src/protocol/functions-ai-http-client.d.ts.map +1 -0
  9. package/dist/types/src/protocol/functions-ai-http-client.test.d.ts +2 -0
  10. package/dist/types/src/protocol/functions-ai-http-client.test.d.ts.map +1 -0
  11. package/dist/types/src/protocol/index.d.ts +2 -0
  12. package/dist/types/src/protocol/index.d.ts.map +1 -0
  13. package/dist/types/src/protocol/protocol.d.ts +19 -0
  14. package/dist/types/src/protocol/protocol.d.ts.map +1 -0
  15. package/dist/types/src/protocol/protocol.test.d.ts +2 -0
  16. package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
  17. package/dist/types/src/sdk.d.ts +10 -0
  18. package/dist/types/src/sdk.d.ts.map +1 -0
  19. package/dist/types/src/services/credentials.d.ts +24 -27
  20. package/dist/types/src/services/credentials.d.ts.map +1 -1
  21. package/dist/types/src/services/function-invocation-service.d.ts +15 -0
  22. package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
  23. package/dist/types/src/services/index.d.ts +3 -7
  24. package/dist/types/src/services/index.d.ts.map +1 -1
  25. package/dist/types/src/services/queues.d.ts +1 -17
  26. package/dist/types/src/services/queues.d.ts.map +1 -1
  27. package/dist/types/src/services/tracing.d.ts +4 -14
  28. package/dist/types/src/services/tracing.d.ts.map +1 -1
  29. package/dist/types/src/types/index.d.ts +2 -0
  30. package/dist/types/src/types/index.d.ts.map +1 -0
  31. package/dist/types/src/types/url.d.ts +13 -0
  32. package/dist/types/src/types/url.d.ts.map +1 -0
  33. package/dist/types/tsconfig.tsbuildinfo +1 -1
  34. package/package.json +28 -65
  35. package/src/index.ts +3 -8
  36. package/src/protocol/functions-ai-http-client.test.ts +105 -0
  37. package/src/protocol/functions-ai-http-client.ts +141 -0
  38. package/src/{executor → protocol}/index.ts +1 -1
  39. package/src/protocol/protocol.test.ts +58 -0
  40. package/src/protocol/protocol.ts +428 -0
  41. package/src/sdk.ts +31 -0
  42. package/src/services/credentials.ts +96 -35
  43. package/src/services/function-invocation-service.ts +33 -0
  44. package/src/services/index.ts +3 -7
  45. package/src/services/queues.ts +1 -33
  46. package/src/services/tracing.ts +4 -23
  47. package/src/{testing → types}/index.ts +1 -1
  48. package/src/types/url.ts +32 -0
  49. package/dist/lib/browser/bundler/index.mjs +0 -236
  50. package/dist/lib/browser/bundler/index.mjs.map +0 -7
  51. package/dist/lib/browser/chunk-WEFZUEL2.mjs +0 -300
  52. package/dist/lib/browser/chunk-WEFZUEL2.mjs.map +0 -7
  53. package/dist/lib/browser/edge/index.mjs +0 -69
  54. package/dist/lib/browser/edge/index.mjs.map +0 -7
  55. package/dist/lib/browser/index.mjs +0 -486
  56. package/dist/lib/browser/index.mjs.map +0 -7
  57. package/dist/lib/browser/meta.json +0 -1
  58. package/dist/lib/browser/testing/index.mjs +0 -28
  59. package/dist/lib/browser/testing/index.mjs.map +0 -7
  60. package/dist/lib/node/bundler/index.cjs +0 -260
  61. package/dist/lib/node/bundler/index.cjs.map +0 -7
  62. package/dist/lib/node/chunk-IJAE7FZK.cjs +0 -320
  63. package/dist/lib/node/chunk-IJAE7FZK.cjs.map +0 -7
  64. package/dist/lib/node/edge/index.cjs +0 -94
  65. package/dist/lib/node/edge/index.cjs.map +0 -7
  66. package/dist/lib/node/index.cjs +0 -522
  67. package/dist/lib/node/index.cjs.map +0 -7
  68. package/dist/lib/node/meta.json +0 -1
  69. package/dist/lib/node/testing/index.cjs +0 -43
  70. package/dist/lib/node/testing/index.cjs.map +0 -7
  71. package/dist/lib/node-esm/bundler/index.mjs +0 -238
  72. package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
  73. package/dist/lib/node-esm/chunk-LIYPMWNQ.mjs +0 -302
  74. package/dist/lib/node-esm/chunk-LIYPMWNQ.mjs.map +0 -7
  75. package/dist/lib/node-esm/edge/index.mjs +0 -71
  76. package/dist/lib/node-esm/edge/index.mjs.map +0 -7
  77. package/dist/lib/node-esm/index.mjs +0 -487
  78. package/dist/lib/node-esm/index.mjs.map +0 -7
  79. package/dist/lib/node-esm/meta.json +0 -1
  80. package/dist/lib/node-esm/testing/index.mjs +0 -29
  81. package/dist/lib/node-esm/testing/index.mjs.map +0 -7
  82. package/dist/types/src/bundler/bundler.d.ts +0 -51
  83. package/dist/types/src/bundler/bundler.d.ts.map +0 -1
  84. package/dist/types/src/bundler/bundler.test.d.ts +0 -2
  85. package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
  86. package/dist/types/src/bundler/index.d.ts +0 -2
  87. package/dist/types/src/bundler/index.d.ts.map +0 -1
  88. package/dist/types/src/edge/functions.d.ts +0 -16
  89. package/dist/types/src/edge/functions.d.ts.map +0 -1
  90. package/dist/types/src/edge/index.d.ts +0 -2
  91. package/dist/types/src/edge/index.d.ts.map +0 -1
  92. package/dist/types/src/executor/executor.d.ts +0 -8
  93. package/dist/types/src/executor/executor.d.ts.map +0 -1
  94. package/dist/types/src/executor/index.d.ts +0 -2
  95. package/dist/types/src/executor/index.d.ts.map +0 -1
  96. package/dist/types/src/handler.d.ts +0 -64
  97. package/dist/types/src/handler.d.ts.map +0 -1
  98. package/dist/types/src/schema.d.ts +0 -38
  99. package/dist/types/src/schema.d.ts.map +0 -1
  100. package/dist/types/src/services/ai.d.ts +0 -12
  101. package/dist/types/src/services/ai.d.ts.map +0 -1
  102. package/dist/types/src/services/database.d.ts +0 -11
  103. package/dist/types/src/services/database.d.ts.map +0 -1
  104. package/dist/types/src/services/event-logger.d.ts +0 -37
  105. package/dist/types/src/services/event-logger.d.ts.map +0 -1
  106. package/dist/types/src/services/function-call-service.d.ts +0 -16
  107. package/dist/types/src/services/function-call-service.d.ts.map +0 -1
  108. package/dist/types/src/services/service-container.d.ts +0 -44
  109. package/dist/types/src/services/service-container.d.ts.map +0 -1
  110. package/dist/types/src/testing/index.d.ts +0 -2
  111. package/dist/types/src/testing/index.d.ts.map +0 -1
  112. package/dist/types/src/testing/logger.d.ts +0 -5
  113. package/dist/types/src/testing/logger.d.ts.map +0 -1
  114. package/dist/types/src/testing/services.d.ts +0 -13
  115. package/dist/types/src/testing/services.d.ts.map +0 -1
  116. package/dist/types/src/trace.d.ts +0 -124
  117. package/dist/types/src/trace.d.ts.map +0 -1
  118. package/dist/types/src/translations.d.ts +0 -12
  119. package/dist/types/src/translations.d.ts.map +0 -1
  120. package/dist/types/src/types.d.ts +0 -411
  121. package/dist/types/src/types.d.ts.map +0 -1
  122. package/dist/types/src/url.d.ts +0 -17
  123. package/dist/types/src/url.d.ts.map +0 -1
  124. package/src/bundler/bundler.test.ts +0 -59
  125. package/src/bundler/bundler.ts +0 -270
  126. package/src/bundler/index.ts +0 -5
  127. package/src/edge/functions.ts +0 -64
  128. package/src/edge/index.ts +0 -9
  129. package/src/executor/executor.ts +0 -47
  130. package/src/handler.ts +0 -113
  131. package/src/schema.ts +0 -57
  132. package/src/services/ai.ts +0 -32
  133. package/src/services/database.ts +0 -28
  134. package/src/services/event-logger.ts +0 -87
  135. package/src/services/function-call-service.ts +0 -64
  136. package/src/services/service-container.ts +0 -109
  137. package/src/testing/logger.ts +0 -16
  138. package/src/testing/services.ts +0 -32
  139. package/src/trace.ts +0 -180
  140. package/src/translations.ts +0 -20
  141. package/src/types.ts +0 -211
  142. package/src/url.ts +0 -52
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var testing_exports = {};
20
- __export(testing_exports, {
21
- createTestServices: () => createTestServices
22
- });
23
- module.exports = __toCommonJS(testing_exports);
24
- var import_chunk_IJAE7FZK = require("../chunk-IJAE7FZK.cjs");
25
- var import_effect = require("effect");
26
- var import_log = require("@dxos/log");
27
- var noopLogger = {
28
- log: () => import_effect.Effect.succeed(void 0),
29
- nodeId: void 0
30
- };
31
- var consoleLogger = (0, import_chunk_IJAE7FZK.createEventLogger)(import_log.LogLevel.INFO);
32
- var createTestServices = ({ ai, queueFactory, enableLogging = false, logger = enableLogging ? consoleLogger : noopLogger } = {}) => {
33
- return new import_chunk_IJAE7FZK.ServiceContainer().setServices({
34
- ai: ai != null ? import_chunk_IJAE7FZK.AiService.make(ai) : void 0,
35
- eventLogger: logger,
36
- queues: queueFactory != null ? import_chunk_IJAE7FZK.QueueService.make(queueFactory, void 0) : void 0
37
- });
38
- };
39
- // Annotate the CommonJS export names for ESM import in node:
40
- 0 && (module.exports = {
41
- createTestServices
42
- });
43
- //# sourceMappingURL=index.cjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/testing/logger.ts", "../../../../src/testing/services.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { Effect, type Context } from 'effect';\n\nimport { LogLevel } from '@dxos/log';\n\nimport { type EventLogger, createEventLogger } from '../services';\n\nexport const noopLogger: Context.Tag.Service<EventLogger> = {\n log: () => Effect.succeed(undefined),\n nodeId: undefined,\n};\n\nexport const consoleLogger: Context.Tag.Service<EventLogger> = createEventLogger(LogLevel.INFO);\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Context } from 'effect';\n\nimport type { AiServiceClient } from '@dxos/ai';\nimport type { QueueFactory } from '@dxos/echo-db';\n\nimport { consoleLogger, noopLogger } from './logger';\nimport { AiService, QueueService, ServiceContainer } from '../services';\nimport type { EventLogger } from '../services/event-logger';\n\nexport type TestServiceOptions = {\n ai?: AiServiceClient;\n queueFactory?: QueueFactory;\n enableLogging?: boolean;\n logger?: Context.Tag.Service<EventLogger>;\n};\n\nexport const createTestServices = ({\n ai,\n queueFactory,\n enableLogging = false,\n logger = enableLogging ? consoleLogger : noopLogger,\n}: TestServiceOptions = {}): ServiceContainer => {\n return new ServiceContainer().setServices({\n ai: ai != null ? AiService.make(ai) : undefined,\n eventLogger: logger,\n queues: queueFactory != null ? QueueService.make(queueFactory, undefined) : undefined,\n });\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,oBAAqC;AAErC,iBAAyB;AAIlB,IAAMA,aAA+C;EAC1DC,KAAK,MAAMC,qBAAOC,QAAQC,MAAAA;EAC1BC,QAAQD;AACV;AAEO,IAAME,oBAAkDC,yCAAkBC,oBAASC,IAAI;ACKvF,IAAMC,qBAAqB,CAAC,EACjCC,IACAC,cACAC,gBAAgB,OAChBC,SAASD,gBAAgBP,gBAAgBN,WAAU,IAC7B,CAAC,MAAC;AACxB,SAAO,IAAIe,uCAAAA,EAAmBC,YAAY;IACxCL,IAAIA,MAAM,OAAOM,gCAAUC,KAAKP,EAAAA,IAAMP;IACtCe,aAAaL;IACbM,QAAQR,gBAAgB,OAAOS,mCAAaH,KAAKN,cAAcR,MAAAA,IAAaA;EAC9E,CAAA;AACF;",
6
- "names": ["noopLogger", "log", "Effect", "succeed", "undefined", "nodeId", "consoleLogger", "createEventLogger", "LogLevel", "INFO", "createTestServices", "ai", "queueFactory", "enableLogging", "logger", "ServiceContainer", "setServices", "AiService", "make", "eventLogger", "queues", "QueueService"]
7
- }
@@ -1,238 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // packages/core/functions/src/bundler/bundler.ts
4
- import { build, initialize } from "esbuild-wasm";
5
- import { subtleCrypto } from "@dxos/crypto";
6
- import { invariant } from "@dxos/invariant";
7
- import { log } from "@dxos/log";
8
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/bundler/bundler.ts";
9
- var initialized;
10
- var initializeBundler = async (options) => {
11
- await (initialized ??= initialize({
12
- wasmURL: options.wasmUrl
13
- }));
14
- };
15
- var Bundler = class {
16
- constructor(_options) {
17
- this._options = _options;
18
- }
19
- async bundle({ path, source }) {
20
- const { sandboxedModules: providedModules, ...options } = this._options;
21
- const createResult = async (result) => {
22
- return {
23
- timestamp: Date.now(),
24
- sourceHash: source ? Buffer.from(await subtleCrypto.digest("SHA-256", Buffer.from(source))) : void 0,
25
- ...result
26
- };
27
- };
28
- if (this._options.platform === "browser") {
29
- invariant(initialized, "Compiler not initialized.", {
30
- F: __dxlog_file,
31
- L: 71,
32
- S: this,
33
- A: [
34
- "initialized",
35
- "'Compiler not initialized.'"
36
- ]
37
- });
38
- await initialized;
39
- }
40
- const imports = source ? analyzeSourceFileImports(source) : [];
41
- try {
42
- const result = await build({
43
- platform: options.platform,
44
- conditions: [
45
- "workerd",
46
- "browser"
47
- ],
48
- metafile: true,
49
- write: false,
50
- entryPoints: [
51
- path ?? "memory:main.tsx"
52
- ],
53
- bundle: true,
54
- format: "esm",
55
- plugins: [
56
- {
57
- name: "memory",
58
- setup: (build2) => {
59
- build2.onResolve({
60
- filter: /^\.\/runtime\.js$/
61
- }, ({ path: path2 }) => {
62
- return {
63
- path: path2,
64
- external: true
65
- };
66
- });
67
- build2.onResolve({
68
- filter: /^dxos:functions$/
69
- }, ({ path: path2 }) => {
70
- return {
71
- path: "./runtime.js",
72
- external: true
73
- };
74
- });
75
- build2.onResolve({
76
- filter: /^memory:/
77
- }, ({ path: path2 }) => {
78
- return {
79
- path: path2.split(":")[1],
80
- namespace: "memory"
81
- };
82
- });
83
- build2.onLoad({
84
- filter: /.*/,
85
- namespace: "memory"
86
- }, ({ path: path2 }) => {
87
- if (path2 === "main.tsx") {
88
- return {
89
- contents: source,
90
- loader: "tsx"
91
- };
92
- }
93
- });
94
- for (const module of providedModules) {
95
- build2.onResolve({
96
- filter: new RegExp(`^${module}$`)
97
- }, ({ path: path2 }) => {
98
- return {
99
- path: path2,
100
- namespace: "injected-module"
101
- };
102
- });
103
- }
104
- build2.onLoad({
105
- filter: /.*/,
106
- namespace: "injected-module"
107
- }, ({ path: path2 }) => {
108
- const namedImports = imports.find((entry) => entry.moduleIdentifier === path2)?.namedImports ?? [];
109
- return {
110
- contents: `
111
- const { ${namedImports.join(",")} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}];
112
- export { ${namedImports.join(",")} };
113
- export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path2)}].default;
114
- `,
115
- loader: "tsx"
116
- };
117
- });
118
- }
119
- },
120
- httpPlugin
121
- ]
122
- });
123
- log("compile complete", result.metafile, {
124
- F: __dxlog_file,
125
- L: 135,
126
- S: this,
127
- C: (f, a) => f(...a)
128
- });
129
- return await createResult({
130
- imports: this.analyzeImports(result),
131
- bundle: result.outputFiles[0].text
132
- });
133
- } catch (err) {
134
- return await createResult({
135
- error: err
136
- });
137
- }
138
- }
139
- // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.
140
- analyzeImports(result) {
141
- invariant(result.outputFiles, void 0, {
142
- F: __dxlog_file,
143
- L: 148,
144
- S: this,
145
- A: [
146
- "result.outputFiles",
147
- ""
148
- ]
149
- });
150
- const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);
151
- return Object.values(result.metafile.outputs)[0].imports.map((entry) => {
152
- const namedImports = [];
153
- const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);
154
- if (parsedImport?.[2]) {
155
- NAMED_IMPORTS_REGEX.lastIndex = 0;
156
- const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);
157
- if (namedImportsMatch) {
158
- namedImportsMatch[1].split(",").forEach((importName) => {
159
- namedImports.push(importName.trim());
160
- });
161
- }
162
- }
163
- return {
164
- moduleUrl: entry.path,
165
- defaultImport: !!parsedImport?.[1],
166
- namedImports
167
- };
168
- });
169
- }
170
- analyzeSourceFileImports(code) {
171
- const parsedImports = allMatches(IMPORT_REGEX, code);
172
- return parsedImports.map((capture) => {
173
- return {
174
- defaultImportName: capture[1],
175
- namedImports: capture[2]?.split(",").map((importName) => importName.trim()),
176
- wildcardImportName: capture[3],
177
- moduleIdentifier: capture[4],
178
- quotes: capture[5]
179
- };
180
- });
181
- }
182
- };
183
- var IMPORT_REGEX = /import(?:(?:(?:[ \n\t]+([^ *\n\t{},]+)[ \n\t]*(?:,|[ \n\t]+))?([ \n\t]*{(?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+})?[ \n\t]*)|[ \n\t]*\*[ \n\t]*as[ \n\t]+([^ \n\t{}]+)[ \n\t]+)from[ \n\t]*(?:['"])([^'"\n]+)(['"])/gm;
184
- var NAMED_IMPORTS_REGEX = /[ \n\t]*{((?:[ \n\t]*[^ \n\t"'{}]+[ \n\t]*,?)+)}[ \n\t]*/gm;
185
- var allMatches = (regex, str) => {
186
- regex.lastIndex = 0;
187
- let match;
188
- const matches = [];
189
- while (match = regex.exec(str)) {
190
- matches.push(match);
191
- }
192
- return matches;
193
- };
194
- var analyzeSourceFileImports = (code) => {
195
- const parsedImports = allMatches(IMPORT_REGEX, code);
196
- return parsedImports.map((capture) => {
197
- return {
198
- defaultImportName: capture[1],
199
- namedImports: capture[2]?.trim().slice(1, -1).split(",").map((importName) => importName.trim()),
200
- wildcardImportName: capture[3],
201
- moduleIdentifier: capture[4],
202
- quotes: capture[5]
203
- };
204
- });
205
- };
206
- var httpPlugin = {
207
- name: "http",
208
- setup: (build2) => {
209
- build2.onResolve({
210
- filter: /^https?:\/\//
211
- }, (args) => ({
212
- path: args.path,
213
- namespace: "http-url"
214
- }));
215
- build2.onResolve({
216
- filter: /.*/,
217
- namespace: "http-url"
218
- }, (args) => ({
219
- path: new URL(args.path, args.importer).toString(),
220
- namespace: "http-url"
221
- }));
222
- build2.onLoad({
223
- filter: /.*/,
224
- namespace: "http-url"
225
- }, async (args) => {
226
- const response = await fetch(args.path);
227
- return {
228
- contents: await response.text(),
229
- loader: "jsx"
230
- };
231
- });
232
- }
233
- };
234
- export {
235
- Bundler,
236
- initializeBundler
237
- };
238
- //# sourceMappingURL=index.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../../src/bundler/bundler.ts"],
4
- "sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { type BuildOptions } from 'esbuild';\nimport { build, initialize, type BuildResult, type Plugin } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\n\nexport type Import = {\n moduleUrl: string;\n defaultImport: boolean;\n namedImports: string[];\n};\n\nexport type BundleOptions = {\n /**\n * Path to the source file on the local file system.\n * If provided, the path will be used instead of the `source` code.\n */\n path?: string;\n\n /**\n * Source code to bundle.\n * Required if `path` is not provided.\n */\n source?: string;\n};\n\nexport type BundleResult = {\n timestamp: number;\n sourceHash?: Buffer;\n imports?: Import[];\n bundle?: string;\n error?: any;\n};\n\nexport type BundlerOptions = {\n platform: BuildOptions['platform'];\n sandboxedModules: string[];\n remoteModules: Record<string, string>;\n};\n\nlet initialized: Promise<void>;\nexport const initializeBundler = async (options: { wasmUrl: string }) => {\n await (initialized ??= initialize({\n wasmURL: options.wasmUrl,\n }));\n};\n\n/**\n * ESBuild bundler.\n */\nexport class Bundler {\n constructor(private readonly _options: BundlerOptions) {}\n\n async bundle({ path, source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n\n const createResult = async (result?: Partial<BundleResult>) => {\n return {\n timestamp: Date.now(),\n sourceHash: source ? Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source))) : undefined,\n ...result,\n };\n };\n\n if (this._options.platform === 'browser') {\n invariant(initialized, 'Compiler not initialized.');\n await initialized;\n }\n\n const imports = source ? analyzeSourceFileImports(source) : [];\n\n // https://esbuild.github.io/api/#build\n try {\n const result = await build({\n platform: options.platform,\n conditions: ['workerd', 'browser'],\n metafile: true,\n write: false,\n entryPoints: [path ?? 'memory:main.tsx'],\n bundle: true,\n format: 'esm',\n plugins: [\n {\n name: 'memory',\n setup: (build) => {\n build.onResolve({ filter: /^\\.\\/runtime\\.js$/ }, ({ path }) => {\n return { path, external: true };\n });\n\n build.onResolve({ filter: /^dxos:functions$/ }, ({ path }) => {\n return { path: './runtime.js', external: true };\n });\n\n build.onResolve({ filter: /^memory:/ }, ({ path }) => {\n return { path: path.split(':')[1], namespace: 'memory' };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'memory' }, ({ path }) => {\n if (path === 'main.tsx') {\n return {\n contents: source,\n loader: 'tsx',\n };\n }\n });\n\n for (const module of providedModules) {\n build.onResolve({ filter: new RegExp(`^${module}$`) }, ({ path }) => {\n return { path, namespace: 'injected-module' };\n });\n }\n\n build.onLoad({ filter: /.*/, namespace: 'injected-module' }, ({ path }) => {\n const namedImports = imports.find((entry) => entry.moduleIdentifier === path)?.namedImports ?? [];\n return {\n contents: `\n const { ${namedImports.join(',')} } = window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}];\n export { ${namedImports.join(',')} };\n export default window.__DXOS_SANDBOX_MODULES__[${JSON.stringify(path)}].default;\n `,\n loader: 'tsx',\n };\n });\n },\n },\n httpPlugin,\n ],\n });\n\n log('compile complete', result.metafile);\n\n return await createResult({\n imports: this.analyzeImports(result),\n bundle: result.outputFiles![0].text,\n });\n } catch (err) {\n return await createResult({ error: err });\n }\n }\n\n // TODO(dmaretskyi): In the future we can replace the compiler with SWC with plugins running in WASM.\n analyzeImports(result: BuildResult): Import[] {\n invariant(result.outputFiles);\n\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, result.outputFiles[0].text);\n return Object.values(result.metafile!.outputs)[0].imports.map((entry): Import => {\n const namedImports: string[] = [];\n\n const parsedImport = parsedImports.find((capture) => capture?.[4] === entry.path);\n if (parsedImport?.[2]) {\n NAMED_IMPORTS_REGEX.lastIndex = 0;\n const namedImportsMatch = NAMED_IMPORTS_REGEX.exec(parsedImport[2]);\n if (namedImportsMatch) {\n namedImportsMatch[1].split(',').forEach((importName) => {\n namedImports.push(importName.trim());\n });\n }\n }\n\n return {\n moduleUrl: entry.path,\n defaultImport: !!parsedImport?.[1],\n namedImports,\n };\n });\n }\n\n analyzeSourceFileImports(code: string): {\n defaultImportName: string;\n namedImports: string[];\n wildcardImportName: string;\n moduleIdentifier: string;\n quotes: string;\n }[] {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]?.split(',').map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n }\n}\n\n// https://regex101.com/r/FEN5ks/1\n// https://stackoverflow.com/a/73265022\n// $1 = default import name (can be non-existent)\n// $2 = destructured exports (can be non-existent)\n// $3 = wildcard import name (can be non-existent)\n// $4 = module identifier\n// $5 = quotes used (either ' or \")\nconst IMPORT_REGEX =\n /import(?:(?:(?:[ \\n\\t]+([^ *\\n\\t{},]+)[ \\n\\t]*(?:,|[ \\n\\t]+))?([ \\n\\t]*{(?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+})?[ \\n\\t]*)|[ \\n\\t]*\\*[ \\n\\t]*as[ \\n\\t]+([^ \\n\\t{}]+)[ \\n\\t]+)from[ \\n\\t]*(?:['\"])([^'\"\\n]+)(['\"])/gm;\n\nconst NAMED_IMPORTS_REGEX = /[ \\n\\t]*{((?:[ \\n\\t]*[^ \\n\\t\"'{}]+[ \\n\\t]*,?)+)}[ \\n\\t]*/gm;\n\nconst allMatches = (regex: RegExp, str: string) => {\n regex.lastIndex = 0;\n\n let match;\n const matches = [];\n while ((match = regex.exec(str))) {\n matches.push(match);\n }\n\n return matches;\n};\n\ntype ParsedImport = {\n defaultImportName?: string;\n namedImports: string[];\n wildcardImportName?: string;\n moduleIdentifier: string;\n quotes: string;\n};\n\nconst analyzeSourceFileImports = (code: string): ParsedImport[] => {\n // TODO(dmaretskyi): Support import aliases and wildcard imports.\n const parsedImports = allMatches(IMPORT_REGEX, code);\n return parsedImports.map((capture) => {\n return {\n defaultImportName: capture[1],\n namedImports: capture[2]\n ?.trim()\n .slice(1, -1)\n .split(',')\n .map((importName) => importName.trim()),\n wildcardImportName: capture[3],\n moduleIdentifier: capture[4],\n quotes: capture[5],\n };\n });\n};\n\nconst httpPlugin: Plugin = {\n name: 'http',\n setup: (build) => {\n // Intercept import paths starting with \"http:\" and \"https:\" so esbuild doesn't attempt to map them to a file system location.\n // Tag them with the \"http-url\" namespace to associate them with this plugin.\n build.onResolve({ filter: /^https?:\\/\\// }, (args) => ({\n path: args.path,\n namespace: 'http-url',\n }));\n\n // We also want to intercept all import paths inside downloaded files and resolve them against the original URL.\n // All of these files will be in the \"http-url\" namespace.\n // Make sure to keep the newly resolved URL in the \"http-url\" namespace so imports inside it will also be resolved as URLs recursively.\n build.onResolve({ filter: /.*/, namespace: 'http-url' }, (args) => ({\n path: new URL(args.path, args.importer).toString(),\n namespace: 'http-url',\n }));\n\n // When a URL is loaded, we want to actually download the content from the internet.\n // This has just enough logic to be able to handle the example import from unpkg.com but in reality this would probably need to be more complex.\n build.onLoad({ filter: /.*/, namespace: 'http-url' }, async (args) => {\n const response = await fetch(args.path);\n return { cont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AACtC,aAAO;QAAE+B,UAAU,MAAMiD,SAASnC,KAAI;QAAIb,QAAQ;MAAM;IAC1D,CAAA;EACF;AACF;",
6
- "names": ["build", "initialize", "subtleCrypto", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "_options", "bundle", "path", "source", "sandboxedModules", "providedModules", "createResult", "result", "timestamp", "Date", "now", "sourceHash", "Buffer", "from", "digest", "undefined", "platform", "imports", "analyzeSourceFileImports", "conditions", "metafile", "write", "entryPoints", "format", "plugins", "name", "setup", "onResolve", "filter", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "analyzeImports", "outputFiles", "text", "err", "error", "parsedImports", "allMatches", "IMPORT_REGEX", "Object", "values", "outputs", "map", "parsedImport", "capture", "NAMED_IMPORTS_REGEX", "lastIndex", "namedImportsMatch", "exec", "forEach", "importName", "push", "trim", "moduleUrl", "defaultImport", "code", "defaultImportName", "wildcardImportName", "quotes", "regex", "str", "match", "matches", "slice", "args", "URL", "importer", "toString", "response", "fetch"]
7
- }
@@ -1,302 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // packages/core/functions/src/services/ai.ts
4
- import { Context, Layer } from "effect";
5
- var AiService = class _AiService extends Context.Tag("AiService")() {
6
- static {
7
- this.make = (client) => {
8
- return {
9
- get client() {
10
- return client;
11
- }
12
- };
13
- };
14
- }
15
- static {
16
- this.makeLayer = (client) => Layer.succeed(_AiService, _AiService.make(client));
17
- }
18
- static {
19
- this.notAvailable = Layer.succeed(_AiService, {
20
- get client() {
21
- throw new Error("AiService not available");
22
- }
23
- });
24
- }
25
- };
26
-
27
- // packages/core/functions/src/services/database.ts
28
- import { Context as Context2, Layer as Layer2 } from "effect";
29
- var DatabaseService = class _DatabaseService extends Context2.Tag("DatabaseService")() {
30
- static {
31
- this.notAvailable = Layer2.succeed(_DatabaseService, {
32
- get db() {
33
- throw new Error("Database not available");
34
- }
35
- });
36
- }
37
- static {
38
- this.make = (db) => {
39
- return {
40
- get db() {
41
- return db;
42
- }
43
- };
44
- };
45
- }
46
- };
47
-
48
- // packages/core/functions/src/services/queues.ts
49
- import { Context as Context3, Layer as Layer3 } from "effect";
50
- var QueueService = class _QueueService extends Context3.Tag("QueueService")() {
51
- static {
52
- this.notAvailable = Layer3.succeed(_QueueService, {
53
- get queues() {
54
- throw new Error("Queues not available");
55
- },
56
- contextQueue: void 0
57
- });
58
- }
59
- static {
60
- this.make = (queues, contextQueue) => {
61
- return {
62
- queues,
63
- contextQueue
64
- };
65
- };
66
- }
67
- };
68
-
69
- // packages/core/functions/src/services/credentials.ts
70
- import { Context as Context4 } from "effect";
71
- var CredentialsService = class extends Context4.Tag("CredentialsService")() {
72
- };
73
- var ConfiguredCredentialsService = class {
74
- constructor(credentials = []) {
75
- this.credentials = credentials;
76
- }
77
- addCredentials(credentials) {
78
- this.credentials.push(...credentials);
79
- return this;
80
- }
81
- async queryCredentials(query) {
82
- return this.credentials.filter((credential) => credential.service === query.service);
83
- }
84
- async getCredential(query) {
85
- const credential = this.credentials.find((credential2) => credential2.service === query.service);
86
- if (!credential) {
87
- throw new Error(`Credential not found for service: ${query.service}`);
88
- }
89
- return credential;
90
- }
91
- };
92
-
93
- // packages/core/functions/src/services/event-logger.ts
94
- import { Effect, Context as Context5 } from "effect";
95
- import { invariant } from "@dxos/invariant";
96
- import { log, LogLevel } from "@dxos/log";
97
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/functions/src/services/event-logger.ts";
98
- var EventLogger = class extends Context5.Tag("EventLogger")() {
99
- static {
100
- this.noop = {
101
- log: () => {
102
- },
103
- nodeId: void 0
104
- };
105
- }
106
- };
107
- var logCustomEvent = (data) => Effect.gen(function* () {
108
- const logger = yield* EventLogger;
109
- if (!logger.nodeId) {
110
- throw new Error("logCustomEvent must be called within a node compute function");
111
- }
112
- logger.log({
113
- type: "custom",
114
- nodeId: logger.nodeId,
115
- event: data
116
- });
117
- });
118
- var createDefectLogger = () => Effect.catchAll((error) => Effect.gen(function* () {
119
- log.error("unhandled effect error", {
120
- error
121
- }, {
122
- F: __dxlog_file,
123
- L: 65,
124
- S: this,
125
- C: (f, a) => f(...a)
126
- });
127
- throw error;
128
- }));
129
- var createEventLogger = (level, message = "event") => {
130
- const logFunction = {
131
- [LogLevel.WARN]: log.warn,
132
- [LogLevel.VERBOSE]: log.verbose,
133
- [LogLevel.DEBUG]: log.debug,
134
- [LogLevel.INFO]: log.info,
135
- [LogLevel.ERROR]: log.error
136
- }[level];
137
- invariant(logFunction, void 0, {
138
- F: __dxlog_file,
139
- L: 80,
140
- S: void 0,
141
- A: [
142
- "logFunction",
143
- ""
144
- ]
145
- });
146
- return {
147
- log: (event) => {
148
- logFunction(message, event);
149
- },
150
- nodeId: void 0
151
- };
152
- };
153
-
154
- // packages/core/functions/src/services/function-call-service.ts
155
- import { Context as Context6 } from "effect";
156
- var FunctionCallService = class extends Context6.Tag("FunctionCallService")() {
157
- static fromClient(baseUrl, spaceId) {
158
- return {
159
- callFunction: async (deployedFunctionId, input) => {
160
- const url = getInvocationUrl(deployedFunctionId, baseUrl, {
161
- spaceId
162
- });
163
- const result = await fetch(url, {
164
- method: "POST",
165
- headers: {
166
- "Content-Type": "application/json"
167
- },
168
- body: JSON.stringify(input)
169
- });
170
- if (result.status >= 300 || result.status < 200) {
171
- throw new Error("Failed to invoke function", {
172
- cause: new Error(`HTTP error: ${await result.text()}`)
173
- });
174
- }
175
- return await result.json();
176
- }
177
- };
178
- }
179
- static {
180
- this.mock = () => {
181
- return {
182
- callFunction: async (deployedFunctionId, input) => {
183
- return input;
184
- }
185
- };
186
- };
187
- }
188
- };
189
- var getInvocationUrl = (functionUrl, edgeUrl, options = {}) => {
190
- const baseUrl = new URL("functions/", edgeUrl);
191
- const relativeUrl = functionUrl.replace(/^\//, "");
192
- const url = new URL(`./${relativeUrl}`, baseUrl.toString());
193
- options.spaceId && url.searchParams.set("spaceId", options.spaceId);
194
- options.subjectId && url.searchParams.set("subjectId", options.subjectId);
195
- url.protocol = isSecure(url.protocol) ? "https" : "http";
196
- return url.toString();
197
- };
198
- var isSecure = (protocol) => {
199
- return protocol === "https:" || protocol === "wss:";
200
- };
201
-
202
- // packages/core/functions/src/services/tracing.ts
203
- import { Context as Context7 } from "effect";
204
- var TracingService = class extends Context7.Tag("TracingService")() {
205
- static {
206
- this.noop = {
207
- write: () => {
208
- }
209
- };
210
- }
211
- static {
212
- this.console = {
213
- write: (event) => {
214
- console.log(event);
215
- }
216
- };
217
- }
218
- };
219
-
220
- // packages/core/functions/src/services/service-container.ts
221
- import { Layer as Layer4 } from "effect";
222
- var SERVICE_MAPPING = {
223
- [AiService.key]: "ai",
224
- [CredentialsService.key]: "credentials",
225
- [DatabaseService.key]: "database",
226
- [EventLogger.key]: "eventLogger",
227
- [FunctionCallService.key]: "functionCallService",
228
- [QueueService.key]: "queues",
229
- [TracingService.key]: "tracing"
230
- };
231
- var SERVICE_TAGS = [
232
- AiService,
233
- CredentialsService,
234
- DatabaseService,
235
- EventLogger,
236
- FunctionCallService,
237
- TracingService,
238
- QueueService
239
- ];
240
- var DEFAULT_SERVICES = {
241
- tracing: TracingService.noop
242
- };
243
- var ServiceContainer = class _ServiceContainer {
244
- constructor() {
245
- this._services = {
246
- ...DEFAULT_SERVICES
247
- };
248
- }
249
- /**
250
- * Set services.
251
- * @param services - Services to set.
252
- * @returns The container instance.
253
- */
254
- setServices(services) {
255
- this._services = {
256
- ...this._services,
257
- ...services
258
- };
259
- return this;
260
- }
261
- getService(tag) {
262
- const serviceKey = SERVICE_MAPPING[tag.key];
263
- const service = serviceKey != null ? this._services[serviceKey] : void 0;
264
- if (!service) {
265
- throw new Error(`Service not available: ${tag.key}`);
266
- }
267
- return service;
268
- }
269
- clone() {
270
- return new _ServiceContainer().setServices({
271
- ...this._services
272
- });
273
- }
274
- // TODO(dmaretskyi): `getService` is designed to error at runtime if the service is not available, but layer forces us to provide all services and makes stubs for the ones that are not available.
275
- createLayer() {
276
- const ai = this._services.ai != null ? Layer4.succeed(AiService, this._services.ai) : AiService.notAvailable;
277
- const credentials = Layer4.succeed(CredentialsService, new ConfiguredCredentialsService());
278
- const database = this._services.database != null ? Layer4.succeed(DatabaseService, this._services.database) : DatabaseService.notAvailable;
279
- const queues = this._services.queues != null ? Layer4.succeed(QueueService, this._services.queues) : QueueService.notAvailable;
280
- const tracing = Layer4.succeed(TracingService, this._services.tracing ?? TracingService.noop);
281
- const eventLogger = Layer4.succeed(EventLogger, this._services.eventLogger ?? EventLogger.noop);
282
- const functionCallService = Layer4.succeed(FunctionCallService, this._services.functionCallService ?? FunctionCallService.mock());
283
- return Layer4.mergeAll(ai, credentials, database, queues, tracing, eventLogger, functionCallService);
284
- }
285
- };
286
-
287
- export {
288
- AiService,
289
- DatabaseService,
290
- QueueService,
291
- CredentialsService,
292
- ConfiguredCredentialsService,
293
- EventLogger,
294
- logCustomEvent,
295
- createDefectLogger,
296
- createEventLogger,
297
- FunctionCallService,
298
- TracingService,
299
- SERVICE_TAGS,
300
- ServiceContainer
301
- };
302
- //# sourceMappingURL=chunk-LIYPMWNQ.mjs.map