@opencode/ai 0.0.0-dev-1302 → 0.0.0-dev-1304
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/dist/cache-policy.js +4 -2
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +10 -1
- package/dist/protocols/alibaba-messages.d.ts +24 -2
- package/dist/protocols/alibaba-responses.d.ts +26 -0
- package/dist/protocols/anthropic-messages.d.ts +70 -6
- package/dist/protocols/anthropic-messages.js +74 -9
- package/dist/protocols/meta-messages.d.ts +24 -2
- package/dist/protocols/meta-responses.d.ts +52 -0
- package/dist/protocols/open-responses.d.ts +250 -24
- package/dist/protocols/open-responses.js +40 -24
- package/dist/protocols/openai-compatible-responses.d.ts +26 -0
- package/dist/protocols/openai-freeform.d.ts +1 -1
- package/dist/protocols/openai-freeform.js +9 -5
- package/dist/protocols/openai-responses.d.ts +153 -0
- package/dist/protocols/openai-responses.js +68 -7
- package/dist/protocols/utils/gateway-protocol.js +1 -0
- package/dist/protocols/utils/responses-compaction.js +7 -3
- package/dist/protocols/xai-responses.d.ts +26 -0
- package/dist/protocols/zai-messages.d.ts +24 -2
- package/dist/providers/alibaba.d.ts +50 -2
- package/dist/providers/amazon-bedrock-mantle.d.ts +50 -2
- package/dist/providers/anthropic-compatible.d.ts +24 -2
- package/dist/providers/anthropic.d.ts +24 -2
- package/dist/providers/azure.d.ts +76 -2
- package/dist/providers/cloudflare-ai-gateway.d.ts +100 -4
- package/dist/providers/digitalocean.d.ts +26 -0
- package/dist/providers/google-vertex-messages.d.ts +24 -2
- package/dist/providers/google-vertex-messages.js +1 -0
- package/dist/providers/google-vertex-responses.d.ts +26 -0
- package/dist/providers/meta.d.ts +50 -2
- package/dist/providers/minimax.d.ts +50 -2
- package/dist/providers/moonshot.d.ts +50 -2
- package/dist/providers/openai-compatible-responses.d.ts +26 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openrouter.d.ts +26 -0
- package/dist/providers/venice.d.ts +26 -0
- package/dist/providers/zai-coding-plan.d.ts +50 -2
- package/dist/public.d.ts +2 -2
- package/dist/public.js +1 -1
- package/dist/route/client.d.ts +2 -0
- package/dist/route/client.js +5 -1
- package/dist/route/protocol.d.ts +3 -0
- package/dist/schema/events.d.ts +5 -0
- package/dist/schema/messages.d.ts +24 -1
- package/dist/schema/messages.js +26 -2
- package/dist/schema/options.d.ts +10 -2
- package/dist/tool-updates.d.ts +34 -0
- package/dist/tool-updates.js +93 -0
- package/dist/tool.d.ts +6 -1
- package/dist/tool.js +1 -1
- package/package.json +3 -3
package/dist/cache-policy.js
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import { CacheHint } from "./schema/options.js";
|
|
14
14
|
import { AssistantMessage, SystemMessage, ToolDefinition, ToolMessage, UserMessage, } from "./schema/messages.js";
|
|
15
15
|
import { effortUpdate } from "./effort-updates.js";
|
|
16
|
+
import { toolsUpdate } from "./tool-updates.js";
|
|
16
17
|
const AUTO = {
|
|
17
18
|
tools: true,
|
|
18
19
|
system: true,
|
|
@@ -151,15 +152,16 @@ const markMessages = (messages, strategy, hint, budget) => {
|
|
|
151
152
|
let remaining = strategy.tail;
|
|
152
153
|
while (remaining > 0 && start > 0) {
|
|
153
154
|
start -= 1;
|
|
154
|
-
if (
|
|
155
|
+
if (!isMarker(messages[start]))
|
|
155
156
|
remaining -= 1;
|
|
156
157
|
}
|
|
157
158
|
let next = messages;
|
|
158
159
|
for (let i = start; i < messages.length; i++)
|
|
159
|
-
if (
|
|
160
|
+
if (!isMarker(messages[i]))
|
|
160
161
|
next = markMessageAt(next, i, hint, budget);
|
|
161
162
|
return next;
|
|
162
163
|
};
|
|
164
|
+
const isMarker = (message) => effortUpdate(message) !== undefined || toolsUpdate(message) !== undefined;
|
|
163
165
|
const countHints = (request) => countToolHints(request.tools) +
|
|
164
166
|
request.system.reduce((count, part) => count + (part.cache === undefined ? 0 : 1), 0) +
|
|
165
167
|
request.messages.reduce((count, message) => count +
|
package/dist/llm.d.ts
CHANGED
|
@@ -15,7 +15,10 @@ export type PromptOrMessages = {
|
|
|
15
15
|
interface TextRequestFields<Model extends LanguageModel> extends BaseRequest<Model, NoInfer<LanguageModelProviderOptions<Model>>>, GenerationOptionsFields {
|
|
16
16
|
readonly id?: string;
|
|
17
17
|
readonly system?: string | SystemPart | ReadonlyArray<SystemPart>;
|
|
18
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Sent in array order. Pass `tool(...)` values or wire entries such as hosted provider tools. The same as a
|
|
20
|
+
* `Message.tools({ add: tools })` leading the history.
|
|
21
|
+
*/
|
|
19
22
|
readonly tools?: ReadonlyArray<Tool | ToolEntryInput>;
|
|
20
23
|
readonly toolChoice?: ToolChoice.Input;
|
|
21
24
|
readonly cache?: CachePolicy;
|
package/dist/llm.js
CHANGED
|
@@ -5,6 +5,7 @@ import { InvalidProviderOutputError, InvalidRequestError, mergeGeneration, AIErr
|
|
|
5
5
|
import { tool } from "./tool.js";
|
|
6
6
|
import { runTools } from "./tool-runtime.js";
|
|
7
7
|
import { addUsage, nextRequest, pendingCalls } from "./loop.js";
|
|
8
|
+
import { foldTools } from "./tool-updates.js";
|
|
8
9
|
export function generate(input, options) {
|
|
9
10
|
return prepare(input).pipe(Effect.flatMap(({ request, output }) => LLMClient.generate(request, options).pipe(Effect.flatMap((response) => output === undefined
|
|
10
11
|
? Effect.succeed(response)
|
|
@@ -15,8 +16,16 @@ export function stream(input, options) {
|
|
|
15
16
|
}
|
|
16
17
|
export function loop(input, options) {
|
|
17
18
|
const { tools, until, ...rest } = input;
|
|
18
|
-
return Stream.unwrap(prepare({ ...rest, tools }).pipe(
|
|
19
|
+
return Stream.unwrap(prepare({ ...rest, tools }).pipe(
|
|
20
|
+
// Untyped callers may omit `tools`.
|
|
21
|
+
Effect.map(({ request, output }) => driveLoop({ tools: runnableTools(tools ?? [], input.messages ?? []), until, output, options }, request, [], undefined))));
|
|
19
22
|
}
|
|
23
|
+
// Tools that `Message.tools(...)` adds run like top-level ones; a later change with the same name replaces or removes them.
|
|
24
|
+
const runnableTools = (tools, messages) => messages
|
|
25
|
+
.reduce((current, message) => message.role === "system" && message.tools !== undefined
|
|
26
|
+
? foldTools(current, message.tools.add ?? [], (message.tools.remove ?? []).map((item) => (typeof item === "string" ? item : item.name)))
|
|
27
|
+
: current, tools)
|
|
28
|
+
.filter((item) => "_definition" in item);
|
|
20
29
|
export { collect } from "./loop.js";
|
|
21
30
|
/**
|
|
22
31
|
* Stream one model call. Its `finish` is held back: `after` gets the completed step and streams what follows it.
|
|
@@ -240,14 +240,36 @@ export declare const protocol: Protocol<{
|
|
|
240
240
|
})[];
|
|
241
241
|
} | {
|
|
242
242
|
readonly role: "system";
|
|
243
|
-
readonly content: readonly {
|
|
243
|
+
readonly content: readonly ({
|
|
244
|
+
readonly type: "tool_addition";
|
|
245
|
+
readonly tool: {
|
|
246
|
+
readonly type: "tool_definition";
|
|
247
|
+
readonly definition: {
|
|
248
|
+
readonly name: string;
|
|
249
|
+
readonly description: string;
|
|
250
|
+
readonly input_schema: {
|
|
251
|
+
readonly [x: string]: unknown;
|
|
252
|
+
};
|
|
253
|
+
readonly cache_control?: {
|
|
254
|
+
readonly type: "ephemeral";
|
|
255
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
256
|
+
} | undefined;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
} | {
|
|
260
|
+
readonly type: "tool_removal";
|
|
261
|
+
readonly tool: {
|
|
262
|
+
readonly type: "tool_reference";
|
|
263
|
+
readonly name: string;
|
|
264
|
+
};
|
|
265
|
+
} | {
|
|
244
266
|
readonly type: "text";
|
|
245
267
|
readonly text: string;
|
|
246
268
|
readonly cache_control?: {
|
|
247
269
|
readonly type: "ephemeral";
|
|
248
270
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
249
271
|
} | undefined;
|
|
250
|
-
}[];
|
|
272
|
+
})[];
|
|
251
273
|
readonly output_config?: {
|
|
252
274
|
readonly effort: string;
|
|
253
275
|
} | undefined;
|
|
@@ -17,6 +17,32 @@ export declare const protocol: Protocol<{
|
|
|
17
17
|
readonly reasoning: {
|
|
18
18
|
readonly effort: OpenResponsesOptions.ReasoningEffort;
|
|
19
19
|
};
|
|
20
|
+
} | {
|
|
21
|
+
readonly type: "additional_tools";
|
|
22
|
+
readonly role: "developer";
|
|
23
|
+
readonly tools: readonly ({
|
|
24
|
+
readonly type: "custom";
|
|
25
|
+
readonly name: string;
|
|
26
|
+
readonly description: string;
|
|
27
|
+
readonly format: {
|
|
28
|
+
readonly type: "text";
|
|
29
|
+
} | {
|
|
30
|
+
readonly type: "grammar";
|
|
31
|
+
readonly syntax: "lark" | "regex";
|
|
32
|
+
readonly definition: string;
|
|
33
|
+
};
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "function";
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly description: string;
|
|
38
|
+
readonly parameters: {
|
|
39
|
+
readonly [x: string]: unknown;
|
|
40
|
+
};
|
|
41
|
+
readonly strict?: boolean | undefined;
|
|
42
|
+
} | {
|
|
43
|
+
readonly [x: string]: unknown;
|
|
44
|
+
readonly type: string;
|
|
45
|
+
})[];
|
|
20
46
|
} | {
|
|
21
47
|
readonly type: "message";
|
|
22
48
|
readonly role: "system";
|
|
@@ -364,14 +364,34 @@ export declare const AnthropicMessagesBody: Schema.Struct<{
|
|
|
364
364
|
}>]>>;
|
|
365
365
|
}>, Schema.Struct<{
|
|
366
366
|
readonly role: Schema.Literal<"system">;
|
|
367
|
-
readonly content: Schema.$Array<Schema.Struct<{
|
|
367
|
+
readonly content: Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
368
368
|
readonly type: Schema.tag<"text">;
|
|
369
369
|
readonly text: Schema.String;
|
|
370
370
|
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
371
371
|
readonly type: Schema.tag<"ephemeral">;
|
|
372
372
|
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
373
373
|
}>>;
|
|
374
|
-
}
|
|
374
|
+
}>, Schema.Struct<{
|
|
375
|
+
readonly type: Schema.tag<"tool_addition">;
|
|
376
|
+
readonly tool: Schema.Struct<{
|
|
377
|
+
readonly type: Schema.tag<"tool_definition">;
|
|
378
|
+
readonly definition: Schema.Struct<{
|
|
379
|
+
readonly name: Schema.String;
|
|
380
|
+
readonly description: Schema.String;
|
|
381
|
+
readonly input_schema: Schema.$Record<Schema.String, Schema.Unknown>;
|
|
382
|
+
readonly cache_control: Schema.optional<Schema.Struct<{
|
|
383
|
+
readonly type: Schema.tag<"ephemeral">;
|
|
384
|
+
readonly ttl: Schema.optional<Schema.TemplateLiteral<readonly [Schema.Number, Schema.Literals<readonly ["ms", "s", "m", "h", "d"]>]>>;
|
|
385
|
+
}>>;
|
|
386
|
+
}>;
|
|
387
|
+
}>;
|
|
388
|
+
}>, Schema.Struct<{
|
|
389
|
+
readonly type: Schema.tag<"tool_removal">;
|
|
390
|
+
readonly tool: Schema.Struct<{
|
|
391
|
+
readonly type: Schema.tag<"tool_reference">;
|
|
392
|
+
readonly name: Schema.String;
|
|
393
|
+
}>;
|
|
394
|
+
}>]>>;
|
|
375
395
|
readonly output_config: Schema.optional<Schema.Struct<{
|
|
376
396
|
readonly effort: Schema.String;
|
|
377
397
|
}>>;
|
|
@@ -672,14 +692,36 @@ export declare const protocol: Protocol<{
|
|
|
672
692
|
})[];
|
|
673
693
|
} | {
|
|
674
694
|
readonly role: "system";
|
|
675
|
-
readonly content: readonly {
|
|
695
|
+
readonly content: readonly ({
|
|
696
|
+
readonly type: "tool_addition";
|
|
697
|
+
readonly tool: {
|
|
698
|
+
readonly type: "tool_definition";
|
|
699
|
+
readonly definition: {
|
|
700
|
+
readonly name: string;
|
|
701
|
+
readonly description: string;
|
|
702
|
+
readonly input_schema: {
|
|
703
|
+
readonly [x: string]: unknown;
|
|
704
|
+
};
|
|
705
|
+
readonly cache_control?: {
|
|
706
|
+
readonly type: "ephemeral";
|
|
707
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
708
|
+
} | undefined;
|
|
709
|
+
};
|
|
710
|
+
};
|
|
711
|
+
} | {
|
|
712
|
+
readonly type: "tool_removal";
|
|
713
|
+
readonly tool: {
|
|
714
|
+
readonly type: "tool_reference";
|
|
715
|
+
readonly name: string;
|
|
716
|
+
};
|
|
717
|
+
} | {
|
|
676
718
|
readonly type: "text";
|
|
677
719
|
readonly text: string;
|
|
678
720
|
readonly cache_control?: {
|
|
679
721
|
readonly type: "ephemeral";
|
|
680
722
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
681
723
|
} | undefined;
|
|
682
|
-
}[];
|
|
724
|
+
})[];
|
|
683
725
|
readonly output_config?: {
|
|
684
726
|
readonly effort: string;
|
|
685
727
|
} | undefined;
|
|
@@ -1067,14 +1109,36 @@ export declare const route: Route<{
|
|
|
1067
1109
|
})[];
|
|
1068
1110
|
} | {
|
|
1069
1111
|
readonly role: "system";
|
|
1070
|
-
readonly content: readonly {
|
|
1112
|
+
readonly content: readonly ({
|
|
1113
|
+
readonly type: "tool_addition";
|
|
1114
|
+
readonly tool: {
|
|
1115
|
+
readonly type: "tool_definition";
|
|
1116
|
+
readonly definition: {
|
|
1117
|
+
readonly name: string;
|
|
1118
|
+
readonly description: string;
|
|
1119
|
+
readonly input_schema: {
|
|
1120
|
+
readonly [x: string]: unknown;
|
|
1121
|
+
};
|
|
1122
|
+
readonly cache_control?: {
|
|
1123
|
+
readonly type: "ephemeral";
|
|
1124
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
1125
|
+
} | undefined;
|
|
1126
|
+
};
|
|
1127
|
+
};
|
|
1128
|
+
} | {
|
|
1129
|
+
readonly type: "tool_removal";
|
|
1130
|
+
readonly tool: {
|
|
1131
|
+
readonly type: "tool_reference";
|
|
1132
|
+
readonly name: string;
|
|
1133
|
+
};
|
|
1134
|
+
} | {
|
|
1071
1135
|
readonly type: "text";
|
|
1072
1136
|
readonly text: string;
|
|
1073
1137
|
readonly cache_control?: {
|
|
1074
1138
|
readonly type: "ephemeral";
|
|
1075
1139
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
1076
1140
|
} | undefined;
|
|
1077
|
-
}[];
|
|
1141
|
+
})[];
|
|
1078
1142
|
readonly output_config?: {
|
|
1079
1143
|
readonly effort: string;
|
|
1080
1144
|
} | undefined;
|
|
@@ -12,6 +12,7 @@ import { AIError, CacheTTL, LLMEvent, mergeJsonRecords, Usage, } from "../schema
|
|
|
12
12
|
import { JsonObject, knownString, optionalArray, optionalNull, ProviderShared, withUntypedFrames } from "./shared.js";
|
|
13
13
|
import { classifyProviderFailure } from "../provider-error.js";
|
|
14
14
|
import { effortUpdate, resolveEffortUpdates } from "../effort-updates.js";
|
|
15
|
+
import { addsTools, foldTools, toolsUpdate, withdrawnTools } from "../tool-updates.js";
|
|
15
16
|
import * as Cache from "./utils/cache.js";
|
|
16
17
|
import { claudeVersion, supportsThinkingBlockBinding, THINKING_BINDING_BETA } from "./utils/claude-model.js";
|
|
17
18
|
import { Lifecycle } from "./utils/lifecycle.js";
|
|
@@ -196,21 +197,29 @@ const AnthropicAssistantBlock = Schema.Union([
|
|
|
196
197
|
AnthropicServerToolUseBlock,
|
|
197
198
|
AnthropicServerToolResultBlock,
|
|
198
199
|
]);
|
|
200
|
+
const AnthropicTool = Schema.Struct({
|
|
201
|
+
name: Schema.String,
|
|
202
|
+
description: Schema.String,
|
|
203
|
+
input_schema: JsonObject,
|
|
204
|
+
cache_control: Schema.optional(AnthropicCacheControl),
|
|
205
|
+
});
|
|
206
|
+
const AnthropicToolAdditionBlock = Schema.Struct({
|
|
207
|
+
type: Schema.tag("tool_addition"),
|
|
208
|
+
tool: Schema.Struct({ type: Schema.tag("tool_definition"), definition: AnthropicTool }),
|
|
209
|
+
});
|
|
210
|
+
const AnthropicToolRemovalBlock = Schema.Struct({
|
|
211
|
+
type: Schema.tag("tool_removal"),
|
|
212
|
+
tool: Schema.Struct({ type: Schema.tag("tool_reference"), name: Schema.String }),
|
|
213
|
+
});
|
|
199
214
|
const AnthropicMessage = Schema.Union([
|
|
200
215
|
Schema.Struct({ role: Schema.Literal("user"), content: Schema.Array(AnthropicUserBlock) }),
|
|
201
216
|
Schema.Struct({ role: Schema.Literal("assistant"), content: Schema.Array(AnthropicAssistantBlock) }),
|
|
202
217
|
Schema.Struct({
|
|
203
218
|
role: Schema.Literal("system"),
|
|
204
|
-
content: Schema.Array(AnthropicTextBlock),
|
|
219
|
+
content: Schema.Array(Schema.Union([AnthropicTextBlock, AnthropicToolAdditionBlock, AnthropicToolRemovalBlock])),
|
|
205
220
|
output_config: Schema.optional(Schema.Struct({ effort: Schema.String })),
|
|
206
221
|
}),
|
|
207
222
|
]).pipe(Schema.toTaggedUnion("role"));
|
|
208
|
-
const AnthropicTool = Schema.Struct({
|
|
209
|
-
name: Schema.String,
|
|
210
|
-
description: Schema.String,
|
|
211
|
-
input_schema: JsonObject,
|
|
212
|
-
cache_control: Schema.optional(AnthropicCacheControl),
|
|
213
|
-
});
|
|
214
223
|
const AnthropicToolChoice = Schema.Union([
|
|
215
224
|
Schema.Struct({
|
|
216
225
|
type: Schema.Literals(["auto", "any", "none"]),
|
|
@@ -634,6 +643,23 @@ const lowerWrappedSystemUpdate = Effect.fnUntraced(function* (message, breakpoin
|
|
|
634
643
|
const part = yield* ProviderShared.wrappedSystemUpdate("Anthropic Messages", message);
|
|
635
644
|
return { type: "text", text: part.text, cache_control: cacheControl(breakpoints, part.cache) };
|
|
636
645
|
});
|
|
646
|
+
const lowerToolsUpdate = Effect.fnUntraced(function* (message, update, withdrawn, breakpoints) {
|
|
647
|
+
const text = message.content.length === 0 ? [] : (yield* lowerNativeSystemUpdate(message, breakpoints)).content;
|
|
648
|
+
return {
|
|
649
|
+
role: "system",
|
|
650
|
+
content: [
|
|
651
|
+
...ProviderShared.flattenTools(update.add).map((tool) => ({
|
|
652
|
+
type: "tool_addition",
|
|
653
|
+
tool: { type: "tool_definition", definition: lowerTool(breakpoints, tool) },
|
|
654
|
+
})),
|
|
655
|
+
...withdrawn.map((name) => ({
|
|
656
|
+
type: "tool_removal",
|
|
657
|
+
tool: { type: "tool_reference", name },
|
|
658
|
+
})),
|
|
659
|
+
...text,
|
|
660
|
+
],
|
|
661
|
+
};
|
|
662
|
+
});
|
|
637
663
|
const appendToUserTurn = (messages, block) => {
|
|
638
664
|
const last = messages.at(-1);
|
|
639
665
|
if (last?.role === "user")
|
|
@@ -648,9 +674,22 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
648
674
|
// user turn, the nearest spot where Anthropic accepts a native system message.
|
|
649
675
|
const holdUpdates = supportsNativeSystemUpdates(request);
|
|
650
676
|
const held = [];
|
|
677
|
+
// The tools declared so far, so each tool update can name the flattened tools it takes away.
|
|
678
|
+
let declared = request.tools;
|
|
651
679
|
const releaseHeld = Effect.fnUntraced(function* () {
|
|
652
680
|
const native = acceptsNativeSystemAfter(messages.findLast((message) => message.role !== "system"));
|
|
653
681
|
for (const update of held.splice(0)) {
|
|
682
|
+
const tools = toolsUpdate(update);
|
|
683
|
+
if (tools !== undefined) {
|
|
684
|
+
if (!native)
|
|
685
|
+
return yield* invalid("Anthropic Messages tool updates must follow a user message or tool result");
|
|
686
|
+
const next = foldTools(declared, tools.add, tools.remove);
|
|
687
|
+
const lowered = yield* lowerToolsUpdate(update, tools, withdrawnTools(declared, next), breakpoints);
|
|
688
|
+
declared = next;
|
|
689
|
+
if (lowered.content.length > 0)
|
|
690
|
+
messages.push(lowered);
|
|
691
|
+
continue;
|
|
692
|
+
}
|
|
654
693
|
if (native)
|
|
655
694
|
messages.push(yield* lowerNativeSystemUpdate(update, breakpoints));
|
|
656
695
|
else
|
|
@@ -665,6 +704,12 @@ const lowerMessages = Effect.fnUntraced(function* (request, breakpoints) {
|
|
|
665
704
|
messages.push({ role: "system", content: [], output_config: { effort: update.effort ?? DEFAULT_EFFORT } });
|
|
666
705
|
continue;
|
|
667
706
|
}
|
|
707
|
+
// Held like text updates, so one between a tool call and its result lands after the result. Planning keeps a
|
|
708
|
+
// marker in place only on models that take native system messages.
|
|
709
|
+
if (toolsUpdate(message) !== undefined) {
|
|
710
|
+
held.push(message);
|
|
711
|
+
continue;
|
|
712
|
+
}
|
|
668
713
|
if (splitsLocalToolResults(request.messages, index))
|
|
669
714
|
return yield* invalid("Anthropic Messages system updates cannot split a local tool call from its tool result");
|
|
670
715
|
if (holdUpdates)
|
|
@@ -776,6 +821,21 @@ const supportsEffortUpdates = (request) => {
|
|
|
776
821
|
return true;
|
|
777
822
|
return version.major > 5 || (version.major === 5 && version.minor >= 1);
|
|
778
823
|
};
|
|
824
|
+
// `tool_addition` adds a tool, or redefines one with the same name; `tool_removal` removes one. A held marker is
|
|
825
|
+
// released just before the next assistant message, where Anthropic only accepts a native system message after a
|
|
826
|
+
// user message or tool result; a marker that would land elsewhere folds.
|
|
827
|
+
const toolUpdates = {
|
|
828
|
+
kinds: ["add", "remove", "replace"],
|
|
829
|
+
placeable: (request, index) => {
|
|
830
|
+
if (!supportsNativeSystemUpdates(request))
|
|
831
|
+
return false;
|
|
832
|
+
const end = request.messages.findIndex((next, at) => at > index && next.role === "assistant");
|
|
833
|
+
const role = request.messages
|
|
834
|
+
.slice(0, end === -1 ? undefined : end)
|
|
835
|
+
.findLast((next) => next.role !== "system")?.role;
|
|
836
|
+
return role === "user" || role === "tool";
|
|
837
|
+
},
|
|
838
|
+
};
|
|
779
839
|
const applyThinkingBindingDefault = (model, thinking) => {
|
|
780
840
|
if (isThinkingOff(thinking))
|
|
781
841
|
return thinking;
|
|
@@ -808,8 +868,9 @@ const fromRequest = Effect.fn("AnthropicMessages.fromRequest")(function* (reques
|
|
|
808
868
|
const breakpoints = Cache.newBreakpoints(ANTHROPIC_BREAKPOINT_CAP);
|
|
809
869
|
const flattened = ProviderShared.flattenToolRequest(updates.request);
|
|
810
870
|
const tools = flattened.tools.length === 0 ? undefined : flattened.tools.map((tool) => lowerTool(breakpoints, tool));
|
|
811
|
-
// Anthropic rejects tool_choice when
|
|
812
|
-
const
|
|
871
|
+
// Anthropic rejects tool_choice when no tool is declared; "none" is only meaningful with tools present.
|
|
872
|
+
const declared = tools !== undefined || addsTools(request);
|
|
873
|
+
const toolChoice = !declared || !request.toolChoice ? undefined : yield* lowerToolChoice(request.toolChoice);
|
|
813
874
|
const systemParts = request.system.filter((part) => part.text.length > 0);
|
|
814
875
|
const system = systemParts.length === 0
|
|
815
876
|
? undefined
|
|
@@ -1298,6 +1359,7 @@ export const protocol = Protocol.make({
|
|
|
1298
1359
|
step,
|
|
1299
1360
|
},
|
|
1300
1361
|
supportsEffortUpdates,
|
|
1362
|
+
toolUpdates,
|
|
1301
1363
|
});
|
|
1302
1364
|
export const transport = () => {
|
|
1303
1365
|
const http = HttpTransport.httpJson({ framing });
|
|
@@ -1331,6 +1393,9 @@ function requiredBetaHeaders(body) {
|
|
|
1331
1393
|
betas.push("compact-2026-01-12");
|
|
1332
1394
|
if (body.messages.some((message) => message.role === "system" && message.output_config !== undefined))
|
|
1333
1395
|
betas.push("mid-conversation-output-config-2026-07-01");
|
|
1396
|
+
if (body.messages.some((message) => message.role === "system" &&
|
|
1397
|
+
message.content.some((block) => block.type === "tool_addition" || block.type === "tool_removal")))
|
|
1398
|
+
betas.push("inline-tools-2026-09-15");
|
|
1334
1399
|
// Opus 5.5 accepts `speed` without this header; earlier fast-mode models reject `speed` without it.
|
|
1335
1400
|
if (body.speed !== undefined)
|
|
1336
1401
|
betas.push("fast-mode-2026-02-01");
|
|
@@ -228,14 +228,36 @@ export declare const protocol: Protocol<{
|
|
|
228
228
|
})[];
|
|
229
229
|
} | {
|
|
230
230
|
readonly role: "system";
|
|
231
|
-
readonly content: readonly {
|
|
231
|
+
readonly content: readonly ({
|
|
232
|
+
readonly type: "tool_addition";
|
|
233
|
+
readonly tool: {
|
|
234
|
+
readonly type: "tool_definition";
|
|
235
|
+
readonly definition: {
|
|
236
|
+
readonly name: string;
|
|
237
|
+
readonly description: string;
|
|
238
|
+
readonly input_schema: {
|
|
239
|
+
readonly [x: string]: unknown;
|
|
240
|
+
};
|
|
241
|
+
readonly cache_control?: {
|
|
242
|
+
readonly type: "ephemeral";
|
|
243
|
+
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
244
|
+
} | undefined;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
} | {
|
|
248
|
+
readonly type: "tool_removal";
|
|
249
|
+
readonly tool: {
|
|
250
|
+
readonly type: "tool_reference";
|
|
251
|
+
readonly name: string;
|
|
252
|
+
};
|
|
253
|
+
} | {
|
|
232
254
|
readonly type: "text";
|
|
233
255
|
readonly text: string;
|
|
234
256
|
readonly cache_control?: {
|
|
235
257
|
readonly type: "ephemeral";
|
|
236
258
|
readonly ttl?: `${number}d` | `${number}h` | `${number}m` | `${number}ms` | `${number}s` | undefined;
|
|
237
259
|
} | undefined;
|
|
238
|
-
}[];
|
|
260
|
+
})[];
|
|
239
261
|
readonly output_config?: {
|
|
240
262
|
readonly effort: string;
|
|
241
263
|
} | undefined;
|
|
@@ -31,6 +31,32 @@ export declare const protocol: Protocol<{
|
|
|
31
31
|
readonly reasoning: {
|
|
32
32
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
33
33
|
};
|
|
34
|
+
} | {
|
|
35
|
+
readonly type: "additional_tools";
|
|
36
|
+
readonly role: "developer";
|
|
37
|
+
readonly tools: readonly ({
|
|
38
|
+
readonly type: "custom";
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly description: string;
|
|
41
|
+
readonly format: {
|
|
42
|
+
readonly type: "text";
|
|
43
|
+
} | {
|
|
44
|
+
readonly type: "grammar";
|
|
45
|
+
readonly syntax: "lark" | "regex";
|
|
46
|
+
readonly definition: string;
|
|
47
|
+
};
|
|
48
|
+
} | {
|
|
49
|
+
readonly type: "function";
|
|
50
|
+
readonly name: string;
|
|
51
|
+
readonly description: string;
|
|
52
|
+
readonly parameters: {
|
|
53
|
+
readonly [x: string]: unknown;
|
|
54
|
+
};
|
|
55
|
+
readonly strict?: boolean | undefined;
|
|
56
|
+
} | {
|
|
57
|
+
readonly [x: string]: unknown;
|
|
58
|
+
readonly type: string;
|
|
59
|
+
})[];
|
|
34
60
|
} | {
|
|
35
61
|
readonly type: "message";
|
|
36
62
|
readonly role: "system";
|
|
@@ -287,6 +313,32 @@ export declare const httpTransport: import("../route/transport/http.js").HttpJso
|
|
|
287
313
|
readonly reasoning: {
|
|
288
314
|
readonly effort: import("../schema/options.js").ReasoningEffort;
|
|
289
315
|
};
|
|
316
|
+
} | {
|
|
317
|
+
readonly type: "additional_tools";
|
|
318
|
+
readonly role: "developer";
|
|
319
|
+
readonly tools: readonly ({
|
|
320
|
+
readonly type: "custom";
|
|
321
|
+
readonly name: string;
|
|
322
|
+
readonly description: string;
|
|
323
|
+
readonly format: {
|
|
324
|
+
readonly type: "text";
|
|
325
|
+
} | {
|
|
326
|
+
readonly type: "grammar";
|
|
327
|
+
readonly syntax: "lark" | "regex";
|
|
328
|
+
readonly definition: string;
|
|
329
|
+
};
|
|
330
|
+
} | {
|
|
331
|
+
readonly type: "function";
|
|
332
|
+
readonly name: string;
|
|
333
|
+
readonly description: string;
|
|
334
|
+
readonly parameters: {
|
|
335
|
+
readonly [x: string]: unknown;
|
|
336
|
+
};
|
|
337
|
+
readonly strict?: boolean | undefined;
|
|
338
|
+
} | {
|
|
339
|
+
readonly [x: string]: unknown;
|
|
340
|
+
readonly type: string;
|
|
341
|
+
})[];
|
|
290
342
|
} | {
|
|
291
343
|
readonly type: "message";
|
|
292
344
|
readonly role: "system";
|