@averyyy/pi-ai 1.0.0-piclient.2 → 1.0.1-piclient.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/README.md +2 -2
- package/dist/api/anthropic-messages.d.ts.map +1 -1
- package/dist/api/anthropic-messages.js +30 -29
- package/dist/api/anthropic-messages.js.map +1 -1
- package/dist/api/bedrock-converse-stream.d.ts.map +1 -1
- package/dist/api/bedrock-converse-stream.js +25 -2
- package/dist/api/bedrock-converse-stream.js.map +1 -1
- package/dist/api/cloudflare-workers-ai-system-one.d.ts.map +1 -1
- package/dist/api/cloudflare-workers-ai-system-one.js +13 -8
- package/dist/api/cloudflare-workers-ai-system-one.js.map +1 -1
- package/dist/auth/oauth/openai-chatgpt.d.ts.map +1 -1
- package/dist/auth/oauth/openai-chatgpt.js +10 -13
- package/dist/auth/oauth/openai-chatgpt.js.map +1 -1
- package/dist/providers/data/.manifest.json +1 -1
- package/dist/providers/data/amazon-bedrock.json +1 -1
- package/dist/providers/data/cloudflare-ai-gateway.json +1 -1
- package/dist/providers/data/cloudflare-workers-ai.json +1 -1
- package/dist/providers/data/openrouter.json +1 -1
- package/dist/providers/data/together.json +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/transcript.d.ts +5 -2
- package/dist/utils/transcript.d.ts.map +1 -1
- package/dist/utils/transcript.js +5 -2
- package/dist/utils/transcript.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -896,7 +896,7 @@ Classifier models consume structured JSON state and answer one or more typed que
|
|
|
896
896
|
| --- | --- | --- |
|
|
897
897
|
| `typesafe` | `jev-latest` | `TYPESAFE_API_KEY` |
|
|
898
898
|
| `openrouter` | `typesafe/jev-1.13`, `~typesafe/jev-latest` | `OPENROUTER_API_KEY` or OpenRouter OAuth |
|
|
899
|
-
| `cloudflare-workers-ai` | `typesafe/jev` | `CLOUDFLARE_API_KEY` and `CLOUDFLARE_ACCOUNT_ID` |
|
|
899
|
+
| `cloudflare-workers-ai` | `typesafe/jev`, `@cf/cloudflare/clef`, `@cf/cloudflare/clef-flash` | `CLOUDFLARE_API_KEY` and `CLOUDFLARE_ACCOUNT_ID` |
|
|
900
900
|
| `vercel-ai-gateway` | `typesafe-ai/jev` | `AI_GATEWAY_API_KEY` |
|
|
901
901
|
| `opencode` | `jev-1.13`, `jev-1.13-free` | `OPENCODE_API_KEY` |
|
|
902
902
|
|
|
@@ -1587,7 +1587,7 @@ getCurrentTools(messages); // []
|
|
|
1587
1587
|
|
|
1588
1588
|
A custom `Provider` or `ProviderStreams` implementation reads the prompt and tools the same way from `context.messages`; `context.systemPrompt` and `context.tools` do not exist at that layer.
|
|
1589
1589
|
|
|
1590
|
-
Models that accept system messages mid-conversation (`supportsMidConvoSystemMessages` in the model's compat settings, set by the generated catalog for verified models) receive each later system message in place, so the cached prefix stays intact; section changes are framed by name for the model. Every other model receives `collapseSystemMessages(transcript)`: the replayed prompt and current tools as the leading system message, with later system messages dropped. Anthropic models that also set `supportsMidConvoToolChanges` send tool changes as native `
|
|
1590
|
+
Models that accept system messages mid-conversation (`supportsMidConvoSystemMessages` in the model's compat settings, set by the generated catalog for verified models) receive each later system message in place, so the cached prefix stays intact; section changes are framed by name for the model. Every other model receives `collapseSystemMessages(transcript)`: the replayed prompt and current tools as the leading system message, with later system messages dropped. Anthropic models that also set `supportsMidConvoToolChanges` send tool changes as native blocks (`inline-tools-2026-09-15` beta): the top-level tool list holds the initial tools plus a stable deferred placeholder and never changes, later tools are defined by value in `tool_addition` blocks (a new definition under an existing name replaces the old one), and removals are `tool_removal` references, so tool changes do not invalidate the prompt cache. That needs at least one initial tool; otherwise the current tool list is sent at the top level with the system text only. OpenAI Responses models with `supportsAdditionalTools` or `supportsToolSearch` anchor additive tool changes at their message; everything else sends the current tool list at the top level.
|
|
1591
1591
|
|
|
1592
1592
|
## Context Serialization
|
|
1593
1593
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAiC,MAAM,mBAAmB,CAAC;AAoBlE,OAAO,KAAK,EASX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"anthropic-messages.d.ts","sourceRoot":"","sources":["../../src/api/anthropic-messages.ts"],"names":[],"mappings":"AAAA,OAAO,SAAiC,MAAM,mBAAmB,CAAC;AAoBlE,OAAO,KAAK,EASX,mBAAmB,EAEnB,cAAc,EACd,aAAa,EAMb,MAAM,aAAa,CAAC;AAmJrB,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC;AAE1E,MAAM,MAAM,wBAAwB,GAAG,YAAY,GAAG,SAAS,CAAC;AA2ChE,MAAM,WAAW,gBAAiB,SAAQ,aAAa;IACtD;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;;;;;;OAWG;IACH,MAAM,CAAC,EAAE,eAAe,CAAC;IACzB;;;;;;;;;;;OAWG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;IAC3C;;;;;OAKG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACtE;;;;OAIG;IACH,MAAM,CAAC,EAAE,SAAS,CAAC;CACnB;AAwRD,eAAO,MAAM,MAAM,EAAE,cAAc,CAAC,oBAAoB,EAAE,gBAAgB,CA0UzE,CAAC;AA2BF,eAAO,MAAM,YAAY,EAAE,cAAc,CAAC,oBAAoB,EAAE,mBAAmB,CAgDlF,CAAC"}
|
|
@@ -10,7 +10,7 @@ import { getProviderEnvValue } from "../utils/provider-env.js";
|
|
|
10
10
|
import { retryProviderRequest } from "../utils/provider-retry.js";
|
|
11
11
|
import { sanitizeSurrogates } from "../utils/sanitize-unicode.js";
|
|
12
12
|
import { getSystemMessageText, renderSystemMessageUpdate } from "../utils/text.js";
|
|
13
|
-
import { getCurrentTools,
|
|
13
|
+
import { getCurrentTools, getInitialSystemMessage, resolveTranscript, } from "../utils/transcript.js";
|
|
14
14
|
import { getJsonSchemaToolParameters, resolveJsonSchemaStrictSampling, } from "./constrained-sampling.js";
|
|
15
15
|
import { buildCopilotDynamicHeaders, hasCopilotVisionInput } from "./github-copilot-headers.js";
|
|
16
16
|
import { adjustMaxTokensForThinking, buildBaseOptions, clampMaxTokensToContext } from "./simple-options.js";
|
|
@@ -116,13 +116,13 @@ const INTERLEAVED_THINKING_BETA = "interleaved-thinking-2025-05-14";
|
|
|
116
116
|
const SERVER_SIDE_FALLBACK_BETA = "server-side-fallback-2026-07-01";
|
|
117
117
|
const MID_CONVERSATION_OUTPUT_CONFIG_BETA = "mid-conversation-output-config-2026-07-01";
|
|
118
118
|
const THINKING_BINDING_CONTROLS_BETA = "thinking-binding-controls-2026-08-01";
|
|
119
|
-
const
|
|
119
|
+
const INLINE_TOOLS_BETA = "inline-tools-2026-09-15";
|
|
120
120
|
/**
|
|
121
121
|
* Stable deferred tool declared whenever native tool changes are in use. Anthropic adds
|
|
122
|
-
* hidden prompt scaffolding
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
122
|
+
* hidden prompt scaffolding for mid-conversation tool changes; declaring this placeholder
|
|
123
|
+
* from the first request keeps that scaffolding in the cached prefix, so the first tool
|
|
124
|
+
* change does not invalidate the cache (measured: full miss without it). It is never
|
|
125
|
+
* activated and the model cannot see it.
|
|
126
126
|
*/
|
|
127
127
|
const DEFERRED_TOOL_PLACEHOLDER = {
|
|
128
128
|
name: "__pi_deferred_placeholder__",
|
|
@@ -852,7 +852,7 @@ function getBetaFeatures(model, context, isOAuthToken, nativeToolChanges, option
|
|
|
852
852
|
features.push(MID_CONVERSATION_OUTPUT_CONFIG_BETA, THINKING_BINDING_CONTROLS_BETA);
|
|
853
853
|
}
|
|
854
854
|
if (nativeToolChanges)
|
|
855
|
-
features.push(
|
|
855
|
+
features.push(INLINE_TOOLS_BETA);
|
|
856
856
|
return [...new Set(features)];
|
|
857
857
|
}
|
|
858
858
|
function buildParams(model, context, isOAuthToken, options) {
|
|
@@ -862,15 +862,15 @@ function buildParams(model, context, isOAuthToken, options) {
|
|
|
862
862
|
const initialSystemText = initialSystemMessage ? getSystemMessageText(initialSystemMessage) : "";
|
|
863
863
|
const transformedMessages = transformMessages(context.messages, model, normalizeToolCallId);
|
|
864
864
|
const conversationMessages = initialSystemMessage ? transformedMessages.slice(1) : transformedMessages;
|
|
865
|
-
// Native tool changes
|
|
866
|
-
//
|
|
867
|
-
//
|
|
865
|
+
// Native tool changes keep the request-level tool list fixed and define every later tool
|
|
866
|
+
// by value in a `tool_addition` block, which also expresses same-name redefinitions.
|
|
867
|
+
// Anthropic rejects a tool list where every tool is deferred, so there must be an initial
|
|
868
|
+
// active tool to anchor the placeholder. Otherwise the current tool list is sent.
|
|
868
869
|
const initialTools = initialSystemMessage?.toolsAdded ?? [];
|
|
869
|
-
const nativeToolChanges = compat.supportsMidConvoSystemMessages &&
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
const converted = convertMessages(conversationMessages, isOAuthToken, cacheControl, compat.allowEmptySignature, model.compat?.supportsMidConvoEffort === true ? model.provider : undefined, nativeToolChanges);
|
|
870
|
+
const nativeToolChanges = compat.supportsMidConvoSystemMessages && compat.supportsMidConvoToolChanges && initialTools.length > 0;
|
|
871
|
+
const converted = convertMessages(conversationMessages, isOAuthToken, cacheControl, compat.allowEmptySignature, model.compat?.supportsMidConvoEffort === true ? model.provider : undefined, nativeToolChanges
|
|
872
|
+
? (tools) => convertTools(tools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools)
|
|
873
|
+
: undefined);
|
|
874
874
|
const activeEffort = options?.effort ?? "high";
|
|
875
875
|
const betaFeatures = getBetaFeatures(model, context, isOAuthToken, nativeToolChanges, options);
|
|
876
876
|
const params = {
|
|
@@ -918,16 +918,13 @@ function buildParams(model, context, isOAuthToken, options) {
|
|
|
918
918
|
}
|
|
919
919
|
const toolCacheControl = compat.supportsCacheControlOnTools ? cacheControl : undefined;
|
|
920
920
|
if (nativeToolChanges) {
|
|
921
|
-
// Initial tools stay active with the cache breakpoint on the last one
|
|
922
|
-
//
|
|
923
|
-
//
|
|
924
|
-
//
|
|
925
|
-
const initialNames = new Set(initialTools.map((tool) => tool.name));
|
|
926
|
-
const laterTools = getDeclaredTools(context.messages).filter((tool) => !initialNames.has(tool.name));
|
|
921
|
+
// Initial tools stay active with the cache breakpoint on the last one, followed by the
|
|
922
|
+
// placeholder. The list never changes afterwards: later tools are defined by value in
|
|
923
|
+
// `tool_addition` blocks and withdrawn by `tool_removal`, so the cached prefix survives
|
|
924
|
+
// every tool change.
|
|
927
925
|
params.tools = [
|
|
928
926
|
...convertTools(initialTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools, toolCacheControl),
|
|
929
927
|
DEFERRED_TOOL_PLACEHOLDER,
|
|
930
|
-
...convertTools(laterTools, isOAuthToken, compat.supportsEagerToolInputStreaming, compat.supportsStrictTools).map((tool) => ({ ...tool, defer_loading: true })),
|
|
931
928
|
];
|
|
932
929
|
}
|
|
933
930
|
else {
|
|
@@ -1003,7 +1000,9 @@ function convertToolResult(msg) {
|
|
|
1003
1000
|
is_error: msg.isError,
|
|
1004
1001
|
};
|
|
1005
1002
|
}
|
|
1006
|
-
function convertMessages(transformedMessages, isOAuthToken, cacheControl, allowEmptySignature = false, managedProvider,
|
|
1003
|
+
function convertMessages(transformedMessages, isOAuthToken, cacheControl, allowEmptySignature = false, managedProvider,
|
|
1004
|
+
/** Converts tool definitions for native `tool_addition` blocks; undefined when tool changes are not native. */
|
|
1005
|
+
convertToolDefinitions) {
|
|
1007
1006
|
const params = [];
|
|
1008
1007
|
const assistantLevels = new Map();
|
|
1009
1008
|
// Later system messages are held back and emitted directly before the next assistant
|
|
@@ -1025,18 +1024,20 @@ function convertMessages(transformedMessages, isOAuthToken, cacheControl, allowE
|
|
|
1025
1024
|
const blocks = [];
|
|
1026
1025
|
if (text.length > 0)
|
|
1027
1026
|
blocks.push({ type: "text", text: sanitizeSurrogates(text) });
|
|
1028
|
-
if (
|
|
1027
|
+
if (convertToolDefinitions) {
|
|
1028
|
+
const added = msg.toolsAdded ?? [];
|
|
1029
|
+
const redefined = new Set(added.map((tool) => tool.name));
|
|
1029
1030
|
for (const tool of msg.toolsRemoved ?? []) {
|
|
1031
|
+
// A new definition under the same name replaces the old one, so no removal is needed.
|
|
1032
|
+
if (redefined.has(tool.name))
|
|
1033
|
+
continue;
|
|
1030
1034
|
blocks.push({
|
|
1031
1035
|
type: "tool_removal",
|
|
1032
1036
|
tool: { type: "tool_reference", name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name },
|
|
1033
1037
|
});
|
|
1034
1038
|
}
|
|
1035
|
-
for (const
|
|
1036
|
-
blocks.push({
|
|
1037
|
-
type: "tool_addition",
|
|
1038
|
-
tool: { type: "tool_reference", name: isOAuthToken ? toClaudeCodeName(tool.name) : tool.name },
|
|
1039
|
-
});
|
|
1039
|
+
for (const definition of convertToolDefinitions(added)) {
|
|
1040
|
+
blocks.push({ type: "tool_addition", tool: { type: "tool_definition", definition } });
|
|
1040
1041
|
}
|
|
1041
1042
|
}
|
|
1042
1043
|
if (blocks.length > 0)
|