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.
Files changed (39) hide show
  1. package/dist/amarsia/inference.js +45 -5
  2. package/dist/cli-agents-template.d.ts +1 -1
  3. package/dist/cli-agents-template.js +13 -4
  4. package/dist/cli.js +22 -9
  5. package/dist/compiler/build-project.js +22 -10
  6. package/dist/integrations/runtime-build.js +17 -6
  7. package/dist/orcha.d.ts +3 -2
  8. package/dist/orcha.js +22 -14
  9. package/dist/playground/server.js +3 -0
  10. package/dist/providers/anthropic.js +67 -58
  11. package/dist/providers/bedrock.js +14 -8
  12. package/dist/providers/deepseek.js +9 -2
  13. package/dist/providers/google-gemini.js +20 -15
  14. package/dist/providers/openai.js +6 -0
  15. package/dist/providers/types.d.ts +1 -0
  16. package/dist/runtime/agent.d.ts +3 -3
  17. package/dist/runtime/agent.js +175 -31
  18. package/dist/runtime/compiler-hook.js +15 -6
  19. package/dist/runtime/context.js +10 -3
  20. package/dist/runtime/session-events.js +19 -0
  21. package/dist/testing.js +3 -0
  22. package/dist/types.d.ts +4 -2
  23. package/dist-cjs/amarsia/inference.js +44 -7
  24. package/dist-cjs/cli-agents-template.js +13 -4
  25. package/dist-cjs/compiler/build-project.js +22 -10
  26. package/dist-cjs/integrations/runtime-build.js +17 -6
  27. package/dist-cjs/orcha.js +26 -18
  28. package/dist-cjs/playground/server.js +1 -0
  29. package/dist-cjs/providers/anthropic.js +65 -60
  30. package/dist-cjs/providers/bedrock.js +17 -9
  31. package/dist-cjs/providers/deepseek.js +10 -2
  32. package/dist-cjs/providers/google-gemini.js +27 -20
  33. package/dist-cjs/providers/openai.js +8 -0
  34. package/dist-cjs/runtime/agent.js +175 -32
  35. package/dist-cjs/runtime/compiler-hook.js +15 -6
  36. package/dist-cjs/runtime/context.js +10 -3
  37. package/dist-cjs/runtime/session-events.js +14 -0
  38. package/dist-cjs/testing.js +1 -0
  39. 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
- type: "tool_result",
307
- tool_use_id: result.callId,
308
- content: JSON.stringify(result.output ?? null),
309
- ...(result.isError ? { is_error: true } : {}),
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(async (block) => {
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
- toolResult: {
98
- toolUseId: result.callId,
99
- content: [
100
- { json: toBedrockDocument(result.output) },
101
- ],
102
- ...(result.isError ? { status: "error" } : {}),
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: JSON.stringify(result.output ?? null),
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}" message content.`);
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: message.results.map((result) => {
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;
@@ -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 = {
@@ -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 | string): Execution;
32
+ run(input: AgentInput | AgentContentInput): Execution;
33
33
  createDelegatedSessionId(): string;
34
- runAsChild(sessionId: string, input: AgentInput | string, lineage: SessionLineage): Execution;
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>;