orchajs 0.23.2 → 0.23.3
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/amarsia/metadata.js +29 -3
- package/dist/bin.js +115 -6
- package/dist/runtime/agent.js +12 -2
- package/dist-cjs/amarsia/metadata.js +29 -3
- package/dist-cjs/runtime/agent.js +15 -2
- package/package.json +1 -1
package/dist/amarsia/metadata.js
CHANGED
|
@@ -31,9 +31,25 @@ export function createAmarsiaProjectMetadata(bundle, projectRoot) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
function flattenAgents(agents) {
|
|
34
|
-
const
|
|
34
|
+
const rootIds = new Set(Object.values(agents).map((manifest) => manifest.key));
|
|
35
|
+
const manifests = new Map();
|
|
36
|
+
const parentIds = new Map();
|
|
37
|
+
const orderedIds = [];
|
|
38
|
+
const traversed = new WeakSet();
|
|
35
39
|
const visit = (manifest, parentExternalId) => {
|
|
36
|
-
|
|
40
|
+
if (!manifests.has(manifest.key)) {
|
|
41
|
+
manifests.set(manifest.key, manifest);
|
|
42
|
+
orderedIds.push(manifest.key);
|
|
43
|
+
}
|
|
44
|
+
if (parentExternalId) {
|
|
45
|
+
const parents = parentIds.get(manifest.key) ?? new Set();
|
|
46
|
+
parents.add(parentExternalId);
|
|
47
|
+
parentIds.set(manifest.key, parents);
|
|
48
|
+
}
|
|
49
|
+
if (traversed.has(manifest)) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
traversed.add(manifest);
|
|
37
53
|
for (const subagent of Object.values(manifest.subagents ?? {})) {
|
|
38
54
|
visit(subagent, manifest.key);
|
|
39
55
|
}
|
|
@@ -41,7 +57,17 @@ function flattenAgents(agents) {
|
|
|
41
57
|
for (const manifest of Object.values(agents)) {
|
|
42
58
|
visit(manifest);
|
|
43
59
|
}
|
|
44
|
-
return
|
|
60
|
+
return orderedIds.map((externalId) => {
|
|
61
|
+
const manifest = manifests.get(externalId);
|
|
62
|
+
if (!manifest) {
|
|
63
|
+
throw new Error(`Missing compiled agent "${externalId}".`);
|
|
64
|
+
}
|
|
65
|
+
const parents = parentIds.get(externalId);
|
|
66
|
+
const parentExternalId = !rootIds.has(externalId) && parents?.size === 1
|
|
67
|
+
? parents.values().next().value
|
|
68
|
+
: undefined;
|
|
69
|
+
return agentMetadata(manifest, parentExternalId);
|
|
70
|
+
});
|
|
45
71
|
}
|
|
46
72
|
function agentMetadata(manifest, parentExternalId) {
|
|
47
73
|
return {
|
package/dist/bin.js
CHANGED
|
@@ -1,13 +1,122 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { resolve } from "node:path";
|
|
5
|
+
const TOOLING_PACKAGES = [
|
|
6
|
+
"@orchajs/playground-ui@^0.2.3",
|
|
7
|
+
"esbuild@^0.25",
|
|
8
|
+
"chokidar@^4",
|
|
9
|
+
"dotenv@^16",
|
|
10
|
+
];
|
|
11
|
+
const BOOTSTRAP_ENV = "ORCHA_TOOLING_BOOTSTRAPPED";
|
|
12
|
+
void run();
|
|
13
|
+
async function run() {
|
|
14
|
+
try {
|
|
15
|
+
await import("./cli.js");
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
if (process.argv[2] === "playground" &&
|
|
19
|
+
process.env[BOOTSTRAP_ENV] !== "1" &&
|
|
20
|
+
isMissingToolingError(error)) {
|
|
21
|
+
await bootstrapPlayground();
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
reportError(error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
async function bootstrapPlayground() {
|
|
28
|
+
const packageManager = detectPackageManager();
|
|
29
|
+
const installation = installCommand(packageManager);
|
|
30
|
+
console.log(`[orcha] Installing development-only playground tooling with ${packageManager}...`);
|
|
31
|
+
const installCode = await runProcess(installation.command, installation.arguments);
|
|
32
|
+
if (installCode !== 0) {
|
|
33
|
+
process.exitCode = installCode;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
const retryCode = await runProcess(process.execPath, [process.argv[1], ...process.argv.slice(2)], {
|
|
37
|
+
...process.env,
|
|
38
|
+
[BOOTSTRAP_ENV]: "1",
|
|
39
|
+
});
|
|
40
|
+
process.exitCode = retryCode;
|
|
41
|
+
}
|
|
42
|
+
function detectPackageManager() {
|
|
43
|
+
const userAgent = process.env.npm_config_user_agent;
|
|
44
|
+
if (userAgent?.startsWith("yarn/")) {
|
|
45
|
+
return "yarn";
|
|
46
|
+
}
|
|
47
|
+
if (userAgent?.startsWith("pnpm/")) {
|
|
48
|
+
return "pnpm";
|
|
49
|
+
}
|
|
50
|
+
if (userAgent?.startsWith("bun/")) {
|
|
51
|
+
return "bun";
|
|
52
|
+
}
|
|
53
|
+
if (existsSync(resolve("yarn.lock"))) {
|
|
54
|
+
return "yarn";
|
|
55
|
+
}
|
|
56
|
+
if (existsSync(resolve("pnpm-lock.yaml"))) {
|
|
57
|
+
return "pnpm";
|
|
58
|
+
}
|
|
59
|
+
if (existsSync(resolve("bun.lock")) ||
|
|
60
|
+
existsSync(resolve("bun.lockb"))) {
|
|
61
|
+
return "bun";
|
|
62
|
+
}
|
|
63
|
+
return "npm";
|
|
64
|
+
}
|
|
65
|
+
function installCommand(packageManager) {
|
|
66
|
+
switch (packageManager) {
|
|
67
|
+
case "yarn":
|
|
68
|
+
return {
|
|
69
|
+
command: executable("yarn"),
|
|
70
|
+
arguments: ["add", "--dev", ...TOOLING_PACKAGES],
|
|
71
|
+
};
|
|
72
|
+
case "pnpm":
|
|
73
|
+
return {
|
|
74
|
+
command: executable("pnpm"),
|
|
75
|
+
arguments: ["add", "--save-dev", ...TOOLING_PACKAGES],
|
|
76
|
+
};
|
|
77
|
+
case "bun":
|
|
78
|
+
return {
|
|
79
|
+
command: executable("bun"),
|
|
80
|
+
arguments: ["add", "--dev", ...TOOLING_PACKAGES],
|
|
81
|
+
};
|
|
82
|
+
default:
|
|
83
|
+
return {
|
|
84
|
+
command: executable("npm"),
|
|
85
|
+
arguments: ["install", "--save-dev", ...TOOLING_PACKAGES],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function executable(command) {
|
|
90
|
+
return process.platform === "win32" ? `${command}.cmd` : command;
|
|
91
|
+
}
|
|
92
|
+
function runProcess(command, arguments_, env = process.env) {
|
|
93
|
+
return new Promise((resolveProcess, reject) => {
|
|
94
|
+
const child = spawn(command, arguments_, {
|
|
95
|
+
cwd: process.cwd(),
|
|
96
|
+
env,
|
|
97
|
+
stdio: "inherit",
|
|
98
|
+
});
|
|
99
|
+
child.once("error", reject);
|
|
100
|
+
child.once("exit", (code, signal) => {
|
|
101
|
+
if (signal) {
|
|
102
|
+
process.kill(process.pid, signal);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
resolveProcess(code ?? 1);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
function isMissingToolingError(error) {
|
|
110
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
111
|
+
return ["@orchajs/playground-ui", "esbuild", "chokidar", "dotenv"].some((name) => message.includes(`"${name}"`) || message.includes(`'${name}'`));
|
|
112
|
+
}
|
|
113
|
+
function reportError(error) {
|
|
3
114
|
const message = error instanceof Error ? error.message : String(error);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
console.error(`Orcha development tooling requires optional dependencies. Install them with:\n\n npm install --save-dev esbuild chokidar dotenv`);
|
|
115
|
+
if (isMissingToolingError(error)) {
|
|
116
|
+
console.error(`Orcha development tooling is missing. Run "orcha playground" to install the development-only playground dependencies automatically.`);
|
|
7
117
|
}
|
|
8
118
|
else {
|
|
9
119
|
console.error(message);
|
|
10
120
|
}
|
|
11
121
|
process.exitCode = 1;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
122
|
+
}
|
package/dist/runtime/agent.js
CHANGED
|
@@ -628,7 +628,7 @@ export class RuntimeAgent {
|
|
|
628
628
|
reasoningLevel: this.#manifest.reasoningLevel,
|
|
629
629
|
outputType: this.#manifest.outputType,
|
|
630
630
|
outputSchema: this.#manifest.outputSchema,
|
|
631
|
-
systemPrompt: buildSystemPrompt(this.#manifest, previousEvents, variables),
|
|
631
|
+
systemPrompt: buildSystemPrompt(this.#manifest, previousEvents, variables, availableToolNames),
|
|
632
632
|
messages,
|
|
633
633
|
tools: providerTools,
|
|
634
634
|
publishOutput: (output) => {
|
|
@@ -1895,8 +1895,18 @@ function renderPrompt(template, variables) {
|
|
|
1895
1895
|
return variables[name];
|
|
1896
1896
|
});
|
|
1897
1897
|
}
|
|
1898
|
-
function buildSystemPrompt(manifest, events, variables) {
|
|
1898
|
+
function buildSystemPrompt(manifest, events, variables, availableActionNames) {
|
|
1899
1899
|
const sections = [renderPrompt(manifest.systemPrompt, variables)];
|
|
1900
|
+
if (availableActionNames.length > 0) {
|
|
1901
|
+
sections.push([
|
|
1902
|
+
"## Available actions",
|
|
1903
|
+
"The following actions are available in this run. Invoke the relevant action when the workflow requires it; do not claim it is unavailable.",
|
|
1904
|
+
...availableActionNames.map((name) => {
|
|
1905
|
+
const action = manifest.actions[name];
|
|
1906
|
+
return `- ${action.name}: ${action.description}`;
|
|
1907
|
+
}),
|
|
1908
|
+
].join("\n"));
|
|
1909
|
+
}
|
|
1900
1910
|
const skills = manifest.skills ?? {};
|
|
1901
1911
|
const availableSkills = Object.values(skills);
|
|
1902
1912
|
if (availableSkills.length > 0) {
|
|
@@ -55,9 +55,27 @@ function createAmarsiaProjectMetadata(bundle, projectRoot) {
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
function flattenAgents(agents) {
|
|
58
|
-
const
|
|
58
|
+
const rootIds = new Set(
|
|
59
|
+
Object.values(agents).map((manifest) => manifest.key)
|
|
60
|
+
);
|
|
61
|
+
const manifests = /* @__PURE__ */ new Map();
|
|
62
|
+
const parentIds = /* @__PURE__ */ new Map();
|
|
63
|
+
const orderedIds = [];
|
|
64
|
+
const traversed = /* @__PURE__ */ new WeakSet();
|
|
59
65
|
const visit = (manifest, parentExternalId) => {
|
|
60
|
-
|
|
66
|
+
if (!manifests.has(manifest.key)) {
|
|
67
|
+
manifests.set(manifest.key, manifest);
|
|
68
|
+
orderedIds.push(manifest.key);
|
|
69
|
+
}
|
|
70
|
+
if (parentExternalId) {
|
|
71
|
+
const parents = parentIds.get(manifest.key) ?? /* @__PURE__ */ new Set();
|
|
72
|
+
parents.add(parentExternalId);
|
|
73
|
+
parentIds.set(manifest.key, parents);
|
|
74
|
+
}
|
|
75
|
+
if (traversed.has(manifest)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
traversed.add(manifest);
|
|
61
79
|
for (const subagent of Object.values(manifest.subagents ?? {})) {
|
|
62
80
|
visit(subagent, manifest.key);
|
|
63
81
|
}
|
|
@@ -65,7 +83,15 @@ function flattenAgents(agents) {
|
|
|
65
83
|
for (const manifest of Object.values(agents)) {
|
|
66
84
|
visit(manifest);
|
|
67
85
|
}
|
|
68
|
-
return
|
|
86
|
+
return orderedIds.map((externalId) => {
|
|
87
|
+
const manifest = manifests.get(externalId);
|
|
88
|
+
if (!manifest) {
|
|
89
|
+
throw new Error(`Missing compiled agent "${externalId}".`);
|
|
90
|
+
}
|
|
91
|
+
const parents = parentIds.get(externalId);
|
|
92
|
+
const parentExternalId = !rootIds.has(externalId) && parents?.size === 1 ? parents.values().next().value : void 0;
|
|
93
|
+
return agentMetadata(manifest, parentExternalId);
|
|
94
|
+
});
|
|
69
95
|
}
|
|
70
96
|
function agentMetadata(manifest, parentExternalId) {
|
|
71
97
|
return {
|
|
@@ -826,7 +826,8 @@ class RuntimeAgent {
|
|
|
826
826
|
systemPrompt: buildSystemPrompt(
|
|
827
827
|
this.#manifest,
|
|
828
828
|
previousEvents,
|
|
829
|
-
variables
|
|
829
|
+
variables,
|
|
830
|
+
availableToolNames
|
|
830
831
|
),
|
|
831
832
|
messages,
|
|
832
833
|
tools: providerTools,
|
|
@@ -2197,8 +2198,20 @@ function renderPrompt(template, variables) {
|
|
|
2197
2198
|
}
|
|
2198
2199
|
);
|
|
2199
2200
|
}
|
|
2200
|
-
function buildSystemPrompt(manifest, events, variables) {
|
|
2201
|
+
function buildSystemPrompt(manifest, events, variables, availableActionNames) {
|
|
2201
2202
|
const sections = [renderPrompt(manifest.systemPrompt, variables)];
|
|
2203
|
+
if (availableActionNames.length > 0) {
|
|
2204
|
+
sections.push(
|
|
2205
|
+
[
|
|
2206
|
+
"## Available actions",
|
|
2207
|
+
"The following actions are available in this run. Invoke the relevant action when the workflow requires it; do not claim it is unavailable.",
|
|
2208
|
+
...availableActionNames.map((name) => {
|
|
2209
|
+
const action = manifest.actions[name];
|
|
2210
|
+
return `- ${action.name}: ${action.description}`;
|
|
2211
|
+
})
|
|
2212
|
+
].join("\n")
|
|
2213
|
+
);
|
|
2214
|
+
}
|
|
2202
2215
|
const skills = manifest.skills ?? {};
|
|
2203
2216
|
const availableSkills = Object.values(skills);
|
|
2204
2217
|
if (availableSkills.length > 0) {
|