orchajs 0.25.0 → 0.26.1
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/inference.js +45 -5
- package/dist/cli-agents-template.d.ts +1 -1
- package/dist/cli-agents-template.js +13 -4
- package/dist/cli.js +22 -9
- package/dist/compiler/build-project.js +22 -10
- package/dist/integrations/runtime-build.js +17 -6
- package/dist/orcha.d.ts +3 -2
- package/dist/orcha.js +22 -14
- package/dist/playground/server.js +3 -0
- package/dist/providers/anthropic.js +67 -58
- package/dist/providers/bedrock.js +14 -8
- package/dist/providers/deepseek.js +9 -2
- package/dist/providers/google-gemini.js +20 -15
- package/dist/providers/openai.js +6 -0
- package/dist/providers/types.d.ts +1 -0
- package/dist/runtime/agent.d.ts +3 -3
- package/dist/runtime/agent.js +175 -31
- package/dist/runtime/compiler-hook.js +15 -6
- package/dist/runtime/context.js +10 -3
- package/dist/runtime/session-events.js +19 -0
- package/dist/testing.js +3 -0
- package/dist/types.d.ts +4 -2
- package/dist-cjs/amarsia/inference.js +44 -7
- package/dist-cjs/cli-agents-template.js +13 -4
- package/dist-cjs/compiler/build-project.js +22 -10
- package/dist-cjs/integrations/runtime-build.js +17 -6
- package/dist-cjs/orcha.js +26 -18
- package/dist-cjs/playground/server.js +1 -0
- package/dist-cjs/providers/anthropic.js +65 -60
- package/dist-cjs/providers/bedrock.js +17 -9
- package/dist-cjs/providers/deepseek.js +10 -2
- package/dist-cjs/providers/google-gemini.js +27 -20
- package/dist-cjs/providers/openai.js +8 -0
- package/dist-cjs/runtime/agent.js +175 -32
- package/dist-cjs/runtime/compiler-hook.js +15 -6
- package/dist-cjs/runtime/context.js +10 -3
- package/dist-cjs/runtime/session-events.js +14 -0
- package/dist-cjs/testing.js +1 -0
- package/package.json +1 -1
|
@@ -34,6 +34,7 @@ const SUPPORTED_AMARSIA_PROVIDERS = /* @__PURE__ */ new Set([
|
|
|
34
34
|
"vertexai",
|
|
35
35
|
"deepseek"
|
|
36
36
|
]);
|
|
37
|
+
const TEXT_ONLY_AMARSIA_PROVIDERS = /* @__PURE__ */ new Set(["deepseek"]);
|
|
37
38
|
function createAmarsiaInferenceGenerator(configuration) {
|
|
38
39
|
const endpoint = (0, import_endpoint.resolveAmarsiaEndpoint)(configuration.endpoint);
|
|
39
40
|
return (provider, _providerConfiguration, request) => generateThroughAmarsia(endpoint, configuration.key, provider, request);
|
|
@@ -56,6 +57,7 @@ async function generateThroughAmarsia(endpoint, key, provider, request) {
|
|
|
56
57
|
`Amarsia Responses does not support "${request.outputType}" as a direct agent output.`
|
|
57
58
|
);
|
|
58
59
|
}
|
|
60
|
+
assertProviderSupportsMessageContent(provider, request.messages);
|
|
59
61
|
const gatewayProvider = provider === "vertexai" ? "googlegenai" : provider;
|
|
60
62
|
const body = {
|
|
61
63
|
provider: gatewayProvider,
|
|
@@ -106,13 +108,47 @@ async function generateThroughAmarsia(endpoint, key, provider, request) {
|
|
|
106
108
|
});
|
|
107
109
|
if (!response.ok) {
|
|
108
110
|
const message = await responseError(response);
|
|
109
|
-
throw
|
|
110
|
-
message ?? `Amarsia inference request failed with HTTP ${response.status}.`
|
|
111
|
-
);
|
|
111
|
+
throw gatewayRequestError(message, response.status);
|
|
112
112
|
}
|
|
113
113
|
const responseBody = response.headers.get("content-type")?.includes("text/event-stream") ? await readGatewayStream(response, request.publishOutput) : await response.json();
|
|
114
114
|
return toProviderResponse(request, responseBody);
|
|
115
115
|
}
|
|
116
|
+
function assertProviderSupportsMessageContent(provider, messages) {
|
|
117
|
+
if (!TEXT_ONLY_AMARSIA_PROVIDERS.has(provider)) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
for (const message of messages) {
|
|
121
|
+
if (message.role === "user" && Array.isArray(message.content)) {
|
|
122
|
+
for (const block of message.content) {
|
|
123
|
+
if (block.type !== "text") {
|
|
124
|
+
throw deepSeekMultimodalError(block.type);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (message.role === "tool") {
|
|
129
|
+
for (const result of message.results) {
|
|
130
|
+
for (const block of result.contents ?? []) {
|
|
131
|
+
if (block.type !== "text") {
|
|
132
|
+
throw deepSeekMultimodalError(block.type);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function deepSeekMultimodalError(contentType) {
|
|
140
|
+
return new import_errors.OrchaError(
|
|
141
|
+
"unsupported_content_type",
|
|
142
|
+
`DeepSeek does not support multimodal content (received "${contentType}"). DeepSeek is text-only and cannot accept images, PDFs, or other file attachments.`
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
function gatewayRequestError(message, statusCode) {
|
|
146
|
+
const detail = message?.trim() || `Amarsia inference request failed with HTTP ${statusCode}.`;
|
|
147
|
+
if (/does not support multimodal|text-only/i.test(detail)) {
|
|
148
|
+
return new import_errors.OrchaError("unsupported_content_type", detail);
|
|
149
|
+
}
|
|
150
|
+
return new Error(detail);
|
|
151
|
+
}
|
|
116
152
|
async function toResponsesInput(messages) {
|
|
117
153
|
const input = [];
|
|
118
154
|
for (const message of messages) {
|
|
@@ -127,10 +163,12 @@ async function toResponsesInput(messages) {
|
|
|
127
163
|
}
|
|
128
164
|
if (message.role === "tool") {
|
|
129
165
|
for (const result of message.results) {
|
|
166
|
+
const contents = result.contents?.length ? await Promise.all(result.contents.map(toResponsesUserContent)) : void 0;
|
|
130
167
|
input.push({
|
|
131
168
|
type: "function_call_output",
|
|
132
169
|
call_id: result.callId,
|
|
133
170
|
output: JSON.stringify(result.output ?? null),
|
|
171
|
+
...contents ? { contents } : {},
|
|
134
172
|
...result.isError ? { is_error: true } : {}
|
|
135
173
|
});
|
|
136
174
|
}
|
|
@@ -210,9 +248,8 @@ async function readGatewayStream(response, publishOutput) {
|
|
|
210
248
|
terminal = event.response;
|
|
211
249
|
} else if (event.type === "response.failed" || event.type === "error") {
|
|
212
250
|
const error = isRecord(event.error) ? event.error : event;
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
);
|
|
251
|
+
const message = typeof error.message === "string" ? error.message : "Amarsia inference streaming request failed.";
|
|
252
|
+
throw gatewayRequestError(message, 500);
|
|
216
253
|
}
|
|
217
254
|
}
|
|
218
255
|
if (!terminal) {
|
|
@@ -321,7 +358,7 @@ function normalizeUsage(usage) {
|
|
|
321
358
|
async function responseError(response) {
|
|
322
359
|
try {
|
|
323
360
|
const body = await response.json();
|
|
324
|
-
return body.error?.message ?? body.message;
|
|
361
|
+
return body.error?.message ?? body.message ?? (typeof body.detail === "string" ? body.detail : void 0);
|
|
325
362
|
} catch {
|
|
326
363
|
return void 0;
|
|
327
364
|
}
|
|
@@ -388,7 +388,7 @@ environment. The complete pause/continue flow is:
|
|
|
388
388
|
}
|
|
389
389
|
5. Application executes every requested action.
|
|
390
390
|
6. Application calls agent.resume(sessionId, {
|
|
391
|
-
toolResults: [{ callId, output, isError? }]
|
|
391
|
+
toolResults: [{ callId, output, contents?, isError? }]
|
|
392
392
|
}).
|
|
393
393
|
7. Orcha validates every callId and output, stores the results, and continues
|
|
394
394
|
the same paused run from its prior model context.
|
|
@@ -428,9 +428,9 @@ const result = await execution.result;
|
|
|
428
428
|
const evaluations = await execution.evaluations;
|
|
429
429
|
\`\`\`
|
|
430
430
|
|
|
431
|
-
\`run()\`
|
|
431
|
+
\`run()\` and conversational \`resume()\` accept either a direct \`AgentContentInput\` (a string, a single content item, or an array of content items) or an object with \`content\` and optional fields:
|
|
432
432
|
|
|
433
|
-
- \`content\` (required): a non-empty string, one content item, or an array.
|
|
433
|
+
- \`content\` (required when passing an options object): a non-empty string, one content item, or an array.
|
|
434
434
|
Use \`{ filePath: "./document.pdf" }\` for a local file or
|
|
435
435
|
\`{ url: "https://example.com/document.pdf" }\` for a remote file.
|
|
436
436
|
\`mimeType\` is optional when it can be inferred from the extension. Durable
|
|
@@ -460,7 +460,11 @@ client actions in the application and submit every result:
|
|
|
460
460
|
\`\`\`ts
|
|
461
461
|
orcha.supportBot.resume(sessionId, {
|
|
462
462
|
toolResults: [
|
|
463
|
-
{
|
|
463
|
+
{
|
|
464
|
+
callId: "call_123",
|
|
465
|
+
output: { approved: true },
|
|
466
|
+
contents: [{ filePath: "./signed-approval.pdf" }], // optional media/content items
|
|
467
|
+
}
|
|
464
468
|
],
|
|
465
469
|
});
|
|
466
470
|
\`\`\`
|
|
@@ -568,6 +572,11 @@ The local action signature is
|
|
|
568
572
|
\`sessionId\`, immutable session \`metadata\`, a stable \`idempotencyKey\`,
|
|
569
573
|
allowlisted \`env\`, guarded \`fetch\`, and prefixed \`log\`.
|
|
570
574
|
|
|
575
|
+
Actions can also return media or multimodal content back to the model alongside
|
|
576
|
+
their structured JSON output by returning \`{ output: jsonOutput, contents: [...] }\`.
|
|
577
|
+
\`contents\` accepts any \`AgentContentInput\` (such as \`{ filePath }\`,
|
|
578
|
+
\`{ url }\`, or content items). \`outputSchema\` validates \`output\` directly.
|
|
579
|
+
|
|
571
580
|
## Skills
|
|
572
581
|
|
|
573
582
|
Skills are lazy-loaded procedural instructions. Direct child folders under
|
|
@@ -114,20 +114,21 @@ async function buildProject(options = {}) {
|
|
|
114
114
|
`The ${target} target supports precompiled native actions only. Set actions.runtime to "native".`
|
|
115
115
|
);
|
|
116
116
|
}
|
|
117
|
+
const compilerDirectory = esmCompilerDirectory();
|
|
117
118
|
const runtimeFactoryPath = (0, import_path.resolve)(
|
|
118
|
-
|
|
119
|
+
compilerDirectory,
|
|
119
120
|
"../runtime/create-orcha.js"
|
|
120
121
|
).replaceAll("\\", "/");
|
|
121
122
|
const runtimePlatformPath = (0, import_path.resolve)(
|
|
122
|
-
|
|
123
|
+
compilerDirectory,
|
|
123
124
|
`../runtime/platform-${target}.js`
|
|
124
125
|
).replaceAll("\\", "/");
|
|
125
126
|
const runtimeEntryPath = (0, import_path.resolve)(
|
|
126
|
-
|
|
127
|
+
compilerDirectory,
|
|
127
128
|
"../runtime-entry.js"
|
|
128
129
|
).replaceAll("\\", "/");
|
|
129
130
|
const providerDispatcherPath = (0, import_path.resolve)(
|
|
130
|
-
|
|
131
|
+
compilerDirectory,
|
|
131
132
|
"../providers/dispatcher.js"
|
|
132
133
|
).replaceAll("\\", "/");
|
|
133
134
|
const sandboxRuntimeSource = compiledBundle.actionRuntime === "sandbox" ? createSandboxRuntimeSource() : "";
|
|
@@ -224,6 +225,17 @@ async function buildProject(options = {}) {
|
|
|
224
225
|
});
|
|
225
226
|
}
|
|
226
227
|
}
|
|
228
|
+
function esmCompilerDirectory() {
|
|
229
|
+
const currentDirectory = (0, import_path.dirname)((0, import_url.fileURLToPath)(__orchaImportMetaUrl));
|
|
230
|
+
const normalized = currentDirectory.replaceAll("\\", "/");
|
|
231
|
+
if (normalized.endsWith("/dist-cjs/compiler")) {
|
|
232
|
+
const esmCandidate = (0, import_path.resolve)(currentDirectory, "../../dist/compiler");
|
|
233
|
+
if ((0, import_fs.existsSync)(esmCandidate)) {
|
|
234
|
+
return esmCandidate;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return currentDirectory;
|
|
238
|
+
}
|
|
227
239
|
function bundleFileName(target) {
|
|
228
240
|
return target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
229
241
|
}
|
|
@@ -237,7 +249,7 @@ function runtimePlatformExport(target) {
|
|
|
237
249
|
return "nodeRuntimePlatform";
|
|
238
250
|
}
|
|
239
251
|
function createSandboxRuntimeSource() {
|
|
240
|
-
const runtimeDirectory = (
|
|
252
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
241
253
|
const executePath = (0, import_path.resolve)(
|
|
242
254
|
runtimeDirectory,
|
|
243
255
|
"../runtime/actions/execute.js"
|
|
@@ -254,7 +266,7 @@ function createSandboxRuntimeSource() {
|
|
|
254
266
|
].join("\n");
|
|
255
267
|
}
|
|
256
268
|
function createPlatformActionRuntimeSource(target) {
|
|
257
|
-
const runtimeDirectory = (
|
|
269
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
258
270
|
const executePath = (0, import_path.resolve)(
|
|
259
271
|
runtimeDirectory,
|
|
260
272
|
"../runtime/actions/execute.js"
|
|
@@ -271,7 +283,7 @@ function createPlatformActionRuntimeSource(target) {
|
|
|
271
283
|
].join("\n");
|
|
272
284
|
}
|
|
273
285
|
function createMcpRuntimeSource(target) {
|
|
274
|
-
const runtimeDirectory = (
|
|
286
|
+
const runtimeDirectory = esmCompilerDirectory();
|
|
275
287
|
const clientPath = (0, import_path.resolve)(
|
|
276
288
|
runtimeDirectory,
|
|
277
289
|
"../runtime/mcp/client.js"
|
|
@@ -292,7 +304,7 @@ function createOptionalFeatureRuntimeSource(options) {
|
|
|
292
304
|
if (!options.inference && !options.cloudStorage) {
|
|
293
305
|
return "";
|
|
294
306
|
}
|
|
295
|
-
const sourceRoot = (
|
|
307
|
+
const sourceRoot = esmCompilerDirectory();
|
|
296
308
|
const hooksPath = (0, import_path.resolve)(
|
|
297
309
|
sourceRoot,
|
|
298
310
|
"../runtime/optional-features.js"
|
|
@@ -328,7 +340,7 @@ function createOptionalFeatureRuntimeSource(options) {
|
|
|
328
340
|
return [...imports, ...registrations, ""].join("\n");
|
|
329
341
|
}
|
|
330
342
|
function createNodeStorageExports() {
|
|
331
|
-
const sourceRoot = (
|
|
343
|
+
const sourceRoot = esmCompilerDirectory();
|
|
332
344
|
const jsonlPath = (0, import_path.resolve)(
|
|
333
345
|
sourceRoot,
|
|
334
346
|
"../storage/node-jsonl.js"
|
|
@@ -351,7 +363,7 @@ function allCompiledAgents(agents) {
|
|
|
351
363
|
}
|
|
352
364
|
function createProviderRuntimeSource(providerNames, target) {
|
|
353
365
|
const providersDirectory = (0, import_path.resolve)(
|
|
354
|
-
(
|
|
366
|
+
esmCompilerDirectory(),
|
|
355
367
|
"../providers"
|
|
356
368
|
);
|
|
357
369
|
const imports = [];
|
|
@@ -28,26 +28,37 @@ var import_path = require("path");
|
|
|
28
28
|
var import_chokidar = require("chokidar");
|
|
29
29
|
var import_build_project = require("../compiler/build-project.js");
|
|
30
30
|
var import_env = require("../env.js");
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
const RUNTIME_BUILD_STATE_KEY = Symbol.for("orchajs.runtimeBuildState");
|
|
32
|
+
function getRuntimeBuildState() {
|
|
33
|
+
const globalRecord = globalThis;
|
|
34
|
+
if (!globalRecord[RUNTIME_BUILD_STATE_KEY]) {
|
|
35
|
+
globalRecord[RUNTIME_BUILD_STATE_KEY] = {
|
|
36
|
+
buildQueue: Promise.resolve(),
|
|
37
|
+
watchedTargets: /* @__PURE__ */ new Set()
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
return globalRecord[RUNTIME_BUILD_STATE_KEY];
|
|
41
|
+
}
|
|
33
42
|
function generatedBundlePath(projectRoot, target) {
|
|
34
43
|
const fileName = target === "node" ? "bundle.js" : `bundle.${target}.js`;
|
|
35
44
|
return (0, import_path.resolve)(projectRoot, ".orcha/dist", fileName);
|
|
36
45
|
}
|
|
37
46
|
function queueRuntimeBuild(projectRoot, target) {
|
|
38
|
-
const
|
|
47
|
+
const state = getRuntimeBuildState();
|
|
48
|
+
const build = state.buildQueue.then(async () => {
|
|
39
49
|
(0, import_env.loadProjectEnvironment)(projectRoot);
|
|
40
50
|
await (0, import_build_project.buildProject)({ projectRoot, target });
|
|
41
51
|
});
|
|
42
|
-
buildQueue = build.catch(() => void 0);
|
|
52
|
+
state.buildQueue = build.catch(() => void 0);
|
|
43
53
|
return build;
|
|
44
54
|
}
|
|
45
55
|
function watchRuntimeTargets(projectRoot, targets) {
|
|
56
|
+
const state = getRuntimeBuildState();
|
|
46
57
|
const key = `${projectRoot}:${targets.join(",")}`;
|
|
47
|
-
if (watchedTargets.has(key)) {
|
|
58
|
+
if (state.watchedTargets.has(key)) {
|
|
48
59
|
return;
|
|
49
60
|
}
|
|
50
|
-
watchedTargets.add(key);
|
|
61
|
+
state.watchedTargets.add(key);
|
|
51
62
|
let timer;
|
|
52
63
|
(0, import_chokidar.watch)((0, import_path.resolve)(projectRoot, "orcha"), { ignoreInitial: true }).on(
|
|
53
64
|
"all",
|
package/dist-cjs/orcha.js
CHANGED
|
@@ -46,25 +46,33 @@ var import_cloud = require("./storage/cloud.js");
|
|
|
46
46
|
});
|
|
47
47
|
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
48
48
|
(0, import_optional_features.setCloudSessionStoreFactory)((options) => new import_cloud.CloudSessionStore(options));
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
const NODE_ORCHA_SINGLETON_KEY = Symbol.for("orchajs.nodeOrchaSingleton");
|
|
50
|
+
function getSharedNodeOrcha() {
|
|
51
|
+
const globalRecord = globalThis;
|
|
52
|
+
if (!globalRecord[NODE_ORCHA_SINGLETON_KEY]) {
|
|
53
|
+
globalRecord[NODE_ORCHA_SINGLETON_KEY] = (0, import_create_orcha.createOrcha)(
|
|
54
|
+
(configuration) => {
|
|
55
|
+
const projectRoot = (0, import_path.resolve)(
|
|
56
|
+
configuration.root ?? process.env.ORCHA_PROJECT_ROOT ?? process.cwd()
|
|
57
|
+
);
|
|
58
|
+
const compiler = (0, import_compiler_hook.getRegistryCompiler)();
|
|
59
|
+
if (process.env.ORCHA_COMPILING === "1" && compiler) {
|
|
60
|
+
return compiler(configuration, projectRoot);
|
|
61
|
+
}
|
|
62
|
+
if (isPrecompiledRuntime() || (0, import_fs.existsSync)(compiledManifestPath(projectRoot))) {
|
|
63
|
+
return loadCompiledManifest(projectRoot, configuration);
|
|
64
|
+
}
|
|
65
|
+
throw new Error(
|
|
66
|
+
'Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.'
|
|
67
|
+
);
|
|
68
|
+
},
|
|
69
|
+
import_providers.generateProviderResponse,
|
|
70
|
+
import_platform_node.nodeRuntimePlatform
|
|
53
71
|
);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (isPrecompiledRuntime() || (0, import_fs.existsSync)(compiledManifestPath(projectRoot))) {
|
|
59
|
-
return loadCompiledManifest(projectRoot, configuration);
|
|
60
|
-
}
|
|
61
|
-
throw new Error(
|
|
62
|
-
'Orcha agents must be compiled before runtime initialization. Run "npx orchajs dev" during development or "npx orchajs build" before starting the application.'
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
import_providers.generateProviderResponse,
|
|
66
|
-
import_platform_node.nodeRuntimePlatform
|
|
67
|
-
);
|
|
72
|
+
}
|
|
73
|
+
return globalRecord[NODE_ORCHA_SINGLETON_KEY];
|
|
74
|
+
}
|
|
75
|
+
const orcha = getSharedNodeOrcha();
|
|
68
76
|
function isPrecompiledRuntime() {
|
|
69
77
|
return process.env.ORCHA_USE_BUILD === "1" || process.env.NODE_ENV === "production" || process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0 || process.env.AWS_EXECUTION_ENV?.startsWith("AWS_Lambda_") === true;
|
|
70
78
|
}
|
|
@@ -640,6 +640,7 @@ function parseToolResults(value) {
|
|
|
640
640
|
return {
|
|
641
641
|
callId: result.callId,
|
|
642
642
|
output: result.output,
|
|
643
|
+
...result.contents !== void 0 ? { contents: parseContent(result.contents) } : {},
|
|
643
644
|
...result.isError === true ? { isError: true } : {}
|
|
644
645
|
};
|
|
645
646
|
});
|
|
@@ -326,11 +326,15 @@ async function toAnthropicMessages(messages) {
|
|
|
326
326
|
if (message.role === "tool") {
|
|
327
327
|
return {
|
|
328
328
|
role: "user",
|
|
329
|
-
content: message.results.map((result) =>
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
329
|
+
content: await Promise.all(message.results.map(async (result) => {
|
|
330
|
+
const serializedOutput = JSON.stringify(result.output ?? null);
|
|
331
|
+
const extraBlocks = result.contents?.length ? await Promise.all(result.contents.map(toAnthropicUserBlock)) : [];
|
|
332
|
+
return {
|
|
333
|
+
type: "tool_result",
|
|
334
|
+
tool_use_id: result.callId,
|
|
335
|
+
content: extraBlocks.length > 0 ? [{ type: "text", text: serializedOutput }, ...extraBlocks] : serializedOutput,
|
|
336
|
+
...result.isError ? { is_error: true } : {}
|
|
337
|
+
};
|
|
334
338
|
}))
|
|
335
339
|
};
|
|
336
340
|
}
|
|
@@ -339,64 +343,65 @@ async function toAnthropicMessages(messages) {
|
|
|
339
343
|
}
|
|
340
344
|
return {
|
|
341
345
|
role: "user",
|
|
342
|
-
content: await Promise.all(message.content.map(
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
return {
|
|
366
|
-
type: "document",
|
|
367
|
-
source: {
|
|
368
|
-
type: "base64",
|
|
369
|
-
media_type: block.mimeType,
|
|
370
|
-
data: file.base64
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
if (block.type === "image" && typeof block.fileUri === "string") {
|
|
376
|
-
return {
|
|
377
|
-
type: "image",
|
|
378
|
-
source: {
|
|
379
|
-
type: "url",
|
|
380
|
-
url: block.fileUri
|
|
381
|
-
}
|
|
382
|
-
};
|
|
346
|
+
content: await Promise.all(message.content.map(toAnthropicUserBlock))
|
|
347
|
+
};
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
async function toAnthropicUserBlock(block) {
|
|
351
|
+
if (!isRecord(block) || typeof block.type !== "string") {
|
|
352
|
+
throw new import_errors.OrchaError(
|
|
353
|
+
"invalid_input",
|
|
354
|
+
"Anthropic message content contains an invalid block."
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
if (block.type === "text") {
|
|
358
|
+
return block;
|
|
359
|
+
}
|
|
360
|
+
if (block.type === "file") {
|
|
361
|
+
const file = await (0, import_file_content.readLocalFileContent)(block);
|
|
362
|
+
if (block.mimeType.startsWith("image/")) {
|
|
363
|
+
return {
|
|
364
|
+
type: "image",
|
|
365
|
+
source: {
|
|
366
|
+
type: "base64",
|
|
367
|
+
media_type: block.mimeType,
|
|
368
|
+
data: file.base64
|
|
383
369
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (block.mimeType === "application/pdf") {
|
|
373
|
+
return {
|
|
374
|
+
type: "document",
|
|
375
|
+
source: {
|
|
376
|
+
type: "base64",
|
|
377
|
+
media_type: block.mimeType,
|
|
378
|
+
data: file.base64
|
|
392
379
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
if (block.type === "image" && typeof block.fileUri === "string") {
|
|
384
|
+
return {
|
|
385
|
+
type: "image",
|
|
386
|
+
source: {
|
|
387
|
+
type: "url",
|
|
388
|
+
url: block.fileUri
|
|
389
|
+
}
|
|
398
390
|
};
|
|
399
|
-
}
|
|
391
|
+
}
|
|
392
|
+
if (block.type === "url" && typeof block.fileUri === "string" && block.mimeType === "application/pdf") {
|
|
393
|
+
return {
|
|
394
|
+
type: "document",
|
|
395
|
+
source: {
|
|
396
|
+
type: "url",
|
|
397
|
+
url: block.fileUri
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
throw new import_errors.OrchaError(
|
|
402
|
+
"unsupported_content_type",
|
|
403
|
+
`Anthropic does not support content type "${block.type}" with MIME type "${String(block.mimeType)}".`
|
|
404
|
+
);
|
|
400
405
|
}
|
|
401
406
|
function isRecord(value) {
|
|
402
407
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -126,15 +126,23 @@ async function toBedrockMessages(messages) {
|
|
|
126
126
|
if (message.role === "tool") {
|
|
127
127
|
output.push({
|
|
128
128
|
role: "user",
|
|
129
|
-
content:
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
content: await Promise.all(
|
|
130
|
+
message.results.map(async (result) => {
|
|
131
|
+
const extraBlocks = result.contents?.length ? await Promise.all(
|
|
132
|
+
result.contents.map(toBedrockUserBlock)
|
|
133
|
+
) : [];
|
|
134
|
+
return {
|
|
135
|
+
toolResult: {
|
|
136
|
+
toolUseId: result.callId,
|
|
137
|
+
content: [
|
|
138
|
+
{ json: toBedrockDocument(result.output) },
|
|
139
|
+
...extraBlocks
|
|
140
|
+
],
|
|
141
|
+
...result.isError ? { status: "error" } : {}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
})
|
|
145
|
+
)
|
|
138
146
|
});
|
|
139
147
|
continue;
|
|
140
148
|
}
|
|
@@ -118,10 +118,18 @@ function toDeepSeekMessages(messages) {
|
|
|
118
118
|
}
|
|
119
119
|
if (message.role === "tool") {
|
|
120
120
|
for (const result of message.results) {
|
|
121
|
+
let text2 = JSON.stringify(result.output ?? null);
|
|
122
|
+
if (result.contents && result.contents.length > 0) {
|
|
123
|
+
const extraText = textOnlyContent(result.contents);
|
|
124
|
+
if (extraText) {
|
|
125
|
+
text2 = `${text2}
|
|
126
|
+
${extraText}`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
121
129
|
output.push({
|
|
122
130
|
role: "tool",
|
|
123
131
|
tool_call_id: result.callId,
|
|
124
|
-
content:
|
|
132
|
+
content: text2
|
|
125
133
|
});
|
|
126
134
|
}
|
|
127
135
|
continue;
|
|
@@ -164,7 +172,7 @@ function textOnlyContent(content) {
|
|
|
164
172
|
if (block.type !== "text") {
|
|
165
173
|
throw new import_errors.OrchaError(
|
|
166
174
|
"unsupported_content_type",
|
|
167
|
-
`DeepSeek does not support "${block.type}"
|
|
175
|
+
`DeepSeek does not support multimodal content (received "${block.type}"). DeepSeek is text-only and cannot accept images, PDFs, or other file attachments.`
|
|
168
176
|
);
|
|
169
177
|
}
|
|
170
178
|
text.push(block.text);
|
|
@@ -202,7 +202,7 @@ async function toGoogleContents(messages, provider) {
|
|
|
202
202
|
continue;
|
|
203
203
|
}
|
|
204
204
|
if (message.role === "assistant") {
|
|
205
|
-
const
|
|
205
|
+
const parts2 = message.content.map((block) => {
|
|
206
206
|
if (block.type === "tool_call") {
|
|
207
207
|
previousCalls.set(block.callId, {
|
|
208
208
|
name: block.name,
|
|
@@ -215,29 +215,36 @@ async function toGoogleContents(messages, provider) {
|
|
|
215
215
|
provider
|
|
216
216
|
);
|
|
217
217
|
});
|
|
218
|
-
contents.push({ role: "model", parts });
|
|
218
|
+
contents.push({ role: "model", parts: parts2 });
|
|
219
219
|
continue;
|
|
220
220
|
}
|
|
221
|
+
const parts = [];
|
|
222
|
+
for (const result of message.results) {
|
|
223
|
+
const call = previousCalls.get(result.callId);
|
|
224
|
+
if (!call) {
|
|
225
|
+
throw new Error(
|
|
226
|
+
`Google Gemini could not match tool result "${result.callId}" to a prior function call.`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
parts.push({
|
|
230
|
+
functionResponse: {
|
|
231
|
+
name: call.name,
|
|
232
|
+
...call.providerCallId ? { id: call.providerCallId } : {},
|
|
233
|
+
response: normalizeFunctionResponse(
|
|
234
|
+
result.output,
|
|
235
|
+
result.isError
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
if (result.contents && result.contents.length > 0) {
|
|
240
|
+
parts.push(
|
|
241
|
+
...await Promise.all(result.contents.map(toGoogleUserPart))
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
221
245
|
contents.push({
|
|
222
246
|
role: "user",
|
|
223
|
-
parts
|
|
224
|
-
const call = previousCalls.get(result.callId);
|
|
225
|
-
if (!call) {
|
|
226
|
-
throw new Error(
|
|
227
|
-
`Google Gemini could not match tool result "${result.callId}" to a prior function call.`
|
|
228
|
-
);
|
|
229
|
-
}
|
|
230
|
-
return {
|
|
231
|
-
functionResponse: {
|
|
232
|
-
name: call.name,
|
|
233
|
-
...call.providerCallId ? { id: call.providerCallId } : {},
|
|
234
|
-
response: normalizeFunctionResponse(
|
|
235
|
-
result.output,
|
|
236
|
-
result.isError
|
|
237
|
-
)
|
|
238
|
-
}
|
|
239
|
-
};
|
|
240
|
-
})
|
|
247
|
+
parts
|
|
241
248
|
});
|
|
242
249
|
}
|
|
243
250
|
return contents;
|
|
@@ -115,6 +115,14 @@ async function toOpenAIInput(messages) {
|
|
|
115
115
|
call_id: result.callId,
|
|
116
116
|
output: JSON.stringify(result.output ?? null)
|
|
117
117
|
});
|
|
118
|
+
if (result.contents && result.contents.length > 0) {
|
|
119
|
+
input.push({
|
|
120
|
+
role: "user",
|
|
121
|
+
content: await Promise.all(
|
|
122
|
+
result.contents.map(toOpenAIUserContent)
|
|
123
|
+
)
|
|
124
|
+
});
|
|
125
|
+
}
|
|
118
126
|
}
|
|
119
127
|
continue;
|
|
120
128
|
}
|