orchajs 0.27.2 → 0.27.4
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/errors.d.ts +1 -0
- package/dist/errors.js +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/orcha.js +14 -8
- package/dist/providers/dependencies.js +15 -4
- package/dist/providers/index.js +7 -1
- package/dist/runtime/agent.js +23 -10
- package/dist/runtime/create-orcha.js +18 -17
- package/dist/runtime/node-module-loader.d.ts +11 -0
- package/dist/runtime/node-module-loader.js +18 -0
- package/dist/runtime/structured-output.d.ts +1 -0
- package/dist/runtime/structured-output.js +10 -1
- package/dist/storage/create-store.js +1 -1
- package/dist/storage/node-sqlite-facade.d.ts +20 -0
- package/dist/storage/node-sqlite-facade.js +48 -0
- 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/errors.js +7 -0
- package/dist-cjs/index.js +2 -2
- package/dist-cjs/orcha.js +19 -8
- package/dist-cjs/providers/dependencies.js +14 -4
- package/dist-cjs/providers/index.js +7 -1
- package/dist-cjs/runtime/agent.js +18 -8
- package/dist-cjs/runtime/create-orcha.js +29 -26
- package/dist-cjs/runtime/node-module-loader.js +42 -0
- package/dist-cjs/runtime/structured-output.js +12 -1
- package/dist-cjs/storage/create-store.js +2 -2
- package/dist-cjs/storage/node-sqlite-facade.js +72 -0
- package/dist-cjs/testing.js +30 -16
- package/package.json +30 -1
|
@@ -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) {
|
package/dist-cjs/errors.js
CHANGED
|
@@ -22,9 +22,11 @@ __export(errors_exports, {
|
|
|
22
22
|
OrchaError: () => OrchaError,
|
|
23
23
|
createProviderHttpError: () => createProviderHttpError,
|
|
24
24
|
describeProviderError: () => describeProviderError,
|
|
25
|
+
isOrchaError: () => isOrchaError,
|
|
25
26
|
isRetryableProviderConnectionError: () => isRetryableProviderConnectionError
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(errors_exports);
|
|
29
|
+
const ORCHA_ERROR_BRAND = Symbol.for("orchajs.OrchaError");
|
|
28
30
|
class OrchaError extends Error {
|
|
29
31
|
code;
|
|
30
32
|
retryable;
|
|
@@ -32,11 +34,15 @@ class OrchaError extends Error {
|
|
|
32
34
|
constructor(code, message, options = {}) {
|
|
33
35
|
super(message, { cause: options.cause });
|
|
34
36
|
this.name = "OrchaError";
|
|
37
|
+
Object.defineProperty(this, ORCHA_ERROR_BRAND, { value: true });
|
|
35
38
|
this.code = code;
|
|
36
39
|
this.retryable = options.retryable ?? false;
|
|
37
40
|
this.details = options.details;
|
|
38
41
|
}
|
|
39
42
|
}
|
|
43
|
+
function isOrchaError(value) {
|
|
44
|
+
return typeof value === "object" && value !== null && value[ORCHA_ERROR_BRAND] === true;
|
|
45
|
+
}
|
|
40
46
|
const NON_RETRYABLE_STATUS_CODES = /* @__PURE__ */ new Set([400, 401, 403, 404, 413, 422]);
|
|
41
47
|
const NON_RETRYABLE_ERROR_NAMES = /* @__PURE__ */ new Set([
|
|
42
48
|
"ValidationException",
|
|
@@ -224,5 +230,6 @@ function stringOrNumberField(value, key) {
|
|
|
224
230
|
OrchaError,
|
|
225
231
|
createProviderHttpError,
|
|
226
232
|
describeProviderError,
|
|
233
|
+
isOrchaError,
|
|
227
234
|
isRetryableProviderConnectionError
|
|
228
235
|
});
|
package/dist-cjs/index.js
CHANGED
|
@@ -21,14 +21,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
23
|
NodeJsonlSessionStore: () => import_node_jsonl.NodeJsonlSessionStore,
|
|
24
|
-
NodeSqliteSessionStore: () =>
|
|
24
|
+
NodeSqliteSessionStore: () => import_node_sqlite_facade.NodeSqliteSessionStore,
|
|
25
25
|
orcha: () => import_orcha.orcha
|
|
26
26
|
});
|
|
27
27
|
module.exports = __toCommonJS(index_exports);
|
|
28
28
|
var import_orcha = require("./orcha.js");
|
|
29
29
|
__reExport(index_exports, require("./runtime-entry.js"), module.exports);
|
|
30
30
|
var import_node_jsonl = require("./storage/node-jsonl.js");
|
|
31
|
-
var
|
|
31
|
+
var import_node_sqlite_facade = require("./storage/node-sqlite-facade.js");
|
|
32
32
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33
33
|
0 && (module.exports = {
|
|
34
34
|
NodeJsonlSessionStore,
|
package/dist-cjs/orcha.js
CHANGED
|
@@ -26,24 +26,26 @@ var import_fs = require("fs");
|
|
|
26
26
|
var import_path = require("path");
|
|
27
27
|
var import_url = require("url");
|
|
28
28
|
var import_inference = require("./amarsia/inference.js");
|
|
29
|
-
var import_compile = require("./compiler/compile.js");
|
|
30
29
|
var import_providers = require("./providers/index.js");
|
|
31
30
|
var import_execute = require("./runtime/actions/execute.js");
|
|
32
31
|
var import_native = require("./runtime/actions/native.js");
|
|
33
32
|
var import_compiler_hook = require("./runtime/compiler-hook.js");
|
|
34
33
|
var import_create_orcha = require("./runtime/create-orcha.js");
|
|
35
34
|
var import_client = require("./runtime/mcp/client.js");
|
|
35
|
+
var import_node_module_loader = require("./runtime/node-module-loader.js");
|
|
36
36
|
var import_optional_features = require("./runtime/optional-features.js");
|
|
37
37
|
var import_platform_node = require("./runtime/platform-node.js");
|
|
38
38
|
var import_cloud = require("./storage/cloud.js");
|
|
39
39
|
(0, import_execute.setNativeRuntimeLoader)(async () => ({ executeNativeAction: import_native.executeNativeAction }));
|
|
40
40
|
(0, import_execute.setSandboxRuntimeLoader)(async () => {
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
return (0, import_node_module_loader.importRuntimeModule)([
|
|
42
|
+
"orchajs",
|
|
43
|
+
"runtime",
|
|
44
|
+
"sandbox"
|
|
45
|
+
]);
|
|
43
46
|
});
|
|
44
47
|
(0, import_client.setMcpClientFactory)(async (server, credentials) => {
|
|
45
|
-
const
|
|
46
|
-
const { createNodeMcpClient } = await import(modulePath);
|
|
48
|
+
const { createNodeMcpClient } = await (0, import_node_module_loader.importRuntimeModule)(["orchajs", "runtime", "mcp-node"]);
|
|
47
49
|
return createNodeMcpClient(server, credentials);
|
|
48
50
|
});
|
|
49
51
|
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
@@ -68,7 +70,7 @@ function getSharedNodeOrcha() {
|
|
|
68
70
|
}
|
|
69
71
|
const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
|
|
70
72
|
if ((0, import_fs.existsSync)(registryRoot)) {
|
|
71
|
-
const compiled = (
|
|
73
|
+
const compiled = compileRegistryAtRuntime(
|
|
72
74
|
configuration.agents,
|
|
73
75
|
registryRoot,
|
|
74
76
|
configuration.actions?.runtime ?? "native",
|
|
@@ -141,7 +143,7 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
141
143
|
if (!(0, import_fs.existsSync)(manifestPath)) {
|
|
142
144
|
const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
|
|
143
145
|
if ((0, import_fs.existsSync)(registryRoot)) {
|
|
144
|
-
const compiled = (
|
|
146
|
+
const compiled = compileRegistryAtRuntime(
|
|
145
147
|
configuration.agents,
|
|
146
148
|
registryRoot,
|
|
147
149
|
configuration.actions?.runtime ?? "native",
|
|
@@ -176,7 +178,7 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
176
178
|
)) {
|
|
177
179
|
const registryRoot = (0, import_path.resolve)(projectRoot, "orcha");
|
|
178
180
|
if (!isPrecompiledRuntime() && (0, import_fs.existsSync)(registryRoot)) {
|
|
179
|
-
const recompiled = (
|
|
181
|
+
const recompiled = compileRegistryAtRuntime(
|
|
180
182
|
configuration.agents,
|
|
181
183
|
registryRoot,
|
|
182
184
|
configuration.actions?.runtime ?? "native",
|
|
@@ -194,6 +196,15 @@ function loadCompiledManifest(projectRoot, configuration) {
|
|
|
194
196
|
function compiledManifestPath(projectRoot) {
|
|
195
197
|
return (0, import_path.resolve)(projectRoot, ".orcha/dist/manifest.json");
|
|
196
198
|
}
|
|
199
|
+
function compileRegistryAtRuntime(registrations, registryRoot, actionRuntime, target) {
|
|
200
|
+
const { compileRegistry } = (0, import_node_module_loader.requireRuntimeModule)(["orchajs", "compiler"]);
|
|
201
|
+
return compileRegistry(
|
|
202
|
+
registrations,
|
|
203
|
+
registryRoot,
|
|
204
|
+
actionRuntime,
|
|
205
|
+
target
|
|
206
|
+
);
|
|
207
|
+
}
|
|
197
208
|
// Annotate the CommonJS export names for ESM import in node:
|
|
198
209
|
0 && (module.exports = {
|
|
199
210
|
orcha
|
|
@@ -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 {
|
|
@@ -24,6 +24,7 @@ __export(providers_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(providers_exports);
|
|
26
26
|
var import_errors = require("../errors.js");
|
|
27
|
+
var import_node_module_loader = require("../runtime/node-module-loader.js");
|
|
27
28
|
var import_catalog = require("./catalog.js");
|
|
28
29
|
var import_catalog2 = require("./catalog.js");
|
|
29
30
|
const loadedProviders = /* @__PURE__ */ new Map();
|
|
@@ -43,7 +44,12 @@ function loadProvider(name) {
|
|
|
43
44
|
);
|
|
44
45
|
}
|
|
45
46
|
const descriptor = import_catalog.builtInProviderCatalog[name];
|
|
46
|
-
const
|
|
47
|
+
const moduleName = descriptor.moduleFile.replace(/\.js$/, "");
|
|
48
|
+
const loading = (0, import_node_module_loader.importRuntimeModule)([
|
|
49
|
+
"orchajs",
|
|
50
|
+
"providers",
|
|
51
|
+
moduleName
|
|
52
|
+
]).then((module2) => {
|
|
47
53
|
const provider = module2[descriptor.exportName];
|
|
48
54
|
if (!isProviderAdapter(provider) || provider.name !== name) {
|
|
49
55
|
throw new Error(
|
|
@@ -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}".`
|
|
@@ -986,7 +996,7 @@ class RuntimeAgent {
|
|
|
986
996
|
output: streamedOutput
|
|
987
997
|
};
|
|
988
998
|
}
|
|
989
|
-
if (
|
|
999
|
+
if ((0, import_structured_output.isStructuredOutputError)(error) && error.response) {
|
|
990
1000
|
const modelDurationMs2 = Math.round(
|
|
991
1001
|
performance.now() - modelStartedAt
|
|
992
1002
|
);
|
|
@@ -1039,7 +1049,7 @@ class RuntimeAgent {
|
|
|
1039
1049
|
details
|
|
1040
1050
|
});
|
|
1041
1051
|
}
|
|
1042
|
-
if (
|
|
1052
|
+
if ((0, import_errors.isOrchaError)(error)) {
|
|
1043
1053
|
throw error;
|
|
1044
1054
|
}
|
|
1045
1055
|
const providerError = (0, import_errors.describeProviderError)(error);
|
|
@@ -1272,9 +1282,9 @@ class RuntimeAgent {
|
|
|
1272
1282
|
};
|
|
1273
1283
|
} catch (error) {
|
|
1274
1284
|
const message = error instanceof Error ? error.message : String(error);
|
|
1275
|
-
const code =
|
|
1276
|
-
const details =
|
|
1277
|
-
const retryable =
|
|
1285
|
+
const code = (0, import_errors.isOrchaError)(error) ? error.code : "execution_failed";
|
|
1286
|
+
const details = (0, import_errors.isOrchaError)(error) ? error.details : void 0;
|
|
1287
|
+
const retryable = (0, import_errors.isOrchaError)(error) ? error.retryable : false;
|
|
1278
1288
|
const usage = usageForRun(previousEvents, writer.run);
|
|
1279
1289
|
await this.#store.append(sessionId, [
|
|
1280
1290
|
writer.create("run.failed", {
|
|
@@ -2036,7 +2046,7 @@ class RuntimeAgent {
|
|
|
2036
2046
|
try {
|
|
2037
2047
|
return await operation();
|
|
2038
2048
|
} catch (error) {
|
|
2039
|
-
const normalized =
|
|
2049
|
+
const normalized = (0, import_errors.isOrchaError)(error) ? error : new import_errors.OrchaError(
|
|
2040
2050
|
"storage_error",
|
|
2041
2051
|
error instanceof Error ? error.message : String(error),
|
|
2042
2052
|
{ retryable: true, cause: error }
|
|
@@ -2062,7 +2072,7 @@ class RuntimeAgent {
|
|
|
2062
2072
|
try {
|
|
2063
2073
|
return await operation();
|
|
2064
2074
|
} catch (error) {
|
|
2065
|
-
if (
|
|
2075
|
+
if ((0, import_errors.isOrchaError)(error)) {
|
|
2066
2076
|
throw error;
|
|
2067
2077
|
}
|
|
2068
2078
|
throw new import_errors.OrchaError(
|
|
@@ -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;
|
|
@@ -0,0 +1,42 @@
|
|
|
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 node_module_loader_exports = {};
|
|
21
|
+
__export(node_module_loader_exports, {
|
|
22
|
+
importRuntimeModule: () => importRuntimeModule,
|
|
23
|
+
requireRuntimeModule: () => requireRuntimeModule
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(node_module_loader_exports);
|
|
26
|
+
var import_module = require("module");
|
|
27
|
+
const runtimeRequire = (0, import_module.createRequire)(__orchaImportMetaUrl);
|
|
28
|
+
const runtimeImport = new Function(
|
|
29
|
+
"specifier",
|
|
30
|
+
"return import(specifier)"
|
|
31
|
+
);
|
|
32
|
+
function requireRuntimeModule(specifierSegments) {
|
|
33
|
+
return runtimeRequire(specifierSegments.join("/"));
|
|
34
|
+
}
|
|
35
|
+
async function importRuntimeModule(specifierSegments) {
|
|
36
|
+
return await runtimeImport(specifierSegments.join("/"));
|
|
37
|
+
}
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
importRuntimeModule,
|
|
41
|
+
requireRuntimeModule
|
|
42
|
+
});
|
|
@@ -20,11 +20,15 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var structured_output_exports = {};
|
|
21
21
|
__export(structured_output_exports, {
|
|
22
22
|
StructuredOutputError: () => StructuredOutputError,
|
|
23
|
+
isStructuredOutputError: () => isStructuredOutputError,
|
|
23
24
|
parseStructuredOutput: () => parseStructuredOutput,
|
|
24
25
|
resolveProviderStructuredOutput: () => resolveProviderStructuredOutput,
|
|
25
26
|
validateStructuredValue: () => validateStructuredValue
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(structured_output_exports);
|
|
29
|
+
const STRUCTURED_OUTPUT_ERROR_BRAND = Symbol.for(
|
|
30
|
+
"orchajs.StructuredOutputError"
|
|
31
|
+
);
|
|
28
32
|
class StructuredOutputError extends Error {
|
|
29
33
|
kind;
|
|
30
34
|
rawText;
|
|
@@ -34,12 +38,18 @@ class StructuredOutputError extends Error {
|
|
|
34
38
|
constructor(message, options) {
|
|
35
39
|
super(message, { cause: options.cause });
|
|
36
40
|
this.name = "StructuredOutputError";
|
|
41
|
+
Object.defineProperty(this, STRUCTURED_OUTPUT_ERROR_BRAND, {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
|
37
44
|
this.kind = options.kind;
|
|
38
45
|
this.rawText = options.rawText;
|
|
39
46
|
this.responsePreview = options.responsePreview;
|
|
40
47
|
this.schemaErrors = options.schemaErrors;
|
|
41
48
|
}
|
|
42
49
|
}
|
|
50
|
+
function isStructuredOutputError(value) {
|
|
51
|
+
return typeof value === "object" && value !== null && value[STRUCTURED_OUTPUT_ERROR_BRAND] === true;
|
|
52
|
+
}
|
|
43
53
|
function resolveProviderStructuredOutput(request, baseResponse, textOutput) {
|
|
44
54
|
if (request.outputType !== "json" || baseResponse.toolCalls.length > 0 || baseResponse.stopReason === "max_tokens" || baseResponse.stopReason === "content_filter") {
|
|
45
55
|
return baseResponse;
|
|
@@ -53,7 +63,7 @@ function resolveProviderStructuredOutput(request, baseResponse, textOutput) {
|
|
|
53
63
|
)
|
|
54
64
|
};
|
|
55
65
|
} catch (error) {
|
|
56
|
-
if (error
|
|
66
|
+
if (isStructuredOutputError(error)) {
|
|
57
67
|
error.response = baseResponse;
|
|
58
68
|
}
|
|
59
69
|
throw error;
|
|
@@ -215,6 +225,7 @@ function isObject(value) {
|
|
|
215
225
|
// Annotate the CommonJS export names for ESM import in node:
|
|
216
226
|
0 && (module.exports = {
|
|
217
227
|
StructuredOutputError,
|
|
228
|
+
isStructuredOutputError,
|
|
218
229
|
parseStructuredOutput,
|
|
219
230
|
resolveProviderStructuredOutput,
|
|
220
231
|
validateStructuredValue
|
|
@@ -23,7 +23,7 @@ __export(create_store_exports, {
|
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(create_store_exports);
|
|
25
25
|
var import_node_jsonl = require("./node-jsonl.js");
|
|
26
|
-
var
|
|
26
|
+
var import_node_sqlite_facade = require("./node-sqlite-facade.js");
|
|
27
27
|
function createSessionStore(options) {
|
|
28
28
|
const strategy = options.strategy ?? "node-jsonl";
|
|
29
29
|
const directory = options.directory ?? ".orcha/sessions";
|
|
@@ -35,7 +35,7 @@ function createSessionStore(options) {
|
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
37
|
if (strategy === "sqlite") {
|
|
38
|
-
return new
|
|
38
|
+
return new import_node_sqlite_facade.NodeSqliteSessionStore(
|
|
39
39
|
directory,
|
|
40
40
|
options.projectRoot,
|
|
41
41
|
options.agentName
|
|
@@ -0,0 +1,72 @@
|
|
|
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 node_sqlite_facade_exports = {};
|
|
21
|
+
__export(node_sqlite_facade_exports, {
|
|
22
|
+
NodeSqliteSessionStore: () => NodeSqliteSessionStore
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(node_sqlite_facade_exports);
|
|
25
|
+
var import_node_module_loader = require("../runtime/node-module-loader.js");
|
|
26
|
+
class NodeSqliteSessionStore {
|
|
27
|
+
#store;
|
|
28
|
+
databasePath;
|
|
29
|
+
agentName;
|
|
30
|
+
constructor(directory = ".orcha/sessions", projectRoot = process.cwd(), agentName) {
|
|
31
|
+
const { NodeSqliteSessionStore: SqliteStore } = (0, import_node_module_loader.requireRuntimeModule)(["orchajs", "storage", "sqlite"]);
|
|
32
|
+
const store = new SqliteStore(directory, projectRoot, agentName);
|
|
33
|
+
this.#store = store;
|
|
34
|
+
this.databasePath = store.databasePath;
|
|
35
|
+
this.agentName = store.agentName;
|
|
36
|
+
}
|
|
37
|
+
read(sessionId) {
|
|
38
|
+
return this.#store.read(sessionId);
|
|
39
|
+
}
|
|
40
|
+
readAfterSequence(sessionId, afterSequence, limit) {
|
|
41
|
+
return this.#store.readAfterSequence?.(
|
|
42
|
+
sessionId,
|
|
43
|
+
afterSequence,
|
|
44
|
+
limit
|
|
45
|
+
) ?? Promise.resolve([]);
|
|
46
|
+
}
|
|
47
|
+
append(sessionId, events) {
|
|
48
|
+
return this.#store.append(sessionId, events);
|
|
49
|
+
}
|
|
50
|
+
listSessionIds() {
|
|
51
|
+
return this.#store.listSessionIds();
|
|
52
|
+
}
|
|
53
|
+
getCloudAcknowledgement(sessionId) {
|
|
54
|
+
return this.#store.getCloudAcknowledgement?.(sessionId) ?? Promise.resolve(0);
|
|
55
|
+
}
|
|
56
|
+
setCloudAcknowledgement(sessionId, sequence) {
|
|
57
|
+
return this.#store.setCloudAcknowledgement?.(sessionId, sequence) ?? Promise.resolve();
|
|
58
|
+
}
|
|
59
|
+
subscribe(sessionId, listener) {
|
|
60
|
+
return this.#store.subscribe?.(sessionId, listener) ?? (() => void 0);
|
|
61
|
+
}
|
|
62
|
+
subscribeAll(listener) {
|
|
63
|
+
return this.#store.subscribeAll?.(listener) ?? (() => void 0);
|
|
64
|
+
}
|
|
65
|
+
describeLocation(sessionId) {
|
|
66
|
+
return this.#store.describeLocation?.(sessionId) ?? Promise.resolve(this.databasePath);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
NodeSqliteSessionStore
|
|
72
|
+
});
|