@dxos/functions 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3
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.
- package/dist/lib/browser/index.mjs +769 -407
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +769 -407
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/errors.d.ts +87 -28
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/{examples → example}/fib.d.ts +1 -1
- package/dist/types/src/example/fib.d.ts.map +1 -0
- package/dist/types/src/example/forex-effect.d.ts +3 -0
- package/dist/types/src/example/forex-effect.d.ts.map +1 -0
- package/dist/types/src/example/index.d.ts +12 -0
- package/dist/types/src/example/index.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/reply.d.ts +1 -1
- package/dist/types/src/example/reply.d.ts.map +1 -0
- package/dist/types/src/{examples → example}/sleep.d.ts +1 -1
- package/dist/types/src/example/sleep.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +5 -7
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/protocol/index.d.ts +2 -0
- package/dist/types/src/protocol/index.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.d.ts +7 -0
- package/dist/types/src/protocol/protocol.d.ts.map +1 -0
- package/dist/types/src/protocol/protocol.test.d.ts +2 -0
- package/dist/types/src/protocol/protocol.test.d.ts.map +1 -0
- package/dist/types/src/sdk.d.ts +89 -0
- package/dist/types/src/sdk.d.ts.map +1 -0
- package/dist/types/src/services/credentials.d.ts +7 -3
- package/dist/types/src/services/credentials.d.ts.map +1 -1
- package/dist/types/src/services/event-logger.d.ts +20 -5
- package/dist/types/src/services/event-logger.d.ts.map +1 -1
- package/dist/types/src/services/function-invocation-service.d.ts +11 -0
- package/dist/types/src/services/function-invocation-service.d.ts.map +1 -0
- package/dist/types/src/services/index.d.ts +6 -6
- package/dist/types/src/services/index.d.ts.map +1 -1
- package/dist/types/src/services/queues.d.ts +4 -1
- package/dist/types/src/services/queues.d.ts.map +1 -1
- package/dist/types/src/services/tracing.d.ts +10 -12
- package/dist/types/src/services/tracing.d.ts.map +1 -1
- package/dist/types/src/types/Function.d.ts +58 -0
- package/dist/types/src/types/Function.d.ts.map +1 -0
- package/dist/types/src/types/Script.d.ts +28 -0
- package/dist/types/src/types/Script.d.ts.map +1 -0
- package/dist/types/src/types/Trigger.d.ts +139 -0
- package/dist/types/src/types/Trigger.d.ts.map +1 -0
- package/dist/types/src/types/TriggerEvent.d.ts +44 -0
- package/dist/types/src/types/TriggerEvent.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +6 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/{url.d.ts → types/url.d.ts} +1 -10
- package/dist/types/src/types/url.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +17 -72
- package/src/errors.ts +13 -5
- package/src/{examples → example}/fib.ts +5 -3
- package/src/example/forex-effect.ts +40 -0
- package/src/example/index.ts +13 -0
- package/src/{examples → example}/reply.ts +6 -3
- package/src/{examples → example}/sleep.ts +5 -3
- package/src/index.ts +5 -9
- package/src/{executor → protocol}/index.ts +1 -1
- package/src/protocol/protocol.test.ts +59 -0
- package/src/protocol/protocol.ts +145 -0
- package/src/sdk.ts +226 -0
- package/src/services/credentials.ts +12 -6
- package/src/services/event-logger.ts +12 -3
- package/src/services/function-invocation-service.ts +23 -0
- package/src/services/index.ts +7 -6
- package/src/services/queues.ts +8 -1
- package/src/services/tracing.ts +26 -52
- package/src/{schema.ts → types/Function.ts} +20 -26
- package/src/types/Script.ts +33 -0
- package/src/types/Trigger.ts +139 -0
- package/src/types/TriggerEvent.ts +62 -0
- package/src/types/index.ts +9 -0
- package/src/types/url.ts +31 -0
- package/dist/lib/browser/bundler/index.mjs +0 -263
- package/dist/lib/browser/bundler/index.mjs.map +0 -7
- package/dist/lib/browser/chunk-7NQ77AIQ.mjs +0 -618
- package/dist/lib/browser/chunk-7NQ77AIQ.mjs.map +0 -7
- package/dist/lib/browser/edge/index.mjs +0 -81
- package/dist/lib/browser/edge/index.mjs.map +0 -7
- package/dist/lib/browser/testing/index.mjs +0 -122
- package/dist/lib/browser/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/bundler/index.mjs +0 -265
- package/dist/lib/node-esm/bundler/index.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-KCGC6QQT.mjs +0 -620
- package/dist/lib/node-esm/chunk-KCGC6QQT.mjs.map +0 -7
- package/dist/lib/node-esm/edge/index.mjs +0 -83
- package/dist/lib/node-esm/edge/index.mjs.map +0 -7
- package/dist/lib/node-esm/testing/index.mjs +0 -123
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/bundler/bundler.d.ts +0 -49
- package/dist/types/src/bundler/bundler.d.ts.map +0 -1
- package/dist/types/src/bundler/bundler.test.d.ts +0 -2
- package/dist/types/src/bundler/bundler.test.d.ts.map +0 -1
- package/dist/types/src/bundler/index.d.ts +0 -2
- package/dist/types/src/bundler/index.d.ts.map +0 -1
- package/dist/types/src/edge/functions.d.ts +0 -17
- package/dist/types/src/edge/functions.d.ts.map +0 -1
- package/dist/types/src/edge/index.d.ts +0 -2
- package/dist/types/src/edge/index.d.ts.map +0 -1
- package/dist/types/src/examples/fib.d.ts.map +0 -1
- package/dist/types/src/examples/reply.d.ts.map +0 -1
- package/dist/types/src/examples/sleep.d.ts.map +0 -1
- package/dist/types/src/executor/executor.d.ts +0 -11
- package/dist/types/src/executor/executor.d.ts.map +0 -1
- package/dist/types/src/executor/index.d.ts +0 -2
- package/dist/types/src/executor/index.d.ts.map +0 -1
- package/dist/types/src/handler.d.ts +0 -65
- package/dist/types/src/handler.d.ts.map +0 -1
- package/dist/types/src/schema.d.ts +0 -43
- package/dist/types/src/schema.d.ts.map +0 -1
- package/dist/types/src/services/database.d.ts +0 -98
- package/dist/types/src/services/database.d.ts.map +0 -1
- package/dist/types/src/services/local-function-execution.d.ts +0 -12
- package/dist/types/src/services/local-function-execution.d.ts.map +0 -1
- package/dist/types/src/services/remote-function-execution-service.d.ts +0 -15
- package/dist/types/src/services/remote-function-execution-service.d.ts.map +0 -1
- package/dist/types/src/services/service-container.d.ts +0 -56
- package/dist/types/src/services/service-container.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.d.ts +0 -29
- package/dist/types/src/services/service-registry.d.ts.map +0 -1
- package/dist/types/src/services/service-registry.test.d.ts +0 -2
- package/dist/types/src/services/service-registry.test.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/layer.d.ts +0 -14
- package/dist/types/src/testing/layer.d.ts.map +0 -1
- package/dist/types/src/testing/logger.d.ts +0 -5
- package/dist/types/src/testing/logger.d.ts.map +0 -1
- package/dist/types/src/testing/persist-database.test.d.ts +0 -2
- package/dist/types/src/testing/persist-database.test.d.ts.map +0 -1
- package/dist/types/src/testing/services.d.ts +0 -59
- package/dist/types/src/testing/services.d.ts.map +0 -1
- package/dist/types/src/trace.d.ts +0 -150
- package/dist/types/src/trace.d.ts.map +0 -1
- package/dist/types/src/translations.d.ts +0 -12
- package/dist/types/src/translations.d.ts.map +0 -1
- package/dist/types/src/types.d.ts +0 -328
- package/dist/types/src/types.d.ts.map +0 -1
- package/dist/types/src/url.d.ts.map +0 -1
- package/src/bundler/bundler.test.ts +0 -58
- package/src/bundler/bundler.ts +0 -291
- package/src/bundler/index.ts +0 -5
- package/src/edge/functions.ts +0 -67
- package/src/edge/index.ts +0 -9
- package/src/executor/executor.ts +0 -54
- package/src/handler.ts +0 -122
- package/src/services/database.ts +0 -170
- package/src/services/local-function-execution.ts +0 -77
- package/src/services/remote-function-execution-service.ts +0 -46
- package/src/services/service-container.ts +0 -114
- package/src/services/service-registry.test.ts +0 -42
- package/src/services/service-registry.ts +0 -59
- package/src/testing/index.ts +0 -6
- package/src/testing/layer.ts +0 -97
- package/src/testing/logger.ts +0 -16
- package/src/testing/persist-database.test.ts +0 -87
- package/src/testing/services.ts +0 -115
- package/src/trace.ts +0 -178
- package/src/translations.ts +0 -20
- package/src/types.ts +0 -203
- package/src/url.ts +0 -55
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../src/bundler/bundler.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport { FetchHttpClient, HttpClient } from '@effect/platform';\nimport { Duration, Effect, Schedule, pipe } from 'effect';\nimport { type BuildOptions, type BuildResult, type Loader, type Plugin, build, initialize } from 'esbuild-wasm';\n\nimport { subtleCrypto } from '@dxos/crypto';\nimport { runAndForwardErrors } from '@dxos/effect';\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 * Source code to bundle.\n */\n source: string;\n};\n\nexport type BundleResult =\n | {\n timestamp: number;\n sourceHash: Buffer;\n error: unknown;\n }\n | {\n timestamp: number;\n sourceHash: Buffer;\n imports: Import[];\n entryPoint: string;\n asset: Uint8Array;\n bundle: string;\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({ source }: BundleOptions): Promise<BundleResult> {\n const { sandboxedModules: providedModules, ...options } = this._options;\n const sourceHash = Buffer.from(await subtleCrypto.digest('SHA-256', Buffer.from(source)));\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: {\n // Gets mapped to `userFunc.js` by esbuild.\n userFunc: 'memory:main.tsx',\n },\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 const entryPoint = 'userFunc.js';\n return {\n timestamp: Date.now(),\n sourceHash,\n imports: this.analyzeImports(result),\n entryPoint,\n asset: result.outputFiles![0].contents,\n bundle: result.outputFiles![0].text,\n };\n } catch (err) {\n return { timestamp: Date.now(), sourceHash, 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 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 let match;\n const matches = [];\n regex.lastIndex = 0;\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 MAX_RETRIES = 5;\nconst INITIAL_DELAY = 1_000;\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 return Effect.gen(function* () {\n const response = yield* HttpClient.get(args.path);\n if (response.status !== 200) {\n throw new Error(`failed to fetch: ${response.status}`);\n }\n\n const text = yield* response.text;\n return { contents: text, loader: 'jsx' as Loader };\n }).pipe(\n Effect.retry(\n pipe(\n Schedule.exponential(Duration.millis(INITIAL_DELAY)),\n Schedule.jittered,\n Schedule.intersect(Schedule.recurs(MAX_RETRIES - 1)),\n ),\n ),\n Effect.provide(FetchHttpClient.layer),\n runAndForwardErrors,\n );\n });\n },\n};\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAASA,iBAAiBC,kBAAkB;AAC5C,SAASC,UAAUC,QAAQC,UAAUC,YAAY;AACjD,SAAwEC,OAAOC,kBAAkB;AAEjG,SAASC,oBAAoB;AAC7B,SAASC,2BAA2B;AACpC,SAASC,iBAAiB;AAC1B,SAASC,WAAW;;;;;;;;;;;;;;;AAoCpB,IAAIC;AACG,IAAMC,oBAAoB,OAAOC,YAAAA;AACtC,SAAOF,gBAAAA,cAAgBL,WAAW;IAChCQ,SAASD,QAAQE;EACnB,CAAA;AACF;AAKO,IAAMC,UAAN,MAAMA;EAGX,MAAMC,OAAO,EAAEC,OAAM,GAA0C;AAC7D,UAAM,EAAEC,kBAAkBC,iBAAiB,GAAGP,QAAAA,IAAY,KAAKQ;AAC/D,UAAMC,aAAaC,OAAOC,KAAK,MAAMjB,aAAakB,OAAO,WAAWF,OAAOC,KAAKN,MAAAA,CAAAA,CAAAA;AAEhF,QAAI,KAAKG,SAASK,aAAa,WAAW;AACxCjB,gBAAUE,aAAa,6BAAA;;;;;;;;;AACvB,YAAMA;IACR;AAEA,UAAMgB,UAAUT,SAASU,yBAAyBV,MAAAA,IAAU,CAAA;AAG5D,QAAI;AACF,YAAMW,SAAS,MAAMxB,MAAM;QACzBqB,UAAUb,QAAQa;QAClBI,YAAY;UAAC;UAAW;;QACxBC,UAAU;QACVC,OAAO;QACPC,aAAa;;UAEXC,UAAU;QACZ;QACAjB,QAAQ;QACRkB,QAAQ;QACRC,SAAS;UACP;YACEC,MAAM;YACNC,OAAO,CAACjC,WAAAA;AAC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C,IAAAA,OAAMkC,UAAU;MAAEC,QAAQ;MAAMI,WAAW;IAAW,GAAG,CAACsD,UAAU;MAClEzD,MAAM,IAAI0D,IAAID,KAAKzD,MAAMyD,KAAKE,QAAQ,EAAEC,SAAQ;MAChDzD,WAAW;IACb,EAAA;AAIAvC,IAAAA,OAAMwC,OAAO;MAAEL,QAAQ;MAAMI,WAAW;IAAW,GAAG,OAAOsD,SAAAA;AAC3D,aAAOhG,OAAOoG,IAAI,aAAA;AAChB,cAAMC,WAAW,OAAOvG,WAAWwG,IAAIN,KAAKzD,IAAI;AAChD,YAAI8D,SAASE,WAAW,KAAK;AAC3B,gBAAM,IAAIC,MAAM,oBAAoBH,SAASE,MAAM,EAAE;QACvD;AAEA,cAAMxC,OAAO,OAAOsC,SAAStC;AAC7B,eAAO;UAAEnB,UAAUmB;UAAMlB,QAAQ;QAAgB;MACnD,CAAA,EAAG3C,KACDF,OAAOyG,MACLvG,KACED,SAASyG,YAAY3G,SAAS4G,OAAOZ,aAAAA,CAAAA,GACrC9F,SAAS2G,UACT3G,SAAS4G,UAAU5G,SAAS6G,OAAOhB,cAAc,CAAA,CAAA,CAAA,CAAA,GAGrD9F,OAAO+G,QAAQlH,gBAAgBmH,KAAK,GACpC1G,mBAAAA;IAEJ,CAAA;EACF;AACF;",
|
|
6
|
-
"names": ["FetchHttpClient", "HttpClient", "Duration", "Effect", "Schedule", "pipe", "build", "initialize", "subtleCrypto", "runAndForwardErrors", "invariant", "log", "initialized", "initializeBundler", "options", "wasmURL", "wasmUrl", "Bundler", "bundle", "source", "sandboxedModules", "providedModules", "_options", "sourceHash", "Buffer", "from", "digest", "platform", "imports", "analyzeSourceFileImports", "result", "conditions", "metafile", "write", "entryPoints", "userFunc", "format", "plugins", "name", "setup", "onResolve", "filter", "path", "external", "split", "namespace", "onLoad", "contents", "loader", "module", "RegExp", "namedImports", "find", "entry", "moduleIdentifier", "join", "JSON", "stringify", "httpPlugin", "entryPoint", "timestamp", "Date", "now", "analyzeImports", "asset", "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", "MAX_RETRIES", "INITIAL_DELAY", "args", "URL", "importer", "toString", "gen", "response", "get", "status", "Error", "retry", "exponential", "millis", "jittered", "intersect", "recurs", "provide", "layer"]
|
|
7
|
-
}
|
|
@@ -1,620 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// src/url.ts
|
|
4
|
-
var FUNCTIONS_META_KEY = "dxos.org/service/function";
|
|
5
|
-
var FUNCTIONS_PRESET_META_KEY = "dxos.org/service/function-preset";
|
|
6
|
-
var isSecure = (protocol) => {
|
|
7
|
-
return protocol === "https:" || protocol === "wss:";
|
|
8
|
-
};
|
|
9
|
-
var getUserFunctionIdInMetadata = (meta) => {
|
|
10
|
-
return meta.keys.find((key) => key.source === FUNCTIONS_META_KEY)?.id;
|
|
11
|
-
};
|
|
12
|
-
var setUserFunctionIdInMetadata = (meta, functionId) => {
|
|
13
|
-
const key = meta.keys.find((key2) => key2.source === FUNCTIONS_META_KEY);
|
|
14
|
-
if (key) {
|
|
15
|
-
if (key.id !== functionId) {
|
|
16
|
-
throw new Error("Metadata mismatch");
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
meta.keys.push({
|
|
20
|
-
source: FUNCTIONS_META_KEY,
|
|
21
|
-
id: functionId
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
var getInvocationUrl = (functionId, edgeUrl, options = {}) => {
|
|
26
|
-
const baseUrl = new URL("functions/", edgeUrl);
|
|
27
|
-
const url = new URL(`./${functionId}`, baseUrl.toString());
|
|
28
|
-
options.spaceId && url.searchParams.set("spaceId", options.spaceId);
|
|
29
|
-
options.subjectId && url.searchParams.set("subjectId", options.subjectId);
|
|
30
|
-
url.protocol = isSecure(url.protocol) ? "https" : "http";
|
|
31
|
-
return url.toString();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/services/database.ts
|
|
35
|
-
import { Context, Effect, Layer, Option } from "effect";
|
|
36
|
-
import { Obj } from "@dxos/echo";
|
|
37
|
-
import { promiseWithCauseCapture } from "@dxos/effect";
|
|
38
|
-
import { BaseError } from "@dxos/errors";
|
|
39
|
-
import { invariant } from "@dxos/invariant";
|
|
40
|
-
function _define_property(obj, key, value) {
|
|
41
|
-
if (key in obj) {
|
|
42
|
-
Object.defineProperty(obj, key, {
|
|
43
|
-
value,
|
|
44
|
-
enumerable: true,
|
|
45
|
-
configurable: true,
|
|
46
|
-
writable: true
|
|
47
|
-
});
|
|
48
|
-
} else {
|
|
49
|
-
obj[key] = value;
|
|
50
|
-
}
|
|
51
|
-
return obj;
|
|
52
|
-
}
|
|
53
|
-
var __dxlog_file = "/__w/dxos/dxos/packages/core/functions/src/services/database.ts";
|
|
54
|
-
var _Context_Tag;
|
|
55
|
-
var DatabaseService = class extends (_Context_Tag = Context.Tag("@dxos/functions/DatabaseService")()) {
|
|
56
|
-
};
|
|
57
|
-
_define_property(DatabaseService, "notAvailable", Layer.succeed(DatabaseService, {
|
|
58
|
-
get db() {
|
|
59
|
-
throw new Error("Database not available");
|
|
60
|
-
}
|
|
61
|
-
}));
|
|
62
|
-
_define_property(DatabaseService, "make", (db) => {
|
|
63
|
-
return {
|
|
64
|
-
get db() {
|
|
65
|
-
return db;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
});
|
|
69
|
-
_define_property(DatabaseService, "layer", (db) => {
|
|
70
|
-
return Layer.succeed(DatabaseService, DatabaseService.make(db));
|
|
71
|
-
});
|
|
72
|
-
_define_property(DatabaseService, "resolve", (dxn, schema) => Effect.gen(function* () {
|
|
73
|
-
const { db } = yield* DatabaseService;
|
|
74
|
-
const object = yield* promiseWithCauseCapture(() => db.graph.createRefResolver({
|
|
75
|
-
context: {
|
|
76
|
-
space: db.spaceId
|
|
77
|
-
}
|
|
78
|
-
}).resolve(dxn));
|
|
79
|
-
if (!object) {
|
|
80
|
-
return yield* Effect.fail(new ObjectNotFoundError({
|
|
81
|
-
dxn
|
|
82
|
-
}));
|
|
83
|
-
}
|
|
84
|
-
invariant(!schema || Obj.instanceOf(schema, object), "Object type mismatch.", {
|
|
85
|
-
F: __dxlog_file,
|
|
86
|
-
L: 70,
|
|
87
|
-
S: this,
|
|
88
|
-
A: [
|
|
89
|
-
"!schema || Obj.instanceOf(schema, object)",
|
|
90
|
-
"'Object type mismatch.'"
|
|
91
|
-
]
|
|
92
|
-
});
|
|
93
|
-
return object;
|
|
94
|
-
}));
|
|
95
|
-
_define_property(DatabaseService, "load", Effect.fn(function* (ref) {
|
|
96
|
-
const object = yield* promiseWithCauseCapture(() => ref.tryLoad());
|
|
97
|
-
if (!object) {
|
|
98
|
-
return yield* Effect.fail(new ObjectNotFoundError({
|
|
99
|
-
dxn: ref.dxn
|
|
100
|
-
}));
|
|
101
|
-
}
|
|
102
|
-
return object;
|
|
103
|
-
}));
|
|
104
|
-
_define_property(DatabaseService, "loadOption", Effect.fn(function* (ref) {
|
|
105
|
-
const object = yield* DatabaseService.load(ref).pipe(Effect.catchTag("OBJECT_NOT_FOUND", () => Effect.succeed(void 0)));
|
|
106
|
-
return Option.fromNullable(object);
|
|
107
|
-
}));
|
|
108
|
-
_define_property(DatabaseService, "add", (obj) => DatabaseService.pipe(Effect.map(({ db }) => db.add(obj))));
|
|
109
|
-
_define_property(DatabaseService, "remove", (obj) => DatabaseService.pipe(Effect.map(({ db }) => db.remove(obj))));
|
|
110
|
-
_define_property(DatabaseService, "flush", (opts) => DatabaseService.pipe(Effect.flatMap(({ db }) => promiseWithCauseCapture(() => db.flush(opts)))));
|
|
111
|
-
_define_property(DatabaseService, "getObjectById", (id) => {
|
|
112
|
-
return DatabaseService.pipe(Effect.map(({ db }) => db.getObjectById(id)));
|
|
113
|
-
});
|
|
114
|
-
_define_property(DatabaseService, "query", (queryOrFilter) => DatabaseService.pipe(Effect.map(({ db }) => db.query(queryOrFilter)), Effect.withSpan("DatabaseService.query")));
|
|
115
|
-
_define_property(DatabaseService, "runQuery", (queryOrFilter) => DatabaseService.query(queryOrFilter).pipe(Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run()))));
|
|
116
|
-
_define_property(DatabaseService, "schemaQuery", (query) => DatabaseService.pipe(Effect.map(({ db }) => db.schemaRegistry.query(query)), Effect.withSpan("DatabaseService.schemaQuery")));
|
|
117
|
-
_define_property(DatabaseService, "runSchemaQuery", (query) => DatabaseService.schemaQuery(query).pipe(Effect.flatMap((queryResult) => promiseWithCauseCapture(() => queryResult.run()))));
|
|
118
|
-
var ObjectNotFoundError = class extends BaseError.extend("OBJECT_NOT_FOUND") {
|
|
119
|
-
constructor(context) {
|
|
120
|
-
super("Object not found", {
|
|
121
|
-
context
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
// src/services/queues.ts
|
|
127
|
-
import { Context as Context2, Effect as Effect2, Layer as Layer2 } from "effect";
|
|
128
|
-
function _define_property2(obj, key, value) {
|
|
129
|
-
if (key in obj) {
|
|
130
|
-
Object.defineProperty(obj, key, {
|
|
131
|
-
value,
|
|
132
|
-
enumerable: true,
|
|
133
|
-
configurable: true,
|
|
134
|
-
writable: true
|
|
135
|
-
});
|
|
136
|
-
} else {
|
|
137
|
-
obj[key] = value;
|
|
138
|
-
}
|
|
139
|
-
return obj;
|
|
140
|
-
}
|
|
141
|
-
var _Context_Tag2;
|
|
142
|
-
var QueueService = class extends (_Context_Tag2 = Context2.Tag("@dxos/functions/QueueService")()) {
|
|
143
|
-
};
|
|
144
|
-
_define_property2(QueueService, "notAvailable", Layer2.succeed(QueueService, {
|
|
145
|
-
queues: {
|
|
146
|
-
get(_dxn) {
|
|
147
|
-
throw new Error("Queues not available");
|
|
148
|
-
},
|
|
149
|
-
create() {
|
|
150
|
-
throw new Error("Queues not available");
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
queue: void 0
|
|
154
|
-
}));
|
|
155
|
-
_define_property2(QueueService, "make", (queues, queue) => {
|
|
156
|
-
return {
|
|
157
|
-
queues,
|
|
158
|
-
queue
|
|
159
|
-
};
|
|
160
|
-
});
|
|
161
|
-
_define_property2(QueueService, "layer", (queues, queue) => Layer2.succeed(QueueService, QueueService.make(queues, queue)));
|
|
162
|
-
_define_property2(QueueService, "getQueue", (dxn) => QueueService.pipe(Effect2.map(({ queues }) => queues.get(dxn))));
|
|
163
|
-
_define_property2(QueueService, "createQueue", (options) => QueueService.pipe(Effect2.map(({ queues }) => queues.create(options))));
|
|
164
|
-
var _Context_Tag1;
|
|
165
|
-
var ContextQueueService = class extends (_Context_Tag1 = Context2.Tag("@dxos/functions/ContextQueueService")()) {
|
|
166
|
-
};
|
|
167
|
-
_define_property2(ContextQueueService, "layer", (queue) => Layer2.succeed(ContextQueueService, {
|
|
168
|
-
queue
|
|
169
|
-
}));
|
|
170
|
-
|
|
171
|
-
// src/services/credentials.ts
|
|
172
|
-
import { HttpClient, HttpClientRequest } from "@effect/platform";
|
|
173
|
-
import { Context as Context3, Effect as Effect3, Layer as Layer3, Redacted } from "effect";
|
|
174
|
-
import { Query } from "@dxos/echo";
|
|
175
|
-
import { DataType } from "@dxos/schema";
|
|
176
|
-
function _define_property3(obj, key, value) {
|
|
177
|
-
if (key in obj) {
|
|
178
|
-
Object.defineProperty(obj, key, {
|
|
179
|
-
value,
|
|
180
|
-
enumerable: true,
|
|
181
|
-
configurable: true,
|
|
182
|
-
writable: true
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
obj[key] = value;
|
|
186
|
-
}
|
|
187
|
-
return obj;
|
|
188
|
-
}
|
|
189
|
-
var _Context_Tag3;
|
|
190
|
-
var CredentialsService = class extends (_Context_Tag3 = Context3.Tag("@dxos/functions/CredentialsService")()) {
|
|
191
|
-
};
|
|
192
|
-
_define_property3(CredentialsService, "getCredential", (query) => Effect3.gen(function* () {
|
|
193
|
-
const credentials = yield* CredentialsService;
|
|
194
|
-
return yield* Effect3.promise(() => credentials.getCredential(query));
|
|
195
|
-
}));
|
|
196
|
-
_define_property3(CredentialsService, "getApiKey", (query) => Effect3.gen(function* () {
|
|
197
|
-
const credential = yield* CredentialsService.getCredential(query);
|
|
198
|
-
if (!credential.apiKey) {
|
|
199
|
-
throw new Error(`API key not found for service: ${query.service}`);
|
|
200
|
-
}
|
|
201
|
-
return Redacted.make(credential.apiKey);
|
|
202
|
-
}));
|
|
203
|
-
_define_property3(CredentialsService, "configuredLayer", (credentials) => Layer3.succeed(CredentialsService, new ConfiguredCredentialsService(credentials)));
|
|
204
|
-
_define_property3(CredentialsService, "layerConfig", (credentials) => Layer3.effect(CredentialsService, Effect3.gen(function* () {
|
|
205
|
-
const serviceCredentials = yield* Effect3.forEach(credentials, ({ service, apiKey }) => Effect3.gen(function* () {
|
|
206
|
-
return {
|
|
207
|
-
service,
|
|
208
|
-
apiKey: Redacted.value(yield* apiKey)
|
|
209
|
-
};
|
|
210
|
-
}));
|
|
211
|
-
return new ConfiguredCredentialsService(serviceCredentials);
|
|
212
|
-
})));
|
|
213
|
-
_define_property3(CredentialsService, "layerFromDatabase", () => Layer3.effect(CredentialsService, Effect3.gen(function* () {
|
|
214
|
-
const dbService = yield* DatabaseService;
|
|
215
|
-
const queryCredentials = async (query) => {
|
|
216
|
-
const { objects: accessTokens } = await dbService.db.query(Query.type(DataType.AccessToken)).run();
|
|
217
|
-
return accessTokens.filter((accessToken) => accessToken.source === query.service).map((accessToken) => ({
|
|
218
|
-
service: accessToken.source,
|
|
219
|
-
apiKey: accessToken.token
|
|
220
|
-
}));
|
|
221
|
-
};
|
|
222
|
-
return {
|
|
223
|
-
getCredential: async (query) => {
|
|
224
|
-
const credentials = await queryCredentials(query);
|
|
225
|
-
if (credentials.length === 0) {
|
|
226
|
-
throw new Error(`Credential not found for service: ${query.service}`);
|
|
227
|
-
}
|
|
228
|
-
return credentials[0];
|
|
229
|
-
},
|
|
230
|
-
queryCredentials: async (query) => {
|
|
231
|
-
return queryCredentials(query);
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
})));
|
|
235
|
-
var ConfiguredCredentialsService = class {
|
|
236
|
-
addCredentials(credentials) {
|
|
237
|
-
this.credentials.push(...credentials);
|
|
238
|
-
return this;
|
|
239
|
-
}
|
|
240
|
-
async queryCredentials(query) {
|
|
241
|
-
return this.credentials.filter((credential) => credential.service === query.service);
|
|
242
|
-
}
|
|
243
|
-
async getCredential(query) {
|
|
244
|
-
const credential = this.credentials.find((credential2) => credential2.service === query.service);
|
|
245
|
-
if (!credential) {
|
|
246
|
-
throw new Error(`Credential not found for service: ${query.service}`);
|
|
247
|
-
}
|
|
248
|
-
return credential;
|
|
249
|
-
}
|
|
250
|
-
constructor(credentials = []) {
|
|
251
|
-
_define_property3(this, "credentials", void 0);
|
|
252
|
-
this.credentials = credentials;
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
var withAuthorization = (query, kind) => HttpClient.mapRequestEffect(Effect3.fnUntraced(function* (request) {
|
|
256
|
-
const key = yield* CredentialsService.getApiKey(query).pipe(Effect3.map(Redacted.value));
|
|
257
|
-
const authorization = kind ? `${kind} ${key}` : key;
|
|
258
|
-
return HttpClientRequest.setHeader(request, "Authorization", authorization);
|
|
259
|
-
}));
|
|
260
|
-
|
|
261
|
-
// src/services/tracing.ts
|
|
262
|
-
import { Context as Context4, Effect as Effect4, Layer as Layer4 } from "effect";
|
|
263
|
-
import { AgentStatus } from "@dxos/ai";
|
|
264
|
-
import { Obj as Obj2 } from "@dxos/echo";
|
|
265
|
-
import { log } from "@dxos/log";
|
|
266
|
-
import { DataType as DataType2 } from "@dxos/schema";
|
|
267
|
-
function _define_property4(obj, key, value) {
|
|
268
|
-
if (key in obj) {
|
|
269
|
-
Object.defineProperty(obj, key, {
|
|
270
|
-
value,
|
|
271
|
-
enumerable: true,
|
|
272
|
-
configurable: true,
|
|
273
|
-
writable: true
|
|
274
|
-
});
|
|
275
|
-
} else {
|
|
276
|
-
obj[key] = value;
|
|
277
|
-
}
|
|
278
|
-
return obj;
|
|
279
|
-
}
|
|
280
|
-
var __dxlog_file2 = "/__w/dxos/dxos/packages/core/functions/src/services/tracing.ts";
|
|
281
|
-
var _Context_Tag4;
|
|
282
|
-
var TracingService = class extends (_Context_Tag4 = Context4.Tag("@dxos/functions/TracingService")()) {
|
|
283
|
-
};
|
|
284
|
-
_define_property4(TracingService, "noop", {
|
|
285
|
-
write: () => {
|
|
286
|
-
},
|
|
287
|
-
getTraceContext: () => ({})
|
|
288
|
-
});
|
|
289
|
-
_define_property4(TracingService, "layerNoop", Layer4.succeed(TracingService, TracingService.noop));
|
|
290
|
-
_define_property4(TracingService, "console", {
|
|
291
|
-
write: (event) => {
|
|
292
|
-
console.log(event);
|
|
293
|
-
},
|
|
294
|
-
getTraceContext: () => ({})
|
|
295
|
-
});
|
|
296
|
-
_define_property4(TracingService, "layerConsole", Layer4.succeed(TracingService, TracingService.console));
|
|
297
|
-
_define_property4(TracingService, "layerLogInfo", () => Layer4.succeed(TracingService, {
|
|
298
|
-
write: (event) => {
|
|
299
|
-
if (Obj2.instanceOf(AgentStatus, event)) {
|
|
300
|
-
log.info("status", {
|
|
301
|
-
message: event.message
|
|
302
|
-
}, {
|
|
303
|
-
F: __dxlog_file2,
|
|
304
|
-
L: 51,
|
|
305
|
-
S: TracingService,
|
|
306
|
-
C: (f, a) => f(...a)
|
|
307
|
-
});
|
|
308
|
-
}
|
|
309
|
-
},
|
|
310
|
-
getTraceContext: () => ({})
|
|
311
|
-
}));
|
|
312
|
-
_define_property4(TracingService, "layerSubframe", (mapContext) => Layer4.effect(TracingService, Effect4.gen(function* () {
|
|
313
|
-
const tracing = yield* TracingService;
|
|
314
|
-
const context = mapContext(tracing.getTraceContext());
|
|
315
|
-
return {
|
|
316
|
-
write: (event) => tracing.write(event),
|
|
317
|
-
getTraceContext: () => context
|
|
318
|
-
};
|
|
319
|
-
})));
|
|
320
|
-
_define_property4(TracingService, "layerQueue", (queue) => Layer4.effect(TracingService, Effect4.gen(function* () {
|
|
321
|
-
return {
|
|
322
|
-
write: (event) => queue.append([
|
|
323
|
-
event
|
|
324
|
-
]),
|
|
325
|
-
getTraceContext: () => ({})
|
|
326
|
-
};
|
|
327
|
-
})));
|
|
328
|
-
_define_property4(TracingService, "emitStatus", Effect4.fnUntraced(function* (data) {
|
|
329
|
-
const tracing = yield* TracingService;
|
|
330
|
-
tracing.write(Obj2.make(AgentStatus, {
|
|
331
|
-
parentMessage: tracing.getTraceContext().parentMessage,
|
|
332
|
-
toolCallId: tracing.getTraceContext().toolCallId,
|
|
333
|
-
...data
|
|
334
|
-
}));
|
|
335
|
-
}));
|
|
336
|
-
_define_property4(TracingService, "emitConverationMessage", Effect4.fnUntraced(function* (data) {
|
|
337
|
-
const tracing = yield* TracingService;
|
|
338
|
-
tracing.write(Obj2.make(DataType2.Message, {
|
|
339
|
-
parentMessage: tracing.getTraceContext().parentMessage,
|
|
340
|
-
...data,
|
|
341
|
-
properties: {
|
|
342
|
-
[MESSAGE_PROPERTY_TOOL_CALL_ID]: tracing.getTraceContext().toolCallId,
|
|
343
|
-
...data.properties
|
|
344
|
-
}
|
|
345
|
-
}));
|
|
346
|
-
}));
|
|
347
|
-
var MESSAGE_PROPERTY_TOOL_CALL_ID = "toolCallId";
|
|
348
|
-
|
|
349
|
-
// src/services/event-logger.ts
|
|
350
|
-
import { Context as Context5, Effect as Effect5, Layer as Layer5, Schema } from "effect";
|
|
351
|
-
import { Obj as Obj3, Type } from "@dxos/echo";
|
|
352
|
-
import { invariant as invariant2 } from "@dxos/invariant";
|
|
353
|
-
import { LogLevel, log as log2 } from "@dxos/log";
|
|
354
|
-
function _define_property5(obj, key, value) {
|
|
355
|
-
if (key in obj) {
|
|
356
|
-
Object.defineProperty(obj, key, {
|
|
357
|
-
value,
|
|
358
|
-
enumerable: true,
|
|
359
|
-
configurable: true,
|
|
360
|
-
writable: true
|
|
361
|
-
});
|
|
362
|
-
} else {
|
|
363
|
-
obj[key] = value;
|
|
364
|
-
}
|
|
365
|
-
return obj;
|
|
366
|
-
}
|
|
367
|
-
var __dxlog_file3 = "/__w/dxos/dxos/packages/core/functions/src/services/event-logger.ts";
|
|
368
|
-
var ComputeEventPayload = Schema.Union(Schema.Struct({
|
|
369
|
-
type: Schema.Literal("begin-compute"),
|
|
370
|
-
nodeId: Schema.String,
|
|
371
|
-
inputs: Schema.Record({
|
|
372
|
-
key: Schema.String,
|
|
373
|
-
value: Schema.Any
|
|
374
|
-
})
|
|
375
|
-
}), Schema.Struct({
|
|
376
|
-
type: Schema.Literal("end-compute"),
|
|
377
|
-
nodeId: Schema.String,
|
|
378
|
-
outputs: Schema.Record({
|
|
379
|
-
key: Schema.String,
|
|
380
|
-
value: Schema.Any
|
|
381
|
-
})
|
|
382
|
-
}), Schema.Struct({
|
|
383
|
-
type: Schema.Literal("compute-input"),
|
|
384
|
-
nodeId: Schema.String,
|
|
385
|
-
property: Schema.String,
|
|
386
|
-
value: Schema.Any
|
|
387
|
-
}), Schema.Struct({
|
|
388
|
-
type: Schema.Literal("compute-output"),
|
|
389
|
-
nodeId: Schema.String,
|
|
390
|
-
property: Schema.String,
|
|
391
|
-
value: Schema.Any
|
|
392
|
-
}), Schema.Struct({
|
|
393
|
-
type: Schema.Literal("custom"),
|
|
394
|
-
nodeId: Schema.String,
|
|
395
|
-
event: Schema.Any
|
|
396
|
-
}));
|
|
397
|
-
var ComputeEvent = Schema.Struct({
|
|
398
|
-
payload: ComputeEventPayload
|
|
399
|
-
}).pipe(Type.Obj({
|
|
400
|
-
typename: "dxos.org/type/ComputeEvent",
|
|
401
|
-
version: "0.1.0"
|
|
402
|
-
}));
|
|
403
|
-
var _Context_Tag5;
|
|
404
|
-
var ComputeEventLogger = class extends (_Context_Tag5 = Context5.Tag("@dxos/functions/ComputeEventLogger")()) {
|
|
405
|
-
};
|
|
406
|
-
_define_property5(ComputeEventLogger, "noop", {
|
|
407
|
-
log: () => {
|
|
408
|
-
},
|
|
409
|
-
nodeId: void 0
|
|
410
|
-
});
|
|
411
|
-
_define_property5(ComputeEventLogger, "layerFromTracing", Layer5.effect(ComputeEventLogger, Effect5.gen(function* () {
|
|
412
|
-
const tracing = yield* TracingService;
|
|
413
|
-
return {
|
|
414
|
-
log: (event) => {
|
|
415
|
-
tracing.write(Obj3.make(ComputeEvent, {
|
|
416
|
-
payload: event
|
|
417
|
-
}));
|
|
418
|
-
},
|
|
419
|
-
nodeId: void 0
|
|
420
|
-
};
|
|
421
|
-
})));
|
|
422
|
-
var logCustomEvent = (data) => Effect5.gen(function* () {
|
|
423
|
-
const logger = yield* ComputeEventLogger;
|
|
424
|
-
if (!logger.nodeId) {
|
|
425
|
-
throw new Error("logCustomEvent must be called within a node compute function");
|
|
426
|
-
}
|
|
427
|
-
logger.log({
|
|
428
|
-
type: "custom",
|
|
429
|
-
nodeId: logger.nodeId,
|
|
430
|
-
event: data
|
|
431
|
-
});
|
|
432
|
-
});
|
|
433
|
-
var createDefectLogger = () => Effect5.catchAll((error) => Effect5.gen(function* () {
|
|
434
|
-
log2.error("unhandled effect error", {
|
|
435
|
-
error
|
|
436
|
-
}, {
|
|
437
|
-
F: __dxlog_file3,
|
|
438
|
-
L: 93,
|
|
439
|
-
S: this,
|
|
440
|
-
C: (f, a) => f(...a)
|
|
441
|
-
});
|
|
442
|
-
throw error;
|
|
443
|
-
}));
|
|
444
|
-
var createEventLogger = (level, message = "event") => {
|
|
445
|
-
const logFunction = {
|
|
446
|
-
[LogLevel.WARN]: log2.warn,
|
|
447
|
-
[LogLevel.VERBOSE]: log2.verbose,
|
|
448
|
-
[LogLevel.DEBUG]: log2.debug,
|
|
449
|
-
[LogLevel.INFO]: log2.info,
|
|
450
|
-
[LogLevel.ERROR]: log2.error
|
|
451
|
-
}[level];
|
|
452
|
-
invariant2(logFunction, void 0, {
|
|
453
|
-
F: __dxlog_file3,
|
|
454
|
-
L: 111,
|
|
455
|
-
S: void 0,
|
|
456
|
-
A: [
|
|
457
|
-
"logFunction",
|
|
458
|
-
""
|
|
459
|
-
]
|
|
460
|
-
});
|
|
461
|
-
return {
|
|
462
|
-
log: (event) => {
|
|
463
|
-
logFunction(message, event);
|
|
464
|
-
},
|
|
465
|
-
nodeId: void 0
|
|
466
|
-
};
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
// src/services/remote-function-execution-service.ts
|
|
470
|
-
import { Context as Context6, Layer as Layer6 } from "effect";
|
|
471
|
-
function _define_property6(obj, key, value) {
|
|
472
|
-
if (key in obj) {
|
|
473
|
-
Object.defineProperty(obj, key, {
|
|
474
|
-
value,
|
|
475
|
-
enumerable: true,
|
|
476
|
-
configurable: true,
|
|
477
|
-
writable: true
|
|
478
|
-
});
|
|
479
|
-
} else {
|
|
480
|
-
obj[key] = value;
|
|
481
|
-
}
|
|
482
|
-
return obj;
|
|
483
|
-
}
|
|
484
|
-
var _Context_Tag6;
|
|
485
|
-
var RemoteFunctionExecutionService = class extends (_Context_Tag6 = Context6.Tag("@dxos/functions/RemoteFunctionExecutionService")()) {
|
|
486
|
-
static fromClient(baseUrl, spaceId) {
|
|
487
|
-
return {
|
|
488
|
-
callFunction: async (deployedFunctionId, input) => {
|
|
489
|
-
const url = getInvocationUrl(deployedFunctionId, baseUrl, {
|
|
490
|
-
spaceId
|
|
491
|
-
});
|
|
492
|
-
const result = await fetch(url, {
|
|
493
|
-
method: "POST",
|
|
494
|
-
headers: {
|
|
495
|
-
"Content-Type": "application/json"
|
|
496
|
-
},
|
|
497
|
-
body: JSON.stringify(input)
|
|
498
|
-
});
|
|
499
|
-
if (result.status >= 300 || result.status < 200) {
|
|
500
|
-
throw new Error("Failed to invoke function", {
|
|
501
|
-
cause: new Error(`HTTP error: ${await result.text()}`)
|
|
502
|
-
});
|
|
503
|
-
}
|
|
504
|
-
return await result.json();
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
_define_property6(RemoteFunctionExecutionService, "mock", () => {
|
|
510
|
-
return {
|
|
511
|
-
callFunction: async (deployedFunctionId, input) => {
|
|
512
|
-
return input;
|
|
513
|
-
}
|
|
514
|
-
};
|
|
515
|
-
});
|
|
516
|
-
_define_property6(RemoteFunctionExecutionService, "mockLayer", Layer6.succeed(RemoteFunctionExecutionService, RemoteFunctionExecutionService.mock()));
|
|
517
|
-
|
|
518
|
-
// src/services/service-container.ts
|
|
519
|
-
import { Layer as Layer7 } from "effect";
|
|
520
|
-
import { AiService } from "@dxos/ai";
|
|
521
|
-
import { entries } from "@dxos/util";
|
|
522
|
-
function _define_property7(obj, key, value) {
|
|
523
|
-
if (key in obj) {
|
|
524
|
-
Object.defineProperty(obj, key, {
|
|
525
|
-
value,
|
|
526
|
-
enumerable: true,
|
|
527
|
-
configurable: true,
|
|
528
|
-
writable: true
|
|
529
|
-
});
|
|
530
|
-
} else {
|
|
531
|
-
obj[key] = value;
|
|
532
|
-
}
|
|
533
|
-
return obj;
|
|
534
|
-
}
|
|
535
|
-
var SERVICES = {
|
|
536
|
-
ai: AiService.AiService,
|
|
537
|
-
credentials: CredentialsService,
|
|
538
|
-
database: DatabaseService,
|
|
539
|
-
eventLogger: ComputeEventLogger,
|
|
540
|
-
functionCallService: RemoteFunctionExecutionService,
|
|
541
|
-
queues: QueueService,
|
|
542
|
-
tracing: TracingService
|
|
543
|
-
};
|
|
544
|
-
var SERVICE_MAPPING = Object.fromEntries(entries(SERVICES).map(([name, tag]) => [
|
|
545
|
-
tag.key,
|
|
546
|
-
name
|
|
547
|
-
]));
|
|
548
|
-
var SERVICE_TAGS = Object.values(SERVICES);
|
|
549
|
-
var DEFAULT_SERVICES = {
|
|
550
|
-
tracing: TracingService.noop
|
|
551
|
-
};
|
|
552
|
-
var ServiceContainer = class _ServiceContainer {
|
|
553
|
-
/**
|
|
554
|
-
* Set services.
|
|
555
|
-
* @param services - Services to set.
|
|
556
|
-
* @returns The container instance.
|
|
557
|
-
*/
|
|
558
|
-
setServices(services) {
|
|
559
|
-
this._services = {
|
|
560
|
-
...this._services,
|
|
561
|
-
...services
|
|
562
|
-
};
|
|
563
|
-
return this;
|
|
564
|
-
}
|
|
565
|
-
getService(tag) {
|
|
566
|
-
const serviceKey = SERVICE_MAPPING[tag.key];
|
|
567
|
-
const service = serviceKey != null ? this._services[serviceKey] : void 0;
|
|
568
|
-
if (!service) {
|
|
569
|
-
throw new Error(`Service not available: ${tag.key}`);
|
|
570
|
-
}
|
|
571
|
-
return service;
|
|
572
|
-
}
|
|
573
|
-
clone() {
|
|
574
|
-
return new _ServiceContainer().setServices({
|
|
575
|
-
...this._services
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
// 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.
|
|
579
|
-
createLayer() {
|
|
580
|
-
const ai = this._services.ai != null ? Layer7.succeed(AiService.AiService, this._services.ai) : AiService.notAvailable;
|
|
581
|
-
const credentials = Layer7.succeed(CredentialsService, this._services.credentials ?? new ConfiguredCredentialsService());
|
|
582
|
-
const database = this._services.database != null ? Layer7.succeed(DatabaseService, this._services.database) : DatabaseService.notAvailable;
|
|
583
|
-
const queues = this._services.queues != null ? Layer7.succeed(QueueService, this._services.queues) : QueueService.notAvailable;
|
|
584
|
-
const tracing = Layer7.succeed(TracingService, this._services.tracing ?? TracingService.noop);
|
|
585
|
-
const eventLogger = Layer7.succeed(ComputeEventLogger, this._services.eventLogger ?? ComputeEventLogger.noop);
|
|
586
|
-
const functionCallService = Layer7.succeed(RemoteFunctionExecutionService, this._services.functionCallService ?? RemoteFunctionExecutionService.mock());
|
|
587
|
-
return Layer7.mergeAll(ai, credentials, database, queues, tracing, eventLogger, functionCallService);
|
|
588
|
-
}
|
|
589
|
-
constructor() {
|
|
590
|
-
_define_property7(this, "_services", {
|
|
591
|
-
...DEFAULT_SERVICES
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
};
|
|
595
|
-
|
|
596
|
-
export {
|
|
597
|
-
FUNCTIONS_META_KEY,
|
|
598
|
-
FUNCTIONS_PRESET_META_KEY,
|
|
599
|
-
getUserFunctionIdInMetadata,
|
|
600
|
-
setUserFunctionIdInMetadata,
|
|
601
|
-
getInvocationUrl,
|
|
602
|
-
DatabaseService,
|
|
603
|
-
QueueService,
|
|
604
|
-
ContextQueueService,
|
|
605
|
-
CredentialsService,
|
|
606
|
-
ConfiguredCredentialsService,
|
|
607
|
-
withAuthorization,
|
|
608
|
-
TracingService,
|
|
609
|
-
MESSAGE_PROPERTY_TOOL_CALL_ID,
|
|
610
|
-
ComputeEventPayload,
|
|
611
|
-
ComputeEvent,
|
|
612
|
-
ComputeEventLogger,
|
|
613
|
-
logCustomEvent,
|
|
614
|
-
createDefectLogger,
|
|
615
|
-
createEventLogger,
|
|
616
|
-
RemoteFunctionExecutionService,
|
|
617
|
-
SERVICE_TAGS,
|
|
618
|
-
ServiceContainer
|
|
619
|
-
};
|
|
620
|
-
//# sourceMappingURL=chunk-KCGC6QQT.mjs.map
|