@cortexkit/pi-anthropic-auth 1.1.1 → 1.1.3
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 +6 -2
- package/dist/commands.js +21 -1
- package/dist/stream.js +35 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -40,7 +40,7 @@ Pi state is stored separately from OpenCode at:
|
|
|
40
40
|
|
|
41
41
|
Override the path with `PI_ANTHROPIC_AUTH_FILE`. The package also respects `PI_AGENT_DIR` when deriving the default sidecar path.
|
|
42
42
|
|
|
43
|
-
The sidecar uses the same JSON shape as the OpenCode package, including `claudeCache`, `claudeFast`, `dump`, `relay`, and fallback `accounts` blocks.
|
|
43
|
+
The sidecar uses the same JSON shape as the OpenCode package, including `claudeCache`, `cacheKeep`, `claudeFast`, `dump`, `relay`, and fallback `accounts` blocks.
|
|
44
44
|
|
|
45
45
|
## Commands
|
|
46
46
|
|
|
@@ -52,6 +52,10 @@ The sidecar uses the same JSON shape as the OpenCode package, including `claudeC
|
|
|
52
52
|
/claude-cache mode automatic
|
|
53
53
|
/claude-cache mode hybrid
|
|
54
54
|
|
|
55
|
+
/claude-cachekeep
|
|
56
|
+
/claude-cachekeep 09-23
|
|
57
|
+
/claude-cachekeep off
|
|
58
|
+
|
|
55
59
|
/claude-dump
|
|
56
60
|
/claude-dump on
|
|
57
61
|
/claude-dump off
|
|
@@ -63,7 +67,7 @@ The sidecar uses the same JSON shape as the OpenCode package, including `claudeC
|
|
|
63
67
|
/claude-quota
|
|
64
68
|
```
|
|
65
69
|
|
|
66
|
-
`/claude-quota` reports sidecar fallback account quota state from `~/.pi/agent/anthropic-auth.json`. `/claude-fast on` adds Anthropic `speed: "fast"` plus the `fast-mode-2026-02-01` beta header for supported Opus models (`claude-opus-4-6` and `claude-opus-4-7`).
|
|
70
|
+
`/claude-quota` reports sidecar fallback account quota state from `~/.pi/agent/anthropic-auth.json`. `/claude-cachekeep HH-HH` keeps recently used hybrid-mode session caches warm during the configured local time window by sending `max_tokens: 0` pre-warm requests about five minutes before the 1-hour TTL expires. `/claude-fast on` adds Anthropic `speed: "fast"` plus the `fast-mode-2026-02-01` beta header for supported Opus models (`claude-opus-4-6` and `claude-opus-4-7`).
|
|
67
71
|
|
|
68
72
|
## Relay
|
|
69
73
|
|
package/dist/commands.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildClaudeQuotaSummary, buildFallbackQuotaSummaries, executeCache1hCommand, executeDumpCommand, executeFastModeCommand, getCache1hPersistentMode, isCache1hPersistentlyEnabled, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, loadAccounts, parseCache1hCommandAction, parseDumpCommandAction, parseFastModeCommandAction, setCache1hPersistentEnabled, setCache1hPersistentMode, setDumpPersistentEnabled, setFastModePersistentEnabled, } from '@cortexkit/anthropic-auth-core';
|
|
1
|
+
import { buildClaudeQuotaSummary, buildFallbackQuotaSummaries, CLAUDE_CACHE_KEEP_COMMAND_NAME, executeCache1hCommand, executeCacheKeepCommand, executeDumpCommand, executeFastModeCommand, getCache1hPersistentMode, getCacheKeepWindow, isCache1hPersistentlyEnabled, isCacheKeepHybridActive, isCacheKeepPersistentlyEnabled, isDumpPersistentlyEnabled, isFastModePersistentlyEnabled, loadAccounts, parseCache1hCommandAction, parseCacheKeepCommandAction, parseDumpCommandAction, parseFastModeCommandAction, setCache1hPersistentEnabled, setCache1hPersistentMode, setCacheKeepPersistentEnabled, setCacheKeepPersistentWindow, setDumpPersistentEnabled, setFastModePersistentEnabled, } from '@cortexkit/anthropic-auth-core';
|
|
2
2
|
import { getPiAccountStoragePath } from "./paths.js";
|
|
3
3
|
function notify(ctx, message, kind = 'info') {
|
|
4
4
|
ctx.ui.notify(message, kind);
|
|
@@ -34,6 +34,26 @@ export function registerCommands(pi) {
|
|
|
34
34
|
}), action.type === 'usage' ? 'warning' : 'info');
|
|
35
35
|
},
|
|
36
36
|
});
|
|
37
|
+
pi.registerCommand(CLAUDE_CACHE_KEEP_COMMAND_NAME, {
|
|
38
|
+
description: 'Keep hybrid Claude cache warm during a local time window',
|
|
39
|
+
handler: async (args, ctx) => {
|
|
40
|
+
const path = getPiAccountStoragePath();
|
|
41
|
+
let storage = await loadAccounts(path);
|
|
42
|
+
const action = parseCacheKeepCommandAction(args ?? '');
|
|
43
|
+
if (action.type === 'window') {
|
|
44
|
+
storage = await setCacheKeepPersistentWindow(action.startHour, action.endHour, path);
|
|
45
|
+
}
|
|
46
|
+
else if (action.type === 'disable') {
|
|
47
|
+
storage = await setCacheKeepPersistentEnabled(false, path);
|
|
48
|
+
}
|
|
49
|
+
notify(ctx, executeCacheKeepCommand({
|
|
50
|
+
argumentsText: args ?? '',
|
|
51
|
+
enabled: isCacheKeepPersistentlyEnabled(storage),
|
|
52
|
+
window: getCacheKeepWindow(storage),
|
|
53
|
+
hybridActive: isCacheKeepHybridActive(storage),
|
|
54
|
+
}), action.type === 'usage' ? 'warning' : 'info');
|
|
55
|
+
},
|
|
56
|
+
});
|
|
37
57
|
pi.registerCommand('claude-dump', {
|
|
38
58
|
description: 'Show or configure Anthropic request/relay dumping',
|
|
39
59
|
handler: async (args, ctx) => {
|
package/dist/stream.js
CHANGED
|
@@ -1,7 +1,33 @@
|
|
|
1
|
-
import { applyClaudeCodeHeaders, FAST_MODE_BETA, FallbackAccountManager, getCache1hPersistentMode, getRelayConfig, isCache1hPersistentlyEnabled, isFastModePersistentlyEnabled, loadAccounts, mergeAnthropicBetas, resolveClaudeCodeIdentity, sendViaRelay, shouldFallbackStatus, } from '@cortexkit/anthropic-auth-core';
|
|
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
2
|
import { calculateCost, createAssistantMessageEventStream, } from '@mariozechner/pi-ai';
|
|
3
3
|
import { buildAnthropicRequest, fromClaudeCodeToolName } from "./convert.js";
|
|
4
4
|
import { getPiAccountStoragePath } from "./paths.js";
|
|
5
|
+
const cacheKeepManager = new CacheKeepManager({
|
|
6
|
+
loadStorage: () => loadAccounts(getPiAccountStoragePath()),
|
|
7
|
+
prepareHeaders: async (headers, target) => {
|
|
8
|
+
const authorization = headers.get('authorization') ?? '';
|
|
9
|
+
const match = /^Bearer\s+(.+)$/i.exec(authorization);
|
|
10
|
+
const accessToken = match?.[1];
|
|
11
|
+
if (!accessToken)
|
|
12
|
+
return headers;
|
|
13
|
+
try {
|
|
14
|
+
const body = JSON.parse(target.bodyText);
|
|
15
|
+
const identity = await resolveClaudeCodeIdentity(accessToken, typeof body.model === 'string' ? body.model : undefined);
|
|
16
|
+
headers.delete('anthropic-beta');
|
|
17
|
+
applyClaudeCodeHeaders(headers, accessToken, { body, identity });
|
|
18
|
+
headers.set('anthropic-beta', mergeAnthropicBetas(headers.get('anthropic-beta'), [
|
|
19
|
+
CACHE_KEEP_EXTENDED_TTL_BETA,
|
|
20
|
+
]));
|
|
21
|
+
if (body.speed === 'fast') {
|
|
22
|
+
headers.set('anthropic-beta', mergeAnthropicBetas(headers.get('anthropic-beta'), [FAST_MODE_BETA]));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
applyClaudeCodeHeaders(headers, accessToken);
|
|
27
|
+
}
|
|
28
|
+
return headers;
|
|
29
|
+
},
|
|
30
|
+
});
|
|
5
31
|
function mapStopReason(reason) {
|
|
6
32
|
switch (reason) {
|
|
7
33
|
case 'end_turn':
|
|
@@ -100,6 +126,14 @@ async function sendAnthropicRequest(options) {
|
|
|
100
126
|
body: bodyText,
|
|
101
127
|
signal: options.streamOptions?.signal,
|
|
102
128
|
};
|
|
129
|
+
await cacheKeepManager.track({
|
|
130
|
+
sessionId: relayAffinity,
|
|
131
|
+
url: input.toString(),
|
|
132
|
+
headers,
|
|
133
|
+
bodyText,
|
|
134
|
+
storage,
|
|
135
|
+
cacheMode: isCacheKeepHybridActive(storage) ? 'hybrid' : 'disabled',
|
|
136
|
+
});
|
|
103
137
|
return sendViaRelay({
|
|
104
138
|
config: getRelayConfig(storage),
|
|
105
139
|
input,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/pi-anthropic-auth",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"prepublishOnly": "bun run build"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@cortexkit/anthropic-auth-core": "1.1.
|
|
38
|
+
"@cortexkit/anthropic-auth-core": "1.1.3"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"@mariozechner/pi-ai": "*",
|