@mariozechner/pi-ai 0.5.41 → 0.5.42
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 +41 -13
- package/dist/agent/agent-loop.d.ts +6 -0
- package/dist/agent/agent-loop.d.ts.map +1 -0
- package/dist/agent/{agent.js → agent-loop.js} +16 -9
- package/dist/agent/agent-loop.js.map +1 -0
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/index.js.map +1 -1
- package/dist/agent/types.d.ts +1 -1
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/agent/types.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/models.generated.d.ts +24 -7
- package/dist/models.generated.d.ts.map +1 -1
- package/dist/models.generated.js +57 -40
- package/dist/models.generated.js.map +1 -1
- package/dist/providers/anthropic.d.ts.map +1 -1
- package/dist/providers/anthropic.js +10 -7
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/google.d.ts.map +1 -1
- package/dist/providers/google.js +16 -7
- package/dist/providers/google.js.map +1 -1
- package/dist/providers/openai-completions.d.ts.map +1 -1
- package/dist/providers/openai-completions.js +12 -8
- package/dist/providers/openai-completions.js.map +1 -1
- package/dist/providers/openai-responses.d.ts.map +1 -1
- package/dist/providers/openai-responses.js +13 -16
- package/dist/providers/openai-responses.js.map +1 -1
- package/dist/types.d.ts +7 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/{event-stream.d.ts → utils/event-stream.d.ts} +1 -1
- package/dist/utils/event-stream.d.ts.map +1 -0
- package/dist/{event-stream.js → utils/event-stream.js} +1 -1
- package/dist/utils/event-stream.js.map +1 -0
- package/dist/utils/json-parse.d.ts.map +1 -0
- package/dist/utils/json-parse.js.map +1 -0
- package/dist/utils/typebox-helpers.d.ts.map +1 -0
- package/dist/utils/typebox-helpers.js.map +1 -0
- package/dist/{validation.d.ts → utils/validation.d.ts} +1 -1
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
- package/dist/agent/agent.d.ts +0 -6
- package/dist/agent/agent.d.ts.map +0 -1
- package/dist/agent/agent.js.map +0 -1
- package/dist/event-stream.d.ts.map +0 -1
- package/dist/event-stream.js.map +0 -1
- package/dist/json-parse.d.ts.map +0 -1
- package/dist/json-parse.js.map +0 -1
- package/dist/typebox-helpers.d.ts.map +0 -1
- package/dist/typebox-helpers.js.map +0 -1
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js.map +0 -1
- /package/dist/{json-parse.d.ts → utils/json-parse.d.ts} +0 -0
- /package/dist/{json-parse.js → utils/json-parse.js} +0 -0
- /package/dist/{typebox-helpers.d.ts → utils/typebox-helpers.d.ts} +0 -0
- /package/dist/{typebox-helpers.js → utils/typebox-helpers.js} +0 -0
- /package/dist/{validation.js → utils/validation.js} +0 -0
package/README.md
CHANGED
|
@@ -267,8 +267,8 @@ All streaming events emitted during assistant message generation:
|
|
|
267
267
|
| `toolcall_start` | Tool call begins | `contentIndex`: Position in content array |
|
|
268
268
|
| `toolcall_delta` | Tool arguments streaming | `delta`: JSON chunk, `partial.content[contentIndex].arguments`: Partial parsed args |
|
|
269
269
|
| `toolcall_end` | Tool call complete | `toolCall`: Complete validated tool call with `id`, `name`, `arguments` |
|
|
270
|
-
| `done` | Stream complete | `reason`: Stop reason, `message`: Final assistant message |
|
|
271
|
-
| `error` | Error occurred | `
|
|
270
|
+
| `done` | Stream complete | `reason`: Stop reason ("stop", "length", "toolUse"), `message`: Final assistant message |
|
|
271
|
+
| `error` | Error occurred | `reason`: Error type ("error" or "aborted"), `error`: AssistantMessage with partial content |
|
|
272
272
|
|
|
273
273
|
## Image Input
|
|
274
274
|
|
|
@@ -399,16 +399,43 @@ for await (const event of s) {
|
|
|
399
399
|
}
|
|
400
400
|
```
|
|
401
401
|
|
|
402
|
-
##
|
|
402
|
+
## Stop Reasons
|
|
403
403
|
|
|
404
|
-
|
|
405
|
-
- `stopReason: 'error'` - Indicates the request ended with an error
|
|
406
|
-
- `error: string` - Error message describing what happened
|
|
407
|
-
- `content: array` - **Partial content** accumulated before the error
|
|
408
|
-
- `usage: Usage` - **Token counts and costs** (may be incomplete depending on when error occurred)
|
|
404
|
+
Every `AssistantMessage` includes a `stopReason` field that indicates how the generation ended:
|
|
409
405
|
|
|
410
|
-
|
|
411
|
-
|
|
406
|
+
- `"stop"` - Normal completion, the model finished its response
|
|
407
|
+
- `"length"` - Output hit the maximum token limit
|
|
408
|
+
- `"toolUse"` - Model is calling tools and expects tool results
|
|
409
|
+
- `"error"` - An error occurred during generation
|
|
410
|
+
- `"aborted"` - Request was cancelled via abort signal
|
|
411
|
+
|
|
412
|
+
## Error Handling
|
|
413
|
+
|
|
414
|
+
When a request ends with an error (including aborts and tool call validation errors), the streaming API emits an error event:
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
// In streaming
|
|
418
|
+
for await (const event of stream) {
|
|
419
|
+
if (event.type === 'error') {
|
|
420
|
+
// event.reason is either "error" or "aborted"
|
|
421
|
+
// event.error is the AssistantMessage with partial content
|
|
422
|
+
console.error(`Error (${event.reason}):`, event.error.errorMessage);
|
|
423
|
+
console.log('Partial content:', event.error.content);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// The final message will have the error details
|
|
428
|
+
const message = await stream.result();
|
|
429
|
+
if (message.stopReason === 'error' || message.stopReason === 'aborted') {
|
|
430
|
+
console.error('Request failed:', message.errorMessage);
|
|
431
|
+
// message.content contains any partial content received before the error
|
|
432
|
+
// message.usage contains partial token counts and costs
|
|
433
|
+
}
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### Aborting Requests
|
|
437
|
+
|
|
438
|
+
The abort signal allows you to cancel in-progress requests. Aborted requests have `stopReason === 'aborted'`:
|
|
412
439
|
|
|
413
440
|
```typescript
|
|
414
441
|
import { getModel, stream } from '@mariozechner/pi-ai';
|
|
@@ -429,14 +456,15 @@ for await (const event of s) {
|
|
|
429
456
|
if (event.type === 'text_delta') {
|
|
430
457
|
process.stdout.write(event.delta);
|
|
431
458
|
} else if (event.type === 'error') {
|
|
432
|
-
|
|
459
|
+
// event.reason tells you if it was "error" or "aborted"
|
|
460
|
+
console.log(`${event.reason === 'aborted' ? 'Aborted' : 'Error'}:`, event.error.errorMessage);
|
|
433
461
|
}
|
|
434
462
|
}
|
|
435
463
|
|
|
436
464
|
// Get results (may be partial if aborted)
|
|
437
465
|
const response = await s.result();
|
|
438
|
-
if (response.stopReason === '
|
|
439
|
-
console.log('
|
|
466
|
+
if (response.stopReason === 'aborted') {
|
|
467
|
+
console.log('Request was aborted:', response.errorMessage);
|
|
440
468
|
console.log('Partial content received:', response.content);
|
|
441
469
|
console.log('Tokens used:', response.usage);
|
|
442
470
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { streamSimple } from "../stream.js";
|
|
2
|
+
import type { UserMessage } from "../types.js";
|
|
3
|
+
import { EventStream } from "../utils/event-stream.js";
|
|
4
|
+
import type { AgentContext, AgentEvent, PromptConfig } from "./types.js";
|
|
5
|
+
export declare function agentLoop(prompt: UserMessage, context: AgentContext, config: PromptConfig, signal?: AbortSignal, streamFn?: typeof streamSimple): EventStream<AgentEvent, AgentContext["messages"]>;
|
|
6
|
+
//# sourceMappingURL=agent-loop.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-loop.d.ts","sourceRoot":"","sources":["../../src/agent/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAyD,WAAW,EAAE,MAAM,aAAa,CAAC;AACtG,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAA8B,YAAY,EAAE,MAAM,YAAY,CAAC;AAGrG,wBAAgB,SAAS,CACxB,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,YAAY,EACrB,MAAM,EAAE,YAAY,EACpB,MAAM,CAAC,EAAE,WAAW,EACpB,QAAQ,CAAC,EAAE,OAAO,YAAY,GAC5B,WAAW,CAAC,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC,CAgEnD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { EventStream } from "../event-stream.js";
|
|
2
1
|
import { streamSimple } from "../stream.js";
|
|
3
|
-
import {
|
|
2
|
+
import { EventStream } from "../utils/event-stream.js";
|
|
3
|
+
import { validateToolArguments } from "../utils/validation.js";
|
|
4
4
|
// Main prompt function - returns a stream of events
|
|
5
|
-
export function
|
|
5
|
+
export function agentLoop(prompt, context, config, signal, streamFn) {
|
|
6
6
|
const stream = new EventStream((event) => event.type === "agent_end", (event) => (event.type === "agent_end" ? event.messages : []));
|
|
7
7
|
// Run the prompt async
|
|
8
8
|
(async () => {
|
|
@@ -31,19 +31,26 @@ export function prompt(prompt, context, config, signal, streamFn) {
|
|
|
31
31
|
firstTurn = false;
|
|
32
32
|
}
|
|
33
33
|
// Stream assistant response
|
|
34
|
-
const
|
|
35
|
-
newMessages.push(
|
|
34
|
+
const message = await streamAssistantResponse(currentContext, config, signal, stream, streamFn);
|
|
35
|
+
newMessages.push(message);
|
|
36
|
+
if (message.stopReason === "error" || message.stopReason === "aborted") {
|
|
37
|
+
// Stop the loop on error or abort
|
|
38
|
+
stream.push({ type: "turn_end", message, toolResults: [] });
|
|
39
|
+
stream.push({ type: "agent_end", messages: newMessages });
|
|
40
|
+
stream.end(newMessages);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
36
43
|
// Check for tool calls
|
|
37
|
-
const toolCalls =
|
|
44
|
+
const toolCalls = message.content.filter((c) => c.type === "toolCall");
|
|
38
45
|
hasMoreToolCalls = toolCalls.length > 0;
|
|
39
46
|
const toolResults = [];
|
|
40
47
|
if (hasMoreToolCalls) {
|
|
41
48
|
// Execute tool calls
|
|
42
|
-
toolResults.push(...(await executeToolCalls(currentContext.tools,
|
|
49
|
+
toolResults.push(...(await executeToolCalls(currentContext.tools, message, signal, stream)));
|
|
43
50
|
currentContext.messages.push(...toolResults);
|
|
44
51
|
newMessages.push(...toolResults);
|
|
45
52
|
}
|
|
46
|
-
stream.push({ type: "turn_end",
|
|
53
|
+
stream.push({ type: "turn_end", message, toolResults: toolResults });
|
|
47
54
|
}
|
|
48
55
|
stream.push({ type: "agent_end", messages: newMessages });
|
|
49
56
|
stream.end(newMessages);
|
|
@@ -160,4 +167,4 @@ async function executeToolCalls(tools, assistantMessage, signal, stream) {
|
|
|
160
167
|
}
|
|
161
168
|
return results;
|
|
162
169
|
}
|
|
163
|
-
//# sourceMappingURL=agent.js.map
|
|
170
|
+
//# sourceMappingURL=agent-loop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-loop.js","sourceRoot":"","sources":["../../src/agent/agent-loop.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,oDAAoD;AACpD,MAAM,UAAU,SAAS,CACxB,MAAmB,EACnB,OAAqB,EACrB,MAAoB,EACpB,MAAoB,EACpB,QAA8B;IAE9B,MAAM,MAAM,GAAG,IAAI,WAAW,CAC7B,CAAC,KAAiB,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EACjD,CAAC,KAAiB,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CACzE,CAAC;IAEF,uBAAuB;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,OAAO,GAAG,IAAI,CAAC;QAChB,CAAC;QAED,MAAM,CAAC,IAAI,CAAC;YACX,IAAI,EAAE,oBAAoB;YAC1B,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,QAAQ,EAAE,QAAQ,CAAC,IAAI;YACvB,MAAM,EAAE,aAAa;YACrB,OAAO;SACP,CAAC,CAAC;QAEH,MAAM,iBAAiB,GAAyB;YAC/C,IAAI,EAAE,YAAY;YAClB,UAAU,EAAE,QAAQ,CAAC,EAAE;YACvB,QAAQ,EAAE,QAAQ,CAAC,IAAI;YACvB,MAAM,EAAE,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM;YAChF,OAAO,EAAE,OAAO,aAAa,KAAK,QAAQ,CAAC,CAAC,CAAE,EAAQ,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO;YAC9E,OAAO;SACP,CAAC;QAEF,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC;QACnE,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,iBAAiB,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import { streamSimple } from \"../stream.js\";\nimport type { AssistantMessage, Context, Message, ToolResultMessage, UserMessage } from \"../types.js\";\nimport { EventStream } from \"../utils/event-stream.js\";\nimport { validateToolArguments } from \"../utils/validation.js\";\nimport type { AgentContext, AgentEvent, AgentTool, AgentToolResult, PromptConfig } from \"./types.js\";\n\n// Main prompt function - returns a stream of events\nexport function agentLoop(\n\tprompt: UserMessage,\n\tcontext: AgentContext,\n\tconfig: PromptConfig,\n\tsignal?: AbortSignal,\n\tstreamFn?: typeof streamSimple,\n): EventStream<AgentEvent, AgentContext[\"messages\"]> {\n\tconst stream = new EventStream<AgentEvent, AgentContext[\"messages\"]>(\n\t\t(event: AgentEvent) => event.type === \"agent_end\",\n\t\t(event: AgentEvent) => (event.type === \"agent_end\" ? event.messages : []),\n\t);\n\n\t// Run the prompt async\n\t(async () => {\n\t\t// Track new messages generated during this prompt\n\t\tconst newMessages: AgentContext[\"messages\"] = [];\n\t\t// Create user message for the prompt\n\t\tconst messages = [...context.messages, prompt];\n\t\tnewMessages.push(prompt);\n\n\t\tstream.push({ type: \"agent_start\" });\n\t\tstream.push({ type: \"turn_start\" });\n\t\tstream.push({ type: \"message_start\", message: prompt });\n\t\tstream.push({ type: \"message_end\", message: prompt });\n\n\t\t// Update context with new messages\n\t\tconst currentContext: AgentContext = {\n\t\t\t...context,\n\t\t\tmessages,\n\t\t};\n\n\t\t// Keep looping while we have tool calls\n\t\tlet hasMoreToolCalls = true;\n\t\tlet firstTurn = true;\n\t\twhile (hasMoreToolCalls) {\n\t\t\tif (!firstTurn) {\n\t\t\t\tstream.push({ type: \"turn_start\" });\n\t\t\t} else {\n\t\t\t\tfirstTurn = false;\n\t\t\t}\n\t\t\t// Stream assistant response\n\t\t\tconst message = await streamAssistantResponse(currentContext, config, signal, stream, streamFn);\n\t\t\tnewMessages.push(message);\n\n\t\t\tif (message.stopReason === \"error\" || message.stopReason === \"aborted\") {\n\t\t\t\t// Stop the loop on error or abort\n\t\t\t\tstream.push({ type: \"turn_end\", message, toolResults: [] });\n\t\t\t\tstream.push({ type: \"agent_end\", messages: newMessages });\n\t\t\t\tstream.end(newMessages);\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Check for tool calls\n\t\t\tconst toolCalls = message.content.filter((c) => c.type === \"toolCall\");\n\t\t\thasMoreToolCalls = toolCalls.length > 0;\n\n\t\t\tconst toolResults: ToolResultMessage[] = [];\n\t\t\tif (hasMoreToolCalls) {\n\t\t\t\t// Execute tool calls\n\t\t\t\ttoolResults.push(...(await executeToolCalls(currentContext.tools, message, signal, stream)));\n\t\t\t\tcurrentContext.messages.push(...toolResults);\n\t\t\t\tnewMessages.push(...toolResults);\n\t\t\t}\n\t\t\tstream.push({ type: \"turn_end\", message, toolResults: toolResults });\n\t\t}\n\t\tstream.push({ type: \"agent_end\", messages: newMessages });\n\t\tstream.end(newMessages);\n\t})();\n\n\treturn stream;\n}\n\n// Helper functions\nasync function streamAssistantResponse(\n\tcontext: AgentContext,\n\tconfig: PromptConfig,\n\tsignal: AbortSignal | undefined,\n\tstream: EventStream<AgentEvent, AgentContext[\"messages\"]>,\n\tstreamFn?: typeof streamSimple,\n): Promise<AssistantMessage> {\n\t// Convert AgentContext to Context for streamSimple\n\t// Use a copy of messages to avoid mutating the original context\n\tconst processedMessages = config.preprocessor\n\t\t? await config.preprocessor(context.messages, signal)\n\t\t: [...context.messages];\n\tconst processedContext: Context = {\n\t\tsystemPrompt: context.systemPrompt,\n\t\tmessages: [...processedMessages].map((m) => {\n\t\t\tif (m.role === \"toolResult\") {\n\t\t\t\tconst { details, ...rest } = m;\n\t\t\t\treturn rest;\n\t\t\t} else {\n\t\t\t\treturn m;\n\t\t\t}\n\t\t}),\n\t\ttools: context.tools, // AgentTool extends Tool, so this works\n\t};\n\n\t// Use custom stream function if provided, otherwise use default streamSimple\n\tconst streamFunction = streamFn || streamSimple;\n\tconst response = await streamFunction(config.model, processedContext, { ...config, signal });\n\n\tlet partialMessage: AssistantMessage | null = null;\n\tlet addedPartial = false;\n\n\tfor await (const event of response) {\n\t\tswitch (event.type) {\n\t\t\tcase \"start\":\n\t\t\t\tpartialMessage = event.partial;\n\t\t\t\tcontext.messages.push(partialMessage);\n\t\t\t\taddedPartial = true;\n\t\t\t\tstream.push({ type: \"message_start\", message: { ...partialMessage } });\n\t\t\t\tbreak;\n\n\t\t\tcase \"text_start\":\n\t\t\tcase \"text_delta\":\n\t\t\tcase \"text_end\":\n\t\t\tcase \"thinking_start\":\n\t\t\tcase \"thinking_delta\":\n\t\t\tcase \"thinking_end\":\n\t\t\tcase \"toolcall_start\":\n\t\t\tcase \"toolcall_delta\":\n\t\t\tcase \"toolcall_end\":\n\t\t\t\tif (partialMessage) {\n\t\t\t\t\tpartialMessage = event.partial;\n\t\t\t\t\tcontext.messages[context.messages.length - 1] = partialMessage;\n\t\t\t\t\tstream.push({ type: \"message_update\", assistantMessageEvent: event, message: { ...partialMessage } });\n\t\t\t\t}\n\t\t\t\tbreak;\n\n\t\t\tcase \"done\":\n\t\t\tcase \"error\": {\n\t\t\t\tconst finalMessage = await response.result();\n\t\t\t\tif (addedPartial) {\n\t\t\t\t\tcontext.messages[context.messages.length - 1] = finalMessage;\n\t\t\t\t} else {\n\t\t\t\t\tcontext.messages.push(finalMessage);\n\t\t\t\t}\n\t\t\t\tstream.push({ type: \"message_end\", message: finalMessage });\n\t\t\t\treturn finalMessage;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn await response.result();\n}\n\nasync function executeToolCalls<T>(\n\ttools: AgentTool<any, T>[] | undefined,\n\tassistantMessage: AssistantMessage,\n\tsignal: AbortSignal | undefined,\n\tstream: EventStream<AgentEvent, Message[]>,\n): Promise<ToolResultMessage<T>[]> {\n\tconst toolCalls = assistantMessage.content.filter((c) => c.type === \"toolCall\");\n\tconst results: ToolResultMessage<any>[] = [];\n\n\tfor (const toolCall of toolCalls) {\n\t\tconst tool = tools?.find((t) => t.name === toolCall.name);\n\n\t\tstream.push({\n\t\t\ttype: \"tool_execution_start\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: toolCall.name,\n\t\t\targs: toolCall.arguments,\n\t\t});\n\n\t\tlet resultOrError: AgentToolResult<T> | string;\n\t\tlet isError = false;\n\n\t\ttry {\n\t\t\tif (!tool) throw new Error(`Tool ${toolCall.name} not found`);\n\n\t\t\t// Validate arguments using shared validation function\n\t\t\tconst validatedArgs = validateToolArguments(tool, toolCall);\n\n\t\t\t// Execute with validated, typed arguments\n\t\t\tresultOrError = await tool.execute(toolCall.id, validatedArgs, signal);\n\t\t} catch (e) {\n\t\t\tresultOrError = e instanceof Error ? e.message : String(e);\n\t\t\tisError = true;\n\t\t}\n\n\t\tstream.push({\n\t\t\ttype: \"tool_execution_end\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: toolCall.name,\n\t\t\tresult: resultOrError,\n\t\t\tisError,\n\t\t});\n\n\t\tconst toolResultMessage: ToolResultMessage<T> = {\n\t\t\trole: \"toolResult\",\n\t\t\ttoolCallId: toolCall.id,\n\t\t\ttoolName: toolCall.name,\n\t\t\toutput: typeof resultOrError === \"string\" ? resultOrError : resultOrError.output,\n\t\t\tdetails: typeof resultOrError === \"string\" ? ({} as T) : resultOrError.details,\n\t\t\tisError,\n\t\t};\n\n\t\tresults.push(toolResultMessage);\n\t\tstream.push({ type: \"message_start\", message: toolResultMessage });\n\t\tstream.push({ type: \"message_end\", message: toolResultMessage });\n\t}\n\n\treturn results;\n}\n"]}
|
package/dist/agent/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC"}
|
package/dist/agent/index.js
CHANGED
package/dist/agent/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/agent/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,cAAc,kBAAkB,CAAC","sourcesContent":["export { agentLoop } from \"./agent-loop.js\";\nexport * from \"./tools/index.js\";\nexport type { AgentContext, AgentEvent, AgentTool, PromptConfig } from \"./types.js\";\n"]}
|
package/dist/agent/types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EACX,gBAAgB,EAChB,qBAAqB,EACrB,OAAO,EACP,KAAK,EACL,mBAAmB,EACnB,IAAI,EACJ,iBAAiB,EACjB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,eAAe,CAAC,CAAC;IAEjC,MAAM,EAAE,MAAM,CAAC;IAEf,OAAO,EAAE,CAAC,CAAC;CACX;AAGD,MAAM,WAAW,SAAS,CAAC,WAAW,SAAS,OAAO,GAAG,OAAO,EAAE,QAAQ,GAAG,GAAG,CAAE,SAAQ,IAAI,CAAC,WAAW,CAAC;IAE1G,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,CACR,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,CAAC,WAAW,CAAC,EAC3B,MAAM,CAAC,EAAE,WAAW,KAChB,OAAO,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC;CACxC;AAGD,MAAM,WAAW,YAAY;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC;CACzB;AAGD,MAAM,MAAM,UAAU,GAEnB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAEvB;IAAE,IAAI,EAAE,YAAY,CAAA;CAAE,GAEtB;IAAE,IAAI,EAAE,eAAe,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;C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CAAC,QAAQ,EAAE,YAAY,CAAC,UAAU,CAAC,EAAE,WAAW,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;CACpH"}
|
package/dist/agent/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Static, TSchema } from \"@sinclair/typebox\";\nimport type {\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tMessage,\n\tModel,\n\tSimpleStreamOptions,\n\tTool,\n\tToolResultMessage,\n} from \"../types.js\";\n\nexport interface AgentToolResult<T> {\n\t// Output of the tool to be given to the LLM in ToolResultMessage.content\n\toutput: string;\n\t// Details to be displayed in a UI or loggedty\n\tdetails: T;\n}\n\n// AgentTool extends Tool but adds the execute function\nexport interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any> extends Tool<TParameters> {\n\t// A human-readable label for the tool to be displayed in UI\n\tlabel: string;\n\texecute: (\n\t\ttoolCallId: string,\n\t\tparams: Static<TParameters>,\n\t\tsignal?: AbortSignal,\n\t) => Promise<AgentToolResult<TDetails>>;\n}\n\n// AgentContext is like Context but uses AgentTool\nexport interface AgentContext {\n\tsystemPrompt: string;\n\tmessages: Message[];\n\ttools?: AgentTool<any>[];\n}\n\n// Event types\nexport type AgentEvent =\n\t// Emitted when the agent starts. An agent can emit multiple turns\n\t| { type: \"agent_start\" }\n\t// Emitted when a turn starts. A turn can emit an optional user message (initial prompt), an assistant message (response) and multiple tool result messages\n\t| { type: \"turn_start\" }\n\t// Emitted when a user, assistant or tool result message starts\n\t| { type: \"message_start\"; message: Message }\n\t// Emitted when an asssitant messages is updated due to streaming\n\t| { type: \"message_update\"; assistantMessageEvent: AssistantMessageEvent; message: AssistantMessage }\n\t// Emitted when a user, assistant or tool result message is complete\n\t| { type: \"message_end\"; message: Message }\n\t// Emitted when a tool execution starts\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: any }\n\t// Emitted when a tool execution completes\n\t| {\n\t\t\ttype: \"tool_execution_end\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\tresult: AgentToolResult<any> | string;\n\t\t\tisError: boolean;\n\t }\n\t// Emitted when a full turn completes\n\t| { type: \"turn_end\";
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/agent/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Static, TSchema } from \"@sinclair/typebox\";\nimport type {\n\tAssistantMessage,\n\tAssistantMessageEvent,\n\tMessage,\n\tModel,\n\tSimpleStreamOptions,\n\tTool,\n\tToolResultMessage,\n} from \"../types.js\";\n\nexport interface AgentToolResult<T> {\n\t// Output of the tool to be given to the LLM in ToolResultMessage.content\n\toutput: string;\n\t// Details to be displayed in a UI or loggedty\n\tdetails: T;\n}\n\n// AgentTool extends Tool but adds the execute function\nexport interface AgentTool<TParameters extends TSchema = TSchema, TDetails = any> extends Tool<TParameters> {\n\t// A human-readable label for the tool to be displayed in UI\n\tlabel: string;\n\texecute: (\n\t\ttoolCallId: string,\n\t\tparams: Static<TParameters>,\n\t\tsignal?: AbortSignal,\n\t) => Promise<AgentToolResult<TDetails>>;\n}\n\n// AgentContext is like Context but uses AgentTool\nexport interface AgentContext {\n\tsystemPrompt: string;\n\tmessages: Message[];\n\ttools?: AgentTool<any>[];\n}\n\n// Event types\nexport type AgentEvent =\n\t// Emitted when the agent starts. An agent can emit multiple turns\n\t| { type: \"agent_start\" }\n\t// Emitted when a turn starts. A turn can emit an optional user message (initial prompt), an assistant message (response) and multiple tool result messages\n\t| { type: \"turn_start\" }\n\t// Emitted when a user, assistant or tool result message starts\n\t| { type: \"message_start\"; message: Message }\n\t// Emitted when an asssitant messages is updated due to streaming\n\t| { type: \"message_update\"; assistantMessageEvent: AssistantMessageEvent; message: AssistantMessage }\n\t// Emitted when a user, assistant or tool result message is complete\n\t| { type: \"message_end\"; message: Message }\n\t// Emitted when a tool execution starts\n\t| { type: \"tool_execution_start\"; toolCallId: string; toolName: string; args: any }\n\t// Emitted when a tool execution completes\n\t| {\n\t\t\ttype: \"tool_execution_end\";\n\t\t\ttoolCallId: string;\n\t\t\ttoolName: string;\n\t\t\tresult: AgentToolResult<any> | string;\n\t\t\tisError: boolean;\n\t }\n\t// Emitted when a full turn completes\n\t| { type: \"turn_end\"; message: AssistantMessage; toolResults: ToolResultMessage[] }\n\t// Emitted when the agent has completed all its turns. All messages from every turn are\n\t// contained in messages, which can be appended to the context\n\t| { type: \"agent_end\"; messages: AgentContext[\"messages\"] };\n\n// Configuration for prompt execution\nexport interface PromptConfig extends SimpleStreamOptions {\n\tmodel: Model<any>;\n\tpreprocessor?: (messages: AgentContext[\"messages\"], abortSignal?: AbortSignal) => Promise<AgentContext[\"messages\"]>;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export * from "./providers/google.js";
|
|
|
5
5
|
export * from "./providers/openai-completions.js";
|
|
6
6
|
export * from "./providers/openai-responses.js";
|
|
7
7
|
export * from "./stream.js";
|
|
8
|
-
export * from "./typebox-helpers.js";
|
|
9
8
|
export * from "./types.js";
|
|
9
|
+
export * from "./utils/typebox-helpers.js";
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,6 +5,6 @@ export * from "./providers/google.js";
|
|
|
5
5
|
export * from "./providers/openai-completions.js";
|
|
6
6
|
export * from "./providers/openai-responses.js";
|
|
7
7
|
export * from "./stream.js";
|
|
8
|
-
export * from "./typebox-helpers.js";
|
|
9
8
|
export * from "./types.js";
|
|
9
|
+
export * from "./utils/typebox-helpers.js";
|
|
10
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC;AAC5B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,aAAa,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mCAAmC,CAAC;AAClD,cAAc,iCAAiC,CAAC;AAChD,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,4BAA4B,CAAC","sourcesContent":["export * from \"./agent/index.js\";\nexport * from \"./models.js\";\nexport * from \"./providers/anthropic.js\";\nexport * from \"./providers/google.js\";\nexport * from \"./providers/openai-completions.js\";\nexport * from \"./providers/openai-responses.js\";\nexport * from \"./stream.js\";\nexport * from \"./types.js\";\nexport * from \"./utils/typebox-helpers.js\";\n"]}
|
|
@@ -1408,6 +1408,23 @@ export declare const MODELS: {
|
|
|
1408
1408
|
};
|
|
1409
1409
|
};
|
|
1410
1410
|
readonly openrouter: {
|
|
1411
|
+
readonly "alibaba/tongyi-deepresearch-30b-a3b": {
|
|
1412
|
+
id: string;
|
|
1413
|
+
name: string;
|
|
1414
|
+
api: "openai-completions";
|
|
1415
|
+
provider: string;
|
|
1416
|
+
baseUrl: string;
|
|
1417
|
+
reasoning: true;
|
|
1418
|
+
input: "text"[];
|
|
1419
|
+
cost: {
|
|
1420
|
+
input: number;
|
|
1421
|
+
output: number;
|
|
1422
|
+
cacheRead: number;
|
|
1423
|
+
cacheWrite: number;
|
|
1424
|
+
};
|
|
1425
|
+
contextWindow: number;
|
|
1426
|
+
maxTokens: number;
|
|
1427
|
+
};
|
|
1411
1428
|
readonly "qwen/qwen3-coder-flash": {
|
|
1412
1429
|
id: string;
|
|
1413
1430
|
name: string;
|
|
@@ -2989,7 +3006,7 @@ export declare const MODELS: {
|
|
|
2989
3006
|
contextWindow: number;
|
|
2990
3007
|
maxTokens: number;
|
|
2991
3008
|
};
|
|
2992
|
-
readonly "cohere/command-r-08-2024": {
|
|
3009
|
+
readonly "cohere/command-r-plus-08-2024": {
|
|
2993
3010
|
id: string;
|
|
2994
3011
|
name: string;
|
|
2995
3012
|
api: "openai-completions";
|
|
@@ -3006,7 +3023,7 @@ export declare const MODELS: {
|
|
|
3006
3023
|
contextWindow: number;
|
|
3007
3024
|
maxTokens: number;
|
|
3008
3025
|
};
|
|
3009
|
-
readonly "cohere/command-r-
|
|
3026
|
+
readonly "cohere/command-r-08-2024": {
|
|
3010
3027
|
id: string;
|
|
3011
3028
|
name: string;
|
|
3012
3029
|
api: "openai-completions";
|
|
@@ -3125,7 +3142,7 @@ export declare const MODELS: {
|
|
|
3125
3142
|
contextWindow: number;
|
|
3126
3143
|
maxTokens: number;
|
|
3127
3144
|
};
|
|
3128
|
-
readonly "mistralai/mistral-7b-instruct
|
|
3145
|
+
readonly "mistralai/mistral-7b-instruct:free": {
|
|
3129
3146
|
id: string;
|
|
3130
3147
|
name: string;
|
|
3131
3148
|
api: "openai-completions";
|
|
@@ -3142,7 +3159,7 @@ export declare const MODELS: {
|
|
|
3142
3159
|
contextWindow: number;
|
|
3143
3160
|
maxTokens: number;
|
|
3144
3161
|
};
|
|
3145
|
-
readonly "mistralai/mistral-7b-instruct
|
|
3162
|
+
readonly "mistralai/mistral-7b-instruct": {
|
|
3146
3163
|
id: string;
|
|
3147
3164
|
name: string;
|
|
3148
3165
|
api: "openai-completions";
|
|
@@ -3159,7 +3176,7 @@ export declare const MODELS: {
|
|
|
3159
3176
|
contextWindow: number;
|
|
3160
3177
|
maxTokens: number;
|
|
3161
3178
|
};
|
|
3162
|
-
readonly "mistralai/mistral-7b-instruct": {
|
|
3179
|
+
readonly "mistralai/mistral-7b-instruct-v0.3": {
|
|
3163
3180
|
id: string;
|
|
3164
3181
|
name: string;
|
|
3165
3182
|
api: "openai-completions";
|
|
@@ -3346,7 +3363,7 @@ export declare const MODELS: {
|
|
|
3346
3363
|
contextWindow: number;
|
|
3347
3364
|
maxTokens: number;
|
|
3348
3365
|
};
|
|
3349
|
-
readonly "mistralai/mistral-
|
|
3366
|
+
readonly "mistralai/mistral-small": {
|
|
3350
3367
|
id: string;
|
|
3351
3368
|
name: string;
|
|
3352
3369
|
api: "openai-completions";
|
|
@@ -3363,7 +3380,7 @@ export declare const MODELS: {
|
|
|
3363
3380
|
contextWindow: number;
|
|
3364
3381
|
maxTokens: number;
|
|
3365
3382
|
};
|
|
3366
|
-
readonly "mistralai/mistral-
|
|
3383
|
+
readonly "mistralai/mistral-tiny": {
|
|
3367
3384
|
id: string;
|
|
3368
3385
|
name: string;
|
|
3369
3386
|
api: "openai-completions";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.generated.d.ts","sourceRoot":"","sources":["../src/models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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA02GT,CAAC"}
|
package/dist/models.generated.js
CHANGED
|
@@ -1410,6 +1410,23 @@ export const MODELS = {
|
|
|
1410
1410
|
},
|
|
1411
1411
|
},
|
|
1412
1412
|
openrouter: {
|
|
1413
|
+
"alibaba/tongyi-deepresearch-30b-a3b": {
|
|
1414
|
+
id: "alibaba/tongyi-deepresearch-30b-a3b",
|
|
1415
|
+
name: "Tongyi DeepResearch 30B A3B",
|
|
1416
|
+
api: "openai-completions",
|
|
1417
|
+
provider: "openrouter",
|
|
1418
|
+
baseUrl: "https://openrouter.ai/api/v1",
|
|
1419
|
+
reasoning: true,
|
|
1420
|
+
input: ["text"],
|
|
1421
|
+
cost: {
|
|
1422
|
+
input: 0.09,
|
|
1423
|
+
output: 0.44999999999999996,
|
|
1424
|
+
cacheRead: 0,
|
|
1425
|
+
cacheWrite: 0,
|
|
1426
|
+
},
|
|
1427
|
+
contextWindow: 131072,
|
|
1428
|
+
maxTokens: 131072,
|
|
1429
|
+
},
|
|
1413
1430
|
"qwen/qwen3-coder-flash": {
|
|
1414
1431
|
id: "qwen/qwen3-coder-flash",
|
|
1415
1432
|
name: "Qwen: Qwen3 Coder Flash",
|
|
@@ -2116,8 +2133,8 @@ export const MODELS = {
|
|
|
2116
2133
|
reasoning: false,
|
|
2117
2134
|
input: ["text", "image"],
|
|
2118
2135
|
cost: {
|
|
2119
|
-
input: 0.
|
|
2120
|
-
output: 0.
|
|
2136
|
+
input: 0.075,
|
|
2137
|
+
output: 0.19999999999999998,
|
|
2121
2138
|
cacheRead: 0,
|
|
2122
2139
|
cacheWrite: 0,
|
|
2123
2140
|
},
|
|
@@ -2405,8 +2422,8 @@ export const MODELS = {
|
|
|
2405
2422
|
reasoning: true,
|
|
2406
2423
|
input: ["text"],
|
|
2407
2424
|
cost: {
|
|
2408
|
-
input: 0.
|
|
2409
|
-
output: 0.
|
|
2425
|
+
input: 0.18,
|
|
2426
|
+
output: 0.54,
|
|
2410
2427
|
cacheRead: 0,
|
|
2411
2428
|
cacheWrite: 0,
|
|
2412
2429
|
},
|
|
@@ -2991,34 +3008,34 @@ export const MODELS = {
|
|
|
2991
3008
|
contextWindow: 32768,
|
|
2992
3009
|
maxTokens: 4096,
|
|
2993
3010
|
},
|
|
2994
|
-
"cohere/command-r-08-2024": {
|
|
2995
|
-
id: "cohere/command-r-08-2024",
|
|
2996
|
-
name: "Cohere: Command R (08-2024)",
|
|
3011
|
+
"cohere/command-r-plus-08-2024": {
|
|
3012
|
+
id: "cohere/command-r-plus-08-2024",
|
|
3013
|
+
name: "Cohere: Command R+ (08-2024)",
|
|
2997
3014
|
api: "openai-completions",
|
|
2998
3015
|
provider: "openrouter",
|
|
2999
3016
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
3000
3017
|
reasoning: false,
|
|
3001
3018
|
input: ["text"],
|
|
3002
3019
|
cost: {
|
|
3003
|
-
input:
|
|
3004
|
-
output:
|
|
3020
|
+
input: 2.5,
|
|
3021
|
+
output: 10,
|
|
3005
3022
|
cacheRead: 0,
|
|
3006
3023
|
cacheWrite: 0,
|
|
3007
3024
|
},
|
|
3008
3025
|
contextWindow: 128000,
|
|
3009
3026
|
maxTokens: 4000,
|
|
3010
3027
|
},
|
|
3011
|
-
"cohere/command-r-
|
|
3012
|
-
id: "cohere/command-r-
|
|
3013
|
-
name: "Cohere: Command R
|
|
3028
|
+
"cohere/command-r-08-2024": {
|
|
3029
|
+
id: "cohere/command-r-08-2024",
|
|
3030
|
+
name: "Cohere: Command R (08-2024)",
|
|
3014
3031
|
api: "openai-completions",
|
|
3015
3032
|
provider: "openrouter",
|
|
3016
3033
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
3017
3034
|
reasoning: false,
|
|
3018
3035
|
input: ["text"],
|
|
3019
3036
|
cost: {
|
|
3020
|
-
input:
|
|
3021
|
-
output:
|
|
3037
|
+
input: 0.15,
|
|
3038
|
+
output: 0.6,
|
|
3022
3039
|
cacheRead: 0,
|
|
3023
3040
|
cacheWrite: 0,
|
|
3024
3041
|
},
|
|
@@ -3068,12 +3085,12 @@ export const MODELS = {
|
|
|
3068
3085
|
reasoning: false,
|
|
3069
3086
|
input: ["text"],
|
|
3070
3087
|
cost: {
|
|
3071
|
-
input: 0.
|
|
3072
|
-
output: 0.
|
|
3088
|
+
input: 0.02,
|
|
3089
|
+
output: 0.03,
|
|
3073
3090
|
cacheRead: 0,
|
|
3074
3091
|
cacheWrite: 0,
|
|
3075
3092
|
},
|
|
3076
|
-
contextWindow:
|
|
3093
|
+
contextWindow: 16384,
|
|
3077
3094
|
maxTokens: 16384,
|
|
3078
3095
|
},
|
|
3079
3096
|
"meta-llama/llama-3.1-405b-instruct": {
|
|
@@ -3127,43 +3144,43 @@ export const MODELS = {
|
|
|
3127
3144
|
contextWindow: 131072,
|
|
3128
3145
|
maxTokens: 16384,
|
|
3129
3146
|
},
|
|
3130
|
-
"mistralai/mistral-7b-instruct
|
|
3131
|
-
id: "mistralai/mistral-7b-instruct
|
|
3132
|
-
name: "Mistral: Mistral 7B Instruct
|
|
3147
|
+
"mistralai/mistral-7b-instruct:free": {
|
|
3148
|
+
id: "mistralai/mistral-7b-instruct:free",
|
|
3149
|
+
name: "Mistral: Mistral 7B Instruct (free)",
|
|
3133
3150
|
api: "openai-completions",
|
|
3134
3151
|
provider: "openrouter",
|
|
3135
3152
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
3136
3153
|
reasoning: false,
|
|
3137
3154
|
input: ["text"],
|
|
3138
3155
|
cost: {
|
|
3139
|
-
input: 0
|
|
3140
|
-
output: 0
|
|
3156
|
+
input: 0,
|
|
3157
|
+
output: 0,
|
|
3141
3158
|
cacheRead: 0,
|
|
3142
3159
|
cacheWrite: 0,
|
|
3143
3160
|
},
|
|
3144
3161
|
contextWindow: 32768,
|
|
3145
3162
|
maxTokens: 16384,
|
|
3146
3163
|
},
|
|
3147
|
-
"mistralai/mistral-7b-instruct
|
|
3148
|
-
id: "mistralai/mistral-7b-instruct
|
|
3149
|
-
name: "Mistral: Mistral 7B Instruct
|
|
3164
|
+
"mistralai/mistral-7b-instruct": {
|
|
3165
|
+
id: "mistralai/mistral-7b-instruct",
|
|
3166
|
+
name: "Mistral: Mistral 7B Instruct",
|
|
3150
3167
|
api: "openai-completions",
|
|
3151
3168
|
provider: "openrouter",
|
|
3152
3169
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
3153
3170
|
reasoning: false,
|
|
3154
3171
|
input: ["text"],
|
|
3155
3172
|
cost: {
|
|
3156
|
-
input: 0,
|
|
3157
|
-
output: 0,
|
|
3173
|
+
input: 0.028,
|
|
3174
|
+
output: 0.054,
|
|
3158
3175
|
cacheRead: 0,
|
|
3159
3176
|
cacheWrite: 0,
|
|
3160
3177
|
},
|
|
3161
3178
|
contextWindow: 32768,
|
|
3162
3179
|
maxTokens: 16384,
|
|
3163
3180
|
},
|
|
3164
|
-
"mistralai/mistral-7b-instruct": {
|
|
3165
|
-
id: "mistralai/mistral-7b-instruct",
|
|
3166
|
-
name: "Mistral: Mistral 7B Instruct",
|
|
3181
|
+
"mistralai/mistral-7b-instruct-v0.3": {
|
|
3182
|
+
id: "mistralai/mistral-7b-instruct-v0.3",
|
|
3183
|
+
name: "Mistral: Mistral 7B Instruct v0.3",
|
|
3167
3184
|
api: "openai-completions",
|
|
3168
3185
|
provider: "openrouter",
|
|
3169
3186
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
@@ -3348,34 +3365,34 @@ export const MODELS = {
|
|
|
3348
3365
|
contextWindow: 128000,
|
|
3349
3366
|
maxTokens: 4096,
|
|
3350
3367
|
},
|
|
3351
|
-
"mistralai/mistral-
|
|
3352
|
-
id: "mistralai/mistral-
|
|
3353
|
-
name: "Mistral
|
|
3368
|
+
"mistralai/mistral-small": {
|
|
3369
|
+
id: "mistralai/mistral-small",
|
|
3370
|
+
name: "Mistral Small",
|
|
3354
3371
|
api: "openai-completions",
|
|
3355
3372
|
provider: "openrouter",
|
|
3356
3373
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
3357
3374
|
reasoning: false,
|
|
3358
3375
|
input: ["text"],
|
|
3359
3376
|
cost: {
|
|
3360
|
-
input: 0.
|
|
3361
|
-
output: 0.
|
|
3377
|
+
input: 0.19999999999999998,
|
|
3378
|
+
output: 0.6,
|
|
3362
3379
|
cacheRead: 0,
|
|
3363
3380
|
cacheWrite: 0,
|
|
3364
3381
|
},
|
|
3365
3382
|
contextWindow: 32768,
|
|
3366
3383
|
maxTokens: 4096,
|
|
3367
3384
|
},
|
|
3368
|
-
"mistralai/mistral-
|
|
3369
|
-
id: "mistralai/mistral-
|
|
3370
|
-
name: "Mistral
|
|
3385
|
+
"mistralai/mistral-tiny": {
|
|
3386
|
+
id: "mistralai/mistral-tiny",
|
|
3387
|
+
name: "Mistral Tiny",
|
|
3371
3388
|
api: "openai-completions",
|
|
3372
3389
|
provider: "openrouter",
|
|
3373
3390
|
baseUrl: "https://openrouter.ai/api/v1",
|
|
3374
3391
|
reasoning: false,
|
|
3375
3392
|
input: ["text"],
|
|
3376
3393
|
cost: {
|
|
3377
|
-
input: 0.
|
|
3378
|
-
output: 0.
|
|
3394
|
+
input: 0.25,
|
|
3395
|
+
output: 0.25,
|
|
3379
3396
|
cacheRead: 0,
|
|
3380
3397
|
cacheWrite: 0,
|
|
3381
3398
|
},
|