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
|
@@ -302,11 +302,19 @@ async function toAnthropicMessages(messages) {
|
|
|
302
302
|
if (message.role === "tool") {
|
|
303
303
|
return {
|
|
304
304
|
role: "user",
|
|
305
|
-
content: message.results.map((result) =>
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
305
|
+
content: await Promise.all(message.results.map(async (result) => {
|
|
306
|
+
const serializedOutput = JSON.stringify(result.output ?? null);
|
|
307
|
+
const extraBlocks = result.contents?.length
|
|
308
|
+
? await Promise.all(result.contents.map(toAnthropicUserBlock))
|
|
309
|
+
: [];
|
|
310
|
+
return {
|
|
311
|
+
type: "tool_result",
|
|
312
|
+
tool_use_id: result.callId,
|
|
313
|
+
content: extraBlocks.length > 0
|
|
314
|
+
? [{ type: "text", text: serializedOutput }, ...extraBlocks]
|
|
315
|
+
: serializedOutput,
|
|
316
|
+
...(result.isError ? { is_error: true } : {}),
|
|
317
|
+
};
|
|
310
318
|
})),
|
|
311
319
|
};
|
|
312
320
|
}
|
|
@@ -315,62 +323,63 @@ async function toAnthropicMessages(messages) {
|
|
|
315
323
|
}
|
|
316
324
|
return {
|
|
317
325
|
role: "user",
|
|
318
|
-
content: await Promise.all(message.content.map(
|
|
319
|
-
if (!isRecord(block) || typeof block.type !== "string") {
|
|
320
|
-
throw new OrchaError("invalid_input", "Anthropic message content contains an invalid block.");
|
|
321
|
-
}
|
|
322
|
-
if (block.type === "text") {
|
|
323
|
-
return block;
|
|
324
|
-
}
|
|
325
|
-
if (block.type === "file") {
|
|
326
|
-
const file = await readLocalFileContent(block);
|
|
327
|
-
if (block.mimeType.startsWith("image/")) {
|
|
328
|
-
return {
|
|
329
|
-
type: "image",
|
|
330
|
-
source: {
|
|
331
|
-
type: "base64",
|
|
332
|
-
media_type: block.mimeType,
|
|
333
|
-
data: file.base64,
|
|
334
|
-
},
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
if (block.mimeType === "application/pdf") {
|
|
338
|
-
return {
|
|
339
|
-
type: "document",
|
|
340
|
-
source: {
|
|
341
|
-
type: "base64",
|
|
342
|
-
media_type: block.mimeType,
|
|
343
|
-
data: file.base64,
|
|
344
|
-
},
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (block.type === "image" &&
|
|
349
|
-
typeof block.fileUri === "string") {
|
|
350
|
-
return {
|
|
351
|
-
type: "image",
|
|
352
|
-
source: {
|
|
353
|
-
type: "url",
|
|
354
|
-
url: block.fileUri,
|
|
355
|
-
},
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
if (block.type === "url" &&
|
|
359
|
-
typeof block.fileUri === "string" &&
|
|
360
|
-
block.mimeType === "application/pdf") {
|
|
361
|
-
return {
|
|
362
|
-
type: "document",
|
|
363
|
-
source: {
|
|
364
|
-
type: "url",
|
|
365
|
-
url: block.fileUri,
|
|
366
|
-
},
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
throw new OrchaError("unsupported_content_type", `Anthropic does not support content type "${block.type}" with MIME type "${String(block.mimeType)}".`);
|
|
370
|
-
})),
|
|
326
|
+
content: await Promise.all(message.content.map(toAnthropicUserBlock)),
|
|
371
327
|
};
|
|
372
328
|
}));
|
|
373
329
|
}
|
|
330
|
+
async function toAnthropicUserBlock(block) {
|
|
331
|
+
if (!isRecord(block) || typeof block.type !== "string") {
|
|
332
|
+
throw new OrchaError("invalid_input", "Anthropic message content contains an invalid block.");
|
|
333
|
+
}
|
|
334
|
+
if (block.type === "text") {
|
|
335
|
+
return block;
|
|
336
|
+
}
|
|
337
|
+
if (block.type === "file") {
|
|
338
|
+
const file = await readLocalFileContent(block);
|
|
339
|
+
if (block.mimeType.startsWith("image/")) {
|
|
340
|
+
return {
|
|
341
|
+
type: "image",
|
|
342
|
+
source: {
|
|
343
|
+
type: "base64",
|
|
344
|
+
media_type: block.mimeType,
|
|
345
|
+
data: file.base64,
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
if (block.mimeType === "application/pdf") {
|
|
350
|
+
return {
|
|
351
|
+
type: "document",
|
|
352
|
+
source: {
|
|
353
|
+
type: "base64",
|
|
354
|
+
media_type: block.mimeType,
|
|
355
|
+
data: file.base64,
|
|
356
|
+
},
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
if (block.type === "image" &&
|
|
361
|
+
typeof block.fileUri === "string") {
|
|
362
|
+
return {
|
|
363
|
+
type: "image",
|
|
364
|
+
source: {
|
|
365
|
+
type: "url",
|
|
366
|
+
url: block.fileUri,
|
|
367
|
+
},
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
if (block.type === "url" &&
|
|
371
|
+
typeof block.fileUri === "string" &&
|
|
372
|
+
block.mimeType === "application/pdf") {
|
|
373
|
+
return {
|
|
374
|
+
type: "document",
|
|
375
|
+
source: {
|
|
376
|
+
type: "url",
|
|
377
|
+
url: block.fileUri,
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
throw new OrchaError("unsupported_content_type", `Anthropic does not support content type "${block.type}" with MIME type "${String(block.mimeType)}".`);
|
|
382
|
+
}
|
|
374
383
|
function isRecord(value) {
|
|
375
384
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
376
385
|
}
|
|
@@ -93,14 +93,20 @@ async function toBedrockMessages(messages) {
|
|
|
93
93
|
if (message.role === "tool") {
|
|
94
94
|
output.push({
|
|
95
95
|
role: "user",
|
|
96
|
-
content: message.results.map((result) =>
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
96
|
+
content: await Promise.all(message.results.map(async (result) => {
|
|
97
|
+
const extraBlocks = result.contents?.length
|
|
98
|
+
? (await Promise.all(result.contents.map(toBedrockUserBlock)))
|
|
99
|
+
: [];
|
|
100
|
+
return {
|
|
101
|
+
toolResult: {
|
|
102
|
+
toolUseId: result.callId,
|
|
103
|
+
content: [
|
|
104
|
+
{ json: toBedrockDocument(result.output) },
|
|
105
|
+
...extraBlocks,
|
|
106
|
+
],
|
|
107
|
+
...(result.isError ? { status: "error" } : {}),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
104
110
|
})),
|
|
105
111
|
});
|
|
106
112
|
continue;
|
|
@@ -81,10 +81,17 @@ function toDeepSeekMessages(messages) {
|
|
|
81
81
|
}
|
|
82
82
|
if (message.role === "tool") {
|
|
83
83
|
for (const result of message.results) {
|
|
84
|
+
let text = JSON.stringify(result.output ?? null);
|
|
85
|
+
if (result.contents && result.contents.length > 0) {
|
|
86
|
+
const extraText = textOnlyContent(result.contents);
|
|
87
|
+
if (extraText) {
|
|
88
|
+
text = `${text}\n${extraText}`;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
84
91
|
output.push({
|
|
85
92
|
role: "tool",
|
|
86
93
|
tool_call_id: result.callId,
|
|
87
|
-
content:
|
|
94
|
+
content: text,
|
|
88
95
|
});
|
|
89
96
|
}
|
|
90
97
|
continue;
|
|
@@ -130,7 +137,7 @@ function textOnlyContent(content) {
|
|
|
130
137
|
const text = [];
|
|
131
138
|
for (const block of content) {
|
|
132
139
|
if (block.type !== "text") {
|
|
133
|
-
throw new OrchaError("unsupported_content_type", `DeepSeek does not support "${block.type}"
|
|
140
|
+
throw new OrchaError("unsupported_content_type", `DeepSeek does not support multimodal content (received "${block.type}"). DeepSeek is text-only and cannot accept images, PDFs, or other file attachments.`);
|
|
134
141
|
}
|
|
135
142
|
text.push(block.text);
|
|
136
143
|
}
|
|
@@ -203,23 +203,28 @@ async function toGoogleContents(messages, provider) {
|
|
|
203
203
|
contents.push({ role: "model", parts });
|
|
204
204
|
continue;
|
|
205
205
|
}
|
|
206
|
+
const parts = [];
|
|
207
|
+
for (const result of message.results) {
|
|
208
|
+
const call = previousCalls.get(result.callId);
|
|
209
|
+
if (!call) {
|
|
210
|
+
throw new Error(`Google Gemini could not match tool result "${result.callId}" to a prior function call.`);
|
|
211
|
+
}
|
|
212
|
+
parts.push({
|
|
213
|
+
functionResponse: {
|
|
214
|
+
name: call.name,
|
|
215
|
+
...(call.providerCallId
|
|
216
|
+
? { id: call.providerCallId }
|
|
217
|
+
: {}),
|
|
218
|
+
response: normalizeFunctionResponse(result.output, result.isError),
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
if (result.contents && result.contents.length > 0) {
|
|
222
|
+
parts.push(...(await Promise.all(result.contents.map(toGoogleUserPart))));
|
|
223
|
+
}
|
|
224
|
+
}
|
|
206
225
|
contents.push({
|
|
207
226
|
role: "user",
|
|
208
|
-
parts
|
|
209
|
-
const call = previousCalls.get(result.callId);
|
|
210
|
-
if (!call) {
|
|
211
|
-
throw new Error(`Google Gemini could not match tool result "${result.callId}" to a prior function call.`);
|
|
212
|
-
}
|
|
213
|
-
return {
|
|
214
|
-
functionResponse: {
|
|
215
|
-
name: call.name,
|
|
216
|
-
...(call.providerCallId
|
|
217
|
-
? { id: call.providerCallId }
|
|
218
|
-
: {}),
|
|
219
|
-
response: normalizeFunctionResponse(result.output, result.isError),
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
}),
|
|
227
|
+
parts,
|
|
223
228
|
});
|
|
224
229
|
}
|
|
225
230
|
return contents;
|
package/dist/providers/openai.js
CHANGED
|
@@ -88,6 +88,12 @@ async function toOpenAIInput(messages) {
|
|
|
88
88
|
call_id: result.callId,
|
|
89
89
|
output: JSON.stringify(result.output ?? null),
|
|
90
90
|
});
|
|
91
|
+
if (result.contents && result.contents.length > 0) {
|
|
92
|
+
input.push({
|
|
93
|
+
role: "user",
|
|
94
|
+
content: await Promise.all(result.contents.map(toOpenAIUserContent)),
|
|
95
|
+
});
|
|
96
|
+
}
|
|
91
97
|
}
|
|
92
98
|
continue;
|
|
93
99
|
}
|
|
@@ -24,6 +24,7 @@ export type ProviderAssistantBlock = ProviderTextBlock | ProviderReasoningBlock
|
|
|
24
24
|
export interface ProviderToolResult {
|
|
25
25
|
callId: string;
|
|
26
26
|
output: unknown;
|
|
27
|
+
contents?: MessageContent[];
|
|
27
28
|
isError?: boolean;
|
|
28
29
|
}
|
|
29
30
|
export type ProviderMessage = {
|
|
@@ -54,6 +55,10 @@ export interface ProviderRequest {
|
|
|
54
55
|
tools: ProviderToolDefinition[];
|
|
55
56
|
publishOutput?: (output: string) => void;
|
|
56
57
|
signal?: AbortSignal;
|
|
58
|
+
trace?: {
|
|
59
|
+
agentExternalId: string;
|
|
60
|
+
sessionId: string;
|
|
61
|
+
};
|
|
57
62
|
}
|
|
58
63
|
export type ProviderStopReason = "end_turn" | "tool_call" | "max_tokens" | "content_filter" | "unknown";
|
|
59
64
|
export interface ProviderResponse {
|
package/dist/react-native.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
+
import { createAmarsiaInferenceGenerator } from "./amarsia/inference.js";
|
|
1
2
|
import { generateBrowserProviderResponse } from "./providers/browser.js";
|
|
2
3
|
import { setNativeRuntimeLoader } from "./runtime/actions/execute.js";
|
|
3
4
|
import { createOrcha } from "./runtime/create-orcha.js";
|
|
5
|
+
import { setCloudSessionStoreFactory, setInferenceGeneratorFactory, } from "./runtime/optional-features.js";
|
|
4
6
|
import { reactNativeRuntimePlatform } from "./runtime/platform-react-native.js";
|
|
7
|
+
import { CloudSessionStore } from "./storage/cloud.js";
|
|
5
8
|
setNativeRuntimeLoader(async () => {
|
|
6
9
|
const modulePath = "./runtime/actions/browser-native.js";
|
|
7
10
|
return import(modulePath);
|
|
8
11
|
});
|
|
12
|
+
setInferenceGeneratorFactory(createAmarsiaInferenceGenerator);
|
|
13
|
+
setCloudSessionStoreFactory((options) => new CloudSessionStore(options));
|
|
9
14
|
export const orcha = createOrcha(() => {
|
|
10
15
|
throw new Error("The React Native runtime requires a precompiled Orcha bundle. Configure the Orcha Metro integration.");
|
|
11
16
|
}, generateBrowserProviderResponse, reactNativeRuntimePlatform);
|
package/dist/runtime/agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProviderResponseGenerator } from "../providers/types.js";
|
|
2
|
-
import type { AgentInput, AgentRuntime, CompiledActionManifest, CompiledAgentManifest, Execution, PaginationOptions, ProjectConfiguration, ResumeInput, SessionEvent, SessionEventListOptions, SessionEvents, SessionHistory, SessionLineage, SessionList, SessionListOptions, SessionSnapshot, SessionStore, SessionUpdate } from "../types.js";
|
|
2
|
+
import type { AgentInput, AgentContentInput, AgentRuntime, CompiledActionManifest, CompiledAgentManifest, Execution, PaginationOptions, ProjectConfiguration, ResumeInput, SessionEvent, SessionEventListOptions, SessionEvents, SessionHistory, SessionLineage, SessionList, SessionListOptions, SessionSnapshot, SessionStore, SessionUpdate } from "../types.js";
|
|
3
3
|
export interface RuntimeSessionControl {
|
|
4
4
|
pauseRequested: boolean;
|
|
5
5
|
controller: AbortController;
|
|
@@ -29,9 +29,9 @@ export declare class RuntimeAgent implements AgentRuntime {
|
|
|
29
29
|
_subscribeAllSessionEvents(listener: (sessionId: string, events: SessionEvent[]) => void): () => void;
|
|
30
30
|
/** @internal Used by the local playground for live child traces. */
|
|
31
31
|
_subscribeSubagentSessionEvents(childSessionId: string, listener: (events: SessionEvent[]) => void): Promise<() => void>;
|
|
32
|
-
run(input: AgentInput |
|
|
32
|
+
run(input: AgentInput | AgentContentInput): Execution;
|
|
33
33
|
createDelegatedSessionId(): string;
|
|
34
|
-
runAsChild(sessionId: string, input: AgentInput |
|
|
34
|
+
runAsChild(sessionId: string, input: AgentInput | AgentContentInput, lineage: SessionLineage): Execution;
|
|
35
35
|
resume(sessionId: string, input?: ResumeInput): Execution;
|
|
36
36
|
get(sessionId: string): Promise<SessionSnapshot>;
|
|
37
37
|
history(sessionId: string, options?: PaginationOptions): Promise<SessionHistory>;
|