orchajs 0.27.2 → 0.27.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/compiler/build-project.js +15 -4
- package/dist/compiler/compile.js +53 -11
- package/dist/providers/dependencies.js +15 -4
- package/dist/runtime/agent.js +14 -1
- package/dist/runtime/create-orcha.js +18 -17
- package/dist/testing.js +23 -14
- package/dist/types.d.ts +1 -0
- package/dist-cjs/compiler/build-project.js +14 -4
- package/dist-cjs/compiler/compile.js +65 -20
- package/dist-cjs/providers/dependencies.js +14 -4
- package/dist-cjs/runtime/agent.js +11 -1
- package/dist-cjs/runtime/create-orcha.js +29 -26
- package/dist-cjs/testing.js +30 -16
- package/package.json +1 -1
|
@@ -290,10 +290,21 @@ function createNodeStorageExports() {
|
|
|
290
290
|
].join("\n");
|
|
291
291
|
}
|
|
292
292
|
function allCompiledAgents(agents) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
293
|
+
const collected = [];
|
|
294
|
+
const visited = new Set();
|
|
295
|
+
const visit = (agent) => {
|
|
296
|
+
if (visited.has(agent))
|
|
297
|
+
return;
|
|
298
|
+
visited.add(agent);
|
|
299
|
+
collected.push(agent);
|
|
300
|
+
for (const child of Object.values(agent.subagents ?? {})) {
|
|
301
|
+
visit(child);
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
for (const agent of Object.values(agents)) {
|
|
305
|
+
visit(agent);
|
|
306
|
+
}
|
|
307
|
+
return collected;
|
|
297
308
|
}
|
|
298
309
|
function createProviderRuntimeSource(providerNames, target) {
|
|
299
310
|
const providersDirectory = resolve(esmCompilerDirectory(), "../providers");
|
package/dist/compiler/compile.js
CHANGED
|
@@ -10,22 +10,55 @@ export function compileRegistry(registrations, registryRoot, actionRuntime = "na
|
|
|
10
10
|
Array.isArray(registrations)) {
|
|
11
11
|
throw new TypeError('orcha.init() requires an "agents" object of registered folder paths.');
|
|
12
12
|
}
|
|
13
|
-
const
|
|
13
|
+
const normalizedRegistrations = {};
|
|
14
|
+
const registrationsByPath = new Map();
|
|
14
15
|
for (const [key, registration] of Object.entries(registrations)) {
|
|
15
16
|
if (!key.trim()) {
|
|
16
17
|
throw new Error("Registered agent names cannot be empty.");
|
|
17
18
|
}
|
|
18
19
|
const normalized = normalizeAgentRegistration(key, registration);
|
|
20
|
+
normalizedRegistrations[key] = normalized;
|
|
21
|
+
const resolvedPath = resolve(registryRoot, normalized.path);
|
|
22
|
+
if (!registrationsByPath.has(resolvedPath)) {
|
|
23
|
+
registrationsByPath.set(resolvedPath, {
|
|
24
|
+
key,
|
|
25
|
+
registration: normalized,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (Object.keys(normalizedRegistrations).length === 0) {
|
|
30
|
+
throw new Error("At least one agent must be registered.");
|
|
31
|
+
}
|
|
32
|
+
const compileRegistrationTree = (key, normalized, ownerPath, ancestry) => {
|
|
33
|
+
const resolvedPath = resolve(registryRoot, normalized.path);
|
|
34
|
+
const inherited = normalizedRegistrations[key] ??
|
|
35
|
+
registrationsByPath.get(resolvedPath)?.registration;
|
|
36
|
+
const effectiveMcp = Object.keys(normalized.mcp).length > 0
|
|
37
|
+
? normalized.mcp
|
|
38
|
+
: (inherited?.mcp ?? {});
|
|
39
|
+
const effectiveSubagentRegistrations = Object.keys(normalized.subagents).length > 0
|
|
40
|
+
? normalized.subagents
|
|
41
|
+
: (inherited?.subagents ?? {});
|
|
19
42
|
const subagents = {};
|
|
20
|
-
for (const [subagentKey,
|
|
43
|
+
for (const [subagentKey, subagentRegistration] of Object.entries(effectiveSubagentRegistrations)) {
|
|
21
44
|
if (!subagentKey.trim()) {
|
|
22
|
-
throw new Error(`Agent "${
|
|
45
|
+
throw new Error(`Agent "${ownerPath}" has an empty subagent name.`);
|
|
23
46
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
47
|
+
const normalizedSubagent = normalizeSubagentRegistration(ownerPath, subagentKey, subagentRegistration);
|
|
48
|
+
const childResolvedPath = resolve(registryRoot, normalizedSubagent.path);
|
|
49
|
+
const cycleExists = ancestry.some((ancestor) => ancestor.resolvedPath === childResolvedPath ||
|
|
50
|
+
ancestor.key === subagentKey);
|
|
51
|
+
if (cycleExists) {
|
|
52
|
+
const chain = [
|
|
53
|
+
...ancestry.map((item) => item.key),
|
|
54
|
+
subagentKey,
|
|
55
|
+
].join(" -> ");
|
|
56
|
+
throw new Error(`Circular subagent registration detected: ${chain}.`);
|
|
57
|
+
}
|
|
58
|
+
subagents[subagentKey] = compileRegistrationTree(subagentKey, normalizedSubagent, `${ownerPath}/${subagentKey}`, [...ancestry, { key: subagentKey, resolvedPath: childResolvedPath }]);
|
|
26
59
|
}
|
|
27
|
-
const parent = compileAgent(key, normalized.path,
|
|
28
|
-
|
|
60
|
+
const parent = compileAgent(key, normalized.path, effectiveMcp, registryRoot, actionRuntime, target);
|
|
61
|
+
return Object.freeze({
|
|
29
62
|
...parent,
|
|
30
63
|
subagentPolicy: Object.keys(subagents).length > 0
|
|
31
64
|
? Object.freeze({
|
|
@@ -35,9 +68,11 @@ export function compileRegistry(registrations, registryRoot, actionRuntime = "na
|
|
|
35
68
|
: parent.subagentPolicy,
|
|
36
69
|
subagents: Object.freeze(subagents),
|
|
37
70
|
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
};
|
|
72
|
+
const agents = {};
|
|
73
|
+
for (const [key, normalized] of Object.entries(normalizedRegistrations)) {
|
|
74
|
+
const resolvedPath = resolve(registryRoot, normalized.path);
|
|
75
|
+
agents[key] = compileRegistrationTree(key, normalized, key, [{ key, resolvedPath }]);
|
|
41
76
|
}
|
|
42
77
|
return Object.freeze({
|
|
43
78
|
schemaVersion: 1,
|
|
@@ -76,7 +111,7 @@ function normalizeSubagentRegistration(parentKey, key, registration) {
|
|
|
76
111
|
if (!registration.trim()) {
|
|
77
112
|
throw new Error(`Subagent "${parentKey}/${key}" must register a folder path.`);
|
|
78
113
|
}
|
|
79
|
-
return { path: registration, mcp: {} };
|
|
114
|
+
return { path: registration, mcp: {}, subagents: {} };
|
|
80
115
|
}
|
|
81
116
|
if (!registration ||
|
|
82
117
|
typeof registration !== "object" ||
|
|
@@ -84,10 +119,17 @@ function normalizeSubagentRegistration(parentKey, key, registration) {
|
|
|
84
119
|
!registration.path.trim()) {
|
|
85
120
|
throw new Error(`Subagent "${parentKey}/${key}" must register a folder path.`);
|
|
86
121
|
}
|
|
122
|
+
if (registration.subagents !== undefined &&
|
|
123
|
+
(!registration.subagents ||
|
|
124
|
+
typeof registration.subagents !== "object" ||
|
|
125
|
+
Array.isArray(registration.subagents))) {
|
|
126
|
+
throw new Error(`Subagent "${parentKey}/${key}" subagents must be an object of named registrations.`);
|
|
127
|
+
}
|
|
87
128
|
validateMcpRegistration(`Subagent "${parentKey}/${key}"`, registration.mcp);
|
|
88
129
|
return {
|
|
89
130
|
path: registration.path,
|
|
90
131
|
mcp: registration.mcp ?? {},
|
|
132
|
+
subagents: registration.subagents ?? {},
|
|
91
133
|
};
|
|
92
134
|
}
|
|
93
135
|
function validateMcpRegistration(owner, registration) {
|
|
@@ -99,10 +99,21 @@ async function readDeclaredPackages(projectRoot) {
|
|
|
99
99
|
return declared;
|
|
100
100
|
}
|
|
101
101
|
function allCompiledAgents(agents) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
const collected = [];
|
|
103
|
+
const visited = new Set();
|
|
104
|
+
const visit = (agent) => {
|
|
105
|
+
if (visited.has(agent))
|
|
106
|
+
return;
|
|
107
|
+
visited.add(agent);
|
|
108
|
+
collected.push(agent);
|
|
109
|
+
for (const child of Object.values(agent.subagents ?? {})) {
|
|
110
|
+
visit(child);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
for (const agent of Object.values(agents)) {
|
|
114
|
+
visit(agent);
|
|
115
|
+
}
|
|
116
|
+
return collected;
|
|
106
117
|
}
|
|
107
118
|
function isInstalled(packageName, projectRoot) {
|
|
108
119
|
try {
|
package/dist/runtime/agent.js
CHANGED
|
@@ -337,7 +337,8 @@ export class RuntimeAgent {
|
|
|
337
337
|
await this.#store.append(sessionId, pauseEvents);
|
|
338
338
|
return projectSessionSnapshot([...events, ...pauseEvents]);
|
|
339
339
|
}
|
|
340
|
-
async #ownedChild(parentSessionId, childSessionId) {
|
|
340
|
+
async #ownedChild(parentSessionId, childSessionId, visited = new Set()) {
|
|
341
|
+
visited.add(this);
|
|
341
342
|
for (const child of Object.values(this.#subagents)) {
|
|
342
343
|
const events = await child.#readSession(childSessionId);
|
|
343
344
|
const lineage = sessionLineage(events);
|
|
@@ -348,6 +349,18 @@ export class RuntimeAgent {
|
|
|
348
349
|
return child;
|
|
349
350
|
}
|
|
350
351
|
}
|
|
352
|
+
if (parentSessionId === undefined) {
|
|
353
|
+
for (const child of Object.values(this.#subagents)) {
|
|
354
|
+
if (visited.has(child))
|
|
355
|
+
continue;
|
|
356
|
+
try {
|
|
357
|
+
return await child.#ownedChild(undefined, childSessionId, visited);
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
// Continue searching sibling subtrees.
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
351
364
|
throw new OrchaError("session_not_found", `Child session "${childSessionId}" was not found for agent "${this.#agentKey}".`);
|
|
352
365
|
}
|
|
353
366
|
async update(sessionId, update) {
|
|
@@ -93,22 +93,19 @@ class OrchaRuntimeCore {
|
|
|
93
93
|
return runtimeStore;
|
|
94
94
|
};
|
|
95
95
|
const agents = new Map();
|
|
96
|
-
|
|
97
|
-
const subagents = Object.fromEntries(Object.entries(manifest.subagents ?? {}).map(([subagentName, subagentManifest]) =>
|
|
98
|
-
subagentName
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}),
|
|
110
|
-
]));
|
|
111
|
-
agents.set(name, new RuntimeAgent({
|
|
96
|
+
const createRuntimeAgent = (manifest, delegatedOnly, ancestry) => {
|
|
97
|
+
const subagents = Object.fromEntries(Object.entries(manifest.subagents ?? {}).map(([subagentName, subagentManifest]) => {
|
|
98
|
+
if (ancestry.has(subagentName)) {
|
|
99
|
+
throw new Error(`Circular subagent registration detected: ${[...ancestry, subagentName].join(" -> ")}.`);
|
|
100
|
+
}
|
|
101
|
+
const nextAncestry = new Set(ancestry);
|
|
102
|
+
nextAncestry.add(subagentName);
|
|
103
|
+
return [
|
|
104
|
+
subagentName,
|
|
105
|
+
createRuntimeAgent(subagentManifest, true, nextAncestry),
|
|
106
|
+
];
|
|
107
|
+
}));
|
|
108
|
+
return new RuntimeAgent({
|
|
112
109
|
manifest,
|
|
113
110
|
configuration: runtimeConfiguration,
|
|
114
111
|
store: createRuntimeStore(manifest),
|
|
@@ -116,9 +113,13 @@ class OrchaRuntimeCore {
|
|
|
116
113
|
sessionControls: this.#sessionControls,
|
|
117
114
|
generateProviderResponse,
|
|
118
115
|
subagents,
|
|
116
|
+
delegatedOnly,
|
|
119
117
|
projectRoot,
|
|
120
118
|
randomUUID: this.#platform.randomUUID,
|
|
121
|
-
})
|
|
119
|
+
});
|
|
120
|
+
};
|
|
121
|
+
for (const [name, manifest] of Object.entries(bundle.agents)) {
|
|
122
|
+
agents.set(name, createRuntimeAgent(manifest, false, new Set([name])));
|
|
122
123
|
}
|
|
123
124
|
this.#bundle = bundle;
|
|
124
125
|
this.#inferenceEnabled = inferenceEnabled;
|
package/dist/testing.js
CHANGED
|
@@ -52,20 +52,29 @@ export async function runTests(orcha, options = {}) {
|
|
|
52
52
|
const store = createStore(manifest);
|
|
53
53
|
const activeSessions = new Set();
|
|
54
54
|
const sessionControls = new Map();
|
|
55
|
-
const
|
|
56
|
-
name
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
55
|
+
const createTestSubagents = (parentManifest, ancestry) => Object.fromEntries(Object.entries(parentManifest.subagents ?? {}).map(([name, subagentManifest]) => {
|
|
56
|
+
if (ancestry.has(name)) {
|
|
57
|
+
throw new Error(`Circular subagent registration detected: ${[...ancestry, name].join(" -> ")}.`);
|
|
58
|
+
}
|
|
59
|
+
const nextAncestry = new Set(ancestry);
|
|
60
|
+
nextAncestry.add(name);
|
|
61
|
+
return [
|
|
62
|
+
name,
|
|
63
|
+
new RuntimeAgent({
|
|
64
|
+
manifest: subagentManifest,
|
|
65
|
+
configuration: context.configuration,
|
|
66
|
+
store: createStore(subagentManifest),
|
|
67
|
+
activeSessions,
|
|
68
|
+
sessionControls,
|
|
69
|
+
generateProviderResponse: context.generateProviderResponse,
|
|
70
|
+
subagents: createTestSubagents(subagentManifest, nextAncestry),
|
|
71
|
+
delegatedOnly: true,
|
|
72
|
+
sessionIdPrefix: "ses_test_",
|
|
73
|
+
projectRoot: context.projectRoot,
|
|
74
|
+
}),
|
|
75
|
+
];
|
|
76
|
+
}));
|
|
77
|
+
const subagents = createTestSubagents(manifest, new Set([manifest.key ?? manifest.name]));
|
|
69
78
|
const agent = new RuntimeAgent({
|
|
70
79
|
manifest: withTestActions(manifest, Object.keys(testCase.configuration.actions ?? {})),
|
|
71
80
|
configuration: context.configuration,
|
package/dist/types.d.ts
CHANGED
|
@@ -54,6 +54,7 @@ export type McpRegistration = Record<string, string>;
|
|
|
54
54
|
export type SubagentRegistration = string | {
|
|
55
55
|
path: string;
|
|
56
56
|
mcp?: McpRegistration;
|
|
57
|
+
subagents?: Record<string, SubagentRegistration>;
|
|
57
58
|
};
|
|
58
59
|
export type AgentRegistration = string | {
|
|
59
60
|
path: string;
|
|
@@ -387,10 +387,20 @@ function createNodeStorageExports() {
|
|
|
387
387
|
].join("\n");
|
|
388
388
|
}
|
|
389
389
|
function allCompiledAgents(agents) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
390
|
+
const collected = [];
|
|
391
|
+
const visited = /* @__PURE__ */ new Set();
|
|
392
|
+
const visit = (agent) => {
|
|
393
|
+
if (visited.has(agent)) return;
|
|
394
|
+
visited.add(agent);
|
|
395
|
+
collected.push(agent);
|
|
396
|
+
for (const child of Object.values(agent.subagents ?? {})) {
|
|
397
|
+
visit(child);
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
for (const agent of Object.values(agents)) {
|
|
401
|
+
visit(agent);
|
|
402
|
+
}
|
|
403
|
+
return collected;
|
|
394
404
|
}
|
|
395
405
|
function createProviderRuntimeSource(providerNames, target) {
|
|
396
406
|
const providersDirectory = (0, import_path.resolve)(
|
|
@@ -35,42 +35,74 @@ function compileRegistry(registrations, registryRoot, actionRuntime = "native",
|
|
|
35
35
|
'orcha.init() requires an "agents" object of registered folder paths.'
|
|
36
36
|
);
|
|
37
37
|
}
|
|
38
|
-
const
|
|
38
|
+
const normalizedRegistrations = {};
|
|
39
|
+
const registrationsByPath = /* @__PURE__ */ new Map();
|
|
39
40
|
for (const [key, registration] of Object.entries(registrations)) {
|
|
40
41
|
if (!key.trim()) {
|
|
41
42
|
throw new Error("Registered agent names cannot be empty.");
|
|
42
43
|
}
|
|
43
44
|
const normalized = normalizeAgentRegistration(key, registration);
|
|
45
|
+
normalizedRegistrations[key] = normalized;
|
|
46
|
+
const resolvedPath = (0, import_path.resolve)(registryRoot, normalized.path);
|
|
47
|
+
if (!registrationsByPath.has(resolvedPath)) {
|
|
48
|
+
registrationsByPath.set(resolvedPath, {
|
|
49
|
+
key,
|
|
50
|
+
registration: normalized
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (Object.keys(normalizedRegistrations).length === 0) {
|
|
55
|
+
throw new Error("At least one agent must be registered.");
|
|
56
|
+
}
|
|
57
|
+
const compileRegistrationTree = (key, normalized, ownerPath, ancestry) => {
|
|
58
|
+
const resolvedPath = (0, import_path.resolve)(registryRoot, normalized.path);
|
|
59
|
+
const inherited = normalizedRegistrations[key] ?? registrationsByPath.get(resolvedPath)?.registration;
|
|
60
|
+
const effectiveMcp = Object.keys(normalized.mcp).length > 0 ? normalized.mcp : inherited?.mcp ?? {};
|
|
61
|
+
const effectiveSubagentRegistrations = Object.keys(normalized.subagents).length > 0 ? normalized.subagents : inherited?.subagents ?? {};
|
|
44
62
|
const subagents = {};
|
|
45
|
-
for (const [subagentKey,
|
|
46
|
-
|
|
63
|
+
for (const [subagentKey, subagentRegistration] of Object.entries(
|
|
64
|
+
effectiveSubagentRegistrations
|
|
47
65
|
)) {
|
|
48
66
|
if (!subagentKey.trim()) {
|
|
49
|
-
throw new Error(`Agent "${
|
|
67
|
+
throw new Error(`Agent "${ownerPath}" has an empty subagent name.`);
|
|
50
68
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
69
|
+
const normalizedSubagent = normalizeSubagentRegistration(
|
|
70
|
+
ownerPath,
|
|
53
71
|
subagentKey,
|
|
54
|
-
|
|
72
|
+
subagentRegistration
|
|
55
73
|
);
|
|
56
|
-
|
|
57
|
-
subagentKey,
|
|
58
|
-
subagent.path,
|
|
59
|
-
subagent.mcp,
|
|
74
|
+
const childResolvedPath = (0, import_path.resolve)(
|
|
60
75
|
registryRoot,
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
normalizedSubagent.path
|
|
77
|
+
);
|
|
78
|
+
const cycleExists = ancestry.some(
|
|
79
|
+
(ancestor) => ancestor.resolvedPath === childResolvedPath || ancestor.key === subagentKey
|
|
80
|
+
);
|
|
81
|
+
if (cycleExists) {
|
|
82
|
+
const chain = [
|
|
83
|
+
...ancestry.map((item) => item.key),
|
|
84
|
+
subagentKey
|
|
85
|
+
].join(" -> ");
|
|
86
|
+
throw new Error(
|
|
87
|
+
`Circular subagent registration detected: ${chain}.`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
subagents[subagentKey] = compileRegistrationTree(
|
|
91
|
+
subagentKey,
|
|
92
|
+
normalizedSubagent,
|
|
93
|
+
`${ownerPath}/${subagentKey}`,
|
|
94
|
+
[...ancestry, { key: subagentKey, resolvedPath: childResolvedPath }]
|
|
63
95
|
);
|
|
64
96
|
}
|
|
65
97
|
const parent = compileAgent(
|
|
66
98
|
key,
|
|
67
99
|
normalized.path,
|
|
68
|
-
|
|
100
|
+
effectiveMcp,
|
|
69
101
|
registryRoot,
|
|
70
102
|
actionRuntime,
|
|
71
103
|
target
|
|
72
104
|
);
|
|
73
|
-
|
|
105
|
+
return Object.freeze({
|
|
74
106
|
...parent,
|
|
75
107
|
subagentPolicy: Object.keys(subagents).length > 0 ? Object.freeze({
|
|
76
108
|
...parent.subagentPolicy,
|
|
@@ -78,9 +110,16 @@ function compileRegistry(registrations, registryRoot, actionRuntime = "native",
|
|
|
78
110
|
}) : parent.subagentPolicy,
|
|
79
111
|
subagents: Object.freeze(subagents)
|
|
80
112
|
});
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
113
|
+
};
|
|
114
|
+
const agents = {};
|
|
115
|
+
for (const [key, normalized] of Object.entries(normalizedRegistrations)) {
|
|
116
|
+
const resolvedPath = (0, import_path.resolve)(registryRoot, normalized.path);
|
|
117
|
+
agents[key] = compileRegistrationTree(
|
|
118
|
+
key,
|
|
119
|
+
normalized,
|
|
120
|
+
key,
|
|
121
|
+
[{ key, resolvedPath }]
|
|
122
|
+
);
|
|
84
123
|
}
|
|
85
124
|
return Object.freeze({
|
|
86
125
|
schemaVersion: 1,
|
|
@@ -120,20 +159,26 @@ function normalizeSubagentRegistration(parentKey, key, registration) {
|
|
|
120
159
|
`Subagent "${parentKey}/${key}" must register a folder path.`
|
|
121
160
|
);
|
|
122
161
|
}
|
|
123
|
-
return { path: registration, mcp: {} };
|
|
162
|
+
return { path: registration, mcp: {}, subagents: {} };
|
|
124
163
|
}
|
|
125
164
|
if (!registration || typeof registration !== "object" || typeof registration.path !== "string" || !registration.path.trim()) {
|
|
126
165
|
throw new Error(
|
|
127
166
|
`Subagent "${parentKey}/${key}" must register a folder path.`
|
|
128
167
|
);
|
|
129
168
|
}
|
|
169
|
+
if (registration.subagents !== void 0 && (!registration.subagents || typeof registration.subagents !== "object" || Array.isArray(registration.subagents))) {
|
|
170
|
+
throw new Error(
|
|
171
|
+
`Subagent "${parentKey}/${key}" subagents must be an object of named registrations.`
|
|
172
|
+
);
|
|
173
|
+
}
|
|
130
174
|
validateMcpRegistration(
|
|
131
175
|
`Subagent "${parentKey}/${key}"`,
|
|
132
176
|
registration.mcp
|
|
133
177
|
);
|
|
134
178
|
return {
|
|
135
179
|
path: registration.path,
|
|
136
|
-
mcp: registration.mcp ?? {}
|
|
180
|
+
mcp: registration.mcp ?? {},
|
|
181
|
+
subagents: registration.subagents ?? {}
|
|
137
182
|
};
|
|
138
183
|
}
|
|
139
184
|
function validateMcpRegistration(owner, registration) {
|
|
@@ -130,10 +130,20 @@ async function readDeclaredPackages(projectRoot) {
|
|
|
130
130
|
return declared;
|
|
131
131
|
}
|
|
132
132
|
function allCompiledAgents(agents) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
const collected = [];
|
|
134
|
+
const visited = /* @__PURE__ */ new Set();
|
|
135
|
+
const visit = (agent) => {
|
|
136
|
+
if (visited.has(agent)) return;
|
|
137
|
+
visited.add(agent);
|
|
138
|
+
collected.push(agent);
|
|
139
|
+
for (const child of Object.values(agent.subagents ?? {})) {
|
|
140
|
+
visit(child);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
for (const agent of Object.values(agents)) {
|
|
144
|
+
visit(agent);
|
|
145
|
+
}
|
|
146
|
+
return collected;
|
|
137
147
|
}
|
|
138
148
|
function isInstalled(packageName, projectRoot) {
|
|
139
149
|
try {
|
|
@@ -439,7 +439,8 @@ class RuntimeAgent {
|
|
|
439
439
|
await this.#store.append(sessionId, pauseEvents);
|
|
440
440
|
return projectSessionSnapshot([...events, ...pauseEvents]);
|
|
441
441
|
}
|
|
442
|
-
async #ownedChild(parentSessionId, childSessionId) {
|
|
442
|
+
async #ownedChild(parentSessionId, childSessionId, visited = /* @__PURE__ */ new Set()) {
|
|
443
|
+
visited.add(this);
|
|
443
444
|
for (const child of Object.values(this.#subagents)) {
|
|
444
445
|
const events = await child.#readSession(childSessionId);
|
|
445
446
|
const lineage = sessionLineage(events);
|
|
@@ -447,6 +448,15 @@ class RuntimeAgent {
|
|
|
447
448
|
return child;
|
|
448
449
|
}
|
|
449
450
|
}
|
|
451
|
+
if (parentSessionId === void 0) {
|
|
452
|
+
for (const child of Object.values(this.#subagents)) {
|
|
453
|
+
if (visited.has(child)) continue;
|
|
454
|
+
try {
|
|
455
|
+
return await child.#ownedChild(void 0, childSessionId, visited);
|
|
456
|
+
} catch {
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
450
460
|
throw new import_errors.OrchaError(
|
|
451
461
|
"session_not_found",
|
|
452
462
|
`Child session "${childSessionId}" was not found for agent "${this.#agentKey}".`
|
|
@@ -117,38 +117,41 @@ class OrchaRuntimeCore {
|
|
|
117
117
|
return runtimeStore;
|
|
118
118
|
};
|
|
119
119
|
const agents = /* @__PURE__ */ new Map();
|
|
120
|
-
|
|
120
|
+
const createRuntimeAgent = (manifest, delegatedOnly, ancestry) => {
|
|
121
121
|
const subagents = Object.fromEntries(
|
|
122
122
|
Object.entries(manifest.subagents ?? {}).map(
|
|
123
|
-
([subagentName, subagentManifest]) =>
|
|
124
|
-
subagentName
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
]
|
|
123
|
+
([subagentName, subagentManifest]) => {
|
|
124
|
+
if (ancestry.has(subagentName)) {
|
|
125
|
+
throw new Error(
|
|
126
|
+
`Circular subagent registration detected: ${[...ancestry, subagentName].join(" -> ")}.`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
const nextAncestry = new Set(ancestry);
|
|
130
|
+
nextAncestry.add(subagentName);
|
|
131
|
+
return [
|
|
132
|
+
subagentName,
|
|
133
|
+
createRuntimeAgent(subagentManifest, true, nextAncestry)
|
|
134
|
+
];
|
|
135
|
+
}
|
|
137
136
|
)
|
|
138
137
|
);
|
|
138
|
+
return new import_agent.RuntimeAgent({
|
|
139
|
+
manifest,
|
|
140
|
+
configuration: runtimeConfiguration,
|
|
141
|
+
store: createRuntimeStore(manifest),
|
|
142
|
+
activeSessions: this.#activeSessions,
|
|
143
|
+
sessionControls: this.#sessionControls,
|
|
144
|
+
generateProviderResponse,
|
|
145
|
+
subagents,
|
|
146
|
+
delegatedOnly,
|
|
147
|
+
projectRoot,
|
|
148
|
+
randomUUID: this.#platform.randomUUID
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
for (const [name, manifest] of Object.entries(bundle.agents)) {
|
|
139
152
|
agents.set(
|
|
140
153
|
name,
|
|
141
|
-
new
|
|
142
|
-
manifest,
|
|
143
|
-
configuration: runtimeConfiguration,
|
|
144
|
-
store: createRuntimeStore(manifest),
|
|
145
|
-
activeSessions: this.#activeSessions,
|
|
146
|
-
sessionControls: this.#sessionControls,
|
|
147
|
-
generateProviderResponse,
|
|
148
|
-
subagents,
|
|
149
|
-
projectRoot,
|
|
150
|
-
randomUUID: this.#platform.randomUUID
|
|
151
|
-
})
|
|
154
|
+
createRuntimeAgent(manifest, false, /* @__PURE__ */ new Set([name]))
|
|
152
155
|
);
|
|
153
156
|
}
|
|
154
157
|
this.#bundle = bundle;
|
package/dist-cjs/testing.js
CHANGED
|
@@ -88,24 +88,38 @@ async function runTests(orcha, options = {}) {
|
|
|
88
88
|
const store = createStore(manifest);
|
|
89
89
|
const activeSessions = /* @__PURE__ */ new Set();
|
|
90
90
|
const sessionControls = /* @__PURE__ */ new Map();
|
|
91
|
-
const
|
|
92
|
-
Object.entries(
|
|
93
|
-
([name, subagentManifest]) =>
|
|
94
|
-
name
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
91
|
+
const createTestSubagents = (parentManifest, ancestry) => Object.fromEntries(
|
|
92
|
+
Object.entries(parentManifest.subagents ?? {}).map(
|
|
93
|
+
([name, subagentManifest]) => {
|
|
94
|
+
if (ancestry.has(name)) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Circular subagent registration detected: ${[...ancestry, name].join(" -> ")}.`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const nextAncestry = new Set(ancestry);
|
|
100
|
+
nextAncestry.add(name);
|
|
101
|
+
return [
|
|
102
|
+
name,
|
|
103
|
+
new import_agent.RuntimeAgent({
|
|
104
|
+
manifest: subagentManifest,
|
|
105
|
+
configuration: context.configuration,
|
|
106
|
+
store: createStore(subagentManifest),
|
|
107
|
+
activeSessions,
|
|
108
|
+
sessionControls,
|
|
109
|
+
generateProviderResponse: context.generateProviderResponse,
|
|
110
|
+
subagents: createTestSubagents(subagentManifest, nextAncestry),
|
|
111
|
+
delegatedOnly: true,
|
|
112
|
+
sessionIdPrefix: "ses_test_",
|
|
113
|
+
projectRoot: context.projectRoot
|
|
114
|
+
})
|
|
115
|
+
];
|
|
116
|
+
}
|
|
107
117
|
)
|
|
108
118
|
);
|
|
119
|
+
const subagents = createTestSubagents(
|
|
120
|
+
manifest,
|
|
121
|
+
/* @__PURE__ */ new Set([manifest.key ?? manifest.name])
|
|
122
|
+
);
|
|
109
123
|
const agent = new import_agent.RuntimeAgent({
|
|
110
124
|
manifest: withTestActions(
|
|
111
125
|
manifest,
|