@cortexkit/pi-anthropic-auth 1.1.3 → 1.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.
@@ -1,2 +1,2 @@
1
- import type { ExtensionAPI } from '@mariozechner/pi-coding-agent';
1
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
2
  export declare function registerCommands(pi: ExtensionAPI): void;
package/dist/convert.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type Cache1hMode, type ClaudeCodeIdentity } from '@cortexkit/anthropic-auth-core';
2
- import type { Context, SimpleStreamOptions, Tool } from '@mariozechner/pi-ai';
2
+ import type { Context, SimpleStreamOptions, Tool } from '@earendil-works/pi-ai';
3
3
  export type AnthropicRequestBody = {
4
4
  model: string;
5
5
  max_tokens: number;
package/dist/convert.js CHANGED
@@ -14,6 +14,14 @@ const CLAUDE_CODE_TOOLS = new Map([
14
14
  function sanitize(text) {
15
15
  return text.replace(/[\uD800-\uDFFF]/g, '\uFFFD');
16
16
  }
17
+ function sanitizeToolId(id) {
18
+ if (!id)
19
+ return 'tool_call_unknown';
20
+ const sanitized = id.replace(/[^a-zA-Z0-9_-]/g, '_');
21
+ if (!sanitized)
22
+ return 'tool_call_unknown';
23
+ return sanitized.slice(0, 256);
24
+ }
17
25
  function toClaudeCodeToolName(name) {
18
26
  return CLAUDE_CODE_TOOLS.get(name.toLowerCase()) ?? name;
19
27
  }
@@ -28,10 +36,13 @@ function convertTextAndImages(content) {
28
36
  .map((item) => sanitize(item.text))
29
37
  .join('\n');
30
38
  }
31
- const blocks = content.map((item) => {
39
+ const blocks = content
40
+ .map((item) => {
32
41
  if (item.type === 'text') {
33
42
  return { type: 'text', text: sanitize(item.text) };
34
43
  }
44
+ if (!item.data)
45
+ return null;
35
46
  return {
36
47
  type: 'image',
37
48
  source: {
@@ -40,7 +51,8 @@ function convertTextAndImages(content) {
40
51
  data: item.data,
41
52
  },
42
53
  };
43
- });
54
+ })
55
+ .filter((block) => block !== null);
44
56
  if (!blocks.some((block) => block.type === 'text')) {
45
57
  blocks.unshift({ type: 'text', text: '(see attached image)' });
46
58
  }
@@ -88,7 +100,7 @@ function convertMessages(messages) {
88
100
  else if (block.type === 'toolCall') {
89
101
  blocks.push({
90
102
  type: 'tool_use',
91
- id: block.id,
103
+ id: sanitizeToolId(block.id),
92
104
  name: toClaudeCodeToolName(block.name),
93
105
  input: block.arguments,
94
106
  });
@@ -101,20 +113,34 @@ function convertMessages(messages) {
101
113
  if (message.role === 'toolResult') {
102
114
  const toolResult = message;
103
115
  const toolResults = [];
116
+ const firstContent = convertTextAndImages(toolResult.content);
117
+ const firstContentArr = Array.isArray(firstContent)
118
+ ? firstContent
119
+ : [{ type: 'text', text: firstContent }];
120
+ if (toolResult.isError && firstContentArr.length === 0) {
121
+ firstContentArr.push({ type: 'text', text: 'Error' });
122
+ }
104
123
  toolResults.push({
105
124
  type: 'tool_result',
106
- tool_use_id: toolResult.toolCallId,
107
- content: convertTextAndImages(toolResult.content),
125
+ tool_use_id: sanitizeToolId(toolResult.toolCallId),
126
+ content: firstContentArr,
108
127
  is_error: toolResult.isError,
109
128
  });
110
129
  let nextIndex = index + 1;
111
130
  while (nextIndex < messages.length &&
112
131
  messages[nextIndex]?.role === 'toolResult') {
113
132
  const next = messages[nextIndex];
133
+ const nextContent = convertTextAndImages(next.content);
134
+ const nextContentArr = Array.isArray(nextContent)
135
+ ? nextContent
136
+ : [{ type: 'text', text: nextContent }];
137
+ if (next.isError && nextContentArr.length === 0) {
138
+ nextContentArr.push({ type: 'text', text: 'Error' });
139
+ }
114
140
  toolResults.push({
115
141
  type: 'tool_result',
116
- tool_use_id: next.toolCallId,
117
- content: convertTextAndImages(next.content),
142
+ tool_use_id: sanitizeToolId(next.toolCallId),
143
+ content: nextContentArr,
118
144
  is_error: next.isError,
119
145
  });
120
146
  nextIndex += 1;
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import type { ExtensionAPI } from '@mariozechner/pi-coding-agent';
1
+ import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
2
2
  export default function cortexKitPiAnthropicAuth(pi: ExtensionAPI): void;
package/dist/stream.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { type Api, type AssistantMessageEventStream, type Context, type Model, type SimpleStreamOptions } from '@mariozechner/pi-ai';
1
+ import { type Api, type AssistantMessageEventStream, type Context, type Model, type SimpleStreamOptions } from '@earendil-works/pi-ai';
2
2
  export declare function streamCortexKitAnthropic(model: Model<Api>, context: Context, options?: SimpleStreamOptions): AssistantMessageEventStream;
package/dist/stream.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { applyClaudeCodeHeaders, CACHE_KEEP_EXTENDED_TTL_BETA, CacheKeepManager, FAST_MODE_BETA, FallbackAccountManager, getCache1hPersistentMode, getRelayConfig, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isFastModePersistentlyEnabled, loadAccounts, mergeAnthropicBetas, resolveClaudeCodeIdentity, sendViaRelay, shouldFallbackStatus, } from '@cortexkit/anthropic-auth-core';
2
- import { calculateCost, createAssistantMessageEventStream, } from '@mariozechner/pi-ai';
2
+ import { calculateCost, createAssistantMessageEventStream, } from '@earendil-works/pi-ai';
3
3
  import { buildAnthropicRequest, fromClaudeCodeToolName } from "./convert.js";
4
4
  import { getPiAccountStoragePath } from "./paths.js";
5
5
  const cacheKeepManager = new CacheKeepManager({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cortexkit/pi-anthropic-auth",
3
- "version": "1.1.3",
3
+ "version": "1.2.1",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,10 +35,11 @@
35
35
  "prepublishOnly": "bun run build"
36
36
  },
37
37
  "dependencies": {
38
- "@cortexkit/anthropic-auth-core": "1.1.3"
38
+ "@cortexkit/anthropic-auth-core": "1.2.1"
39
39
  },
40
40
  "peerDependencies": {
41
- "@mariozechner/pi-ai": "*",
42
- "@mariozechner/pi-coding-agent": "*"
41
+ "@earendil-works/pi-ai": "*",
42
+ "@earendil-works/pi-coding-agent": "*",
43
+ "@earendil-works/pi-tui": "*"
43
44
  }
44
45
  }