@arcships/aimux 0.1.0 → 0.1.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/aimux.darwin-arm64.node +0 -0
- package/aimux.linux-x64-gnu.node +0 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +78 -0
- package/dist/types/AiMuxError.d.ts +34 -0
- package/dist/types/AiMuxError.js +3 -0
- package/dist/types/AspectRatio.d.ts +11 -0
- package/dist/types/AspectRatio.js +3 -0
- package/dist/types/AudioChunk.d.ts +8 -0
- package/dist/types/AudioChunk.js +3 -0
- package/dist/types/AudioData.d.ts +11 -0
- package/dist/types/AudioData.js +3 -0
- package/dist/types/AudioInput.d.ts +8 -0
- package/dist/types/AudioInput.js +3 -0
- package/dist/types/CallOptions.d.ts +80 -0
- package/dist/types/CallOptions.js +2 -0
- package/dist/types/ContentPart.d.ts +77 -0
- package/dist/types/ContentPart.js +2 -0
- package/dist/types/EmbeddingCallOptions.d.ts +24 -0
- package/dist/types/EmbeddingCallOptions.js +2 -0
- package/dist/types/EmbeddingResponse.d.ts +16 -0
- package/dist/types/EmbeddingResponse.js +2 -0
- package/dist/types/EmbeddingResult.d.ts +33 -0
- package/dist/types/EmbeddingResult.js +2 -0
- package/dist/types/EmbeddingUsage.d.ts +9 -0
- package/dist/types/EmbeddingUsage.js +3 -0
- package/dist/types/FileBytes.d.ts +12 -0
- package/dist/types/FileBytes.js +3 -0
- package/dist/types/FileData.d.ts +25 -0
- package/dist/types/FileData.js +2 -0
- package/dist/types/FinishReason.d.ts +14 -0
- package/dist/types/FinishReason.js +2 -0
- package/dist/types/FinishReasonUnified.d.ts +4 -0
- package/dist/types/FinishReasonUnified.js +3 -0
- package/dist/types/FunctionTool.d.ts +35 -0
- package/dist/types/FunctionTool.js +2 -0
- package/dist/types/GenerateContent.d.ts +33 -0
- package/dist/types/GenerateContent.js +2 -0
- package/dist/types/GenerateResult.d.ts +45 -0
- package/dist/types/GenerateResult.js +2 -0
- package/dist/types/GenerateTextOptions.d.ts +38 -0
- package/dist/types/GenerateTextOptions.js +2 -0
- package/dist/types/GenerateTextResult.d.ts +34 -0
- package/dist/types/GenerateTextResult.js +2 -0
- package/dist/types/ImageCallOptions.d.ts +54 -0
- package/dist/types/ImageCallOptions.js +2 -0
- package/dist/types/ImageFile.d.ts +25 -0
- package/dist/types/ImageFile.js +2 -0
- package/dist/types/ImageFileData.d.ts +8 -0
- package/dist/types/ImageFileData.js +3 -0
- package/dist/types/ImageOutputs.d.ts +14 -0
- package/dist/types/ImageOutputs.js +3 -0
- package/dist/types/ImageResponse.d.ts +19 -0
- package/dist/types/ImageResponse.js +3 -0
- package/dist/types/ImageResult.d.ts +34 -0
- package/dist/types/ImageResult.js +2 -0
- package/dist/types/ImageUsage.d.ts +19 -0
- package/dist/types/ImageUsage.js +3 -0
- package/dist/types/InputAudioFormat.d.ts +13 -0
- package/dist/types/InputAudioFormat.js +3 -0
- package/dist/types/LanguageModelPromptMessage.d.ts +20 -0
- package/dist/types/LanguageModelPromptMessage.js +2 -0
- package/dist/types/MessageContent.d.ts +5 -0
- package/dist/types/MessageContent.js +2 -0
- package/dist/types/ModelId.d.ts +7 -0
- package/dist/types/ModelId.js +3 -0
- package/dist/types/ModelMessage.d.ts +9 -0
- package/dist/types/ModelMessage.js +2 -0
- package/dist/types/ModelPrompt.d.ts +7 -0
- package/dist/types/ModelPrompt.js +2 -0
- package/dist/types/ProviderTool.d.ts +24 -0
- package/dist/types/ProviderTool.js +2 -0
- package/dist/types/ReasoningEffort.d.ts +7 -0
- package/dist/types/ReasoningEffort.js +3 -0
- package/dist/types/RequestInfo.d.ts +12 -0
- package/dist/types/RequestInfo.js +2 -0
- package/dist/types/RerankingCallOptions.d.ts +33 -0
- package/dist/types/RerankingCallOptions.js +2 -0
- package/dist/types/RerankingDocuments.d.ts +15 -0
- package/dist/types/RerankingDocuments.js +2 -0
- package/dist/types/RerankingRank.d.ts +13 -0
- package/dist/types/RerankingRank.js +3 -0
- package/dist/types/RerankingResponse.d.ts +28 -0
- package/dist/types/RerankingResponse.js +2 -0
- package/dist/types/RerankingResult.d.ts +31 -0
- package/dist/types/RerankingResult.js +2 -0
- package/dist/types/ResponseFormat.d.ts +11 -0
- package/dist/types/ResponseFormat.js +2 -0
- package/dist/types/ResponseInfo.d.ts +30 -0
- package/dist/types/ResponseInfo.js +2 -0
- package/dist/types/ResponseMetadata.d.ts +8 -0
- package/dist/types/ResponseMetadata.js +3 -0
- package/dist/types/Role.d.ts +4 -0
- package/dist/types/Role.js +3 -0
- package/dist/types/SearchCallOptions.d.ts +46 -0
- package/dist/types/SearchCallOptions.js +2 -0
- package/dist/types/SearchResponse.d.ts +16 -0
- package/dist/types/SearchResponse.js +2 -0
- package/dist/types/SearchResult.d.ts +32 -0
- package/dist/types/SearchResult.js +2 -0
- package/dist/types/SearchResultItem.d.ts +33 -0
- package/dist/types/SearchResultItem.js +2 -0
- package/dist/types/Size.d.ts +11 -0
- package/dist/types/Size.js +3 -0
- package/dist/types/SpeechCallOptions.d.ts +47 -0
- package/dist/types/SpeechCallOptions.js +2 -0
- package/dist/types/SpeechRequest.d.ts +10 -0
- package/dist/types/SpeechRequest.js +2 -0
- package/dist/types/SpeechResponse.d.ts +24 -0
- package/dist/types/SpeechResponse.js +2 -0
- package/dist/types/SpeechResult.d.ts +34 -0
- package/dist/types/SpeechResult.js +2 -0
- package/dist/types/StreamPart.d.ts +104 -0
- package/dist/types/StreamPart.js +2 -0
- package/dist/types/TokenUsage.d.ts +29 -0
- package/dist/types/TokenUsage.js +3 -0
- package/dist/types/Tool.d.ts +12 -0
- package/dist/types/Tool.js +2 -0
- package/dist/types/ToolCall.d.ts +18 -0
- package/dist/types/ToolCall.js +2 -0
- package/dist/types/ToolChoice.d.ts +12 -0
- package/dist/types/ToolChoice.js +3 -0
- package/dist/types/ToolResult.d.ts +14 -0
- package/dist/types/ToolResult.js +2 -0
- package/dist/types/UploadFileCallOptions.d.ts +27 -0
- package/dist/types/UploadFileCallOptions.js +2 -0
- package/dist/types/UploadFileData.d.ts +17 -0
- package/dist/types/UploadFileData.js +2 -0
- package/dist/types/UploadFileResult.d.ts +35 -0
- package/dist/types/UploadFileResult.js +2 -0
- package/dist/types/Usage.d.ts +8 -0
- package/dist/types/Usage.js +2 -0
- package/dist/types/VideoCallOptions.d.ts +69 -0
- package/dist/types/VideoCallOptions.js +2 -0
- package/dist/types/VideoData.d.ts +22 -0
- package/dist/types/VideoData.js +3 -0
- package/dist/types/VideoFile.d.ts +29 -0
- package/dist/types/VideoFile.js +2 -0
- package/dist/types/VideoFileData.d.ts +8 -0
- package/dist/types/VideoFileData.js +3 -0
- package/dist/types/VideoFrameImage.d.ts +17 -0
- package/dist/types/VideoFrameImage.js +2 -0
- package/dist/types/VideoFrameType.d.ts +6 -0
- package/dist/types/VideoFrameType.js +3 -0
- package/dist/types/VideoResponse.d.ts +19 -0
- package/dist/types/VideoResponse.js +3 -0
- package/dist/types/VideoResult.d.ts +29 -0
- package/dist/types/VideoResult.js +2 -0
- package/dist/types/Warning.d.ts +23 -0
- package/dist/types/Warning.js +3 -0
- package/dist/types/serde_json/JsonValue.d.ts +3 -0
- package/dist/types/serde_json/JsonValue.js +3 -0
- package/dist/types.d.ts +73 -0
- package/dist/types.js +5 -0
- package/package.json +8 -6
- package/src/index.ts +0 -134
package/aimux.darwin-arm64.node
CHANGED
|
Binary file
|
package/aimux.linux-x64-gnu.node
CHANGED
|
Binary file
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { Model } from '../index.js';
|
|
2
|
+
import type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage, Tool, ToolChoice, ToolCall, ToolResult, Usage, FinishReason, Warning, Role, MessageContent, ContentPart, ResponseFormat, ReasoningEffort, AiMuxError, GenerateResult, FunctionTool } from './types';
|
|
3
|
+
export { Model, StreamTextGenerator, openai, anthropic, deepseek } from '../index.js';
|
|
4
|
+
export type { GenerateTextOptions, GenerateTextResult, StreamPart, ModelMessage, Tool, ToolChoice, ToolCall, ToolResult, Usage, FinishReason, Warning, Role, MessageContent, ContentPart, ResponseFormat, ReasoningEffort, AiMuxError, GenerateResult, FunctionTool, };
|
|
5
|
+
/**
|
|
6
|
+
* A raw napi `Model` instance returned by `openai()` / `anthropic()` / …
|
|
7
|
+
*
|
|
8
|
+
* The wrapper accepts one of these and hides the JSON-string boundary behind
|
|
9
|
+
* typed inputs and outputs. `RawModel` is just an alias for the napi `Model`
|
|
10
|
+
* class instance type — pass the exact object a provider factory gives you.
|
|
11
|
+
*/
|
|
12
|
+
export type RawModel = Model;
|
|
13
|
+
/**
|
|
14
|
+
* Generate text (non-streaming). Returns a typed {@link GenerateTextResult}.
|
|
15
|
+
*
|
|
16
|
+
* @param model - A raw model instance from `openai()`, `anthropic()`, etc.
|
|
17
|
+
* @param prompt - A plain string or an array of typed chat messages.
|
|
18
|
+
* @param options - Optional typed generation options (tools, tool_choice,
|
|
19
|
+
* temperature, response_format, …).
|
|
20
|
+
*
|
|
21
|
+
* Internally calls the raw
|
|
22
|
+
* `model.generateText(JSON.stringify(prompt), options ? JSON.stringify(options) : undefined)`
|
|
23
|
+
* and `JSON.parse`s the returned JSON into a typed object.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* import { openai, generateText } from 'aimux'
|
|
28
|
+
* const model = await openai(apiKey, 'gpt-4o')
|
|
29
|
+
* const result = await generateText(model, 'What is Rust?')
|
|
30
|
+
* console.log(result.text, result.usage)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare function generateText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptions): Promise<GenerateTextResult>;
|
|
34
|
+
/**
|
|
35
|
+
* Stream text from a model. Yields typed {@link StreamPart}s.
|
|
36
|
+
*
|
|
37
|
+
* @param model - A raw model instance from `openai()`, `anthropic()`, etc.
|
|
38
|
+
* @param prompt - A plain string or an array of typed chat messages.
|
|
39
|
+
* @param options - Optional typed generation options (tools, tool_choice, …).
|
|
40
|
+
*
|
|
41
|
+
* Internally drives the raw `model.streamText(JSON.stringify(prompt), …)`
|
|
42
|
+
* async generator and `JSON.parse`s each JSON-string chunk before yielding it
|
|
43
|
+
* as a typed `StreamPart`.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* import { openai, streamText } from 'aimux'
|
|
48
|
+
* const model = await openai(apiKey, 'gpt-4o')
|
|
49
|
+
* for await (const part of streamText(model, 'Write a haiku about Rust.')) {
|
|
50
|
+
* if ('TextDelta' in part) process.stdout.write(part.TextDelta.delta)
|
|
51
|
+
* }
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function streamText(model: RawModel, prompt: string | ModelMessage[], options?: GenerateTextOptions): AsyncGenerator<StreamPart>;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// aimux — Typed wrapper layer for the Node.js (napi-rs) binding.
|
|
3
|
+
//
|
|
4
|
+
// The native binding speaks JSON strings:
|
|
5
|
+
// generateText(prompt: string, options?: string): Promise<string>
|
|
6
|
+
// streamText(prompt: string, options?: string): Promise<AsyncGenerator<string>>
|
|
7
|
+
// Users would otherwise have to JSON.stringify every input and JSON.parse every
|
|
8
|
+
// output, with no static types. This wrapper erases that JSON boundary: inputs
|
|
9
|
+
// and outputs are typed objects, using the ts-rs generated types from
|
|
10
|
+
// `./types.ts` (synced from `aimux-core/bindings` — single source of truth in
|
|
11
|
+
// the Rust core, local copy packaged with the npm tarball).
|
|
12
|
+
//
|
|
13
|
+
// The raw napi API (`index.js` / `index.d.ts`, auto-generated) is untouched.
|
|
14
|
+
// This is purely an extra TypeScript layer on top.
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.deepseek = exports.anthropic = exports.openai = exports.StreamTextGenerator = exports.Model = void 0;
|
|
17
|
+
exports.generateText = generateText;
|
|
18
|
+
exports.streamText = streamText;
|
|
19
|
+
// Re-export the raw napi constructors/factories so consumers can do everything
|
|
20
|
+
// from a single import: `import { openai, generateText } from 'aimux'`.
|
|
21
|
+
var index_js_1 = require("../index.js");
|
|
22
|
+
Object.defineProperty(exports, "Model", { enumerable: true, get: function () { return index_js_1.Model; } });
|
|
23
|
+
Object.defineProperty(exports, "StreamTextGenerator", { enumerable: true, get: function () { return index_js_1.StreamTextGenerator; } });
|
|
24
|
+
Object.defineProperty(exports, "openai", { enumerable: true, get: function () { return index_js_1.openai; } });
|
|
25
|
+
Object.defineProperty(exports, "anthropic", { enumerable: true, get: function () { return index_js_1.anthropic; } });
|
|
26
|
+
Object.defineProperty(exports, "deepseek", { enumerable: true, get: function () { return index_js_1.deepseek; } });
|
|
27
|
+
/**
|
|
28
|
+
* Generate text (non-streaming). Returns a typed {@link GenerateTextResult}.
|
|
29
|
+
*
|
|
30
|
+
* @param model - A raw model instance from `openai()`, `anthropic()`, etc.
|
|
31
|
+
* @param prompt - A plain string or an array of typed chat messages.
|
|
32
|
+
* @param options - Optional typed generation options (tools, tool_choice,
|
|
33
|
+
* temperature, response_format, …).
|
|
34
|
+
*
|
|
35
|
+
* Internally calls the raw
|
|
36
|
+
* `model.generateText(JSON.stringify(prompt), options ? JSON.stringify(options) : undefined)`
|
|
37
|
+
* and `JSON.parse`s the returned JSON into a typed object.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { openai, generateText } from 'aimux'
|
|
42
|
+
* const model = await openai(apiKey, 'gpt-4o')
|
|
43
|
+
* const result = await generateText(model, 'What is Rust?')
|
|
44
|
+
* console.log(result.text, result.usage)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
async function generateText(model, prompt, options) {
|
|
48
|
+
const optsJson = options ? JSON.stringify(options) : undefined;
|
|
49
|
+
const resultJson = await model.generateText(JSON.stringify(prompt), optsJson);
|
|
50
|
+
return JSON.parse(resultJson);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Stream text from a model. Yields typed {@link StreamPart}s.
|
|
54
|
+
*
|
|
55
|
+
* @param model - A raw model instance from `openai()`, `anthropic()`, etc.
|
|
56
|
+
* @param prompt - A plain string or an array of typed chat messages.
|
|
57
|
+
* @param options - Optional typed generation options (tools, tool_choice, …).
|
|
58
|
+
*
|
|
59
|
+
* Internally drives the raw `model.streamText(JSON.stringify(prompt), …)`
|
|
60
|
+
* async generator and `JSON.parse`s each JSON-string chunk before yielding it
|
|
61
|
+
* as a typed `StreamPart`.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { openai, streamText } from 'aimux'
|
|
66
|
+
* const model = await openai(apiKey, 'gpt-4o')
|
|
67
|
+
* for await (const part of streamText(model, 'Write a haiku about Rust.')) {
|
|
68
|
+
* if ('TextDelta' in part) process.stdout.write(part.TextDelta.delta)
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
async function* streamText(model, prompt, options) {
|
|
73
|
+
const optsJson = options ? JSON.stringify(options) : undefined;
|
|
74
|
+
const gen = await model.streamText(JSON.stringify(prompt), optsJson);
|
|
75
|
+
for await (const json of gen) {
|
|
76
|
+
yield JSON.parse(json);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unified error type for all aimux operations.
|
|
3
|
+
*/
|
|
4
|
+
export type AiMuxError = {
|
|
5
|
+
"Provider": string;
|
|
6
|
+
} | {
|
|
7
|
+
"Http": string;
|
|
8
|
+
} | {
|
|
9
|
+
"Json": string;
|
|
10
|
+
} | {
|
|
11
|
+
"Stream": string;
|
|
12
|
+
} | {
|
|
13
|
+
"Tool": string;
|
|
14
|
+
} | {
|
|
15
|
+
"InvalidArgument": string;
|
|
16
|
+
} | {
|
|
17
|
+
"InvalidPrompt": string;
|
|
18
|
+
} | {
|
|
19
|
+
"RateLimited": {
|
|
20
|
+
retry_after_ms: bigint;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
"Auth": string;
|
|
24
|
+
} | {
|
|
25
|
+
"ModelNotFound": string;
|
|
26
|
+
} | {
|
|
27
|
+
"Unsupported": string;
|
|
28
|
+
} | {
|
|
29
|
+
"NoSuchModel": string;
|
|
30
|
+
} | {
|
|
31
|
+
"ApiCall": string;
|
|
32
|
+
} | {
|
|
33
|
+
"Other": string;
|
|
34
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aspect ratio in `{width}:{height}` format (e.g. `"16:9"`).
|
|
3
|
+
*
|
|
4
|
+
* Newtype that enforces the `W:H` format used by V4 image and video
|
|
5
|
+
* `aspectRatio` options. Aligned with the TS template-literal type
|
|
6
|
+
* `` `${number}:${number}` ``.
|
|
7
|
+
*/
|
|
8
|
+
export type AspectRatio = {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated audio: a base64-encoded string or raw binary bytes.
|
|
3
|
+
*
|
|
4
|
+
* The TS result type is `string | Uint8Array`. Providers should return data
|
|
5
|
+
* without unnecessary conversion.
|
|
6
|
+
*/
|
|
7
|
+
export type AudioData = {
|
|
8
|
+
"Base64": string;
|
|
9
|
+
} | {
|
|
10
|
+
"Binary": Array<number>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { LanguageModelPromptMessage } from "./LanguageModelPromptMessage";
|
|
2
|
+
import type { ReasoningEffort } from "./ReasoningEffort";
|
|
3
|
+
import type { ResponseFormat } from "./ResponseFormat";
|
|
4
|
+
import type { Tool } from "./Tool";
|
|
5
|
+
import type { ToolChoice } from "./ToolChoice";
|
|
6
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
7
|
+
/**
|
|
8
|
+
* Options passed to `LanguageModel::do_generate` / `do_stream`.
|
|
9
|
+
*
|
|
10
|
+
* This is the **provider-facing** options struct. Users interact with
|
|
11
|
+
* `GenerateTextOptions` (user-facing) which is converted to `CallOptions`
|
|
12
|
+
* by the `generate_text` / `stream_text` functions.
|
|
13
|
+
*/
|
|
14
|
+
export type CallOptions = {
|
|
15
|
+
/**
|
|
16
|
+
* The standardized prompt (message array). Required.
|
|
17
|
+
*/
|
|
18
|
+
prompt: Array<LanguageModelPromptMessage>;
|
|
19
|
+
/**
|
|
20
|
+
* Maximum tokens to generate.
|
|
21
|
+
*/
|
|
22
|
+
max_output_tokens: number | null;
|
|
23
|
+
/**
|
|
24
|
+
* Sampling temperature.
|
|
25
|
+
*/
|
|
26
|
+
temperature: number | null;
|
|
27
|
+
/**
|
|
28
|
+
* Stop sequences.
|
|
29
|
+
*/
|
|
30
|
+
stop_sequences: Array<string> | null;
|
|
31
|
+
/**
|
|
32
|
+
* Nucleus sampling `top_p`.
|
|
33
|
+
*/
|
|
34
|
+
top_p: number | null;
|
|
35
|
+
/**
|
|
36
|
+
* Top-k sampling.
|
|
37
|
+
*/
|
|
38
|
+
top_k: number | null;
|
|
39
|
+
/**
|
|
40
|
+
* Presence penalty.
|
|
41
|
+
*/
|
|
42
|
+
presence_penalty: number | null;
|
|
43
|
+
/**
|
|
44
|
+
* Frequency penalty.
|
|
45
|
+
*/
|
|
46
|
+
frequency_penalty: number | null;
|
|
47
|
+
/**
|
|
48
|
+
* Response format (text or JSON).
|
|
49
|
+
*/
|
|
50
|
+
response_format: ResponseFormat | null;
|
|
51
|
+
/**
|
|
52
|
+
* Seed for reproducibility.
|
|
53
|
+
*/
|
|
54
|
+
seed: bigint | null;
|
|
55
|
+
/**
|
|
56
|
+
* Tools available to the model (function tools and/or provider-defined tools).
|
|
57
|
+
*/
|
|
58
|
+
tools: Array<Tool> | null;
|
|
59
|
+
/**
|
|
60
|
+
* How the model should choose tools.
|
|
61
|
+
*/
|
|
62
|
+
tool_choice: ToolChoice;
|
|
63
|
+
/**
|
|
64
|
+
* Extra HTTP headers.
|
|
65
|
+
*/
|
|
66
|
+
headers: {
|
|
67
|
+
[key in string]: string;
|
|
68
|
+
} | null;
|
|
69
|
+
/**
|
|
70
|
+
* Provider-specific options (keyed by provider name).
|
|
71
|
+
*/
|
|
72
|
+
provider_options: {
|
|
73
|
+
[key in string]: JsonValue;
|
|
74
|
+
} | null;
|
|
75
|
+
/**
|
|
76
|
+
* Top-level reasoning effort. Maps to OpenAI `reasoning_effort` and
|
|
77
|
+
* Anthropic `thinking` config.
|
|
78
|
+
*/
|
|
79
|
+
reasoning: ReasoningEffort | null;
|
|
80
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
2
|
+
/**
|
|
3
|
+
* A part of a multi-part message.
|
|
4
|
+
*
|
|
5
|
+
* Shared between `ModelMessage` (user-facing) and `LanguageModelPrompt` (provider-facing).
|
|
6
|
+
*/
|
|
7
|
+
export type ContentPart = {
|
|
8
|
+
"type": "text";
|
|
9
|
+
text: string;
|
|
10
|
+
/**
|
|
11
|
+
* Provider-specific options for this part (e.g. `openai.promptCacheBreakpoint`).
|
|
12
|
+
*/
|
|
13
|
+
provider_options?: JsonValue | null;
|
|
14
|
+
} | {
|
|
15
|
+
"type": "image";
|
|
16
|
+
image: Array<number>;
|
|
17
|
+
media_type: string;
|
|
18
|
+
provider_options?: JsonValue | null;
|
|
19
|
+
} | {
|
|
20
|
+
"type": "file";
|
|
21
|
+
data: Array<number>;
|
|
22
|
+
media_type: string;
|
|
23
|
+
filename?: string | null;
|
|
24
|
+
provider_options?: JsonValue | null;
|
|
25
|
+
} | {
|
|
26
|
+
"type": "file_base64";
|
|
27
|
+
data: string;
|
|
28
|
+
media_type: string;
|
|
29
|
+
filename?: string | null;
|
|
30
|
+
provider_options?: JsonValue | null;
|
|
31
|
+
} | {
|
|
32
|
+
"type": "file_url";
|
|
33
|
+
url: string;
|
|
34
|
+
media_type: string;
|
|
35
|
+
provider_options?: JsonValue | null;
|
|
36
|
+
} | {
|
|
37
|
+
"type": "file_reference";
|
|
38
|
+
media_type: string;
|
|
39
|
+
reference: JsonValue;
|
|
40
|
+
filename?: string | null;
|
|
41
|
+
provider_options?: JsonValue | null;
|
|
42
|
+
} | {
|
|
43
|
+
"type": "reasoning";
|
|
44
|
+
text: string;
|
|
45
|
+
signature: string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Provider-specific options for this part (e.g.
|
|
48
|
+
* `anthropic.signature`, `anthropic.redactedData`,
|
|
49
|
+
* `anthropic.cacheControl`).
|
|
50
|
+
*/
|
|
51
|
+
provider_options?: JsonValue | null;
|
|
52
|
+
} | {
|
|
53
|
+
"type": "tool_call";
|
|
54
|
+
tool_call_id: string;
|
|
55
|
+
tool_name: string;
|
|
56
|
+
/**
|
|
57
|
+
* Arguments as a JSON value (usually an object).
|
|
58
|
+
*/
|
|
59
|
+
input: JsonValue;
|
|
60
|
+
/**
|
|
61
|
+
* Provider-specific options for this part (e.g.
|
|
62
|
+
* `anthropic.cacheControl`).
|
|
63
|
+
*/
|
|
64
|
+
provider_options?: JsonValue | null;
|
|
65
|
+
} | {
|
|
66
|
+
"type": "tool_result";
|
|
67
|
+
tool_call_id: string;
|
|
68
|
+
/**
|
|
69
|
+
* The tool's output (usually a JSON value or plain text).
|
|
70
|
+
*/
|
|
71
|
+
output: JsonValue;
|
|
72
|
+
/**
|
|
73
|
+
* Provider-specific options for this part (e.g.
|
|
74
|
+
* `anthropic.cacheControl`).
|
|
75
|
+
*/
|
|
76
|
+
provider_options?: JsonValue | null;
|
|
77
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
2
|
+
/**
|
|
3
|
+
* Options passed to [`EmbeddingModel::do_embed`].
|
|
4
|
+
*
|
|
5
|
+
* Aligned with V4 `EmbeddingModelV4CallOptions`.
|
|
6
|
+
*/
|
|
7
|
+
export type EmbeddingCallOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* List of text values to generate embeddings for.
|
|
10
|
+
*/
|
|
11
|
+
values: Array<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Additional provider-specific options, keyed by provider name.
|
|
14
|
+
*/
|
|
15
|
+
provider_options: {
|
|
16
|
+
[key in string]: JsonValue;
|
|
17
|
+
} | null;
|
|
18
|
+
/**
|
|
19
|
+
* Additional HTTP headers to send with the request.
|
|
20
|
+
*/
|
|
21
|
+
headers: {
|
|
22
|
+
[key in string]: string;
|
|
23
|
+
} | null;
|
|
24
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
2
|
+
/**
|
|
3
|
+
* Debugging response info specific to embedding calls.
|
|
4
|
+
*/
|
|
5
|
+
export type EmbeddingResponse = {
|
|
6
|
+
/**
|
|
7
|
+
* Response headers.
|
|
8
|
+
*/
|
|
9
|
+
headers: {
|
|
10
|
+
[key in string]: string;
|
|
11
|
+
} | null;
|
|
12
|
+
/**
|
|
13
|
+
* The response body (opaque JSON).
|
|
14
|
+
*/
|
|
15
|
+
body: JsonValue | null;
|
|
16
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { EmbeddingResponse } from "./EmbeddingResponse";
|
|
2
|
+
import type { EmbeddingUsage } from "./EmbeddingUsage";
|
|
3
|
+
import type { Warning } from "./Warning";
|
|
4
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
5
|
+
/**
|
|
6
|
+
* The result of [`EmbeddingModel::do_embed`].
|
|
7
|
+
*
|
|
8
|
+
* Aligned with V4 `EmbeddingModelV4Result`.
|
|
9
|
+
*/
|
|
10
|
+
export type EmbeddingResult = {
|
|
11
|
+
/**
|
|
12
|
+
* Generated embeddings, in the same order as the input `values`.
|
|
13
|
+
*/
|
|
14
|
+
embeddings: Array<Array<number>>;
|
|
15
|
+
/**
|
|
16
|
+
* Token usage (input tokens only).
|
|
17
|
+
*/
|
|
18
|
+
usage: EmbeddingUsage | null;
|
|
19
|
+
/**
|
|
20
|
+
* Additional provider-specific metadata.
|
|
21
|
+
*/
|
|
22
|
+
provider_metadata: {
|
|
23
|
+
[key in string]: JsonValue;
|
|
24
|
+
} | null;
|
|
25
|
+
/**
|
|
26
|
+
* Optional response information for debugging.
|
|
27
|
+
*/
|
|
28
|
+
response: EmbeddingResponse | null;
|
|
29
|
+
/**
|
|
30
|
+
* Warnings for the call, e.g. unsupported settings.
|
|
31
|
+
*/
|
|
32
|
+
warnings: Array<Warning>;
|
|
33
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Either raw bytes or a base64-encoded string.
|
|
3
|
+
*
|
|
4
|
+
* Providers should pass file data through without unnecessary conversion: if
|
|
5
|
+
* the upstream API returns base64, return [`FileBytes::Base64`]; if it
|
|
6
|
+
* returns binary, return [`FileBytes::Binary`].
|
|
7
|
+
*/
|
|
8
|
+
export type FileBytes = {
|
|
9
|
+
"Binary": Array<number>;
|
|
10
|
+
} | {
|
|
11
|
+
"Base64": string;
|
|
12
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FileBytes } from "./FileBytes";
|
|
2
|
+
/**
|
|
3
|
+
* File data as a tagged discriminated union.
|
|
4
|
+
*
|
|
5
|
+
* Aligned with V4 `SharedV4FileData`.
|
|
6
|
+
*/
|
|
7
|
+
export type FileData = {
|
|
8
|
+
"Data": {
|
|
9
|
+
data: FileBytes;
|
|
10
|
+
};
|
|
11
|
+
} | {
|
|
12
|
+
"Url": {
|
|
13
|
+
url: string;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
"Reference": {
|
|
17
|
+
reference: {
|
|
18
|
+
[key in string]: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
} | {
|
|
22
|
+
"Text": {
|
|
23
|
+
text: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { FinishReasonUnified } from "./FinishReasonUnified";
|
|
2
|
+
/**
|
|
3
|
+
* Unified finish reason (why the model stopped generating).
|
|
4
|
+
*/
|
|
5
|
+
export type FinishReason = {
|
|
6
|
+
/**
|
|
7
|
+
* The unified reason.
|
|
8
|
+
*/
|
|
9
|
+
unified: FinishReasonUnified;
|
|
10
|
+
/**
|
|
11
|
+
* The raw provider-specific reason string.
|
|
12
|
+
*/
|
|
13
|
+
raw: string | null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
2
|
+
/**
|
|
3
|
+
* A tool definition passed to the model in `CallOptions.tools`.
|
|
4
|
+
*/
|
|
5
|
+
export type FunctionTool = {
|
|
6
|
+
/**
|
|
7
|
+
* Unique tool name.
|
|
8
|
+
*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**
|
|
11
|
+
* Human-readable description.
|
|
12
|
+
*/
|
|
13
|
+
description: string | null;
|
|
14
|
+
/**
|
|
15
|
+
* JSON Schema describing the tool's parameters.
|
|
16
|
+
*/
|
|
17
|
+
input_schema: JsonValue;
|
|
18
|
+
/**
|
|
19
|
+
* Whether the tool supports strict schema enforcement (OpenAI strict mode).
|
|
20
|
+
*/
|
|
21
|
+
strict: boolean | null;
|
|
22
|
+
/**
|
|
23
|
+
* Provider-specific options, keyed by provider name
|
|
24
|
+
* (e.g. `{"anthropic": {"eagerInputStreaming": true}}`). Aligned with the
|
|
25
|
+
* V4 `providerOptions` field on function tools.
|
|
26
|
+
*/
|
|
27
|
+
provider_options?: {
|
|
28
|
+
[key in string]: JsonValue;
|
|
29
|
+
} | null;
|
|
30
|
+
/**
|
|
31
|
+
* Example inputs for the tool (V4 `inputExamples`), used by some providers
|
|
32
|
+
* to emit `input_examples` in the request body.
|
|
33
|
+
*/
|
|
34
|
+
input_examples?: Array<JsonValue> | null;
|
|
35
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { JsonValue } from "./serde_json/JsonValue";
|
|
2
|
+
/**
|
|
3
|
+
* A content item in the generation result.
|
|
4
|
+
*/
|
|
5
|
+
export type GenerateContent = {
|
|
6
|
+
"Text": {
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
} | {
|
|
10
|
+
"ToolCall": {
|
|
11
|
+
tool_call_id: string;
|
|
12
|
+
tool_name: string;
|
|
13
|
+
input: JsonValue;
|
|
14
|
+
};
|
|
15
|
+
} | {
|
|
16
|
+
"Source": {
|
|
17
|
+
id: string;
|
|
18
|
+
source_type: string;
|
|
19
|
+
url: string | null;
|
|
20
|
+
title: string | null;
|
|
21
|
+
};
|
|
22
|
+
} | {
|
|
23
|
+
"Reasoning": {
|
|
24
|
+
text: string;
|
|
25
|
+
provider_metadata: JsonValue | null;
|
|
26
|
+
};
|
|
27
|
+
} | {
|
|
28
|
+
"ToolResult": {
|
|
29
|
+
tool_call_id: string;
|
|
30
|
+
tool_name: string;
|
|
31
|
+
result: JsonValue;
|
|
32
|
+
};
|
|
33
|
+
};
|