orchajs 0.20.3 → 0.22.0
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/README.md +103 -0
- package/dist/amarsia/analytics.d.ts +21 -0
- package/dist/amarsia/analytics.js +457 -0
- package/dist/amarsia/endpoint.d.ts +1 -0
- package/dist/amarsia/endpoint.js +8 -0
- package/dist/amarsia/sync.js +1 -4
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +13 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +12 -0
- package/dist/cli.js +35 -9
- package/dist/compiler/build-project.d.ts +1 -0
- package/dist/compiler/build-project.js +75 -8
- package/dist/compiler/compile.d.ts +1 -1
- package/dist/compiler/compile.js +11 -9
- package/dist/errors.d.ts +5 -0
- package/dist/errors.js +102 -0
- package/dist/file-content.js +42 -6
- package/dist/index.d.ts +1 -5
- package/dist/index.js +1 -2
- package/dist/integrations/esbuild.js +5 -2
- package/dist/integrations/expo.d.ts +1 -0
- package/dist/integrations/expo.js +1 -0
- package/dist/integrations/metro.d.ts +15 -0
- package/dist/integrations/metro.js +25 -0
- package/dist/integrations/next.d.ts +23 -0
- package/dist/integrations/next.js +53 -0
- package/dist/integrations/runtime-build.d.ts +4 -0
- package/dist/integrations/runtime-build.js +32 -0
- package/dist/integrations/vite.d.ts +23 -0
- package/dist/integrations/vite.js +32 -0
- package/dist/integrations/webpack.d.ts +24 -0
- package/dist/integrations/webpack.js +21 -0
- package/dist/orcha.js +17 -8
- package/dist/playground/server.js +57 -7
- package/dist/project-loader.js +3 -0
- package/dist/providers/browser.d.ts +2 -0
- package/dist/providers/browser.js +20 -0
- package/dist/react-native.d.ts +2 -0
- package/dist/react-native.js +12 -0
- package/dist/runtime/actions/browser-native.d.ts +3 -0
- package/dist/runtime/actions/browser-native.js +28 -0
- package/dist/runtime/actions/execute.d.ts +7 -0
- package/dist/runtime/actions/execute.js +9 -2
- package/dist/runtime/agent.d.ts +1 -0
- package/dist/runtime/agent.js +38 -10
- package/dist/runtime/compiler-hook.d.ts +5 -0
- package/dist/runtime/compiler-hook.js +8 -0
- package/dist/runtime/create-orcha.d.ts +6 -1
- package/dist/runtime/create-orcha.js +35 -21
- package/dist/runtime/platform-browser.d.ts +2 -0
- package/dist/runtime/platform-browser.js +15 -0
- package/dist/runtime/platform-node.d.ts +2 -0
- package/dist/runtime/platform-node.js +31 -0
- package/dist/runtime/platform-react-native.d.ts +2 -0
- package/dist/runtime/platform-react-native.js +15 -0
- package/dist/runtime/platform.d.ts +15 -0
- package/dist/runtime/platform.js +1 -0
- package/dist/runtime/random-id.d.ts +1 -0
- package/dist/runtime/random-id.js +26 -0
- package/dist/runtime-entry.d.ts +5 -0
- package/dist/runtime-entry.js +2 -0
- package/dist/storage/browser-indexeddb.d.ts +7 -16
- package/dist/storage/browser-indexeddb.js +102 -19
- package/dist/storage/react-native-jsonl.d.ts +7 -16
- package/dist/storage/react-native-jsonl.js +65 -19
- package/dist/types.d.ts +54 -1
- package/dist-cjs/amarsia/analytics.js +447 -0
- package/dist-cjs/amarsia/endpoint.js +32 -0
- package/dist-cjs/amarsia/sync.js +2 -5
- package/dist-cjs/browser.js +48 -0
- package/dist-cjs/compiler/build-project.js +97 -8
- package/dist-cjs/compiler/compile.js +17 -9
- package/dist-cjs/errors.js +92 -2
- package/dist-cjs/file-content.js +42 -7
- package/dist-cjs/index.js +4 -9
- package/dist-cjs/integrations/esbuild.js +6 -2
- package/dist-cjs/integrations/expo.js +29 -0
- package/dist-cjs/integrations/metro.js +51 -0
- package/dist-cjs/integrations/next.js +75 -0
- package/dist-cjs/integrations/runtime-build.js +70 -0
- package/dist-cjs/integrations/vite.js +57 -0
- package/dist-cjs/integrations/webpack.js +51 -0
- package/dist-cjs/orcha.js +17 -12
- package/dist-cjs/playground/server.js +62 -9
- package/dist-cjs/project-loader.js +10 -0
- package/dist-cjs/providers/browser.js +61 -0
- package/dist-cjs/react-native.js +48 -0
- package/dist-cjs/runtime/actions/browser-native.js +68 -0
- package/dist-cjs/runtime/actions/execute.js +12 -2
- package/dist-cjs/runtime/agent.js +37 -14
- package/dist-cjs/runtime/compiler-hook.js +37 -0
- package/dist-cjs/runtime/create-orcha.js +34 -23
- package/dist-cjs/runtime/platform-browser.js +48 -0
- package/dist-cjs/runtime/platform-node.js +59 -0
- package/dist-cjs/runtime/platform-react-native.js +45 -0
- package/dist-cjs/runtime/platform.js +17 -0
- package/dist-cjs/runtime/random-id.js +55 -0
- package/dist-cjs/runtime-entry.js +34 -0
- package/dist-cjs/storage/browser-indexeddb.js +102 -5
- package/dist-cjs/storage/react-native-jsonl.js +73 -5
- package/dist-cjs/types/react-native-async-storage.d.js +2 -0
- package/package.json +69 -9
- package/dist/playground/public/app.css +0 -1
- package/dist/playground/public/app.js +0 -31
- package/dist/playground/public/index.html +0 -15
- package/dist/playground/public/orcha-logo.svg +0 -4
|
@@ -28,9 +28,21 @@ var import_path = require("path");
|
|
|
28
28
|
var import_url = require("url");
|
|
29
29
|
var import_esbuild = require("esbuild");
|
|
30
30
|
var import_orcha = require("../orcha.js");
|
|
31
|
+
var import_compiler_hook = require("../runtime/compiler-hook.js");
|
|
32
|
+
var import_compile = require("./compile.js");
|
|
31
33
|
var import_catalog = require("../providers/catalog.js");
|
|
34
|
+
let registryImportSequence = 0;
|
|
32
35
|
async function buildProject(options = {}) {
|
|
33
36
|
const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
|
|
37
|
+
const target = options.target ?? "node";
|
|
38
|
+
(0, import_compiler_hook.setRegistryCompiler)(
|
|
39
|
+
(configuration, compilerProjectRoot) => (0, import_compile.compileRegistry)(
|
|
40
|
+
configuration.agents,
|
|
41
|
+
(0, import_path.resolve)(compilerProjectRoot, "orcha"),
|
|
42
|
+
configuration.actions?.runtime ?? "native",
|
|
43
|
+
target
|
|
44
|
+
)
|
|
45
|
+
);
|
|
34
46
|
const registryPath = (0, import_path.resolve)(projectRoot, "orcha/index.ts");
|
|
35
47
|
if (!(0, import_fs.existsSync)(registryPath)) {
|
|
36
48
|
throw new Error('Missing "orcha/index.ts". Run "orcha init" first.');
|
|
@@ -41,7 +53,10 @@ async function buildProject(options = {}) {
|
|
|
41
53
|
temporaryDirectory,
|
|
42
54
|
"production-entry.mjs"
|
|
43
55
|
);
|
|
44
|
-
const outputPath = (0, import_path.resolve)(
|
|
56
|
+
const outputPath = (0, import_path.resolve)(
|
|
57
|
+
projectRoot,
|
|
58
|
+
`.orcha/dist/${bundleFileName(target)}`
|
|
59
|
+
);
|
|
45
60
|
const manifestPath = (0, import_path.resolve)(
|
|
46
61
|
projectRoot,
|
|
47
62
|
".orcha/dist/manifest.json"
|
|
@@ -64,7 +79,7 @@ async function buildProject(options = {}) {
|
|
|
64
79
|
process.env.ORCHA_COMPILING = "1";
|
|
65
80
|
process.env.ORCHA_PROJECT_ROOT = projectRoot;
|
|
66
81
|
try {
|
|
67
|
-
await import(`${(0, import_url.pathToFileURL)(registryBundlePath).href}?
|
|
82
|
+
await import(`${(0, import_url.pathToFileURL)(registryBundlePath).href}?build=${Date.now()}-${registryImportSequence++}`);
|
|
68
83
|
} finally {
|
|
69
84
|
if (previousCompiling === void 0) {
|
|
70
85
|
delete process.env.ORCHA_COMPILING;
|
|
@@ -78,15 +93,30 @@ async function buildProject(options = {}) {
|
|
|
78
93
|
}
|
|
79
94
|
}
|
|
80
95
|
const compiledBundle = import_orcha.orcha.getCompiledBundle();
|
|
96
|
+
if (target !== "node" && compiledBundle.actionRuntime === "sandbox") {
|
|
97
|
+
throw new Error(
|
|
98
|
+
`The ${target} target supports precompiled native actions only. Set actions.runtime to "native".`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
81
101
|
const runtimeFactoryPath = (0, import_path.resolve)(
|
|
82
102
|
(0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
|
|
83
103
|
"../runtime/create-orcha.js"
|
|
84
104
|
).replaceAll("\\", "/");
|
|
105
|
+
const runtimePlatformPath = (0, import_path.resolve)(
|
|
106
|
+
(0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
|
|
107
|
+
`../runtime/platform-${target}.js`
|
|
108
|
+
).replaceAll("\\", "/");
|
|
109
|
+
const runtimeEntryPath = (0, import_path.resolve)(
|
|
110
|
+
(0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
|
|
111
|
+
"../runtime-entry.js"
|
|
112
|
+
).replaceAll("\\", "/");
|
|
85
113
|
const providerDispatcherPath = (0, import_path.resolve)(
|
|
86
114
|
(0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
|
|
87
115
|
"../providers/dispatcher.js"
|
|
88
116
|
).replaceAll("\\", "/");
|
|
89
117
|
const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox" ? createSandboxRuntimeSource() : "";
|
|
118
|
+
const platformActionRuntimeSource = createPlatformActionRuntimeSource(target);
|
|
119
|
+
const nodeStorageExports = target === "node" ? createNodeStorageExports() : "";
|
|
90
120
|
const includedProviders = [
|
|
91
121
|
...new Set(
|
|
92
122
|
allCompiledAgents(compiledBundle.agents).flatMap(
|
|
@@ -97,18 +127,22 @@ async function buildProject(options = {}) {
|
|
|
97
127
|
)
|
|
98
128
|
)
|
|
99
129
|
];
|
|
100
|
-
const providerRuntimeSource = createProviderRuntimeSource(includedProviders);
|
|
130
|
+
const providerRuntimeSource = createProviderRuntimeSource(includedProviders, target);
|
|
101
131
|
const needsNodeRequire = compiledBundle.actionRuntime === "sandbox" || includedProviders.includes("vertexai") || includedProviders.includes("bedrock");
|
|
102
132
|
await (0, import_promises.writeFile)(
|
|
103
133
|
productionEntryPath,
|
|
104
134
|
[
|
|
105
135
|
`import { createOrcha } from ${JSON.stringify(runtimeFactoryPath)};`,
|
|
136
|
+
`import { ${runtimePlatformExport(target)} as runtimePlatform } from ${JSON.stringify(runtimePlatformPath)};`,
|
|
106
137
|
`import { createProviderResponseGenerator } from ${JSON.stringify(providerDispatcherPath)};`,
|
|
138
|
+
`export * from ${JSON.stringify(runtimeEntryPath)};`,
|
|
139
|
+
nodeStorageExports,
|
|
107
140
|
providerRuntimeSource,
|
|
141
|
+
platformActionRuntimeSource,
|
|
108
142
|
sandboxRuntimeSource,
|
|
109
143
|
`const compiledBundle = ${JSON.stringify(compiledBundle)};`,
|
|
110
144
|
"const generateProviderResponse = createProviderResponseGenerator(includedProviders);",
|
|
111
|
-
"export const orcha = createOrcha(() => compiledBundle, generateProviderResponse);",
|
|
145
|
+
"export const orcha = createOrcha(() => compiledBundle, generateProviderResponse, runtimePlatform);",
|
|
112
146
|
"export default orcha;",
|
|
113
147
|
""
|
|
114
148
|
].join("\n"),
|
|
@@ -119,8 +153,8 @@ async function buildProject(options = {}) {
|
|
|
119
153
|
outfile: outputPath,
|
|
120
154
|
bundle: true,
|
|
121
155
|
format: "esm",
|
|
122
|
-
platform: "node",
|
|
123
|
-
target: "node18",
|
|
156
|
+
platform: target === "node" ? "node" : "browser",
|
|
157
|
+
target: target === "node" ? "node18" : target === "browser" ? ["chrome110", "firefox110", "safari16"] : "es2022",
|
|
124
158
|
minify: true,
|
|
125
159
|
legalComments: "none",
|
|
126
160
|
define: {
|
|
@@ -128,7 +162,7 @@ async function buildProject(options = {}) {
|
|
|
128
162
|
compiledBundle.actionRuntime === "sandbox" ? "1" : "0"
|
|
129
163
|
)
|
|
130
164
|
},
|
|
131
|
-
...needsNodeRequire ? {
|
|
165
|
+
...needsNodeRequire && target === "node" ? {
|
|
132
166
|
banner: {
|
|
133
167
|
js: [
|
|
134
168
|
'import { createRequire as __orchaCreateRequire } from "module";',
|
|
@@ -136,6 +170,11 @@ async function buildProject(options = {}) {
|
|
|
136
170
|
].join("\n")
|
|
137
171
|
}
|
|
138
172
|
} : {},
|
|
173
|
+
...target === "react-native" ? {
|
|
174
|
+
external: [
|
|
175
|
+
"@react-native-async-storage/async-storage"
|
|
176
|
+
]
|
|
177
|
+
} : {},
|
|
139
178
|
logLevel: "silent"
|
|
140
179
|
});
|
|
141
180
|
await (0, import_promises.writeFile)(
|
|
@@ -152,6 +191,18 @@ async function buildProject(options = {}) {
|
|
|
152
191
|
});
|
|
153
192
|
}
|
|
154
193
|
}
|
|
194
|
+
function bundleFileName(target) {
|
|
195
|
+
return target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
196
|
+
}
|
|
197
|
+
function runtimePlatformExport(target) {
|
|
198
|
+
if (target === "browser") {
|
|
199
|
+
return "browserRuntimePlatform";
|
|
200
|
+
}
|
|
201
|
+
if (target === "react-native") {
|
|
202
|
+
return "reactNativeRuntimePlatform";
|
|
203
|
+
}
|
|
204
|
+
return "nodeRuntimePlatform";
|
|
205
|
+
}
|
|
155
206
|
function createSandboxRuntimeSource() {
|
|
156
207
|
const runtimeDirectory = (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl));
|
|
157
208
|
const executePath = (0, import_path.resolve)(
|
|
@@ -169,13 +220,46 @@ function createSandboxRuntimeSource() {
|
|
|
169
220
|
""
|
|
170
221
|
].join("\n");
|
|
171
222
|
}
|
|
223
|
+
function createPlatformActionRuntimeSource(target) {
|
|
224
|
+
const runtimeDirectory = (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl));
|
|
225
|
+
const executePath = (0, import_path.resolve)(
|
|
226
|
+
runtimeDirectory,
|
|
227
|
+
"../runtime/actions/execute.js"
|
|
228
|
+
).replaceAll("\\", "/");
|
|
229
|
+
const nativePath = (0, import_path.resolve)(
|
|
230
|
+
runtimeDirectory,
|
|
231
|
+
target === "node" ? "../runtime/actions/native.js" : "../runtime/actions/browser-native.js"
|
|
232
|
+
).replaceAll("\\", "/");
|
|
233
|
+
return [
|
|
234
|
+
`import { setNativeRuntimeLoader } from ${JSON.stringify(executePath)};`,
|
|
235
|
+
`import { executeNativeAction } from ${JSON.stringify(nativePath)};`,
|
|
236
|
+
"setNativeRuntimeLoader(async () => ({ executeNativeAction }));",
|
|
237
|
+
""
|
|
238
|
+
].join("\n");
|
|
239
|
+
}
|
|
240
|
+
function createNodeStorageExports() {
|
|
241
|
+
const sourceRoot = (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl));
|
|
242
|
+
const jsonlPath = (0, import_path.resolve)(
|
|
243
|
+
sourceRoot,
|
|
244
|
+
"../storage/node-jsonl.js"
|
|
245
|
+
).replaceAll("\\", "/");
|
|
246
|
+
const sqlitePath = (0, import_path.resolve)(
|
|
247
|
+
sourceRoot,
|
|
248
|
+
"../storage/node-sqlite.js"
|
|
249
|
+
).replaceAll("\\", "/");
|
|
250
|
+
return [
|
|
251
|
+
`export { NodeJsonlSessionStore } from ${JSON.stringify(jsonlPath)};`,
|
|
252
|
+
`export { NodeSqliteSessionStore } from ${JSON.stringify(sqlitePath)};`,
|
|
253
|
+
""
|
|
254
|
+
].join("\n");
|
|
255
|
+
}
|
|
172
256
|
function allCompiledAgents(agents) {
|
|
173
257
|
return Object.values(agents).flatMap((agent) => [
|
|
174
258
|
agent,
|
|
175
259
|
...Object.values(agent.subagents ?? {})
|
|
176
260
|
]);
|
|
177
261
|
}
|
|
178
|
-
function createProviderRuntimeSource(providerNames) {
|
|
262
|
+
function createProviderRuntimeSource(providerNames, target) {
|
|
179
263
|
const providersDirectory = (0, import_path.resolve)(
|
|
180
264
|
(0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl)),
|
|
181
265
|
"../providers"
|
|
@@ -186,6 +270,11 @@ function createProviderRuntimeSource(providerNames) {
|
|
|
186
270
|
if (!(0, import_catalog.isBuiltInProvider)(name)) {
|
|
187
271
|
throw new Error(`Provider "${name}" is not built in.`);
|
|
188
272
|
}
|
|
273
|
+
if (target !== "node" && (name === "bedrock" || name === "vertexai")) {
|
|
274
|
+
throw new Error(
|
|
275
|
+
`Provider "${name}" is not available for the ${target} target.`
|
|
276
|
+
);
|
|
277
|
+
}
|
|
189
278
|
const descriptor = import_catalog.builtInProviderCatalog[name];
|
|
190
279
|
const localName = `provider${index}`;
|
|
191
280
|
imports.push(
|
|
@@ -28,7 +28,7 @@ var import_fs = require("fs");
|
|
|
28
28
|
var import_path = require("path");
|
|
29
29
|
var import_esbuild = require("esbuild");
|
|
30
30
|
var import_catalog = require("../providers/catalog.js");
|
|
31
|
-
function compileRegistry(registrations, registryRoot, actionRuntime = "native") {
|
|
31
|
+
function compileRegistry(registrations, registryRoot, actionRuntime = "native", target = "node") {
|
|
32
32
|
if (!registrations || typeof registrations !== "object" || Array.isArray(registrations)) {
|
|
33
33
|
throw new TypeError(
|
|
34
34
|
'orcha.init() requires an "agents" object of registered folder paths.'
|
|
@@ -51,14 +51,16 @@ function compileRegistry(registrations, registryRoot, actionRuntime = "native")
|
|
|
51
51
|
subagentKey,
|
|
52
52
|
registeredPath,
|
|
53
53
|
registryRoot,
|
|
54
|
-
actionRuntime
|
|
54
|
+
actionRuntime,
|
|
55
|
+
target
|
|
55
56
|
);
|
|
56
57
|
}
|
|
57
58
|
const parent = compileAgent(
|
|
58
59
|
key,
|
|
59
60
|
normalized.path,
|
|
60
61
|
registryRoot,
|
|
61
|
-
actionRuntime
|
|
62
|
+
actionRuntime,
|
|
63
|
+
target
|
|
62
64
|
);
|
|
63
65
|
agents[key] = Object.freeze({
|
|
64
66
|
...parent,
|
|
@@ -108,7 +110,7 @@ function normalizeAgentRegistration(key, registration) {
|
|
|
108
110
|
subagents: registration.subagents ?? {}
|
|
109
111
|
};
|
|
110
112
|
}
|
|
111
|
-
function compileAgent(key, registeredPath, registryRoot, actionRuntime) {
|
|
113
|
+
function compileAgent(key, registeredPath, registryRoot, actionRuntime, target) {
|
|
112
114
|
const name = key;
|
|
113
115
|
const sourceDirectory = (0, import_path.resolve)(registryRoot, registeredPath);
|
|
114
116
|
const configPath = (0, import_path.resolve)(sourceDirectory, "index.json");
|
|
@@ -195,14 +197,19 @@ function compileAgent(key, registeredPath, registryRoot, actionRuntime) {
|
|
|
195
197
|
reasoningLevel: configuration.reasoningLevel,
|
|
196
198
|
outputType: configuration.outputType ?? "text",
|
|
197
199
|
outputSchema: configuration.outputSchema,
|
|
198
|
-
actions: compileActions(
|
|
200
|
+
actions: compileActions(
|
|
201
|
+
name,
|
|
202
|
+
sourceDirectory,
|
|
203
|
+
actionRuntime,
|
|
204
|
+
target
|
|
205
|
+
),
|
|
199
206
|
skills: compileSkills(name, sourceDirectory),
|
|
200
207
|
evaluations: compileEvaluations(name, sourceDirectory),
|
|
201
208
|
subagentPolicy: configuration.subagents ? Object.freeze({ ...configuration.subagents }) : void 0,
|
|
202
209
|
subagents: Object.freeze({})
|
|
203
210
|
});
|
|
204
211
|
}
|
|
205
|
-
function compileActions(agentName, sourceDirectory, actionRuntime) {
|
|
212
|
+
function compileActions(agentName, sourceDirectory, actionRuntime, target) {
|
|
206
213
|
const actionsDirectory = (0, import_path.resolve)(sourceDirectory, "actions");
|
|
207
214
|
if (!(0, import_fs.existsSync)(actionsDirectory)) {
|
|
208
215
|
return {};
|
|
@@ -306,7 +313,8 @@ function compileActions(agentName, sourceDirectory, actionRuntime) {
|
|
|
306
313
|
agentName,
|
|
307
314
|
entry.name,
|
|
308
315
|
actionsDirectory,
|
|
309
|
-
actionRuntime
|
|
316
|
+
actionRuntime,
|
|
317
|
+
target
|
|
310
318
|
) : void 0;
|
|
311
319
|
actions[configuration.name] = Object.freeze({
|
|
312
320
|
...configuration,
|
|
@@ -498,7 +506,7 @@ function validateEvaluationConfiguration(agentName, registrationName, configurat
|
|
|
498
506
|
names.add(metric.name);
|
|
499
507
|
}
|
|
500
508
|
}
|
|
501
|
-
function compileLocalAction(agentName, directoryName, actionsDirectory, actionRuntime) {
|
|
509
|
+
function compileLocalAction(agentName, directoryName, actionsDirectory, actionRuntime, target) {
|
|
502
510
|
const entryPath = (0, import_path.resolve)(actionsDirectory, directoryName, "index.js");
|
|
503
511
|
if (!(0, import_fs.existsSync)(entryPath)) {
|
|
504
512
|
throw new Error(
|
|
@@ -513,7 +521,7 @@ function compileLocalAction(agentName, directoryName, actionsDirectory, actionRu
|
|
|
513
521
|
write: false,
|
|
514
522
|
format: "iife",
|
|
515
523
|
globalName: "__orchaActionModule",
|
|
516
|
-
platform: actionRuntime === "native" ? "node" : "
|
|
524
|
+
platform: actionRuntime === "native" && target === "node" ? "node" : "browser",
|
|
517
525
|
target: "es2022",
|
|
518
526
|
logLevel: "silent"
|
|
519
527
|
});
|
package/dist-cjs/errors.js
CHANGED
|
@@ -19,7 +19,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var errors_exports = {};
|
|
21
21
|
__export(errors_exports, {
|
|
22
|
-
OrchaError: () => OrchaError
|
|
22
|
+
OrchaError: () => OrchaError,
|
|
23
|
+
describeProviderError: () => describeProviderError,
|
|
24
|
+
isRetryableProviderConnectionError: () => isRetryableProviderConnectionError
|
|
23
25
|
});
|
|
24
26
|
module.exports = __toCommonJS(errors_exports);
|
|
25
27
|
class OrchaError extends Error {
|
|
@@ -34,7 +36,95 @@ class OrchaError extends Error {
|
|
|
34
36
|
this.details = options.details;
|
|
35
37
|
}
|
|
36
38
|
}
|
|
39
|
+
function describeProviderError(error) {
|
|
40
|
+
const rootMessage = errorMessage(error);
|
|
41
|
+
const cause = deepestUsefulCause(error);
|
|
42
|
+
if (!cause) {
|
|
43
|
+
return { message: rootMessage };
|
|
44
|
+
}
|
|
45
|
+
const causeMessage = errorMessage(cause);
|
|
46
|
+
const causeCode = stringOrNumberField(cause, "code");
|
|
47
|
+
const syscall = stringField(cause, "syscall");
|
|
48
|
+
const hostname = stringField(cause, "hostname");
|
|
49
|
+
const explanation = causeMessage !== rootMessage ? causeMessage : causeCode ? String(causeCode) : void 0;
|
|
50
|
+
const details = {
|
|
51
|
+
...causeCode !== void 0 ? { causeCode } : {},
|
|
52
|
+
...syscall ? { syscall } : {},
|
|
53
|
+
...hostname ? { hostname } : {},
|
|
54
|
+
...explanation ? { causeMessage: explanation } : {}
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
message: explanation ? `${rootMessage}: ${explanation}` : rootMessage,
|
|
58
|
+
...Object.keys(details).length > 0 ? { details } : {}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function isRetryableProviderConnectionError(error) {
|
|
62
|
+
const retryableCodes = /* @__PURE__ */ new Set([
|
|
63
|
+
"UND_ERR_CONNECT_TIMEOUT",
|
|
64
|
+
"EAI_AGAIN",
|
|
65
|
+
"ENETUNREACH",
|
|
66
|
+
"EHOSTUNREACH",
|
|
67
|
+
"ECONNREFUSED"
|
|
68
|
+
]);
|
|
69
|
+
const pending = [error];
|
|
70
|
+
const visited = /* @__PURE__ */ new Set();
|
|
71
|
+
while (pending.length > 0 && visited.size < 8) {
|
|
72
|
+
const current = pending.shift();
|
|
73
|
+
if (typeof current !== "object" || current === null || visited.has(current)) {
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
visited.add(current);
|
|
77
|
+
const record = current;
|
|
78
|
+
if (typeof record.code === "string" && retryableCodes.has(record.code)) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (record.cause !== void 0) pending.push(record.cause);
|
|
82
|
+
if (Array.isArray(record.errors)) pending.push(...record.errors);
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
function deepestUsefulCause(error) {
|
|
87
|
+
let current = error;
|
|
88
|
+
let useful;
|
|
89
|
+
const visited = /* @__PURE__ */ new Set();
|
|
90
|
+
for (let depth = 0; depth < 5; depth += 1) {
|
|
91
|
+
if (typeof current !== "object" || current === null || visited.has(current)) {
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
visited.add(current);
|
|
95
|
+
const record = current;
|
|
96
|
+
const next = record.cause ?? (Array.isArray(record.errors) ? record.errors[0] : void 0);
|
|
97
|
+
if (next === void 0) break;
|
|
98
|
+
useful = next;
|
|
99
|
+
current = next;
|
|
100
|
+
}
|
|
101
|
+
return useful;
|
|
102
|
+
}
|
|
103
|
+
function errorMessage(error) {
|
|
104
|
+
if (error instanceof Error && error.message.trim()) {
|
|
105
|
+
return error.message.trim();
|
|
106
|
+
}
|
|
107
|
+
if (typeof error === "object" && error !== null) {
|
|
108
|
+
const message = error.message;
|
|
109
|
+
if (typeof message === "string" && message.trim()) {
|
|
110
|
+
return message.trim();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return String(error);
|
|
114
|
+
}
|
|
115
|
+
function stringField(value, key) {
|
|
116
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
117
|
+
const field = value[key];
|
|
118
|
+
return typeof field === "string" && field.trim() ? field : void 0;
|
|
119
|
+
}
|
|
120
|
+
function stringOrNumberField(value, key) {
|
|
121
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
122
|
+
const field = value[key];
|
|
123
|
+
return typeof field === "string" || typeof field === "number" ? field : void 0;
|
|
124
|
+
}
|
|
37
125
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
126
|
0 && (module.exports = {
|
|
39
|
-
OrchaError
|
|
127
|
+
OrchaError,
|
|
128
|
+
describeProviderError,
|
|
129
|
+
isRetryableProviderConnectionError
|
|
40
130
|
});
|
package/dist-cjs/file-content.js
CHANGED
|
@@ -24,8 +24,6 @@ __export(file_content_exports, {
|
|
|
24
24
|
readLocalFileContent: () => readLocalFileContent
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(file_content_exports);
|
|
27
|
-
var import_promises = require("fs/promises");
|
|
28
|
-
var import_path = require("path");
|
|
29
27
|
const MIME_TYPES = {
|
|
30
28
|
".csv": "text/csv",
|
|
31
29
|
".doc": "application/msword",
|
|
@@ -47,8 +45,8 @@ const MIME_TYPES = {
|
|
|
47
45
|
".xls": "application/vnd.ms-excel",
|
|
48
46
|
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
49
47
|
};
|
|
50
|
-
function normalizeLocalFile(filePath, mimeType, projectRoot =
|
|
51
|
-
const absolutePath = (
|
|
48
|
+
function normalizeLocalFile(filePath, mimeType, projectRoot = ".") {
|
|
49
|
+
const absolutePath = resolvePortablePath(projectRoot, filePath);
|
|
52
50
|
return {
|
|
53
51
|
type: "file",
|
|
54
52
|
filePath: absolutePath,
|
|
@@ -72,20 +70,22 @@ function normalizeUrlContent(url, mimeType) {
|
|
|
72
70
|
};
|
|
73
71
|
}
|
|
74
72
|
async function readLocalFileContent(content) {
|
|
75
|
-
const
|
|
73
|
+
const fsModule = "fs/promises";
|
|
74
|
+
const { readFile } = await import(fsModule);
|
|
75
|
+
const bytes = await readFile(content.filePath);
|
|
76
76
|
const base64 = bytes.toString("base64");
|
|
77
77
|
return {
|
|
78
78
|
bytes,
|
|
79
79
|
base64,
|
|
80
80
|
dataUri: `data:${content.mimeType};base64,${base64}`,
|
|
81
|
-
fileName: (
|
|
81
|
+
fileName: portableBasename(content.filePath)
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
function normalizeMimeType(mimeType, source) {
|
|
85
85
|
if (mimeType?.trim()) {
|
|
86
86
|
return mimeType.trim().toLowerCase();
|
|
87
87
|
}
|
|
88
|
-
const inferred = MIME_TYPES[(
|
|
88
|
+
const inferred = MIME_TYPES[portableExtension(source).toLowerCase()];
|
|
89
89
|
if (!inferred) {
|
|
90
90
|
throw new Error(
|
|
91
91
|
`Could not infer a MIME type for "${source}". Provide mimeType explicitly.`
|
|
@@ -93,6 +93,41 @@ function normalizeMimeType(mimeType, source) {
|
|
|
93
93
|
}
|
|
94
94
|
return inferred;
|
|
95
95
|
}
|
|
96
|
+
function resolvePortablePath(root, filePath) {
|
|
97
|
+
if (/^(?:\/|[a-zA-Z]:[\\/])/.test(filePath)) {
|
|
98
|
+
return normalizePath(filePath);
|
|
99
|
+
}
|
|
100
|
+
return normalizePath(`${root.replace(/[\\/]+$/, "")}/${filePath}`);
|
|
101
|
+
}
|
|
102
|
+
function normalizePath(path) {
|
|
103
|
+
const separator = path.includes("\\") ? "\\" : "/";
|
|
104
|
+
const prefix = path.match(/^(?:[a-zA-Z]:)?[\\/]/)?.[0] ?? "";
|
|
105
|
+
const source = prefix ? path.slice(prefix.length) : path;
|
|
106
|
+
const parts = [];
|
|
107
|
+
for (const part of source.split(/[\\/]+/)) {
|
|
108
|
+
if (!part || part === ".") {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if (part === "..") {
|
|
112
|
+
if (parts.length > 0 && parts.at(-1) !== "..") {
|
|
113
|
+
parts.pop();
|
|
114
|
+
} else if (!prefix) {
|
|
115
|
+
parts.push(part);
|
|
116
|
+
}
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
parts.push(part);
|
|
120
|
+
}
|
|
121
|
+
return `${prefix}${parts.join(separator)}` || ".";
|
|
122
|
+
}
|
|
123
|
+
function portableBasename(path) {
|
|
124
|
+
return path.split(/[\\/]/).at(-1) ?? path;
|
|
125
|
+
}
|
|
126
|
+
function portableExtension(path) {
|
|
127
|
+
const name = portableBasename(path);
|
|
128
|
+
const index = name.lastIndexOf(".");
|
|
129
|
+
return index > 0 ? name.slice(index) : "";
|
|
130
|
+
}
|
|
96
131
|
// Annotate the CommonJS export names for ESM import in node:
|
|
97
132
|
0 && (module.exports = {
|
|
98
133
|
normalizeLocalFile,
|
package/dist-cjs/index.js
CHANGED
|
@@ -16,28 +16,23 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
16
|
}
|
|
17
17
|
return to;
|
|
18
18
|
};
|
|
19
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
19
20
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
21
|
var index_exports = {};
|
|
21
22
|
__export(index_exports, {
|
|
22
23
|
NodeJsonlSessionStore: () => import_node_jsonl.NodeJsonlSessionStore,
|
|
23
24
|
NodeSqliteSessionStore: () => import_node_sqlite.NodeSqliteSessionStore,
|
|
24
|
-
OrchaError: () => import_errors.OrchaError,
|
|
25
|
-
exportSessionJsonl: () => import_migrate.exportSessionJsonl,
|
|
26
|
-
migrateSessionStore: () => import_migrate.migrateSessionStore,
|
|
27
25
|
orcha: () => import_orcha.orcha
|
|
28
26
|
});
|
|
29
27
|
module.exports = __toCommonJS(index_exports);
|
|
30
28
|
var import_orcha = require("./orcha.js");
|
|
31
|
-
|
|
29
|
+
__reExport(index_exports, require("./runtime-entry.js"), module.exports);
|
|
32
30
|
var import_node_jsonl = require("./storage/node-jsonl.js");
|
|
33
31
|
var import_node_sqlite = require("./storage/node-sqlite.js");
|
|
34
|
-
var import_migrate = require("./storage/migrate.js");
|
|
35
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
36
33
|
0 && (module.exports = {
|
|
37
34
|
NodeJsonlSessionStore,
|
|
38
35
|
NodeSqliteSessionStore,
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
migrateSessionStore,
|
|
42
|
-
orcha
|
|
36
|
+
orcha,
|
|
37
|
+
...require("./runtime-entry.js")
|
|
43
38
|
});
|
|
@@ -26,12 +26,16 @@ var import_path = require("path");
|
|
|
26
26
|
var import_build_project = require("../compiler/build-project.js");
|
|
27
27
|
function orchaPlugin(options = {}) {
|
|
28
28
|
const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
|
|
29
|
-
const generatedBundle = (0, import_path.resolve)(projectRoot, ".orcha/dist/bundle.js");
|
|
30
29
|
return {
|
|
31
30
|
name: "orchajs",
|
|
32
31
|
setup(builder) {
|
|
32
|
+
const target = builder.initialOptions.platform === "browser" ? "browser" : "node";
|
|
33
|
+
const generatedBundle = (0, import_path.resolve)(
|
|
34
|
+
projectRoot,
|
|
35
|
+
`.orcha/dist/${target === "node" ? "bundle.js" : "bundle.browser.js"}`
|
|
36
|
+
);
|
|
33
37
|
builder.onStart(async () => {
|
|
34
|
-
await (0, import_build_project.buildProject)({ projectRoot });
|
|
38
|
+
await (0, import_build_project.buildProject)({ projectRoot, target });
|
|
35
39
|
});
|
|
36
40
|
builder.onResolve({ filter: /^orchajs$/ }, () => ({
|
|
37
41
|
path: generatedBundle
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var expo_exports = {};
|
|
21
|
+
__export(expo_exports, {
|
|
22
|
+
withOrchaExpo: () => import_metro.withOrchaMetro
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(expo_exports);
|
|
25
|
+
var import_metro = require("./metro.js");
|
|
26
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
+
0 && (module.exports = {
|
|
28
|
+
withOrchaExpo
|
|
29
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict"; const __orchaImportMetaUrl = require("url").pathToFileURL(__filename).href;
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
var metro_exports = {};
|
|
21
|
+
__export(metro_exports, {
|
|
22
|
+
withOrchaMetro: () => withOrchaMetro
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(metro_exports);
|
|
25
|
+
var import_path = require("path");
|
|
26
|
+
var import_runtime_build = require("./runtime-build.js");
|
|
27
|
+
async function withOrchaMetro(configuration, options = {}) {
|
|
28
|
+
const projectRoot = (0, import_path.resolve)(options.projectRoot ?? process.cwd());
|
|
29
|
+
await (0, import_runtime_build.queueRuntimeBuild)(projectRoot, "react-native");
|
|
30
|
+
if (process.env.NODE_ENV !== "production") {
|
|
31
|
+
(0, import_runtime_build.watchRuntimeTargets)(projectRoot, ["react-native"]);
|
|
32
|
+
}
|
|
33
|
+
const existingResolver = configuration.resolver?.resolveRequest;
|
|
34
|
+
return {
|
|
35
|
+
...configuration,
|
|
36
|
+
resolver: {
|
|
37
|
+
...configuration.resolver,
|
|
38
|
+
resolveRequest(context, moduleName, platform) {
|
|
39
|
+
const requestedModule = moduleName === "orchajs" ? (0, import_runtime_build.generatedBundlePath)(projectRoot, "react-native") : moduleName;
|
|
40
|
+
if (existingResolver) {
|
|
41
|
+
return existingResolver(context, requestedModule, platform);
|
|
42
|
+
}
|
|
43
|
+
return context.resolveRequest(context, requestedModule, platform);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
49
|
+
0 && (module.exports = {
|
|
50
|
+
withOrchaMetro
|
|
51
|
+
});
|