@cortexkit/pi-anthropic-auth 2.1.2 → 2.2.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/dist/convert.d.ts +3 -0
- package/dist/convert.js +24 -6
- package/dist/stream.js +1 -0
- package/package.json +2 -2
package/dist/convert.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ export declare function buildAnthropicRequest(modelId: string, context: Context,
|
|
|
33
33
|
}, fastModeEnabled?: boolean, identity?: ClaudeCodeIdentity, controls?: {
|
|
34
34
|
effortTransitions?: readonly MidConversationEffortTransition[];
|
|
35
35
|
thinkingPrefixMismatchBehavior?: ThinkingPrefixMismatchBehavior;
|
|
36
|
+
turnEndNote?: {
|
|
37
|
+
tools: string[];
|
|
38
|
+
};
|
|
36
39
|
}): Promise<{
|
|
37
40
|
body: AnthropicRequestBody;
|
|
38
41
|
bodyText: string;
|
package/dist/convert.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyClaudeCodeMetadata, applyMidConversationOutputConfig, applyThinkingBindingControls, assertNoMeaningfulTrailingAssistant, buildBillingHeaderValue, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_IDENTITY, CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING, CLAUDE_HAIKU_5_5_ADAPTIVE_THINKING, CLAUDE_OPUS_5_5_ADAPTIVE_THINKING, CLAUDE_OPUS_5_ADAPTIVE_THINKING, CLAUDE_SONNET_5_5_ADAPTIVE_THINKING, CLAUDE_SONNET_5_ADAPTIVE_THINKING, ClaudeCodeFirstUserTextTracker, isClaudeFableOrMythos5Model, isClaudeHaiku55Model, isClaudeOpus5Model, isClaudeOpus55Model, isClaudeSonnet5Model, isClaudeSonnet55Model, isFastModeSupportedModel, isOpenAIReasoningSignature, orderClaudeCodeBody, signRequestBody, stripEmptyTrailingAssistantMessages, } from '@cortexkit/anthropic-auth-core';
|
|
1
|
+
import { applyClaudeCodeMetadata, applyMidConversationOutputConfig, applyThinkingBindingControls, applyTurnEndNotes, assertNoMeaningfulTrailingAssistant, buildBillingHeaderValue, CLAUDE_CODE_ENTRYPOINT, CLAUDE_CODE_IDENTITY, CLAUDE_FABLE_MYTHOS_5_SUMMARIZED_THINKING, CLAUDE_HAIKU_5_5_ADAPTIVE_THINKING, CLAUDE_OPUS_5_5_ADAPTIVE_THINKING, CLAUDE_OPUS_5_ADAPTIVE_THINKING, CLAUDE_SONNET_5_5_ADAPTIVE_THINKING, CLAUDE_SONNET_5_ADAPTIVE_THINKING, ClaudeCodeFirstUserTextTracker, isClaudeFableOrMythos5Model, isClaudeHaiku55Model, isClaudeOpus5Model, isClaudeOpus55Model, isClaudeSonnet5Model, isClaudeSonnet55Model, isFastModeSupportedModel, isOpenAIReasoningSignature, orderClaudeCodeBody, signRequestBody, stripEmptyTrailingAssistantMessages, } from '@cortexkit/anthropic-auth-core';
|
|
2
2
|
import { collapseSystemMessages, getCurrentSystemPrompt, getCurrentTools, normalizeContext, } from './transcript.js';
|
|
3
3
|
// Anchor identifying Pi's documentation paragraph — the only part of the prompt
|
|
4
4
|
// that Anthropic currently rejects in system[]. Unknown prompt shapes take the
|
|
@@ -111,7 +111,7 @@ function convertTextAndImages(content) {
|
|
|
111
111
|
}
|
|
112
112
|
return blocks;
|
|
113
113
|
}
|
|
114
|
-
function convertMessages(messages, targetModelId) {
|
|
114
|
+
function convertMessages(messages, targetModelId, visibleReplies) {
|
|
115
115
|
const result = [];
|
|
116
116
|
for (let index = 0; index < messages.length; index++) {
|
|
117
117
|
const message = messages[index];
|
|
@@ -142,9 +142,12 @@ function convertMessages(messages, targetModelId) {
|
|
|
142
142
|
continue;
|
|
143
143
|
}
|
|
144
144
|
const blocks = [];
|
|
145
|
+
let visibleText = '';
|
|
145
146
|
for (const block of message.content) {
|
|
146
147
|
if (block.type === 'text' && block.text.trim()) {
|
|
147
|
-
|
|
148
|
+
const text = sanitize(block.text);
|
|
149
|
+
blocks.push({ type: 'text', text });
|
|
150
|
+
visibleText += text;
|
|
148
151
|
}
|
|
149
152
|
else if (block.type === 'thinking') {
|
|
150
153
|
const thinking = block;
|
|
@@ -213,8 +216,15 @@ function convertMessages(messages, targetModelId) {
|
|
|
213
216
|
});
|
|
214
217
|
}
|
|
215
218
|
}
|
|
216
|
-
if (blocks.length)
|
|
217
|
-
|
|
219
|
+
if (blocks.length) {
|
|
220
|
+
const converted = { role: 'assistant', content: blocks };
|
|
221
|
+
result.push(converted);
|
|
222
|
+
// Converted thinking can become text for replay, but it was never a
|
|
223
|
+
// visible reply. Count only actual text blocks, using the exact outgoing
|
|
224
|
+
// strings collected above, so the note decision for this message stays
|
|
225
|
+
// the same on every later request.
|
|
226
|
+
visibleReplies.set(converted, visibleText);
|
|
227
|
+
}
|
|
218
228
|
continue;
|
|
219
229
|
}
|
|
220
230
|
if (message.role === 'toolResult') {
|
|
@@ -453,7 +463,8 @@ export async function buildAnthropicRequest(modelId, context, options, cache, fa
|
|
|
453
463
|
// first so those losses cannot hide a meaningful final assistant turn. Check
|
|
454
464
|
// the Anthropic messages again after conversion removes empty user messages.
|
|
455
465
|
assertNoMeaningfulTrailingAssistant(context.messages);
|
|
456
|
-
const
|
|
466
|
+
const visibleReplies = new WeakMap();
|
|
467
|
+
const messages = convertMessages(context.messages, modelId, visibleReplies);
|
|
457
468
|
stripEmptyTrailingAssistantMessages(messages);
|
|
458
469
|
const system = [
|
|
459
470
|
{
|
|
@@ -566,6 +577,13 @@ export async function buildAnthropicRequest(modelId, context, options, cache, fa
|
|
|
566
577
|
}
|
|
567
578
|
}
|
|
568
579
|
applyMidConversationOutputConfig(body, controls.effortTransitions ?? []);
|
|
580
|
+
if (identity) {
|
|
581
|
+
applyTurnEndNotes(body, {
|
|
582
|
+
tools: controls.turnEndNote?.tools,
|
|
583
|
+
mapToolName: toClaudeCodeToolName,
|
|
584
|
+
visibleText: (message) => visibleReplies.get(message) ?? '',
|
|
585
|
+
});
|
|
586
|
+
}
|
|
569
587
|
addEphemeralCacheControl(body);
|
|
570
588
|
applyCacheMode(body, cache.enabled, cache.mode);
|
|
571
589
|
if (identity) {
|
package/dist/stream.js
CHANGED
|
@@ -363,6 +363,7 @@ async function sendAnthropicRequest(options) {
|
|
|
363
363
|
mode: getCache1hPersistentMode(storage),
|
|
364
364
|
}, isFastModePersistentlyEnabled(storage), identity, {
|
|
365
365
|
effortTransitions: options.apiAccount ? [] : options.effortTransitions,
|
|
366
|
+
turnEndNote: storage.turnEndNote,
|
|
366
367
|
thinkingPrefixMismatchBehavior: options.apiAccount
|
|
367
368
|
? 'account-default'
|
|
368
369
|
: getThinkingPrefixMismatchBehavior(storage),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/pi-anthropic-auth",
|
|
3
|
-
"version": "2.1
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"prepublishOnly": "bun run build"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@cortexkit/anthropic-auth-core": "2.1
|
|
39
|
+
"@cortexkit/anthropic-auth-core": "2.2.1"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@earendil-works/pi-ai": ">=0.86.1 <2",
|