@opencode/ai 0.0.0-dev-20453 → 0.0.0-dev-20456
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 +1 -1
- package/dist/protocols/cohere-chat.d.ts +178 -0
- package/dist/protocols/cohere-chat.js +292 -0
- package/dist/protocols/gemini.d.ts +2 -2
- package/dist/protocols/index.d.ts +1 -0
- package/dist/protocols/index.js +1 -0
- package/dist/protocols/mistral-chat.d.ts +3 -3
- package/dist/provider-error.js +7 -1
- package/dist/providers/cohere/chat.d.ts +4 -0
- package/dist/providers/cohere/chat.js +8 -0
- package/dist/providers/cohere.d.ts +395 -0
- package/dist/providers/cohere.js +48 -0
- package/dist/providers/google-vertex.d.ts +1 -1
- package/dist/providers/google.d.ts +1 -1
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/mistral.d.ts +2 -2
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1223,7 +1223,7 @@ const gateway = CloudflareAIGateway.configure({
|
|
|
1223
1223
|
}).model("workers-ai/@cf/meta/llama-3.1-8b-instruct")
|
|
1224
1224
|
```
|
|
1225
1225
|
|
|
1226
|
-
Included LLM providers: OpenAI, Anthropic, Google (Gemini), Google Vertex, Amazon Bedrock, Azure OpenAI, Baseten, Cerebras, Cloudflare AI Gateway, Cloudflare Workers AI, DeepInfra, DeepSeek, Fireworks, Groq, Mistral, OpenRouter, TogetherAI, and xAI. Z.ai currently exposes image generation. Generic Chat Completions, Responses, and Anthropic Messages-compatible entrypoints support custom endpoints.
|
|
1226
|
+
Included LLM providers: OpenAI, Anthropic, Google (Gemini), Google Vertex, Amazon Bedrock, Azure OpenAI, Baseten, Cerebras, Cohere, Cloudflare AI Gateway, Cloudflare Workers AI, DeepInfra, DeepSeek, Fireworks, Groq, Mistral, OpenRouter, TogetherAI, and xAI. Z.ai currently exposes image generation. Generic Chat Completions, Responses, and Anthropic Messages-compatible entrypoints support custom endpoints.
|
|
1227
1227
|
|
|
1228
1228
|
Each named provider owns its module, endpoint, authentication, and route setup. Providers with the same wire format compose the shared protocol directly:
|
|
1229
1229
|
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import { Protocol } from "../route/protocol.js";
|
|
4
|
+
import { Lifecycle } from "./utils/lifecycle.js";
|
|
5
|
+
import { ToolStream } from "./utils/tool-stream.js";
|
|
6
|
+
export declare const DEFAULT_BASE_URL = "https://api.cohere.com/v2";
|
|
7
|
+
declare const Options: Schema.Struct<{
|
|
8
|
+
readonly thinking: Schema.optional<Schema.Struct<{
|
|
9
|
+
readonly type: Schema.optional<Schema.Literals<readonly ["enabled", "disabled"]>>;
|
|
10
|
+
readonly tokenBudget: Schema.optional<Schema.Int>;
|
|
11
|
+
}>>;
|
|
12
|
+
}>;
|
|
13
|
+
export type ProviderOptionsInput = Schema.Schema.Type<typeof Options>;
|
|
14
|
+
export declare const protocol: Protocol<{
|
|
15
|
+
readonly model: string;
|
|
16
|
+
readonly messages: readonly {
|
|
17
|
+
readonly role: "tool" | "system" | "user" | "assistant";
|
|
18
|
+
readonly content?: string | readonly ({
|
|
19
|
+
readonly type: "text";
|
|
20
|
+
readonly text: string;
|
|
21
|
+
} | {
|
|
22
|
+
readonly type: "thinking";
|
|
23
|
+
readonly thinking: string;
|
|
24
|
+
} | {
|
|
25
|
+
readonly type: "image_url";
|
|
26
|
+
readonly image_url: {
|
|
27
|
+
readonly url: string;
|
|
28
|
+
};
|
|
29
|
+
})[] | undefined;
|
|
30
|
+
readonly tool_calls?: readonly {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly type: "function";
|
|
33
|
+
readonly function: {
|
|
34
|
+
readonly name: string;
|
|
35
|
+
readonly arguments: string;
|
|
36
|
+
};
|
|
37
|
+
}[] | undefined;
|
|
38
|
+
readonly tool_call_id?: string | undefined;
|
|
39
|
+
readonly tool_plan?: string | undefined;
|
|
40
|
+
}[];
|
|
41
|
+
readonly stream: true;
|
|
42
|
+
readonly max_tokens?: number | undefined;
|
|
43
|
+
readonly tools?: readonly {
|
|
44
|
+
readonly type: "function";
|
|
45
|
+
readonly function: {
|
|
46
|
+
readonly name: string;
|
|
47
|
+
readonly parameters: unknown;
|
|
48
|
+
readonly description?: string | undefined;
|
|
49
|
+
};
|
|
50
|
+
}[] | undefined;
|
|
51
|
+
readonly temperature?: number | undefined;
|
|
52
|
+
readonly seed?: number | undefined;
|
|
53
|
+
readonly thinking?: {
|
|
54
|
+
readonly type: string;
|
|
55
|
+
readonly token_budget?: number | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
58
|
+
readonly stop_sequences?: readonly string[] | undefined;
|
|
59
|
+
readonly p?: number | undefined;
|
|
60
|
+
readonly k?: number | undefined;
|
|
61
|
+
readonly frequency_penalty?: number | undefined;
|
|
62
|
+
readonly presence_penalty?: number | undefined;
|
|
63
|
+
}, string, {
|
|
64
|
+
readonly type: "message-start";
|
|
65
|
+
} | {
|
|
66
|
+
readonly type: "content-start" | "content-delta";
|
|
67
|
+
readonly index: number;
|
|
68
|
+
readonly delta: {
|
|
69
|
+
readonly message: {
|
|
70
|
+
readonly content: {
|
|
71
|
+
readonly text?: string | undefined;
|
|
72
|
+
readonly thinking?: string | undefined;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
} | {
|
|
77
|
+
readonly type: "content-end";
|
|
78
|
+
readonly index: number;
|
|
79
|
+
} | {
|
|
80
|
+
readonly type: "tool-plan-delta";
|
|
81
|
+
readonly delta: {
|
|
82
|
+
readonly message: {
|
|
83
|
+
readonly tool_plan: string;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
} | {
|
|
87
|
+
readonly type: "tool-call-start" | "tool-call-delta";
|
|
88
|
+
readonly index: number;
|
|
89
|
+
readonly delta: {
|
|
90
|
+
readonly message: {
|
|
91
|
+
readonly tool_calls: {
|
|
92
|
+
readonly function: {
|
|
93
|
+
readonly name?: string | undefined;
|
|
94
|
+
readonly arguments?: string | undefined;
|
|
95
|
+
};
|
|
96
|
+
readonly id?: string | undefined;
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
};
|
|
100
|
+
} | {
|
|
101
|
+
readonly type: "tool-call-end";
|
|
102
|
+
readonly index: number;
|
|
103
|
+
} | {
|
|
104
|
+
readonly type: "message-end";
|
|
105
|
+
readonly delta: {
|
|
106
|
+
readonly finish_reason: string;
|
|
107
|
+
readonly usage?: {
|
|
108
|
+
readonly tokens?: {
|
|
109
|
+
readonly input_tokens?: number | undefined;
|
|
110
|
+
readonly output_tokens?: number | undefined;
|
|
111
|
+
readonly reasoning_tokens?: number | undefined;
|
|
112
|
+
} | undefined;
|
|
113
|
+
readonly billed_units?: {
|
|
114
|
+
readonly input_tokens?: number | undefined;
|
|
115
|
+
readonly output_tokens?: number | undefined;
|
|
116
|
+
readonly reasoning_tokens?: number | undefined;
|
|
117
|
+
} | undefined;
|
|
118
|
+
readonly cached_tokens?: number | undefined;
|
|
119
|
+
} | undefined;
|
|
120
|
+
};
|
|
121
|
+
} | {
|
|
122
|
+
readonly type: "citation-start" | "citation-end";
|
|
123
|
+
}, {
|
|
124
|
+
readonly tools: Partial<Record<number, ToolStream.PendingTool>>;
|
|
125
|
+
readonly lifecycle: Lifecycle.State;
|
|
126
|
+
readonly finished: boolean;
|
|
127
|
+
}>;
|
|
128
|
+
export declare const route: Route<{
|
|
129
|
+
readonly model: string;
|
|
130
|
+
readonly messages: readonly {
|
|
131
|
+
readonly role: "tool" | "system" | "user" | "assistant";
|
|
132
|
+
readonly content?: string | readonly ({
|
|
133
|
+
readonly type: "text";
|
|
134
|
+
readonly text: string;
|
|
135
|
+
} | {
|
|
136
|
+
readonly type: "thinking";
|
|
137
|
+
readonly thinking: string;
|
|
138
|
+
} | {
|
|
139
|
+
readonly type: "image_url";
|
|
140
|
+
readonly image_url: {
|
|
141
|
+
readonly url: string;
|
|
142
|
+
};
|
|
143
|
+
})[] | undefined;
|
|
144
|
+
readonly tool_calls?: readonly {
|
|
145
|
+
readonly id: string;
|
|
146
|
+
readonly type: "function";
|
|
147
|
+
readonly function: {
|
|
148
|
+
readonly name: string;
|
|
149
|
+
readonly arguments: string;
|
|
150
|
+
};
|
|
151
|
+
}[] | undefined;
|
|
152
|
+
readonly tool_call_id?: string | undefined;
|
|
153
|
+
readonly tool_plan?: string | undefined;
|
|
154
|
+
}[];
|
|
155
|
+
readonly stream: true;
|
|
156
|
+
readonly max_tokens?: number | undefined;
|
|
157
|
+
readonly tools?: readonly {
|
|
158
|
+
readonly type: "function";
|
|
159
|
+
readonly function: {
|
|
160
|
+
readonly name: string;
|
|
161
|
+
readonly parameters: unknown;
|
|
162
|
+
readonly description?: string | undefined;
|
|
163
|
+
};
|
|
164
|
+
}[] | undefined;
|
|
165
|
+
readonly temperature?: number | undefined;
|
|
166
|
+
readonly seed?: number | undefined;
|
|
167
|
+
readonly thinking?: {
|
|
168
|
+
readonly type: string;
|
|
169
|
+
readonly token_budget?: number | undefined;
|
|
170
|
+
} | undefined;
|
|
171
|
+
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
172
|
+
readonly stop_sequences?: readonly string[] | undefined;
|
|
173
|
+
readonly p?: number | undefined;
|
|
174
|
+
readonly k?: number | undefined;
|
|
175
|
+
readonly frequency_penalty?: number | undefined;
|
|
176
|
+
readonly presence_penalty?: number | undefined;
|
|
177
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
178
|
+
export * as CohereChat from "./cohere-chat.js";
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { Effect, Schema } from "effect";
|
|
2
|
+
import { Route } from "../route/client.js";
|
|
3
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
4
|
+
import { Framing } from "../route/framing.js";
|
|
5
|
+
import { Protocol } from "../route/protocol.js";
|
|
6
|
+
import { LLMEvent, Usage } from "../schema/index.js";
|
|
7
|
+
import { ProviderShared } from "./shared.js";
|
|
8
|
+
import { Lifecycle } from "./utils/lifecycle.js";
|
|
9
|
+
import { ToolStream } from "./utils/tool-stream.js";
|
|
10
|
+
const ADAPTER = "cohere-chat";
|
|
11
|
+
export const DEFAULT_BASE_URL = "https://api.cohere.com/v2";
|
|
12
|
+
const Options = Schema.Struct({
|
|
13
|
+
thinking: Schema.optional(Schema.Struct({
|
|
14
|
+
type: Schema.optional(Schema.Literals(["enabled", "disabled"])),
|
|
15
|
+
tokenBudget: Schema.optional(Schema.Int.check(Schema.isGreaterThan(0))),
|
|
16
|
+
})),
|
|
17
|
+
});
|
|
18
|
+
const Content = Schema.Union([
|
|
19
|
+
Schema.Struct({ type: Schema.Literal("text"), text: Schema.String }),
|
|
20
|
+
Schema.Struct({ type: Schema.Literal("thinking"), thinking: Schema.String }),
|
|
21
|
+
Schema.Struct({ type: Schema.Literal("image_url"), image_url: Schema.Struct({ url: Schema.String }) }),
|
|
22
|
+
]);
|
|
23
|
+
const ToolCall = Schema.Struct({
|
|
24
|
+
id: Schema.String,
|
|
25
|
+
type: Schema.Literal("function"),
|
|
26
|
+
function: Schema.Struct({ name: Schema.String, arguments: Schema.String }),
|
|
27
|
+
});
|
|
28
|
+
const Message = Schema.Struct({
|
|
29
|
+
role: Schema.Literals(["system", "user", "assistant", "tool"]),
|
|
30
|
+
content: Schema.optional(Schema.Union([Schema.String, Schema.Array(Content)])),
|
|
31
|
+
tool_calls: Schema.optional(Schema.Array(ToolCall)),
|
|
32
|
+
tool_call_id: Schema.optional(Schema.String),
|
|
33
|
+
tool_plan: Schema.optional(Schema.String),
|
|
34
|
+
});
|
|
35
|
+
const Body = Schema.Struct({
|
|
36
|
+
model: Schema.String,
|
|
37
|
+
messages: Schema.Array(Message),
|
|
38
|
+
stream: Schema.Literal(true),
|
|
39
|
+
tools: Schema.optional(Schema.Array(Schema.Struct({
|
|
40
|
+
type: Schema.Literal("function"),
|
|
41
|
+
function: Schema.Struct({
|
|
42
|
+
name: Schema.String,
|
|
43
|
+
description: Schema.optional(Schema.String),
|
|
44
|
+
parameters: Schema.Unknown,
|
|
45
|
+
}),
|
|
46
|
+
}))),
|
|
47
|
+
tool_choice: Schema.optional(Schema.Literals(["NONE", "REQUIRED"])),
|
|
48
|
+
thinking: Schema.optional(Schema.Struct({ type: Schema.String, token_budget: Schema.optional(Schema.Number) })),
|
|
49
|
+
max_tokens: Schema.optional(Schema.Number),
|
|
50
|
+
temperature: Schema.optional(Schema.Number),
|
|
51
|
+
p: Schema.optional(Schema.Number),
|
|
52
|
+
k: Schema.optional(Schema.Number),
|
|
53
|
+
seed: Schema.optional(Schema.Number),
|
|
54
|
+
stop_sequences: Schema.optional(Schema.Array(Schema.String)),
|
|
55
|
+
frequency_penalty: Schema.optional(Schema.Number),
|
|
56
|
+
presence_penalty: Schema.optional(Schema.Number),
|
|
57
|
+
});
|
|
58
|
+
const TokenCounts = Schema.Struct({
|
|
59
|
+
input_tokens: Schema.optional(Schema.Number),
|
|
60
|
+
output_tokens: Schema.optional(Schema.Number),
|
|
61
|
+
reasoning_tokens: Schema.optional(Schema.Number),
|
|
62
|
+
});
|
|
63
|
+
const NativeUsage = Schema.Struct({
|
|
64
|
+
tokens: Schema.optional(TokenCounts),
|
|
65
|
+
billed_units: Schema.optional(TokenCounts),
|
|
66
|
+
cached_tokens: Schema.optional(Schema.Number),
|
|
67
|
+
});
|
|
68
|
+
const Event = Schema.Union([
|
|
69
|
+
Schema.Struct({ type: Schema.Literal("message-start") }),
|
|
70
|
+
Schema.Struct({
|
|
71
|
+
type: Schema.Literals(["content-start", "content-delta"]),
|
|
72
|
+
index: Schema.Number,
|
|
73
|
+
delta: Schema.Struct({
|
|
74
|
+
message: Schema.Struct({
|
|
75
|
+
content: Schema.Struct({ text: Schema.optional(Schema.String), thinking: Schema.optional(Schema.String) }),
|
|
76
|
+
}),
|
|
77
|
+
}),
|
|
78
|
+
}),
|
|
79
|
+
Schema.Struct({ type: Schema.Literal("content-end"), index: Schema.Number }),
|
|
80
|
+
Schema.Struct({
|
|
81
|
+
type: Schema.Literal("tool-plan-delta"),
|
|
82
|
+
delta: Schema.Struct({ message: Schema.Struct({ tool_plan: Schema.String }) }),
|
|
83
|
+
}),
|
|
84
|
+
Schema.Struct({
|
|
85
|
+
type: Schema.Literals(["tool-call-start", "tool-call-delta"]),
|
|
86
|
+
index: Schema.Number,
|
|
87
|
+
delta: Schema.Struct({
|
|
88
|
+
message: Schema.Struct({
|
|
89
|
+
tool_calls: Schema.Struct({
|
|
90
|
+
id: Schema.optional(Schema.String),
|
|
91
|
+
function: Schema.Struct({ name: Schema.optional(Schema.String), arguments: Schema.optional(Schema.String) }),
|
|
92
|
+
}),
|
|
93
|
+
}),
|
|
94
|
+
}),
|
|
95
|
+
}),
|
|
96
|
+
Schema.Struct({ type: Schema.Literal("tool-call-end"), index: Schema.Number }),
|
|
97
|
+
Schema.Struct({
|
|
98
|
+
type: Schema.Literal("message-end"),
|
|
99
|
+
delta: Schema.Struct({ finish_reason: Schema.String, usage: Schema.optional(NativeUsage) }),
|
|
100
|
+
}),
|
|
101
|
+
// Citation output is outside this basic chat surface.
|
|
102
|
+
Schema.Struct({ type: Schema.Literals(["citation-start", "citation-end"]) }),
|
|
103
|
+
]);
|
|
104
|
+
const TOOL_CHOICE = { auto: undefined, none: "NONE", required: "REQUIRED", tool: "REQUIRED" };
|
|
105
|
+
const fromRequest = Effect.fn("CohereChat.fromRequest")(function* (request) {
|
|
106
|
+
const options = yield* ProviderShared.validateWith(Schema.decodeUnknownEffect(Options))(request.providerOptions ?? {});
|
|
107
|
+
const flattened = ProviderShared.flattenToolRequest(request);
|
|
108
|
+
const messages = request.system.length
|
|
109
|
+
? [{ role: "system", content: ProviderShared.joinText(request.system) }]
|
|
110
|
+
: [];
|
|
111
|
+
for (const message of flattened.request.messages) {
|
|
112
|
+
if (message.role === "system") {
|
|
113
|
+
messages.push({ role: "user", content: (yield* ProviderShared.wrappedSystemUpdate("Cohere Chat", message)).text });
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (message.role === "tool") {
|
|
117
|
+
for (const part of message.content) {
|
|
118
|
+
if (part.type !== "tool-result")
|
|
119
|
+
return yield* ProviderShared.unsupportedContent("Cohere Chat", "tool", ["tool-result"]);
|
|
120
|
+
if (part.result.type === "content" && part.result.value.some((item) => item.type === "file"))
|
|
121
|
+
return yield* ProviderShared.invalidRequest("Cohere Chat does not support file content in tool results");
|
|
122
|
+
messages.push({ role: "tool", tool_call_id: part.id, content: ProviderShared.toolResultText(part) });
|
|
123
|
+
}
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
const content = [];
|
|
127
|
+
const calls = [];
|
|
128
|
+
const plans = [];
|
|
129
|
+
for (const part of message.content) {
|
|
130
|
+
if (part.type === "text") {
|
|
131
|
+
content.push({ type: "text", text: part.text });
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (message.role === "assistant" && part.type === "reasoning") {
|
|
135
|
+
if (part.providerMetadata?.cohere?.toolPlan === true)
|
|
136
|
+
plans.push(part.text);
|
|
137
|
+
else
|
|
138
|
+
content.push({ type: "thinking", thinking: part.text });
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (message.role === "assistant" && part.type === "tool-call") {
|
|
142
|
+
const args = ProviderShared.encodeJson(part.input);
|
|
143
|
+
calls.push({ id: part.id, type: "function", function: { name: part.name, arguments: args } });
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (message.role === "user" && part.type === "media" && part.media.mediaType.startsWith("image/")) {
|
|
147
|
+
const url = ProviderShared.mediaUrl(part.media) ??
|
|
148
|
+
(yield* ProviderShared.requireInlineMedia("Cohere Chat", part.media)).dataUrl;
|
|
149
|
+
content.push({ type: "image_url", image_url: { url } });
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
return yield* ProviderShared.unsupportedContent("Cohere Chat", message.role, message.role === "user" ? ["text", "media"] : ["text", "reasoning", "tool-call"]);
|
|
153
|
+
}
|
|
154
|
+
messages.push({
|
|
155
|
+
role: message.role,
|
|
156
|
+
content: content.length ? content : undefined,
|
|
157
|
+
tool_calls: calls.length ? calls : undefined,
|
|
158
|
+
tool_plan: plans.length ? plans.join("") : undefined,
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
const selected = request.toolChoice?.type === "tool" ? request.toolChoice.name : undefined;
|
|
162
|
+
const tools = selected === undefined ? flattened.tools : flattened.tools.filter((tool) => tool.name === selected);
|
|
163
|
+
if (selected !== undefined && tools.length === 0)
|
|
164
|
+
return yield* ProviderShared.invalidRequest("Cohere Chat tool choice must name an available tool");
|
|
165
|
+
if (tools.some((tool) => tool.native !== undefined))
|
|
166
|
+
return yield* ProviderShared.invalidRequest("Cohere Chat does not support provider-defined tools");
|
|
167
|
+
return {
|
|
168
|
+
model: request.model.id,
|
|
169
|
+
messages,
|
|
170
|
+
stream: true,
|
|
171
|
+
tools: tools.length
|
|
172
|
+
? tools.map((tool) => ({
|
|
173
|
+
type: "function",
|
|
174
|
+
function: { name: tool.name, description: tool.description, parameters: tool.inputSchema },
|
|
175
|
+
}))
|
|
176
|
+
: undefined,
|
|
177
|
+
tool_choice: TOOL_CHOICE[request.toolChoice?.type ?? "auto"],
|
|
178
|
+
thinking: options.thinking && {
|
|
179
|
+
type: options.thinking.type ?? "enabled",
|
|
180
|
+
// Cohere rejects budgets above max_tokens; fitting also leaves room for the answer.
|
|
181
|
+
token_budget: options.thinking.tokenBudget === undefined
|
|
182
|
+
? undefined
|
|
183
|
+
: ProviderShared.fitThinkingBudget(options.thinking.tokenBudget, request.generation?.maxTokens),
|
|
184
|
+
},
|
|
185
|
+
max_tokens: request.generation?.maxTokens,
|
|
186
|
+
temperature: request.generation?.temperature,
|
|
187
|
+
p: request.generation?.topP,
|
|
188
|
+
k: request.generation?.topK,
|
|
189
|
+
seed: request.generation?.seed,
|
|
190
|
+
stop_sequences: request.generation?.stop,
|
|
191
|
+
frequency_penalty: request.generation?.frequencyPenalty,
|
|
192
|
+
presence_penalty: request.generation?.presencePenalty,
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
const finishReason = (raw) => {
|
|
196
|
+
switch (raw) {
|
|
197
|
+
case "COMPLETE":
|
|
198
|
+
case "STOP_SEQUENCE":
|
|
199
|
+
return { normalized: "stop", raw };
|
|
200
|
+
case "MAX_TOKENS":
|
|
201
|
+
return { normalized: "length", raw };
|
|
202
|
+
case "TOOL_CALL":
|
|
203
|
+
return { normalized: "tool-calls", raw };
|
|
204
|
+
case "ERROR":
|
|
205
|
+
case "TIMEOUT":
|
|
206
|
+
return { normalized: "error", raw };
|
|
207
|
+
default:
|
|
208
|
+
return { normalized: "unknown", raw };
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const mapUsage = (usage) => new Usage({
|
|
212
|
+
inputTokens: usage.tokens?.input_tokens,
|
|
213
|
+
outputTokens: usage.tokens?.output_tokens,
|
|
214
|
+
nonCachedInputTokens: ProviderShared.subtractTokens(usage.tokens?.input_tokens, usage.cached_tokens),
|
|
215
|
+
cacheReadInputTokens: usage.cached_tokens,
|
|
216
|
+
reasoningTokens: usage.tokens?.reasoning_tokens,
|
|
217
|
+
totalTokens: ProviderShared.totalTokens(usage.tokens?.input_tokens, usage.tokens?.output_tokens, undefined),
|
|
218
|
+
providerMetadata: { cohere: usage },
|
|
219
|
+
});
|
|
220
|
+
// Lifecycle deltas open blocks on demand and ends are no-ops for closed blocks, so content-start needs no handling.
|
|
221
|
+
const step = Effect.fn("CohereChat.step")(function* (state, event) {
|
|
222
|
+
const events = [];
|
|
223
|
+
switch (event.type) {
|
|
224
|
+
case "message-start":
|
|
225
|
+
return [{ ...state, lifecycle: Lifecycle.stepStart(state.lifecycle, events) }, events];
|
|
226
|
+
case "content-delta": {
|
|
227
|
+
const id = String(event.index);
|
|
228
|
+
const content = event.delta.message.content;
|
|
229
|
+
const lifecycle = content.thinking !== undefined
|
|
230
|
+
? Lifecycle.reasoningDelta(state.lifecycle, events, id, content.thinking)
|
|
231
|
+
: Lifecycle.textDelta(state.lifecycle, events, id, content.text ?? "");
|
|
232
|
+
return [{ ...state, lifecycle }, events];
|
|
233
|
+
}
|
|
234
|
+
case "content-end": {
|
|
235
|
+
const id = String(event.index);
|
|
236
|
+
const lifecycle = Lifecycle.textEnd(Lifecycle.reasoningEnd(state.lifecycle, events, id), events, id);
|
|
237
|
+
return [{ ...state, lifecycle }, events];
|
|
238
|
+
}
|
|
239
|
+
case "tool-plan-delta": {
|
|
240
|
+
const plan = event.delta.message.tool_plan;
|
|
241
|
+
const lifecycle = Lifecycle.reasoningDelta(state.lifecycle, events, "tool-plan", plan, {
|
|
242
|
+
cohere: { toolPlan: true },
|
|
243
|
+
});
|
|
244
|
+
return [{ ...state, lifecycle }, events];
|
|
245
|
+
}
|
|
246
|
+
case "tool-call-start":
|
|
247
|
+
case "tool-call-delta": {
|
|
248
|
+
const call = event.delta.message.tool_calls;
|
|
249
|
+
const result = ToolStream.appendOrStart(ADAPTER, state.tools, event.index, { id: call.id, name: call.function.name, text: call.function.arguments ?? "" }, "Cohere tool call is missing id or name");
|
|
250
|
+
if (ToolStream.isError(result))
|
|
251
|
+
return yield* result;
|
|
252
|
+
return [{ ...state, tools: result.tools }, result.events];
|
|
253
|
+
}
|
|
254
|
+
case "tool-call-end": {
|
|
255
|
+
const result = yield* ToolStream.finish(ADAPTER, state.tools, event.index);
|
|
256
|
+
return [{ ...state, tools: result.tools }, result.events ?? []];
|
|
257
|
+
}
|
|
258
|
+
case "message-end": {
|
|
259
|
+
const pending = yield* ToolStream.finishAll(ADAPTER, state.tools);
|
|
260
|
+
events.push(...pending.events);
|
|
261
|
+
const lifecycle = Lifecycle.finish(state.lifecycle, events, {
|
|
262
|
+
reason: finishReason(event.delta.finish_reason),
|
|
263
|
+
usage: event.delta.usage && mapUsage(event.delta.usage),
|
|
264
|
+
});
|
|
265
|
+
return [{ tools: pending.tools, lifecycle, finished: true }, events];
|
|
266
|
+
}
|
|
267
|
+
default:
|
|
268
|
+
return [state, events];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
export const protocol = Protocol.make({
|
|
272
|
+
id: ADAPTER,
|
|
273
|
+
body: { schema: Body, from: fromRequest },
|
|
274
|
+
stream: {
|
|
275
|
+
event: Protocol.jsonEvent(Event),
|
|
276
|
+
initial: () => ({ lifecycle: Lifecycle.initial(), tools: ToolStream.empty(), finished: false }),
|
|
277
|
+
step,
|
|
278
|
+
terminal: (event) => event.type === "message-end",
|
|
279
|
+
onHalt: (state) => state.finished
|
|
280
|
+
? Effect.succeed([])
|
|
281
|
+
: Effect.fail(ProviderShared.eventError(ADAPTER, "Cohere stream ended without message-end")),
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
export const route = Route.make({
|
|
285
|
+
id: ADAPTER,
|
|
286
|
+
provider: "cohere",
|
|
287
|
+
providerMetadataKey: "cohere",
|
|
288
|
+
protocol,
|
|
289
|
+
endpoint: Endpoint.path("/chat", { baseURL: DEFAULT_BASE_URL }),
|
|
290
|
+
framing: Framing.sse,
|
|
291
|
+
});
|
|
292
|
+
export * as CohereChat from "./cohere-chat.js";
|
|
@@ -158,7 +158,7 @@ export declare const protocol: Protocol<{
|
|
|
158
158
|
readonly serviceTier?: string | undefined;
|
|
159
159
|
readonly toolConfig?: {
|
|
160
160
|
readonly functionCallingConfig: {
|
|
161
|
-
readonly mode: "
|
|
161
|
+
readonly mode: "NONE" | "AUTO" | "ANY";
|
|
162
162
|
readonly allowedFunctionNames?: readonly string[] | undefined;
|
|
163
163
|
};
|
|
164
164
|
} | undefined;
|
|
@@ -272,7 +272,7 @@ export declare const route: Route<{
|
|
|
272
272
|
readonly serviceTier?: string | undefined;
|
|
273
273
|
readonly toolConfig?: {
|
|
274
274
|
readonly functionCallingConfig: {
|
|
275
|
-
readonly mode: "
|
|
275
|
+
readonly mode: "NONE" | "AUTO" | "ANY";
|
|
276
276
|
readonly allowedFunctionNames?: readonly string[] | undefined;
|
|
277
277
|
};
|
|
278
278
|
} | undefined;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CohereChat from "./cohere-chat.js";
|
|
3
4
|
export * as Gemini from "./gemini.js";
|
|
4
5
|
export * as MistralChat from "./mistral-chat.js";
|
|
5
6
|
export * as OpenAIChat from "./openai-chat.js";
|
package/dist/protocols/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as AnthropicMessages from "./anthropic-messages.js";
|
|
2
2
|
export * as BedrockConverse from "./bedrock-converse.js";
|
|
3
|
+
export * as CohereChat from "./cohere-chat.js";
|
|
3
4
|
export * as Gemini from "./gemini.js";
|
|
4
5
|
export * as MistralChat from "./mistral-chat.js";
|
|
5
6
|
export * as OpenAIChat from "./openai-chat.js";
|
|
@@ -310,9 +310,9 @@ export declare const protocol: Protocol<{
|
|
|
310
310
|
};
|
|
311
311
|
} | undefined;
|
|
312
312
|
readonly top_p?: number | undefined;
|
|
313
|
-
readonly random_seed?: number | undefined;
|
|
314
313
|
readonly frequency_penalty?: number | undefined;
|
|
315
314
|
readonly presence_penalty?: number | undefined;
|
|
315
|
+
readonly random_seed?: number | undefined;
|
|
316
316
|
readonly prompt_cache_key?: string | undefined;
|
|
317
317
|
readonly safe_prompt?: boolean | undefined;
|
|
318
318
|
readonly document_image_limit?: number | undefined;
|
|
@@ -444,9 +444,9 @@ export declare const httpTransport: HttpTransport.HttpJsonTransport<{
|
|
|
444
444
|
};
|
|
445
445
|
} | undefined;
|
|
446
446
|
readonly top_p?: number | undefined;
|
|
447
|
-
readonly random_seed?: number | undefined;
|
|
448
447
|
readonly frequency_penalty?: number | undefined;
|
|
449
448
|
readonly presence_penalty?: number | undefined;
|
|
449
|
+
readonly random_seed?: number | undefined;
|
|
450
450
|
readonly prompt_cache_key?: string | undefined;
|
|
451
451
|
readonly safe_prompt?: boolean | undefined;
|
|
452
452
|
readonly document_image_limit?: number | undefined;
|
|
@@ -532,9 +532,9 @@ export declare const route: Route<{
|
|
|
532
532
|
};
|
|
533
533
|
} | undefined;
|
|
534
534
|
readonly top_p?: number | undefined;
|
|
535
|
-
readonly random_seed?: number | undefined;
|
|
536
535
|
readonly frequency_penalty?: number | undefined;
|
|
537
536
|
readonly presence_penalty?: number | undefined;
|
|
537
|
+
readonly random_seed?: number | undefined;
|
|
538
538
|
readonly prompt_cache_key?: string | undefined;
|
|
539
539
|
readonly safe_prompt?: boolean | undefined;
|
|
540
540
|
readonly document_image_limit?: number | undefined;
|
package/dist/provider-error.js
CHANGED
|
@@ -40,7 +40,13 @@ const patterns = [
|
|
|
40
40
|
/request_too_large/i,
|
|
41
41
|
];
|
|
42
42
|
const payloadPatterns = [/request entity too large/i, /payload too large/i, /request too large/i];
|
|
43
|
-
const exclusions = [
|
|
43
|
+
const exclusions = [
|
|
44
|
+
/^(throttling error|service unavailable):/i,
|
|
45
|
+
/rate limit/i,
|
|
46
|
+
/too many requests/i,
|
|
47
|
+
// Cohere reports an output limit above the model maximum as "too many tokens"; compaction cannot fix it.
|
|
48
|
+
/max[_ ]tokens must be less than/i,
|
|
49
|
+
];
|
|
44
50
|
export const isContextOverflow = (message) => !exclusions.some((pattern) => pattern.test(message)) &&
|
|
45
51
|
(patterns.some((pattern) => pattern.test(message)) || /^4(?:00|13)\s*(status code)?\s*\(no body\)/i.test(message));
|
|
46
52
|
export const isPayloadTooLarge = (message) => payloadPatterns.some((pattern) => pattern.test(message));
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ProviderPackage } from "../../provider-package.js";
|
|
2
|
+
import { Cohere } from "../cohere.js";
|
|
3
|
+
export type Settings = Cohere.Settings<Cohere.ChatOptionsInput>;
|
|
4
|
+
export declare const model: ProviderPackage.Definition<Settings, Cohere.ChatOptionsInput>["model"];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Cohere } from "../cohere.js";
|
|
2
|
+
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => Cohere.configure({
|
|
3
|
+
apiKey,
|
|
4
|
+
baseURL,
|
|
5
|
+
headers,
|
|
6
|
+
http: body === undefined ? undefined : { body: { ...body } },
|
|
7
|
+
providerOptions,
|
|
8
|
+
}).chat(modelID);
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import { CohereChat } from "../protocols/cohere-chat.js";
|
|
2
|
+
import { Route, type RouteDefaultsInput } from "../route/client.js";
|
|
3
|
+
import { type ProviderAuthOption } from "../route/auth-options.js";
|
|
4
|
+
import { type ModelID, type OpenString } from "../schema/index.js";
|
|
5
|
+
import type { ProviderPackage } from "../provider-package.js";
|
|
6
|
+
export declare const id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
7
|
+
export type ChatOptionsInput = {
|
|
8
|
+
readonly reasoningEffort?: OpenString<"none" | "high">;
|
|
9
|
+
};
|
|
10
|
+
export type ProviderOptions = CohereChat.ProviderOptionsInput & ChatOptionsInput;
|
|
11
|
+
export type LanguageModelOptions = Omit<RouteDefaultsInput, "providerOptions"> & ProviderAuthOption<"optional"> & {
|
|
12
|
+
readonly baseURL?: string;
|
|
13
|
+
readonly providerOptions?: ProviderOptions;
|
|
14
|
+
};
|
|
15
|
+
export type Settings<Options = CohereChat.ProviderOptionsInput> = ProviderPackage.Settings & Options & {
|
|
16
|
+
readonly apiKey?: string;
|
|
17
|
+
readonly baseURL?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare const route: Route<{
|
|
20
|
+
readonly model: string;
|
|
21
|
+
readonly messages: readonly {
|
|
22
|
+
readonly role: "tool" | "system" | "user" | "assistant";
|
|
23
|
+
readonly content?: string | readonly ({
|
|
24
|
+
readonly type: "text";
|
|
25
|
+
readonly text: string;
|
|
26
|
+
} | {
|
|
27
|
+
readonly type: "thinking";
|
|
28
|
+
readonly thinking: string;
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "image_url";
|
|
31
|
+
readonly image_url: {
|
|
32
|
+
readonly url: string;
|
|
33
|
+
};
|
|
34
|
+
})[] | undefined;
|
|
35
|
+
readonly tool_calls?: readonly {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
readonly type: "function";
|
|
38
|
+
readonly function: {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly arguments: string;
|
|
41
|
+
};
|
|
42
|
+
}[] | undefined;
|
|
43
|
+
readonly tool_call_id?: string | undefined;
|
|
44
|
+
readonly tool_plan?: string | undefined;
|
|
45
|
+
}[];
|
|
46
|
+
readonly stream: true;
|
|
47
|
+
readonly max_tokens?: number | undefined;
|
|
48
|
+
readonly tools?: readonly {
|
|
49
|
+
readonly type: "function";
|
|
50
|
+
readonly function: {
|
|
51
|
+
readonly name: string;
|
|
52
|
+
readonly parameters: unknown;
|
|
53
|
+
readonly description?: string | undefined;
|
|
54
|
+
};
|
|
55
|
+
}[] | undefined;
|
|
56
|
+
readonly temperature?: number | undefined;
|
|
57
|
+
readonly seed?: number | undefined;
|
|
58
|
+
readonly thinking?: {
|
|
59
|
+
readonly type: string;
|
|
60
|
+
readonly token_budget?: number | undefined;
|
|
61
|
+
} | undefined;
|
|
62
|
+
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
63
|
+
readonly stop_sequences?: readonly string[] | undefined;
|
|
64
|
+
readonly p?: number | undefined;
|
|
65
|
+
readonly k?: number | undefined;
|
|
66
|
+
readonly frequency_penalty?: number | undefined;
|
|
67
|
+
readonly presence_penalty?: number | undefined;
|
|
68
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
69
|
+
export declare const chatRoute: Route<{
|
|
70
|
+
readonly model: string;
|
|
71
|
+
readonly messages: readonly ({
|
|
72
|
+
readonly role: "system";
|
|
73
|
+
readonly content: string | readonly ({
|
|
74
|
+
readonly type: "text";
|
|
75
|
+
readonly text: string;
|
|
76
|
+
readonly cache_control?: {
|
|
77
|
+
readonly type: "ephemeral";
|
|
78
|
+
readonly ttl?: string | undefined;
|
|
79
|
+
} | undefined;
|
|
80
|
+
} | {
|
|
81
|
+
readonly type: "image_url";
|
|
82
|
+
readonly image_url: {
|
|
83
|
+
readonly url: string;
|
|
84
|
+
};
|
|
85
|
+
} | {
|
|
86
|
+
readonly type: "file";
|
|
87
|
+
readonly file: {
|
|
88
|
+
readonly filename: string;
|
|
89
|
+
readonly file_data: string;
|
|
90
|
+
};
|
|
91
|
+
})[];
|
|
92
|
+
} | {
|
|
93
|
+
readonly role: "user";
|
|
94
|
+
readonly content: string | readonly ({
|
|
95
|
+
readonly type: "text";
|
|
96
|
+
readonly text: string;
|
|
97
|
+
readonly cache_control?: {
|
|
98
|
+
readonly type: "ephemeral";
|
|
99
|
+
readonly ttl?: string | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
} | {
|
|
102
|
+
readonly type: "image_url";
|
|
103
|
+
readonly image_url: {
|
|
104
|
+
readonly url: string;
|
|
105
|
+
};
|
|
106
|
+
} | {
|
|
107
|
+
readonly type: "file";
|
|
108
|
+
readonly file: {
|
|
109
|
+
readonly filename: string;
|
|
110
|
+
readonly file_data: string;
|
|
111
|
+
};
|
|
112
|
+
})[];
|
|
113
|
+
} | {
|
|
114
|
+
readonly [x: string]: unknown;
|
|
115
|
+
readonly content: string | readonly {
|
|
116
|
+
readonly type: "text";
|
|
117
|
+
readonly text: string;
|
|
118
|
+
readonly cache_control?: {
|
|
119
|
+
readonly type: "ephemeral";
|
|
120
|
+
readonly ttl?: string | undefined;
|
|
121
|
+
} | undefined;
|
|
122
|
+
}[] | null;
|
|
123
|
+
readonly role: "assistant";
|
|
124
|
+
readonly reasoning?: string | undefined;
|
|
125
|
+
readonly reasoning_content?: string | undefined;
|
|
126
|
+
readonly reasoning_text?: string | undefined;
|
|
127
|
+
readonly tool_calls?: readonly {
|
|
128
|
+
readonly function: {
|
|
129
|
+
readonly name: string;
|
|
130
|
+
readonly arguments: string;
|
|
131
|
+
};
|
|
132
|
+
readonly id: string;
|
|
133
|
+
readonly type: "function";
|
|
134
|
+
readonly extra_content?: {
|
|
135
|
+
readonly google: {
|
|
136
|
+
readonly thought_signature: string;
|
|
137
|
+
};
|
|
138
|
+
} | undefined;
|
|
139
|
+
}[] | undefined;
|
|
140
|
+
readonly reasoning_details?: unknown;
|
|
141
|
+
} | {
|
|
142
|
+
readonly role: "tool";
|
|
143
|
+
readonly tool_call_id: string;
|
|
144
|
+
readonly content: string | readonly {
|
|
145
|
+
readonly type: "text";
|
|
146
|
+
readonly text: string;
|
|
147
|
+
readonly cache_control?: {
|
|
148
|
+
readonly type: "ephemeral";
|
|
149
|
+
readonly ttl?: string | undefined;
|
|
150
|
+
} | undefined;
|
|
151
|
+
}[];
|
|
152
|
+
})[];
|
|
153
|
+
readonly stream: true;
|
|
154
|
+
readonly max_completion_tokens?: number | undefined;
|
|
155
|
+
readonly max_tokens?: number | undefined;
|
|
156
|
+
readonly tools?: readonly {
|
|
157
|
+
readonly function: {
|
|
158
|
+
readonly description: string;
|
|
159
|
+
readonly name: string;
|
|
160
|
+
readonly parameters: {
|
|
161
|
+
readonly [x: string]: unknown;
|
|
162
|
+
};
|
|
163
|
+
readonly strict?: boolean | undefined;
|
|
164
|
+
};
|
|
165
|
+
readonly type: "function";
|
|
166
|
+
readonly cache_control?: {
|
|
167
|
+
readonly type: "ephemeral";
|
|
168
|
+
readonly ttl?: string | undefined;
|
|
169
|
+
} | undefined;
|
|
170
|
+
}[] | undefined;
|
|
171
|
+
readonly stop?: readonly string[] | undefined;
|
|
172
|
+
readonly temperature?: number | undefined;
|
|
173
|
+
readonly seed?: number | undefined;
|
|
174
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
175
|
+
readonly type: "function";
|
|
176
|
+
readonly function: {
|
|
177
|
+
readonly name: string;
|
|
178
|
+
};
|
|
179
|
+
} | undefined;
|
|
180
|
+
readonly top_p?: number | undefined;
|
|
181
|
+
readonly frequency_penalty?: number | undefined;
|
|
182
|
+
readonly presence_penalty?: number | undefined;
|
|
183
|
+
readonly prompt_cache_key?: string | undefined;
|
|
184
|
+
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
185
|
+
readonly store?: boolean | undefined;
|
|
186
|
+
readonly stream_options?: {
|
|
187
|
+
readonly include_usage: boolean;
|
|
188
|
+
} | undefined;
|
|
189
|
+
readonly tool_stream?: boolean | undefined;
|
|
190
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>;
|
|
191
|
+
export declare const routes: (Route<{
|
|
192
|
+
readonly model: string;
|
|
193
|
+
readonly messages: readonly {
|
|
194
|
+
readonly role: "tool" | "system" | "user" | "assistant";
|
|
195
|
+
readonly content?: string | readonly ({
|
|
196
|
+
readonly type: "text";
|
|
197
|
+
readonly text: string;
|
|
198
|
+
} | {
|
|
199
|
+
readonly type: "thinking";
|
|
200
|
+
readonly thinking: string;
|
|
201
|
+
} | {
|
|
202
|
+
readonly type: "image_url";
|
|
203
|
+
readonly image_url: {
|
|
204
|
+
readonly url: string;
|
|
205
|
+
};
|
|
206
|
+
})[] | undefined;
|
|
207
|
+
readonly tool_calls?: readonly {
|
|
208
|
+
readonly id: string;
|
|
209
|
+
readonly type: "function";
|
|
210
|
+
readonly function: {
|
|
211
|
+
readonly name: string;
|
|
212
|
+
readonly arguments: string;
|
|
213
|
+
};
|
|
214
|
+
}[] | undefined;
|
|
215
|
+
readonly tool_call_id?: string | undefined;
|
|
216
|
+
readonly tool_plan?: string | undefined;
|
|
217
|
+
}[];
|
|
218
|
+
readonly stream: true;
|
|
219
|
+
readonly max_tokens?: number | undefined;
|
|
220
|
+
readonly tools?: readonly {
|
|
221
|
+
readonly type: "function";
|
|
222
|
+
readonly function: {
|
|
223
|
+
readonly name: string;
|
|
224
|
+
readonly parameters: unknown;
|
|
225
|
+
readonly description?: string | undefined;
|
|
226
|
+
};
|
|
227
|
+
}[] | undefined;
|
|
228
|
+
readonly temperature?: number | undefined;
|
|
229
|
+
readonly seed?: number | undefined;
|
|
230
|
+
readonly thinking?: {
|
|
231
|
+
readonly type: string;
|
|
232
|
+
readonly token_budget?: number | undefined;
|
|
233
|
+
} | undefined;
|
|
234
|
+
readonly tool_choice?: "NONE" | "REQUIRED" | undefined;
|
|
235
|
+
readonly stop_sequences?: readonly string[] | undefined;
|
|
236
|
+
readonly p?: number | undefined;
|
|
237
|
+
readonly k?: number | undefined;
|
|
238
|
+
readonly frequency_penalty?: number | undefined;
|
|
239
|
+
readonly presence_penalty?: number | undefined;
|
|
240
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined> | Route<{
|
|
241
|
+
readonly model: string;
|
|
242
|
+
readonly messages: readonly ({
|
|
243
|
+
readonly role: "system";
|
|
244
|
+
readonly content: string | readonly ({
|
|
245
|
+
readonly type: "text";
|
|
246
|
+
readonly text: string;
|
|
247
|
+
readonly cache_control?: {
|
|
248
|
+
readonly type: "ephemeral";
|
|
249
|
+
readonly ttl?: string | undefined;
|
|
250
|
+
} | undefined;
|
|
251
|
+
} | {
|
|
252
|
+
readonly type: "image_url";
|
|
253
|
+
readonly image_url: {
|
|
254
|
+
readonly url: string;
|
|
255
|
+
};
|
|
256
|
+
} | {
|
|
257
|
+
readonly type: "file";
|
|
258
|
+
readonly file: {
|
|
259
|
+
readonly filename: string;
|
|
260
|
+
readonly file_data: string;
|
|
261
|
+
};
|
|
262
|
+
})[];
|
|
263
|
+
} | {
|
|
264
|
+
readonly role: "user";
|
|
265
|
+
readonly content: string | readonly ({
|
|
266
|
+
readonly type: "text";
|
|
267
|
+
readonly text: string;
|
|
268
|
+
readonly cache_control?: {
|
|
269
|
+
readonly type: "ephemeral";
|
|
270
|
+
readonly ttl?: string | undefined;
|
|
271
|
+
} | undefined;
|
|
272
|
+
} | {
|
|
273
|
+
readonly type: "image_url";
|
|
274
|
+
readonly image_url: {
|
|
275
|
+
readonly url: string;
|
|
276
|
+
};
|
|
277
|
+
} | {
|
|
278
|
+
readonly type: "file";
|
|
279
|
+
readonly file: {
|
|
280
|
+
readonly filename: string;
|
|
281
|
+
readonly file_data: string;
|
|
282
|
+
};
|
|
283
|
+
})[];
|
|
284
|
+
} | {
|
|
285
|
+
readonly [x: string]: unknown;
|
|
286
|
+
readonly content: string | readonly {
|
|
287
|
+
readonly type: "text";
|
|
288
|
+
readonly text: string;
|
|
289
|
+
readonly cache_control?: {
|
|
290
|
+
readonly type: "ephemeral";
|
|
291
|
+
readonly ttl?: string | undefined;
|
|
292
|
+
} | undefined;
|
|
293
|
+
}[] | null;
|
|
294
|
+
readonly role: "assistant";
|
|
295
|
+
readonly reasoning?: string | undefined;
|
|
296
|
+
readonly reasoning_content?: string | undefined;
|
|
297
|
+
readonly reasoning_text?: string | undefined;
|
|
298
|
+
readonly tool_calls?: readonly {
|
|
299
|
+
readonly function: {
|
|
300
|
+
readonly name: string;
|
|
301
|
+
readonly arguments: string;
|
|
302
|
+
};
|
|
303
|
+
readonly id: string;
|
|
304
|
+
readonly type: "function";
|
|
305
|
+
readonly extra_content?: {
|
|
306
|
+
readonly google: {
|
|
307
|
+
readonly thought_signature: string;
|
|
308
|
+
};
|
|
309
|
+
} | undefined;
|
|
310
|
+
}[] | undefined;
|
|
311
|
+
readonly reasoning_details?: unknown;
|
|
312
|
+
} | {
|
|
313
|
+
readonly role: "tool";
|
|
314
|
+
readonly tool_call_id: string;
|
|
315
|
+
readonly content: string | readonly {
|
|
316
|
+
readonly type: "text";
|
|
317
|
+
readonly text: string;
|
|
318
|
+
readonly cache_control?: {
|
|
319
|
+
readonly type: "ephemeral";
|
|
320
|
+
readonly ttl?: string | undefined;
|
|
321
|
+
} | undefined;
|
|
322
|
+
}[];
|
|
323
|
+
})[];
|
|
324
|
+
readonly stream: true;
|
|
325
|
+
readonly max_completion_tokens?: number | undefined;
|
|
326
|
+
readonly max_tokens?: number | undefined;
|
|
327
|
+
readonly tools?: readonly {
|
|
328
|
+
readonly function: {
|
|
329
|
+
readonly description: string;
|
|
330
|
+
readonly name: string;
|
|
331
|
+
readonly parameters: {
|
|
332
|
+
readonly [x: string]: unknown;
|
|
333
|
+
};
|
|
334
|
+
readonly strict?: boolean | undefined;
|
|
335
|
+
};
|
|
336
|
+
readonly type: "function";
|
|
337
|
+
readonly cache_control?: {
|
|
338
|
+
readonly type: "ephemeral";
|
|
339
|
+
readonly ttl?: string | undefined;
|
|
340
|
+
} | undefined;
|
|
341
|
+
}[] | undefined;
|
|
342
|
+
readonly stop?: readonly string[] | undefined;
|
|
343
|
+
readonly temperature?: number | undefined;
|
|
344
|
+
readonly seed?: number | undefined;
|
|
345
|
+
readonly tool_choice?: "required" | "auto" | "none" | {
|
|
346
|
+
readonly type: "function";
|
|
347
|
+
readonly function: {
|
|
348
|
+
readonly name: string;
|
|
349
|
+
};
|
|
350
|
+
} | undefined;
|
|
351
|
+
readonly top_p?: number | undefined;
|
|
352
|
+
readonly frequency_penalty?: number | undefined;
|
|
353
|
+
readonly presence_penalty?: number | undefined;
|
|
354
|
+
readonly prompt_cache_key?: string | undefined;
|
|
355
|
+
readonly reasoning_effort?: import("../schema/options.js").ReasoningEffort | undefined;
|
|
356
|
+
readonly store?: boolean | undefined;
|
|
357
|
+
readonly stream_options?: {
|
|
358
|
+
readonly include_usage: boolean;
|
|
359
|
+
} | undefined;
|
|
360
|
+
readonly tool_stream?: boolean | undefined;
|
|
361
|
+
}, import("../route/transport/http.js").HttpPrepared<string>, import("../route/client.js").CompactionOperations | undefined>)[];
|
|
362
|
+
export declare const configure: (input?: LanguageModelOptions) => {
|
|
363
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
364
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
365
|
+
readonly thinking?: {
|
|
366
|
+
readonly type?: "enabled" | "disabled" | undefined;
|
|
367
|
+
readonly tokenBudget?: number | undefined;
|
|
368
|
+
} | undefined;
|
|
369
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
370
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
371
|
+
configure: (input?: LanguageModelOptions) => /*elided*/ any;
|
|
372
|
+
};
|
|
373
|
+
export declare const provider: {
|
|
374
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
375
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
376
|
+
readonly thinking?: {
|
|
377
|
+
readonly type?: "enabled" | "disabled" | undefined;
|
|
378
|
+
readonly tokenBudget?: number | undefined;
|
|
379
|
+
} | undefined;
|
|
380
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
381
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
382
|
+
configure: (input?: LanguageModelOptions) => {
|
|
383
|
+
id: string & import("effect/Brand").Brand<"AI.ProviderID">;
|
|
384
|
+
model: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<{
|
|
385
|
+
readonly thinking?: {
|
|
386
|
+
readonly type?: "enabled" | "disabled" | undefined;
|
|
387
|
+
readonly tokenBudget?: number | undefined;
|
|
388
|
+
} | undefined;
|
|
389
|
+
}, import("../route/client.js").CompactionOperations | undefined>;
|
|
390
|
+
chat: (modelID: string | ModelID) => import("../schema/options.js").LanguageModel<ChatOptionsInput, import("../route/client.js").CompactionOperations | undefined>;
|
|
391
|
+
configure: /*elided*/ any;
|
|
392
|
+
};
|
|
393
|
+
};
|
|
394
|
+
export declare const model: ProviderPackage.Definition<Settings, CohereChat.ProviderOptionsInput>["model"];
|
|
395
|
+
export * as Cohere from "./cohere.js";
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { CohereChat } from "../protocols/cohere-chat.js";
|
|
2
|
+
import { OpenAIChat } from "../protocols/openai-chat.js";
|
|
3
|
+
import { Route } from "../route/client.js";
|
|
4
|
+
import { Endpoint } from "../route/endpoint.js";
|
|
5
|
+
import { AuthOptions } from "../route/auth-options.js";
|
|
6
|
+
import { ProviderID } from "../schema/index.js";
|
|
7
|
+
export const id = ProviderID.make("cohere");
|
|
8
|
+
const COMPATIBILITY_BASE_URL = "https://api.cohere.ai/compatibility/v1";
|
|
9
|
+
export const route = CohereChat.route;
|
|
10
|
+
export const chatRoute = Route.make({
|
|
11
|
+
id: "cohere-chat-completions",
|
|
12
|
+
provider: id,
|
|
13
|
+
providerMetadataKey: "cohere",
|
|
14
|
+
protocol: OpenAIChat.protocol,
|
|
15
|
+
endpoint: Endpoint.path("/chat/completions", { baseURL: COMPATIBILITY_BASE_URL }),
|
|
16
|
+
framing: OpenAIChat.framing,
|
|
17
|
+
});
|
|
18
|
+
export const routes = [route, chatRoute];
|
|
19
|
+
export const configure = (input = {}) => {
|
|
20
|
+
const { apiKey: _apiKey, auth: _auth, baseURL, ...defaults } = input;
|
|
21
|
+
const auth = AuthOptions.bearer(input, "COHERE_API_KEY");
|
|
22
|
+
const native = route.with({ ...defaults, auth, endpoint: { baseURL: baseURL ?? CohereChat.DEFAULT_BASE_URL } });
|
|
23
|
+
const chat = chatRoute.with({ ...defaults, auth, endpoint: { baseURL: baseURL ?? COMPATIBILITY_BASE_URL } });
|
|
24
|
+
return {
|
|
25
|
+
id,
|
|
26
|
+
model: (modelID) => native.model({ id: modelID }),
|
|
27
|
+
chat: (modelID) => chat.model({
|
|
28
|
+
id: modelID,
|
|
29
|
+
compatibility: {
|
|
30
|
+
maxTokensField: "max_tokens",
|
|
31
|
+
supportsStore: false,
|
|
32
|
+
supportsUsageInStreaming: true,
|
|
33
|
+
reasoningField: "reasoning_content",
|
|
34
|
+
supportsStrictMode: false,
|
|
35
|
+
},
|
|
36
|
+
}),
|
|
37
|
+
configure,
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export const provider = configure();
|
|
41
|
+
export const model = (modelID, { apiKey, baseURL, body, headers, ...providerOptions }) => configure({
|
|
42
|
+
apiKey,
|
|
43
|
+
baseURL,
|
|
44
|
+
headers,
|
|
45
|
+
http: body === undefined ? undefined : { body: { ...body } },
|
|
46
|
+
providerOptions,
|
|
47
|
+
}).model(modelID);
|
|
48
|
+
export * as Cohere from "./cohere.js";
|
|
@@ -77,7 +77,7 @@ export declare const routes: Route<{
|
|
|
77
77
|
readonly serviceTier?: string | undefined;
|
|
78
78
|
readonly toolConfig?: {
|
|
79
79
|
readonly functionCallingConfig: {
|
|
80
|
-
readonly mode: "
|
|
80
|
+
readonly mode: "NONE" | "AUTO" | "ANY";
|
|
81
81
|
readonly allowedFunctionNames?: readonly string[] | undefined;
|
|
82
82
|
};
|
|
83
83
|
} | undefined;
|
|
@@ -62,7 +62,7 @@ export declare const routes: import("../route/client.js").Route<{
|
|
|
62
62
|
readonly serviceTier?: string | undefined;
|
|
63
63
|
readonly toolConfig?: {
|
|
64
64
|
readonly functionCallingConfig: {
|
|
65
|
-
readonly mode: "
|
|
65
|
+
readonly mode: "NONE" | "AUTO" | "ANY";
|
|
66
66
|
readonly allowedFunctionNames?: readonly string[] | undefined;
|
|
67
67
|
};
|
|
68
68
|
} | undefined;
|
|
@@ -9,6 +9,7 @@ export * as Baseten from "./baseten.js";
|
|
|
9
9
|
export * as BlackForestLabs from "./black-forest-labs.js";
|
|
10
10
|
export * as Cartesia from "./cartesia.js";
|
|
11
11
|
export * as Cerebras from "./cerebras.js";
|
|
12
|
+
export * as Cohere from "./cohere.js";
|
|
12
13
|
export * as CloudflareAIGateway from "./cloudflare-ai-gateway.js";
|
|
13
14
|
export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
14
15
|
export * as DeepInfra from "./deepinfra.js";
|
package/dist/providers/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export * as Baseten from "./baseten.js";
|
|
|
9
9
|
export * as BlackForestLabs from "./black-forest-labs.js";
|
|
10
10
|
export * as Cartesia from "./cartesia.js";
|
|
11
11
|
export * as Cerebras from "./cerebras.js";
|
|
12
|
+
export * as Cohere from "./cohere.js";
|
|
12
13
|
export * as CloudflareAIGateway from "./cloudflare-ai-gateway.js";
|
|
13
14
|
export * as CloudflareWorkersAI from "./cloudflare-workers-ai.js";
|
|
14
15
|
export * as DeepInfra from "./deepinfra.js";
|
|
@@ -90,9 +90,9 @@ export declare const route: import("../route/client.js").Route<{
|
|
|
90
90
|
};
|
|
91
91
|
} | undefined;
|
|
92
92
|
readonly top_p?: number | undefined;
|
|
93
|
-
readonly random_seed?: number | undefined;
|
|
94
93
|
readonly frequency_penalty?: number | undefined;
|
|
95
94
|
readonly presence_penalty?: number | undefined;
|
|
95
|
+
readonly random_seed?: number | undefined;
|
|
96
96
|
readonly prompt_cache_key?: string | undefined;
|
|
97
97
|
readonly safe_prompt?: boolean | undefined;
|
|
98
98
|
readonly document_image_limit?: number | undefined;
|
|
@@ -178,9 +178,9 @@ export declare const routes: import("../route/client.js").Route<{
|
|
|
178
178
|
};
|
|
179
179
|
} | undefined;
|
|
180
180
|
readonly top_p?: number | undefined;
|
|
181
|
-
readonly random_seed?: number | undefined;
|
|
182
181
|
readonly frequency_penalty?: number | undefined;
|
|
183
182
|
readonly presence_penalty?: number | undefined;
|
|
183
|
+
readonly random_seed?: number | undefined;
|
|
184
184
|
readonly prompt_cache_key?: string | undefined;
|
|
185
185
|
readonly safe_prompt?: boolean | undefined;
|
|
186
186
|
readonly document_image_limit?: number | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package.json",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20456",
|
|
4
4
|
"name": "@opencode/ai",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@clack/prompts": "1.0.0-alpha.1",
|
|
36
36
|
"@effect/platform-node": "4.0.0-rc.112",
|
|
37
|
-
"@opencode/http-recorder": "0.0.0-dev-
|
|
37
|
+
"@opencode/http-recorder": "0.0.0-dev-20456",
|
|
38
38
|
"@tsconfig/bun": "1.0.9",
|
|
39
39
|
"@types/bun": "1.4.0",
|
|
40
40
|
"@typescript/native-preview": "7.0.0-dev.20251207.1",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@aws-sdk/credential-providers": "3.1057.0",
|
|
45
45
|
"@smithy/eventstream-codec": "4.2.14",
|
|
46
46
|
"@smithy/util-utf8": "4.2.2",
|
|
47
|
-
"@opencode/schema": "0.0.0-dev-
|
|
47
|
+
"@opencode/schema": "0.0.0-dev-20456",
|
|
48
48
|
"aws4fetch": "1.0.20",
|
|
49
49
|
"effect": "4.0.0-rc.112",
|
|
50
50
|
"google-auth-library": "10.5.0"
|