orchajs 0.20.2 → 0.21.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 +129 -0
- 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-agents-template.d.ts +1 -1
- package/dist/cli-agents-template.js +22 -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/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 +8 -5
- package/dist/runtime/compiler-hook.d.ts +5 -0
- package/dist/runtime/compiler-hook.js +8 -0
- package/dist/runtime/create-orcha.d.ts +2 -1
- package/dist/runtime/create-orcha.js +15 -19
- 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 +3 -1
- package/dist-cjs/browser.js +48 -0
- package/dist-cjs/cli-agents-template.js +22 -0
- package/dist-cjs/compiler/build-project.js +97 -8
- package/dist-cjs/compiler/compile.js +17 -9
- 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 +8 -6
- package/dist-cjs/runtime/compiler-hook.js +37 -0
- package/dist-cjs/runtime/create-orcha.js +18 -21
- 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
|
@@ -4,9 +4,14 @@ import { dirname, resolve } from "node:path";
|
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import { build as bundleEntry } from "esbuild";
|
|
6
6
|
import { orcha } from "../orcha.js";
|
|
7
|
+
import { setRegistryCompiler } from "../runtime/compiler-hook.js";
|
|
8
|
+
import { compileRegistry } from "./compile.js";
|
|
7
9
|
import { builtInProviderCatalog, isBuiltInProvider, } from "../providers/catalog.js";
|
|
10
|
+
let registryImportSequence = 0;
|
|
8
11
|
export async function buildProject(options = {}) {
|
|
9
12
|
const projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
13
|
+
const target = options.target ?? "node";
|
|
14
|
+
setRegistryCompiler((configuration, compilerProjectRoot) => compileRegistry(configuration.agents, resolve(compilerProjectRoot, "orcha"), configuration.actions?.runtime ?? "native", target));
|
|
10
15
|
const registryPath = resolve(projectRoot, "orcha/index.ts");
|
|
11
16
|
if (!existsSync(registryPath)) {
|
|
12
17
|
throw new Error('Missing "orcha/index.ts". Run "orcha init" first.');
|
|
@@ -14,7 +19,7 @@ export async function buildProject(options = {}) {
|
|
|
14
19
|
const temporaryDirectory = resolve(projectRoot, ".orcha/.build");
|
|
15
20
|
const registryBundlePath = resolve(temporaryDirectory, "registry.mjs");
|
|
16
21
|
const productionEntryPath = resolve(temporaryDirectory, "production-entry.mjs");
|
|
17
|
-
const outputPath = resolve(projectRoot,
|
|
22
|
+
const outputPath = resolve(projectRoot, `.orcha/dist/${bundleFileName(target)}`);
|
|
18
23
|
const manifestPath = resolve(projectRoot, ".orcha/dist/manifest.json");
|
|
19
24
|
await mkdir(temporaryDirectory, { recursive: true });
|
|
20
25
|
await mkdir(dirname(outputPath), { recursive: true });
|
|
@@ -34,7 +39,7 @@ export async function buildProject(options = {}) {
|
|
|
34
39
|
process.env.ORCHA_COMPILING = "1";
|
|
35
40
|
process.env.ORCHA_PROJECT_ROOT = projectRoot;
|
|
36
41
|
try {
|
|
37
|
-
await import(`${pathToFileURL(registryBundlePath).href}?
|
|
42
|
+
await import(`${pathToFileURL(registryBundlePath).href}?build=${Date.now()}-${registryImportSequence++}`);
|
|
38
43
|
}
|
|
39
44
|
finally {
|
|
40
45
|
if (previousCompiling === undefined) {
|
|
@@ -51,11 +56,19 @@ export async function buildProject(options = {}) {
|
|
|
51
56
|
}
|
|
52
57
|
}
|
|
53
58
|
const compiledBundle = orcha.getCompiledBundle();
|
|
59
|
+
if (target !== "node" &&
|
|
60
|
+
compiledBundle.actionRuntime === "sandbox") {
|
|
61
|
+
throw new Error(`The ${target} target supports precompiled native actions only. Set actions.runtime to "native".`);
|
|
62
|
+
}
|
|
54
63
|
const runtimeFactoryPath = resolve(dirname(fileURLToPath(import.meta.url)), "../runtime/create-orcha.js").replaceAll("\\", "/");
|
|
64
|
+
const runtimePlatformPath = resolve(dirname(fileURLToPath(import.meta.url)), `../runtime/platform-${target}.js`).replaceAll("\\", "/");
|
|
65
|
+
const runtimeEntryPath = resolve(dirname(fileURLToPath(import.meta.url)), "../runtime-entry.js").replaceAll("\\", "/");
|
|
55
66
|
const providerDispatcherPath = resolve(dirname(fileURLToPath(import.meta.url)), "../providers/dispatcher.js").replaceAll("\\", "/");
|
|
56
67
|
const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox"
|
|
57
68
|
? createSandboxRuntimeSource()
|
|
58
69
|
: "";
|
|
70
|
+
const platformActionRuntimeSource = createPlatformActionRuntimeSource(target);
|
|
71
|
+
const nodeStorageExports = target === "node" ? createNodeStorageExports() : "";
|
|
59
72
|
const includedProviders = [
|
|
60
73
|
...new Set(allCompiledAgents(compiledBundle.agents).flatMap((agent) => [
|
|
61
74
|
agent.provider,
|
|
@@ -64,18 +77,22 @@ export async function buildProject(options = {}) {
|
|
|
64
77
|
.map((evaluation) => evaluation.provider),
|
|
65
78
|
])),
|
|
66
79
|
];
|
|
67
|
-
const providerRuntimeSource = createProviderRuntimeSource(includedProviders);
|
|
80
|
+
const providerRuntimeSource = createProviderRuntimeSource(includedProviders, target);
|
|
68
81
|
const needsNodeRequire = compiledBundle.actionRuntime === "sandbox" ||
|
|
69
82
|
includedProviders.includes("vertexai") ||
|
|
70
83
|
includedProviders.includes("bedrock");
|
|
71
84
|
await writeFile(productionEntryPath, [
|
|
72
85
|
`import { createOrcha } from ${JSON.stringify(runtimeFactoryPath)};`,
|
|
86
|
+
`import { ${runtimePlatformExport(target)} as runtimePlatform } from ${JSON.stringify(runtimePlatformPath)};`,
|
|
73
87
|
`import { createProviderResponseGenerator } from ${JSON.stringify(providerDispatcherPath)};`,
|
|
88
|
+
`export * from ${JSON.stringify(runtimeEntryPath)};`,
|
|
89
|
+
nodeStorageExports,
|
|
74
90
|
providerRuntimeSource,
|
|
91
|
+
platformActionRuntimeSource,
|
|
75
92
|
sandboxRuntimeSource,
|
|
76
93
|
`const compiledBundle = ${JSON.stringify(compiledBundle)};`,
|
|
77
94
|
"const generateProviderResponse = createProviderResponseGenerator(includedProviders);",
|
|
78
|
-
"export const orcha = createOrcha(() => compiledBundle, generateProviderResponse);",
|
|
95
|
+
"export const orcha = createOrcha(() => compiledBundle, generateProviderResponse, runtimePlatform);",
|
|
79
96
|
"export default orcha;",
|
|
80
97
|
"",
|
|
81
98
|
].join("\n"), "utf8");
|
|
@@ -84,14 +101,18 @@ export async function buildProject(options = {}) {
|
|
|
84
101
|
outfile: outputPath,
|
|
85
102
|
bundle: true,
|
|
86
103
|
format: "esm",
|
|
87
|
-
platform: "node",
|
|
88
|
-
target: "
|
|
104
|
+
platform: target === "node" ? "node" : "browser",
|
|
105
|
+
target: target === "node"
|
|
106
|
+
? "node18"
|
|
107
|
+
: target === "browser"
|
|
108
|
+
? ["chrome110", "firefox110", "safari16"]
|
|
109
|
+
: "es2022",
|
|
89
110
|
minify: true,
|
|
90
111
|
legalComments: "none",
|
|
91
112
|
define: {
|
|
92
113
|
"process.env.ORCHA_INCLUDE_SANDBOX": JSON.stringify(compiledBundle.actionRuntime === "sandbox" ? "1" : "0"),
|
|
93
114
|
},
|
|
94
|
-
...(needsNodeRequire
|
|
115
|
+
...(needsNodeRequire && target === "node"
|
|
95
116
|
? {
|
|
96
117
|
banner: {
|
|
97
118
|
js: [
|
|
@@ -101,6 +122,13 @@ export async function buildProject(options = {}) {
|
|
|
101
122
|
},
|
|
102
123
|
}
|
|
103
124
|
: {}),
|
|
125
|
+
...(target === "react-native"
|
|
126
|
+
? {
|
|
127
|
+
external: [
|
|
128
|
+
"@react-native-async-storage/async-storage",
|
|
129
|
+
],
|
|
130
|
+
}
|
|
131
|
+
: {}),
|
|
104
132
|
logLevel: "silent",
|
|
105
133
|
});
|
|
106
134
|
await writeFile(manifestPath, `${JSON.stringify(compiledBundle)}\n`, "utf8");
|
|
@@ -113,6 +141,18 @@ export async function buildProject(options = {}) {
|
|
|
113
141
|
});
|
|
114
142
|
}
|
|
115
143
|
}
|
|
144
|
+
function bundleFileName(target) {
|
|
145
|
+
return target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
146
|
+
}
|
|
147
|
+
function runtimePlatformExport(target) {
|
|
148
|
+
if (target === "browser") {
|
|
149
|
+
return "browserRuntimePlatform";
|
|
150
|
+
}
|
|
151
|
+
if (target === "react-native") {
|
|
152
|
+
return "reactNativeRuntimePlatform";
|
|
153
|
+
}
|
|
154
|
+
return "nodeRuntimePlatform";
|
|
155
|
+
}
|
|
116
156
|
function createSandboxRuntimeSource() {
|
|
117
157
|
const runtimeDirectory = dirname(fileURLToPath(import.meta.url));
|
|
118
158
|
const executePath = resolve(runtimeDirectory, "../runtime/actions/execute.js").replaceAll("\\", "/");
|
|
@@ -124,13 +164,36 @@ function createSandboxRuntimeSource() {
|
|
|
124
164
|
"",
|
|
125
165
|
].join("\n");
|
|
126
166
|
}
|
|
167
|
+
function createPlatformActionRuntimeSource(target) {
|
|
168
|
+
const runtimeDirectory = dirname(fileURLToPath(import.meta.url));
|
|
169
|
+
const executePath = resolve(runtimeDirectory, "../runtime/actions/execute.js").replaceAll("\\", "/");
|
|
170
|
+
const nativePath = resolve(runtimeDirectory, target === "node"
|
|
171
|
+
? "../runtime/actions/native.js"
|
|
172
|
+
: "../runtime/actions/browser-native.js").replaceAll("\\", "/");
|
|
173
|
+
return [
|
|
174
|
+
`import { setNativeRuntimeLoader } from ${JSON.stringify(executePath)};`,
|
|
175
|
+
`import { executeNativeAction } from ${JSON.stringify(nativePath)};`,
|
|
176
|
+
"setNativeRuntimeLoader(async () => ({ executeNativeAction }));",
|
|
177
|
+
"",
|
|
178
|
+
].join("\n");
|
|
179
|
+
}
|
|
180
|
+
function createNodeStorageExports() {
|
|
181
|
+
const sourceRoot = dirname(fileURLToPath(import.meta.url));
|
|
182
|
+
const jsonlPath = resolve(sourceRoot, "../storage/node-jsonl.js").replaceAll("\\", "/");
|
|
183
|
+
const sqlitePath = resolve(sourceRoot, "../storage/node-sqlite.js").replaceAll("\\", "/");
|
|
184
|
+
return [
|
|
185
|
+
`export { NodeJsonlSessionStore } from ${JSON.stringify(jsonlPath)};`,
|
|
186
|
+
`export { NodeSqliteSessionStore } from ${JSON.stringify(sqlitePath)};`,
|
|
187
|
+
"",
|
|
188
|
+
].join("\n");
|
|
189
|
+
}
|
|
127
190
|
function allCompiledAgents(agents) {
|
|
128
191
|
return Object.values(agents).flatMap((agent) => [
|
|
129
192
|
agent,
|
|
130
193
|
...Object.values(agent.subagents ?? {}),
|
|
131
194
|
]);
|
|
132
195
|
}
|
|
133
|
-
function createProviderRuntimeSource(providerNames) {
|
|
196
|
+
function createProviderRuntimeSource(providerNames, target) {
|
|
134
197
|
const providersDirectory = resolve(dirname(fileURLToPath(import.meta.url)), "../providers");
|
|
135
198
|
const imports = [];
|
|
136
199
|
const entries = [];
|
|
@@ -138,6 +201,10 @@ function createProviderRuntimeSource(providerNames) {
|
|
|
138
201
|
if (!isBuiltInProvider(name)) {
|
|
139
202
|
throw new Error(`Provider "${name}" is not built in.`);
|
|
140
203
|
}
|
|
204
|
+
if (target !== "node" &&
|
|
205
|
+
(name === "bedrock" || name === "vertexai")) {
|
|
206
|
+
throw new Error(`Provider "${name}" is not available for the ${target} target.`);
|
|
207
|
+
}
|
|
141
208
|
const descriptor = builtInProviderCatalog[name];
|
|
142
209
|
const localName = `provider${index}`;
|
|
143
210
|
imports.push(`import { ${descriptor.exportName} as ${localName} } from ${JSON.stringify(resolve(providersDirectory, descriptor.moduleFile))};`);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { AgentRegistration, CompiledBundle } from "../types.js";
|
|
2
|
-
export declare function compileRegistry(registrations: Record<string, AgentRegistration>, registryRoot: string, actionRuntime?: "native" | "sandbox"): CompiledBundle;
|
|
2
|
+
export declare function compileRegistry(registrations: Record<string, AgentRegistration>, registryRoot: string, actionRuntime?: "native" | "sandbox", target?: "node" | "browser" | "react-native"): CompiledBundle;
|
|
3
3
|
export declare function serializeBundle(bundle: CompiledBundle): string;
|
package/dist/compiler/compile.js
CHANGED
|
@@ -3,7 +3,7 @@ import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { buildSync } from "esbuild";
|
|
5
5
|
import { isBuiltInProvider } from "../providers/catalog.js";
|
|
6
|
-
export function compileRegistry(registrations, registryRoot, actionRuntime = "native") {
|
|
6
|
+
export function compileRegistry(registrations, registryRoot, actionRuntime = "native", target = "node") {
|
|
7
7
|
if (!registrations ||
|
|
8
8
|
typeof registrations !== "object" ||
|
|
9
9
|
Array.isArray(registrations)) {
|
|
@@ -20,9 +20,9 @@ export function compileRegistry(registrations, registryRoot, actionRuntime = "na
|
|
|
20
20
|
if (!subagentKey.trim()) {
|
|
21
21
|
throw new Error(`Agent "${key}" has an empty subagent name.`);
|
|
22
22
|
}
|
|
23
|
-
subagents[subagentKey] = compileAgent(subagentKey, registeredPath, registryRoot, actionRuntime);
|
|
23
|
+
subagents[subagentKey] = compileAgent(subagentKey, registeredPath, registryRoot, actionRuntime, target);
|
|
24
24
|
}
|
|
25
|
-
const parent = compileAgent(key, normalized.path, registryRoot, actionRuntime);
|
|
25
|
+
const parent = compileAgent(key, normalized.path, registryRoot, actionRuntime, target);
|
|
26
26
|
agents[key] = Object.freeze({
|
|
27
27
|
...parent,
|
|
28
28
|
subagentPolicy: Object.keys(subagents).length > 0
|
|
@@ -72,7 +72,7 @@ function normalizeAgentRegistration(key, registration) {
|
|
|
72
72
|
subagents: registration.subagents ?? {},
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
function compileAgent(key, registeredPath, registryRoot, actionRuntime) {
|
|
75
|
+
function compileAgent(key, registeredPath, registryRoot, actionRuntime, target) {
|
|
76
76
|
const name = key;
|
|
77
77
|
const sourceDirectory = resolve(registryRoot, registeredPath);
|
|
78
78
|
const configPath = resolve(sourceDirectory, "index.json");
|
|
@@ -148,7 +148,7 @@ function compileAgent(key, registeredPath, registryRoot, actionRuntime) {
|
|
|
148
148
|
reasoningLevel: configuration.reasoningLevel,
|
|
149
149
|
outputType: configuration.outputType ?? "text",
|
|
150
150
|
outputSchema: configuration.outputSchema,
|
|
151
|
-
actions: compileActions(name, sourceDirectory, actionRuntime),
|
|
151
|
+
actions: compileActions(name, sourceDirectory, actionRuntime, target),
|
|
152
152
|
skills: compileSkills(name, sourceDirectory),
|
|
153
153
|
evaluations: compileEvaluations(name, sourceDirectory),
|
|
154
154
|
subagentPolicy: configuration.subagents
|
|
@@ -157,7 +157,7 @@ function compileAgent(key, registeredPath, registryRoot, actionRuntime) {
|
|
|
157
157
|
subagents: Object.freeze({}),
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
-
function compileActions(agentName, sourceDirectory, actionRuntime) {
|
|
160
|
+
function compileActions(agentName, sourceDirectory, actionRuntime, target) {
|
|
161
161
|
const actionsDirectory = resolve(sourceDirectory, "actions");
|
|
162
162
|
if (!existsSync(actionsDirectory)) {
|
|
163
163
|
return {};
|
|
@@ -229,7 +229,7 @@ function compileActions(agentName, sourceDirectory, actionRuntime) {
|
|
|
229
229
|
throw new Error(`Agent "${agentName}" has duplicate action name "${configuration.name}".`);
|
|
230
230
|
}
|
|
231
231
|
const compiledSource = execution === "local"
|
|
232
|
-
? compileLocalAction(agentName, entry.name, actionsDirectory, actionRuntime)
|
|
232
|
+
? compileLocalAction(agentName, entry.name, actionsDirectory, actionRuntime, target)
|
|
233
233
|
: undefined;
|
|
234
234
|
actions[configuration.name] = Object.freeze({
|
|
235
235
|
...configuration,
|
|
@@ -413,7 +413,7 @@ function validateEvaluationConfiguration(agentName, registrationName, configurat
|
|
|
413
413
|
names.add(metric.name);
|
|
414
414
|
}
|
|
415
415
|
}
|
|
416
|
-
function compileLocalAction(agentName, directoryName, actionsDirectory, actionRuntime) {
|
|
416
|
+
function compileLocalAction(agentName, directoryName, actionsDirectory, actionRuntime, target) {
|
|
417
417
|
const entryPath = resolve(actionsDirectory, directoryName, "index.js");
|
|
418
418
|
if (!existsSync(entryPath)) {
|
|
419
419
|
throw new Error(`Local action "${agentName}/${directoryName}" requires index.js.`);
|
|
@@ -426,7 +426,9 @@ function compileLocalAction(agentName, directoryName, actionsDirectory, actionRu
|
|
|
426
426
|
write: false,
|
|
427
427
|
format: "iife",
|
|
428
428
|
globalName: "__orchaActionModule",
|
|
429
|
-
platform: actionRuntime === "native"
|
|
429
|
+
platform: actionRuntime === "native" && target === "node"
|
|
430
|
+
? "node"
|
|
431
|
+
: "browser",
|
|
430
432
|
target: "es2022",
|
|
431
433
|
logLevel: "silent",
|
|
432
434
|
});
|
package/dist/file-content.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { readFile } from "node:fs/promises";
|
|
2
|
-
import { basename, extname, resolve } from "node:path";
|
|
3
1
|
const MIME_TYPES = {
|
|
4
2
|
".csv": "text/csv",
|
|
5
3
|
".doc": "application/msword",
|
|
@@ -21,8 +19,8 @@ const MIME_TYPES = {
|
|
|
21
19
|
".xls": "application/vnd.ms-excel",
|
|
22
20
|
".xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
23
21
|
};
|
|
24
|
-
export function normalizeLocalFile(filePath, mimeType, projectRoot =
|
|
25
|
-
const absolutePath =
|
|
22
|
+
export function normalizeLocalFile(filePath, mimeType, projectRoot = ".") {
|
|
23
|
+
const absolutePath = resolvePortablePath(projectRoot, filePath);
|
|
26
24
|
return {
|
|
27
25
|
type: "file",
|
|
28
26
|
filePath: absolutePath,
|
|
@@ -47,22 +45,60 @@ export function normalizeUrlContent(url, mimeType) {
|
|
|
47
45
|
};
|
|
48
46
|
}
|
|
49
47
|
export async function readLocalFileContent(content) {
|
|
48
|
+
const fsModule = "node:fs/promises";
|
|
49
|
+
const { readFile } = await import(fsModule);
|
|
50
50
|
const bytes = await readFile(content.filePath);
|
|
51
51
|
const base64 = bytes.toString("base64");
|
|
52
52
|
return {
|
|
53
53
|
bytes,
|
|
54
54
|
base64,
|
|
55
55
|
dataUri: `data:${content.mimeType};base64,${base64}`,
|
|
56
|
-
fileName:
|
|
56
|
+
fileName: portableBasename(content.filePath),
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
59
|
function normalizeMimeType(mimeType, source) {
|
|
60
60
|
if (mimeType?.trim()) {
|
|
61
61
|
return mimeType.trim().toLowerCase();
|
|
62
62
|
}
|
|
63
|
-
const inferred = MIME_TYPES[
|
|
63
|
+
const inferred = MIME_TYPES[portableExtension(source).toLowerCase()];
|
|
64
64
|
if (!inferred) {
|
|
65
65
|
throw new Error(`Could not infer a MIME type for "${source}". Provide mimeType explicitly.`);
|
|
66
66
|
}
|
|
67
67
|
return inferred;
|
|
68
68
|
}
|
|
69
|
+
function resolvePortablePath(root, filePath) {
|
|
70
|
+
if (/^(?:\/|[a-zA-Z]:[\\/])/.test(filePath)) {
|
|
71
|
+
return normalizePath(filePath);
|
|
72
|
+
}
|
|
73
|
+
return normalizePath(`${root.replace(/[\\/]+$/, "")}/${filePath}`);
|
|
74
|
+
}
|
|
75
|
+
function normalizePath(path) {
|
|
76
|
+
const separator = path.includes("\\") ? "\\" : "/";
|
|
77
|
+
const prefix = path.match(/^(?:[a-zA-Z]:)?[\\/]/)?.[0] ?? "";
|
|
78
|
+
const source = prefix ? path.slice(prefix.length) : path;
|
|
79
|
+
const parts = [];
|
|
80
|
+
for (const part of source.split(/[\\/]+/)) {
|
|
81
|
+
if (!part || part === ".") {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (part === "..") {
|
|
85
|
+
if (parts.length > 0 && parts.at(-1) !== "..") {
|
|
86
|
+
parts.pop();
|
|
87
|
+
}
|
|
88
|
+
else if (!prefix) {
|
|
89
|
+
parts.push(part);
|
|
90
|
+
}
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
parts.push(part);
|
|
94
|
+
}
|
|
95
|
+
return `${prefix}${parts.join(separator)}` || ".";
|
|
96
|
+
}
|
|
97
|
+
function portableBasename(path) {
|
|
98
|
+
return path.split(/[\\/]/).at(-1) ?? path;
|
|
99
|
+
}
|
|
100
|
+
function portableExtension(path) {
|
|
101
|
+
const name = portableBasename(path);
|
|
102
|
+
const index = name.lastIndexOf(".");
|
|
103
|
+
return index > 0 ? name.slice(index) : "";
|
|
104
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
export { orcha } from "./orcha.js";
|
|
2
|
-
export
|
|
3
|
-
export type { Orcha, OrchaClient } from "./orcha.js";
|
|
2
|
+
export * from "./runtime-entry.js";
|
|
4
3
|
export { NodeJsonlSessionStore } from "./storage/node-jsonl.js";
|
|
5
4
|
export { NodeSqliteSessionStore } from "./storage/node-sqlite.js";
|
|
6
|
-
export { exportSessionJsonl, migrateSessionStore, } from "./storage/migrate.js";
|
|
7
|
-
export type { SessionStoreMigrationResult, } from "./storage/migrate.js";
|
|
8
|
-
export type { ActionConfiguration, AgentTestActionConfiguration, AgentTestActionExpectation, AgentTestActionResponse, AgentTestAssertionResult, AgentTestCaseConfiguration, AgentTestCaseReport, AgentTestCaseSummary, AgentTestExpectation, AgentTestReport, AgentTestTextExpectation, AgentTestValueExpectation, AgentTestWarning, ApiKeyProviderConfiguration, AwsCredentials, AgentContinueInput, AgentConfiguration, AgentContentInput, AgentInput, AgentRegistration, AgentRuntime, ClientCapability, ClientToolCall, CompletedRunResult, CompiledActionManifest, CompiledAgentManifest, CompiledBundle, CompiledEvaluationManifest, CompiledSkillManifest, EvaluationConfiguration, EvaluationMetricConfiguration, EvaluationMetricResult, EvaluationResult, Execution, ExecutionSnapshot, FailedRunResult, FileContent, FilePathContentInput, LocalFileContent, LocalActionRuntimeConfiguration, MessageContent, MessageContentInput, MetadataValue, OrchaErrorCode, OrchaInitConfiguration, PausedRunResult, PaginationOptions, ProjectConfiguration, ProviderConfiguration, ProviderInitConfigurations, ProviderName, BedrockProviderConfiguration, RunError, RunStatus, RunTestsOptions, ResumeInput, RunResult, SessionEvent, SessionEventListOptions, SessionEvents, SessionEventType, SessionHistory, SessionHistoryItem, SessionList, SessionListOptions, SessionMetadata, SessionSnapshot, SessionStatus, SessionStore, SkillConfiguration, SessionUpdate, StreamingRunSnapshot, SubagentConfiguration, TextContent, ToolResult, ToolResumeInput, UrlContentInput, Usage, VertexAIProviderConfiguration, GoogleServiceAccountCredentials, WaitingRunResult, WaitingForSubagentSnapshot, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { orcha } from "./orcha.js";
|
|
2
|
-
export
|
|
2
|
+
export * from "./runtime-entry.js";
|
|
3
3
|
export { NodeJsonlSessionStore } from "./storage/node-jsonl.js";
|
|
4
4
|
export { NodeSqliteSessionStore } from "./storage/node-sqlite.js";
|
|
5
|
-
export { exportSessionJsonl, migrateSessionStore, } from "./storage/migrate.js";
|
|
@@ -6,12 +6,15 @@ import { buildProject } from "../compiler/build-project.js";
|
|
|
6
6
|
*/
|
|
7
7
|
export function orchaPlugin(options = {}) {
|
|
8
8
|
const projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
9
|
-
const generatedBundle = resolve(projectRoot, ".orcha/dist/bundle.js");
|
|
10
9
|
return {
|
|
11
10
|
name: "orchajs",
|
|
12
11
|
setup(builder) {
|
|
12
|
+
const target = builder.initialOptions.platform === "browser"
|
|
13
|
+
? "browser"
|
|
14
|
+
: "node";
|
|
15
|
+
const generatedBundle = resolve(projectRoot, `.orcha/dist/${target === "node" ? "bundle.js" : "bundle.browser.js"}`);
|
|
13
16
|
builder.onStart(async () => {
|
|
14
|
-
await buildProject({ projectRoot });
|
|
17
|
+
await buildProject({ projectRoot, target });
|
|
15
18
|
});
|
|
16
19
|
builder.onResolve({ filter: /^orchajs$/ }, () => ({
|
|
17
20
|
path: generatedBundle,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { withOrchaMetro as withOrchaExpo, type OrchaMetroOptions as OrchaExpoOptions, } from "./metro.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { withOrchaMetro as withOrchaExpo, } from "./metro.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface OrchaMetroOptions {
|
|
2
|
+
projectRoot?: string;
|
|
3
|
+
}
|
|
4
|
+
interface MetroResolverContext {
|
|
5
|
+
resolveRequest(context: MetroResolverContext, moduleName: string, platform: string | null): unknown;
|
|
6
|
+
}
|
|
7
|
+
interface MetroConfiguration {
|
|
8
|
+
resolver?: {
|
|
9
|
+
resolveRequest?: MetroResolverContext["resolveRequest"];
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
}
|
|
14
|
+
export declare function withOrchaMetro<T extends MetroConfiguration>(configuration: T, options?: OrchaMetroOptions): Promise<T>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { generatedBundlePath, queueRuntimeBuild, watchRuntimeTargets, } from "./runtime-build.js";
|
|
3
|
+
export async function withOrchaMetro(configuration, options = {}) {
|
|
4
|
+
const projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
5
|
+
await queueRuntimeBuild(projectRoot, "react-native");
|
|
6
|
+
if (process.env.NODE_ENV !== "production") {
|
|
7
|
+
watchRuntimeTargets(projectRoot, ["react-native"]);
|
|
8
|
+
}
|
|
9
|
+
const existingResolver = configuration.resolver?.resolveRequest;
|
|
10
|
+
return {
|
|
11
|
+
...configuration,
|
|
12
|
+
resolver: {
|
|
13
|
+
...configuration.resolver,
|
|
14
|
+
resolveRequest(context, moduleName, platform) {
|
|
15
|
+
const requestedModule = moduleName === "orchajs"
|
|
16
|
+
? generatedBundlePath(projectRoot, "react-native")
|
|
17
|
+
: moduleName;
|
|
18
|
+
if (existingResolver) {
|
|
19
|
+
return existingResolver(context, requestedModule, platform);
|
|
20
|
+
}
|
|
21
|
+
return context.resolveRequest(context, requestedModule, platform);
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface OrchaNextOptions {
|
|
2
|
+
projectRoot?: string;
|
|
3
|
+
}
|
|
4
|
+
interface NextWebpackContext {
|
|
5
|
+
isServer: boolean;
|
|
6
|
+
nextRuntime?: string;
|
|
7
|
+
}
|
|
8
|
+
interface WebpackConfiguration {
|
|
9
|
+
plugins?: unknown[];
|
|
10
|
+
resolve?: {
|
|
11
|
+
alias?: Record<string, unknown>;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
interface NextConfiguration {
|
|
15
|
+
turbopack?: {
|
|
16
|
+
resolveAlias?: Record<string, unknown>;
|
|
17
|
+
[key: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
webpack?: (configuration: WebpackConfiguration, context: NextWebpackContext) => WebpackConfiguration;
|
|
20
|
+
[key: string]: unknown;
|
|
21
|
+
}
|
|
22
|
+
export declare function withOrcha<T extends NextConfiguration>(configuration?: T, options?: OrchaNextOptions): Promise<T>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { generatedBundlePath, queueRuntimeBuild, watchRuntimeTargets, } from "./runtime-build.js";
|
|
3
|
+
import { OrchaWebpackPlugin } from "./webpack.js";
|
|
4
|
+
export async function withOrcha(configuration = {}, options = {}) {
|
|
5
|
+
const projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
6
|
+
await queueRuntimeBuild(projectRoot, "browser");
|
|
7
|
+
await queueRuntimeBuild(projectRoot, "node");
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
watchRuntimeTargets(projectRoot, ["browser", "node"]);
|
|
10
|
+
}
|
|
11
|
+
const existingWebpack = configuration.webpack;
|
|
12
|
+
return {
|
|
13
|
+
...configuration,
|
|
14
|
+
turbopack: {
|
|
15
|
+
...configuration.turbopack,
|
|
16
|
+
resolveAlias: {
|
|
17
|
+
...configuration.turbopack?.resolveAlias,
|
|
18
|
+
orchajs: {
|
|
19
|
+
browser: generatedBundlePath(projectRoot, "browser"),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
webpack(webpackConfiguration, context) {
|
|
24
|
+
const target = nextTarget(context);
|
|
25
|
+
if (target === "node") {
|
|
26
|
+
return existingWebpack
|
|
27
|
+
? existingWebpack(webpackConfiguration, context)
|
|
28
|
+
: webpackConfiguration;
|
|
29
|
+
}
|
|
30
|
+
const plugin = new OrchaWebpackPlugin({
|
|
31
|
+
projectRoot,
|
|
32
|
+
target,
|
|
33
|
+
});
|
|
34
|
+
webpackConfiguration.resolve ??= {};
|
|
35
|
+
webpackConfiguration.resolve.alias = {
|
|
36
|
+
...webpackConfiguration.resolve.alias,
|
|
37
|
+
orchajs$: plugin.bundlePath,
|
|
38
|
+
};
|
|
39
|
+
webpackConfiguration.plugins = [
|
|
40
|
+
...(webpackConfiguration.plugins ?? []),
|
|
41
|
+
plugin,
|
|
42
|
+
];
|
|
43
|
+
return existingWebpack
|
|
44
|
+
? existingWebpack(webpackConfiguration, context)
|
|
45
|
+
: webpackConfiguration;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function nextTarget(context) {
|
|
50
|
+
return context.isServer && context.nextRuntime !== "edge"
|
|
51
|
+
? "node"
|
|
52
|
+
: "browser";
|
|
53
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export type RuntimeBuildTarget = "node" | "browser" | "react-native";
|
|
2
|
+
export declare function generatedBundlePath(projectRoot: string, target: RuntimeBuildTarget): string;
|
|
3
|
+
export declare function queueRuntimeBuild(projectRoot: string, target: RuntimeBuildTarget): Promise<void>;
|
|
4
|
+
export declare function watchRuntimeTargets(projectRoot: string, targets: RuntimeBuildTarget[]): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { watch } from "chokidar";
|
|
3
|
+
import { buildProject } from "../compiler/build-project.js";
|
|
4
|
+
import { loadProjectEnvironment } from "../env.js";
|
|
5
|
+
let buildQueue = Promise.resolve();
|
|
6
|
+
const watchedTargets = new Set();
|
|
7
|
+
export function generatedBundlePath(projectRoot, target) {
|
|
8
|
+
const fileName = target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
9
|
+
return resolve(projectRoot, ".orcha/dist", fileName);
|
|
10
|
+
}
|
|
11
|
+
export function queueRuntimeBuild(projectRoot, target) {
|
|
12
|
+
const build = buildQueue.then(async () => {
|
|
13
|
+
loadProjectEnvironment(projectRoot);
|
|
14
|
+
await buildProject({ projectRoot, target });
|
|
15
|
+
});
|
|
16
|
+
buildQueue = build.catch(() => undefined);
|
|
17
|
+
return build;
|
|
18
|
+
}
|
|
19
|
+
export function watchRuntimeTargets(projectRoot, targets) {
|
|
20
|
+
const key = `${projectRoot}:${targets.join(",")}`;
|
|
21
|
+
if (watchedTargets.has(key)) {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
watchedTargets.add(key);
|
|
25
|
+
let timer;
|
|
26
|
+
watch(resolve(projectRoot, "orcha"), { ignoreInitial: true }).on("all", () => {
|
|
27
|
+
clearTimeout(timer);
|
|
28
|
+
timer = setTimeout(() => {
|
|
29
|
+
void targets.reduce((pending, target) => pending.then(() => queueRuntimeBuild(projectRoot, target)), Promise.resolve());
|
|
30
|
+
}, 75);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface OrchaVitePluginOptions {
|
|
2
|
+
projectRoot?: string;
|
|
3
|
+
}
|
|
4
|
+
export declare function orchaVitePlugin(options?: OrchaVitePluginOptions): {
|
|
5
|
+
name: string;
|
|
6
|
+
enforce: "pre";
|
|
7
|
+
configResolved(config: {
|
|
8
|
+
root: string;
|
|
9
|
+
}): void;
|
|
10
|
+
buildStart(): Promise<void>;
|
|
11
|
+
configureServer(server: {
|
|
12
|
+
watcher: {
|
|
13
|
+
add(path: string): void;
|
|
14
|
+
on(event: "all", listener: (_event: string, path: string) => void): void;
|
|
15
|
+
};
|
|
16
|
+
ws: {
|
|
17
|
+
send(message: {
|
|
18
|
+
type: "full-reload";
|
|
19
|
+
}): void;
|
|
20
|
+
};
|
|
21
|
+
}): void;
|
|
22
|
+
resolveId(source: string): string | undefined;
|
|
23
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { resolve, sep } from "node:path";
|
|
2
|
+
import { generatedBundlePath, queueRuntimeBuild, } from "./runtime-build.js";
|
|
3
|
+
export function orchaVitePlugin(options = {}) {
|
|
4
|
+
let projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
5
|
+
return {
|
|
6
|
+
name: "orchajs",
|
|
7
|
+
enforce: "pre",
|
|
8
|
+
configResolved(config) {
|
|
9
|
+
projectRoot = resolve(options.projectRoot ?? config.root);
|
|
10
|
+
},
|
|
11
|
+
async buildStart() {
|
|
12
|
+
await queueRuntimeBuild(projectRoot, "browser");
|
|
13
|
+
},
|
|
14
|
+
configureServer(server) {
|
|
15
|
+
const registryDirectory = resolve(projectRoot, "orcha");
|
|
16
|
+
server.watcher.add(registryDirectory);
|
|
17
|
+
server.watcher.on("all", (_event, path) => {
|
|
18
|
+
if (path === registryDirectory ||
|
|
19
|
+
path.startsWith(`${registryDirectory}${sep}`)) {
|
|
20
|
+
void queueRuntimeBuild(projectRoot, "browser").then(() => {
|
|
21
|
+
server.ws.send({ type: "full-reload" });
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
},
|
|
26
|
+
resolveId(source) {
|
|
27
|
+
return source === "orchajs"
|
|
28
|
+
? generatedBundlePath(projectRoot, "browser")
|
|
29
|
+
: undefined;
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RuntimeBuildTarget } from "./runtime-build.js";
|
|
2
|
+
export interface OrchaWebpackPluginOptions {
|
|
3
|
+
projectRoot?: string;
|
|
4
|
+
target?: RuntimeBuildTarget;
|
|
5
|
+
}
|
|
6
|
+
interface WebpackCompiler {
|
|
7
|
+
hooks: {
|
|
8
|
+
beforeCompile: {
|
|
9
|
+
tapPromise(name: string, callback: () => Promise<void>): void;
|
|
10
|
+
};
|
|
11
|
+
afterCompile: {
|
|
12
|
+
tap(name: string, callback: (compilation: {
|
|
13
|
+
contextDependencies: Set<string>;
|
|
14
|
+
}) => void): void;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare class OrchaWebpackPlugin {
|
|
19
|
+
#private;
|
|
20
|
+
constructor(options?: OrchaWebpackPluginOptions);
|
|
21
|
+
get bundlePath(): string;
|
|
22
|
+
apply(compiler: WebpackCompiler): void;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { resolve } from "node:path";
|
|
2
|
+
import { generatedBundlePath, queueRuntimeBuild, } from "./runtime-build.js";
|
|
3
|
+
export class OrchaWebpackPlugin {
|
|
4
|
+
#projectRoot;
|
|
5
|
+
#target;
|
|
6
|
+
constructor(options = {}) {
|
|
7
|
+
this.#projectRoot = resolve(options.projectRoot ?? process.cwd());
|
|
8
|
+
this.#target = options.target ?? "browser";
|
|
9
|
+
}
|
|
10
|
+
get bundlePath() {
|
|
11
|
+
return generatedBundlePath(this.#projectRoot, this.#target);
|
|
12
|
+
}
|
|
13
|
+
apply(compiler) {
|
|
14
|
+
compiler.hooks.beforeCompile.tapPromise("orchajs", async () => {
|
|
15
|
+
await queueRuntimeBuild(this.#projectRoot, this.#target);
|
|
16
|
+
});
|
|
17
|
+
compiler.hooks.afterCompile.tap("orchajs", (compilation) => {
|
|
18
|
+
compilation.contextDependencies.add(resolve(this.#projectRoot, "orcha"));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|