orchajs 0.23.10 → 0.23.11
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 +4 -2
- package/dist/bin.js +54 -14
- package/dist/cli.js +2 -63
- package/dist/initialize-project.d.ts +1 -0
- package/dist/initialize-project.js +65 -0
- package/dist-cjs/initialize-project.js +101 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -322,10 +322,12 @@ npm install quickjs-emscripten-core @jitl/quickjs-singlefile-cjs-release-sync
|
|
|
322
322
|
## Quick start
|
|
323
323
|
|
|
324
324
|
```bash
|
|
325
|
-
|
|
326
|
-
npx orcha init
|
|
325
|
+
npx orchajs init
|
|
327
326
|
```
|
|
328
327
|
|
|
328
|
+
This installs `orchajs` and its development tooling in the current project,
|
|
329
|
+
then creates the starter agent files.
|
|
330
|
+
|
|
329
331
|
The default installation includes the compiler, CLI, native actions, JSONL
|
|
330
332
|
storage, and fetch-based Anthropic, DeepSeek, and OpenAI adapters. Install an
|
|
331
333
|
optional integration only in applications that use it:
|
package/dist/bin.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn } from "node:child_process";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
4
5
|
import { resolve } from "node:path";
|
|
5
6
|
const TOOLING_PACKAGES = [
|
|
6
7
|
"@orchajs/playground-ui@^0.2.5",
|
|
@@ -12,6 +13,15 @@ const BOOTSTRAP_ENV = "ORCHA_TOOLING_BOOTSTRAPPED";
|
|
|
12
13
|
void run();
|
|
13
14
|
async function run() {
|
|
14
15
|
try {
|
|
16
|
+
if (process.argv[2] === "init") {
|
|
17
|
+
if (process.argv.length > 3) {
|
|
18
|
+
throw new Error("Usage: orcha init");
|
|
19
|
+
}
|
|
20
|
+
await installProjectDependencies();
|
|
21
|
+
const { initializeProject } = await import("./initialize-project.js");
|
|
22
|
+
await initializeProject(process.cwd());
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
15
25
|
await import("./cli.js");
|
|
16
26
|
}
|
|
17
27
|
catch (error) {
|
|
@@ -26,7 +36,7 @@ async function run() {
|
|
|
26
36
|
}
|
|
27
37
|
async function bootstrapPlayground() {
|
|
28
38
|
const packageManager = detectPackageManager();
|
|
29
|
-
const installation = installCommand(packageManager);
|
|
39
|
+
const installation = installCommand(packageManager, TOOLING_PACKAGES, true);
|
|
30
40
|
console.log(`[orcha] Installing development-only playground tooling with ${packageManager}...`);
|
|
31
41
|
const installCode = await runProcess(installation.command, installation.arguments);
|
|
32
42
|
if (installCode !== 0) {
|
|
@@ -39,17 +49,29 @@ async function bootstrapPlayground() {
|
|
|
39
49
|
});
|
|
40
50
|
process.exitCode = retryCode;
|
|
41
51
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
52
|
+
async function installProjectDependencies() {
|
|
53
|
+
const packagePath = resolve("package.json");
|
|
54
|
+
if (!existsSync(packagePath)) {
|
|
55
|
+
throw new Error('Missing "package.json". Run your package manager initialization command first, or use "npx create-orcha <project-directory>" to create a new project.');
|
|
46
56
|
}
|
|
47
|
-
|
|
48
|
-
|
|
57
|
+
const packageManager = detectPackageManager();
|
|
58
|
+
const ownPackage = JSON.parse(await readFile(new URL("../package.json", import.meta.url), "utf8"));
|
|
59
|
+
if (typeof ownPackage.version !== "string") {
|
|
60
|
+
throw new Error("Could not determine the installed orchajs version.");
|
|
49
61
|
}
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
console.log(`[orcha] Installing Orcha and development tooling with ${packageManager}...`);
|
|
63
|
+
const runtimeInstallation = installCommand(packageManager, [`orchajs@${ownPackage.version}`], false);
|
|
64
|
+
const runtimeCode = await runProcess(runtimeInstallation.command, runtimeInstallation.arguments);
|
|
65
|
+
if (runtimeCode !== 0) {
|
|
66
|
+
throw new Error("Failed to install orchajs in the current project.");
|
|
67
|
+
}
|
|
68
|
+
const toolingInstallation = installCommand(packageManager, TOOLING_PACKAGES, true);
|
|
69
|
+
const toolingCode = await runProcess(toolingInstallation.command, toolingInstallation.arguments);
|
|
70
|
+
if (toolingCode !== 0) {
|
|
71
|
+
throw new Error("Failed to install Orcha development tooling in the current project.");
|
|
52
72
|
}
|
|
73
|
+
}
|
|
74
|
+
function detectPackageManager() {
|
|
53
75
|
if (existsSync(resolve("yarn.lock"))) {
|
|
54
76
|
return "yarn";
|
|
55
77
|
}
|
|
@@ -60,29 +82,47 @@ function detectPackageManager() {
|
|
|
60
82
|
existsSync(resolve("bun.lockb"))) {
|
|
61
83
|
return "bun";
|
|
62
84
|
}
|
|
85
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
86
|
+
if (userAgent?.startsWith("yarn/")) {
|
|
87
|
+
return "yarn";
|
|
88
|
+
}
|
|
89
|
+
if (userAgent?.startsWith("pnpm/")) {
|
|
90
|
+
return "pnpm";
|
|
91
|
+
}
|
|
92
|
+
if (userAgent?.startsWith("bun/")) {
|
|
93
|
+
return "bun";
|
|
94
|
+
}
|
|
63
95
|
return "npm";
|
|
64
96
|
}
|
|
65
|
-
function installCommand(packageManager) {
|
|
97
|
+
function installCommand(packageManager, packages, development) {
|
|
66
98
|
switch (packageManager) {
|
|
67
99
|
case "yarn":
|
|
68
100
|
return {
|
|
69
101
|
command: executable("yarn"),
|
|
70
|
-
arguments: ["add", "--dev", ...
|
|
102
|
+
arguments: ["add", ...(development ? ["--dev"] : []), ...packages],
|
|
71
103
|
};
|
|
72
104
|
case "pnpm":
|
|
73
105
|
return {
|
|
74
106
|
command: executable("pnpm"),
|
|
75
|
-
arguments: [
|
|
107
|
+
arguments: [
|
|
108
|
+
"add",
|
|
109
|
+
...(development ? ["--save-dev"] : []),
|
|
110
|
+
...packages,
|
|
111
|
+
],
|
|
76
112
|
};
|
|
77
113
|
case "bun":
|
|
78
114
|
return {
|
|
79
115
|
command: executable("bun"),
|
|
80
|
-
arguments: ["add", "--dev", ...
|
|
116
|
+
arguments: ["add", ...(development ? ["--dev"] : []), ...packages],
|
|
81
117
|
};
|
|
82
118
|
default:
|
|
83
119
|
return {
|
|
84
120
|
command: executable("npm"),
|
|
85
|
-
arguments: [
|
|
121
|
+
arguments: [
|
|
122
|
+
"install",
|
|
123
|
+
...(development ? ["--save-dev"] : []),
|
|
124
|
+
...packages,
|
|
125
|
+
],
|
|
86
126
|
};
|
|
87
127
|
}
|
|
88
128
|
}
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync } from "node:fs";
|
|
3
|
-
import {
|
|
3
|
+
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { dirname, relative, resolve } from "node:path";
|
|
5
5
|
import { watch } from "chokidar";
|
|
6
|
-
import { AGENTS_MD } from "./cli-agents-template.js";
|
|
7
6
|
import { buildProject } from "./compiler/build-project.js";
|
|
8
7
|
import { loadProjectEnvironment } from "./env.js";
|
|
8
|
+
import { initializeProject } from "./initialize-project.js";
|
|
9
9
|
import { orcha } from "./orcha.js";
|
|
10
10
|
import { startPlayground } from "./playground/server.js";
|
|
11
11
|
import { loadProject } from "./project-loader.js";
|
|
@@ -60,55 +60,6 @@ switch (command) {
|
|
|
60
60
|
default:
|
|
61
61
|
throw new Error(`Unknown command "${command}". Run "orcha --help".`);
|
|
62
62
|
}
|
|
63
|
-
async function initializeProject(projectRoot) {
|
|
64
|
-
const files = new Map([
|
|
65
|
-
[
|
|
66
|
-
"orcha/exampleAgent/index.json",
|
|
67
|
-
`${JSON.stringify({
|
|
68
|
-
name: "Example Agent",
|
|
69
|
-
description: "Answer general questions clearly and concisely.",
|
|
70
|
-
provider: "anthropic",
|
|
71
|
-
model: "claude-sonnet-4-6",
|
|
72
|
-
region: "provider_managed",
|
|
73
|
-
maxTokens: 10240,
|
|
74
|
-
outputType: "text",
|
|
75
|
-
}, null, 2)}\n`,
|
|
76
|
-
],
|
|
77
|
-
[
|
|
78
|
-
"orcha/exampleAgent/instructions.md",
|
|
79
|
-
"You are a concise and helpful assistant.\n",
|
|
80
|
-
],
|
|
81
|
-
[
|
|
82
|
-
"orcha/index.ts",
|
|
83
|
-
[
|
|
84
|
-
'import { orcha } from "orchajs";',
|
|
85
|
-
"",
|
|
86
|
-
"orcha.init({",
|
|
87
|
-
" providers: {",
|
|
88
|
-
" anthropic: process.env.ANTHROPIC_API_KEY ?? \"\",",
|
|
89
|
-
" },",
|
|
90
|
-
" agents: {",
|
|
91
|
-
" exampleAgent: \"./exampleAgent\",",
|
|
92
|
-
" },",
|
|
93
|
-
"});",
|
|
94
|
-
"",
|
|
95
|
-
].join("\n"),
|
|
96
|
-
],
|
|
97
|
-
["AGENTS.md", AGENTS_MD],
|
|
98
|
-
]);
|
|
99
|
-
for (const [relativePath, contents] of files) {
|
|
100
|
-
const path = resolve(projectRoot, relativePath);
|
|
101
|
-
if (existsSync(path)) {
|
|
102
|
-
console.log(`Skipped existing ${relativePath}`);
|
|
103
|
-
continue;
|
|
104
|
-
}
|
|
105
|
-
await mkdir(dirname(path), { recursive: true });
|
|
106
|
-
await writeFile(path, contents, "utf8");
|
|
107
|
-
console.log(`Created ${relativePath}`);
|
|
108
|
-
}
|
|
109
|
-
await ensureGitignore(projectRoot);
|
|
110
|
-
console.log('\nRun "orcha dev" to validate changes or "orcha run exampleAgent --input \\"Hello\\"" to execute the agent.');
|
|
111
|
-
}
|
|
112
63
|
async function watchProject(projectRoot, targets) {
|
|
113
64
|
const registryDirectory = resolve(projectRoot, "orcha");
|
|
114
65
|
if (!existsSync(registryDirectory)) {
|
|
@@ -607,18 +558,6 @@ function assertNoArguments(arguments_, command) {
|
|
|
607
558
|
throw new Error(`Usage: orcha ${command}`);
|
|
608
559
|
}
|
|
609
560
|
}
|
|
610
|
-
async function ensureGitignore(projectRoot) {
|
|
611
|
-
const path = resolve(projectRoot, ".gitignore");
|
|
612
|
-
const entry = ".orcha/";
|
|
613
|
-
const current = existsSync(path) ? await readFile(path, "utf8") : "";
|
|
614
|
-
const entries = current.split(/\r?\n/).map((line) => line.trim());
|
|
615
|
-
if (entries.includes(entry)) {
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
|
|
619
|
-
await appendFile(path, `${prefix}${entry}\n`, "utf8");
|
|
620
|
-
console.log("Updated .gitignore");
|
|
621
|
-
}
|
|
622
561
|
function printUsage() {
|
|
623
562
|
console.log([
|
|
624
563
|
"Usage: orcha <command>",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function initializeProject(projectRoot: string): Promise<void>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { appendFile, mkdir, readFile, writeFile, } from "node:fs/promises";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { AGENTS_MD } from "./cli-agents-template.js";
|
|
5
|
+
export async function initializeProject(projectRoot) {
|
|
6
|
+
const files = new Map([
|
|
7
|
+
[
|
|
8
|
+
"orcha/exampleAgent/index.json",
|
|
9
|
+
`${JSON.stringify({
|
|
10
|
+
name: "Example Agent",
|
|
11
|
+
description: "Answer general questions clearly and concisely.",
|
|
12
|
+
provider: "anthropic",
|
|
13
|
+
model: "claude-sonnet-4-6",
|
|
14
|
+
region: "provider_managed",
|
|
15
|
+
maxTokens: 10240,
|
|
16
|
+
outputType: "text",
|
|
17
|
+
}, null, 2)}\n`,
|
|
18
|
+
],
|
|
19
|
+
[
|
|
20
|
+
"orcha/exampleAgent/instructions.md",
|
|
21
|
+
"You are a concise and helpful assistant.\n",
|
|
22
|
+
],
|
|
23
|
+
[
|
|
24
|
+
"orcha/index.ts",
|
|
25
|
+
[
|
|
26
|
+
'import { orcha } from "orchajs";',
|
|
27
|
+
"",
|
|
28
|
+
"orcha.init({",
|
|
29
|
+
" providers: {",
|
|
30
|
+
" anthropic: process.env.ANTHROPIC_API_KEY ?? \"\",",
|
|
31
|
+
" },",
|
|
32
|
+
" agents: {",
|
|
33
|
+
" exampleAgent: \"./exampleAgent\",",
|
|
34
|
+
" },",
|
|
35
|
+
"});",
|
|
36
|
+
"",
|
|
37
|
+
].join("\n"),
|
|
38
|
+
],
|
|
39
|
+
["AGENTS.md", AGENTS_MD],
|
|
40
|
+
]);
|
|
41
|
+
for (const [relativePath, contents] of files) {
|
|
42
|
+
const path = resolve(projectRoot, relativePath);
|
|
43
|
+
if (existsSync(path)) {
|
|
44
|
+
console.log(`Skipped existing ${relativePath}`);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
await mkdir(dirname(path), { recursive: true });
|
|
48
|
+
await writeFile(path, contents, "utf8");
|
|
49
|
+
console.log(`Created ${relativePath}`);
|
|
50
|
+
}
|
|
51
|
+
await ensureGitignore(projectRoot);
|
|
52
|
+
console.log('\nRun "orcha dev" to validate changes or "orcha run exampleAgent --input \\"Hello\\"" to execute the agent.');
|
|
53
|
+
}
|
|
54
|
+
async function ensureGitignore(projectRoot) {
|
|
55
|
+
const path = resolve(projectRoot, ".gitignore");
|
|
56
|
+
const entry = ".orcha/";
|
|
57
|
+
const current = existsSync(path) ? await readFile(path, "utf8") : "";
|
|
58
|
+
const entries = current.split(/\r?\n/).map((line) => line.trim());
|
|
59
|
+
if (entries.includes(entry)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
|
|
63
|
+
await appendFile(path, `${prefix}${entry}\n`, "utf8");
|
|
64
|
+
console.log("Updated .gitignore");
|
|
65
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
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 initialize_project_exports = {};
|
|
21
|
+
__export(initialize_project_exports, {
|
|
22
|
+
initializeProject: () => initializeProject
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(initialize_project_exports);
|
|
25
|
+
var import_fs = require("fs");
|
|
26
|
+
var import_promises = require("fs/promises");
|
|
27
|
+
var import_path = require("path");
|
|
28
|
+
var import_cli_agents_template = require("./cli-agents-template.js");
|
|
29
|
+
async function initializeProject(projectRoot) {
|
|
30
|
+
const files = /* @__PURE__ */ new Map([
|
|
31
|
+
[
|
|
32
|
+
"orcha/exampleAgent/index.json",
|
|
33
|
+
`${JSON.stringify(
|
|
34
|
+
{
|
|
35
|
+
name: "Example Agent",
|
|
36
|
+
description: "Answer general questions clearly and concisely.",
|
|
37
|
+
provider: "anthropic",
|
|
38
|
+
model: "claude-sonnet-4-6",
|
|
39
|
+
region: "provider_managed",
|
|
40
|
+
maxTokens: 10240,
|
|
41
|
+
outputType: "text"
|
|
42
|
+
},
|
|
43
|
+
null,
|
|
44
|
+
2
|
|
45
|
+
)}
|
|
46
|
+
`
|
|
47
|
+
],
|
|
48
|
+
[
|
|
49
|
+
"orcha/exampleAgent/instructions.md",
|
|
50
|
+
"You are a concise and helpful assistant.\n"
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
"orcha/index.ts",
|
|
54
|
+
[
|
|
55
|
+
'import { orcha } from "orchajs";',
|
|
56
|
+
"",
|
|
57
|
+
"orcha.init({",
|
|
58
|
+
" providers: {",
|
|
59
|
+
' anthropic: process.env.ANTHROPIC_API_KEY ?? "",',
|
|
60
|
+
" },",
|
|
61
|
+
" agents: {",
|
|
62
|
+
' exampleAgent: "./exampleAgent",',
|
|
63
|
+
" },",
|
|
64
|
+
"});",
|
|
65
|
+
""
|
|
66
|
+
].join("\n")
|
|
67
|
+
],
|
|
68
|
+
["AGENTS.md", import_cli_agents_template.AGENTS_MD]
|
|
69
|
+
]);
|
|
70
|
+
for (const [relativePath, contents] of files) {
|
|
71
|
+
const path = (0, import_path.resolve)(projectRoot, relativePath);
|
|
72
|
+
if ((0, import_fs.existsSync)(path)) {
|
|
73
|
+
console.log(`Skipped existing ${relativePath}`);
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
await (0, import_promises.mkdir)((0, import_path.dirname)(path), { recursive: true });
|
|
77
|
+
await (0, import_promises.writeFile)(path, contents, "utf8");
|
|
78
|
+
console.log(`Created ${relativePath}`);
|
|
79
|
+
}
|
|
80
|
+
await ensureGitignore(projectRoot);
|
|
81
|
+
console.log(
|
|
82
|
+
'\nRun "orcha dev" to validate changes or "orcha run exampleAgent --input \\"Hello\\"" to execute the agent.'
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
async function ensureGitignore(projectRoot) {
|
|
86
|
+
const path = (0, import_path.resolve)(projectRoot, ".gitignore");
|
|
87
|
+
const entry = ".orcha/";
|
|
88
|
+
const current = (0, import_fs.existsSync)(path) ? await (0, import_promises.readFile)(path, "utf8") : "";
|
|
89
|
+
const entries = current.split(/\r?\n/).map((line) => line.trim());
|
|
90
|
+
if (entries.includes(entry)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const prefix = current.length > 0 && !current.endsWith("\n") ? "\n" : "";
|
|
94
|
+
await (0, import_promises.appendFile)(path, `${prefix}${entry}
|
|
95
|
+
`, "utf8");
|
|
96
|
+
console.log("Updated .gitignore");
|
|
97
|
+
}
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
initializeProject
|
|
101
|
+
});
|