orchajs 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +50 -3
- package/dist/amarsia/analytics.js +12 -0
- package/dist/amarsia/inference.d.ts +6 -0
- package/dist/amarsia/inference.js +377 -0
- package/dist/browser.js +5 -0
- package/dist/cli-agents-template.d.ts +1 -1
- package/dist/cli-agents-template.js +44 -11
- package/dist/cli.js +22 -9
- package/dist/compiler/build-project.js +57 -14
- package/dist/compiler/node-esm-banner.d.ts +2 -0
- package/dist/compiler/node-esm-banner.js +5 -0
- package/dist/orcha.js +5 -0
- package/dist/playground/server.js +3 -0
- package/dist/project-loader.js +4 -2
- 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 +5 -0
- package/dist/react-native.js +5 -0
- package/dist/runtime/agent.d.ts +3 -3
- package/dist/runtime/agent.js +278 -45
- package/dist/runtime/compiler-hook.d.ts +4 -0
- package/dist/runtime/compiler-hook.js +9 -0
- package/dist/runtime/create-orcha.d.ts +19 -0
- package/dist/runtime/create-orcha.js +109 -12
- package/dist/runtime/optional-features.d.ts +19 -0
- package/dist/runtime/optional-features.js +22 -0
- package/dist/runtime/platform-browser.js +16 -3
- package/dist/runtime/platform-node.js +16 -2
- package/dist/runtime/platform-react-native.js +16 -3
- package/dist/runtime/session-events.js +19 -0
- package/dist/storage/browser-indexeddb.d.ts +3 -0
- package/dist/storage/browser-indexeddb.js +72 -8
- package/dist/storage/cloud-outbox.d.ts +30 -0
- package/dist/storage/cloud-outbox.js +628 -0
- package/dist/storage/cloud.d.ts +1 -0
- package/dist/storage/cloud.js +1 -0
- package/dist/storage/node-jsonl.d.ts +3 -0
- package/dist/storage/node-jsonl.js +273 -4
- package/dist/storage/node-sqlite.d.ts +3 -0
- package/dist/storage/node-sqlite.js +66 -17
- package/dist/storage/react-native-jsonl.d.ts +3 -0
- package/dist/storage/react-native-jsonl.js +223 -0
- package/dist/testing.js +3 -0
- package/dist/types.d.ts +25 -4
- package/dist-cjs/amarsia/analytics.js +12 -0
- package/dist-cjs/amarsia/inference.js +372 -0
- package/dist-cjs/browser.js +5 -0
- package/dist-cjs/cli-agents-template.js +44 -11
- package/dist-cjs/compiler/build-project.js +68 -4
- package/dist-cjs/compiler/node-esm-banner.js +32 -0
- package/dist-cjs/orcha.js +5 -0
- package/dist-cjs/playground/server.js +1 -0
- package/dist-cjs/project-loader.js +7 -5
- 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/react-native.js +5 -0
- package/dist-cjs/runtime/agent.js +311 -61
- package/dist-cjs/runtime/compiler-hook.js +11 -0
- package/dist-cjs/runtime/create-orcha.js +117 -12
- package/dist-cjs/runtime/optional-features.js +58 -0
- package/dist-cjs/runtime/platform-browser.js +16 -3
- package/dist-cjs/runtime/platform-node.js +16 -2
- package/dist-cjs/runtime/platform-react-native.js +18 -3
- package/dist-cjs/runtime/session-events.js +14 -0
- package/dist-cjs/storage/browser-indexeddb.js +73 -8
- package/dist-cjs/storage/cloud-outbox.js +646 -0
- package/dist-cjs/storage/cloud.js +29 -0
- package/dist-cjs/storage/node-jsonl.js +246 -3
- package/dist-cjs/storage/node-sqlite.js +70 -19
- package/dist-cjs/storage/react-native-jsonl.js +207 -0
- package/dist-cjs/testing.js +1 -0
- package/package.json +1 -1
package/dist-cjs/orcha.js
CHANGED
|
@@ -24,13 +24,16 @@ __export(orcha_exports, {
|
|
|
24
24
|
module.exports = __toCommonJS(orcha_exports);
|
|
25
25
|
var import_fs = require("fs");
|
|
26
26
|
var import_path = require("path");
|
|
27
|
+
var import_inference = require("./amarsia/inference.js");
|
|
27
28
|
var import_providers = require("./providers/index.js");
|
|
28
29
|
var import_execute = require("./runtime/actions/execute.js");
|
|
29
30
|
var import_native = require("./runtime/actions/native.js");
|
|
30
31
|
var import_compiler_hook = require("./runtime/compiler-hook.js");
|
|
31
32
|
var import_create_orcha = require("./runtime/create-orcha.js");
|
|
32
33
|
var import_client = require("./runtime/mcp/client.js");
|
|
34
|
+
var import_optional_features = require("./runtime/optional-features.js");
|
|
33
35
|
var import_platform_node = require("./runtime/platform-node.js");
|
|
36
|
+
var import_cloud = require("./storage/cloud.js");
|
|
34
37
|
(0, import_execute.setNativeRuntimeLoader)(async () => ({ executeNativeAction: import_native.executeNativeAction }));
|
|
35
38
|
(0, import_execute.setSandboxRuntimeLoader)(async () => {
|
|
36
39
|
const modulePath = "./runtime/actions/sandbox.js";
|
|
@@ -41,6 +44,8 @@ var import_platform_node = require("./runtime/platform-node.js");
|
|
|
41
44
|
const { createNodeMcpClient } = await import(modulePath);
|
|
42
45
|
return createNodeMcpClient(server, credentials);
|
|
43
46
|
});
|
|
47
|
+
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
48
|
+
(0, import_optional_features.setCloudSessionStoreFactory)((options) => new import_cloud.CloudSessionStore(options));
|
|
44
49
|
const orcha = (0, import_create_orcha.createOrcha)(
|
|
45
50
|
(configuration) => {
|
|
46
51
|
const projectRoot = (0, import_path.resolve)(
|
|
@@ -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
|
});
|
|
@@ -76,13 +76,15 @@ async function loadProject(projectRoot) {
|
|
|
76
76
|
}
|
|
77
77
|
if (!import_orcha.orcha.isInitialized() || import_orcha.orcha.getCompiledBundle() === previousBundle) {
|
|
78
78
|
throw new Error(
|
|
79
|
-
'"orcha/index.ts" must call orcha.init({
|
|
79
|
+
'"orcha/index.ts" must call orcha.init({ agents, ... }).'
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
if (!import_orcha.orcha.isInferenceEnabled()) {
|
|
83
|
+
await (0, import_dependencies.ensureCompiledProviderDependencies)(
|
|
84
|
+
import_orcha.orcha.getCompiledBundle(),
|
|
85
|
+
projectRoot
|
|
80
86
|
);
|
|
81
87
|
}
|
|
82
|
-
await (0, import_dependencies.ensureCompiledProviderDependencies)(
|
|
83
|
-
import_orcha.orcha.getCompiledBundle(),
|
|
84
|
-
projectRoot
|
|
85
|
-
);
|
|
86
88
|
await (0, import_dependencies.ensureCompiledMcpDependencies)(
|
|
87
89
|
import_orcha.orcha.getCompiledBundle(),
|
|
88
90
|
projectRoot
|
|
@@ -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
|
}
|
package/dist-cjs/react-native.js
CHANGED
|
@@ -23,15 +23,20 @@ __export(react_native_exports, {
|
|
|
23
23
|
orcha: () => orcha
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(react_native_exports);
|
|
26
|
+
var import_inference = require("./amarsia/inference.js");
|
|
26
27
|
var import_browser = require("./providers/browser.js");
|
|
27
28
|
var import_execute = require("./runtime/actions/execute.js");
|
|
28
29
|
var import_create_orcha = require("./runtime/create-orcha.js");
|
|
30
|
+
var import_optional_features = require("./runtime/optional-features.js");
|
|
29
31
|
var import_platform_react_native = require("./runtime/platform-react-native.js");
|
|
32
|
+
var import_cloud = require("./storage/cloud.js");
|
|
30
33
|
__reExport(react_native_exports, require("./runtime-entry.js"), module.exports);
|
|
31
34
|
(0, import_execute.setNativeRuntimeLoader)(async () => {
|
|
32
35
|
const modulePath = "./runtime/actions/browser-native.js";
|
|
33
36
|
return import(modulePath);
|
|
34
37
|
});
|
|
38
|
+
(0, import_optional_features.setInferenceGeneratorFactory)(import_inference.createAmarsiaInferenceGenerator);
|
|
39
|
+
(0, import_optional_features.setCloudSessionStoreFactory)((options) => new import_cloud.CloudSessionStore(options));
|
|
35
40
|
const orcha = (0, import_create_orcha.createOrcha)(
|
|
36
41
|
() => {
|
|
37
42
|
throw new Error(
|