dsh-plugin-subscription-usage 0.0.0-stage → 0.1.0
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/LICENSE +22 -0
- package/README.md +38 -2
- package/cordis.patch.yml +5 -0
- package/icon.svg +9 -0
- package/lib/auth/claude-code-creds.d.ts +23 -0
- package/lib/auth/claude-code-creds.js +172 -0
- package/lib/auth/device-flow.d.ts +55 -0
- package/lib/auth/device-flow.js +177 -0
- package/lib/auth/jwt.d.ts +10 -0
- package/lib/auth/jwt.js +25 -0
- package/lib/auth/oauth-flow.d.ts +91 -0
- package/lib/auth/oauth-flow.js +227 -0
- package/lib/auth/pkce.d.ts +31 -0
- package/lib/auth/pkce.js +35 -0
- package/lib/auth/rpc.d.ts +233 -0
- package/lib/auth/rpc.js +501 -0
- package/lib/auth/store.d.ts +198 -0
- package/lib/auth/store.js +473 -0
- package/lib/client/Footer.d.ts +3 -0
- package/lib/client/Footer.js +73 -0
- package/lib/client/Gauge.d.ts +28 -0
- package/lib/client/Gauge.js +139 -0
- package/lib/client/ImageGallery.d.ts +54 -0
- package/lib/client/ImageGallery.js +112 -0
- package/lib/client/ImageGenerateToolview.d.ts +48 -0
- package/lib/client/ImageGenerateToolview.js +130 -0
- package/lib/client/Notice.d.ts +15 -0
- package/lib/client/Notice.js +93 -0
- package/lib/client/ProviderCard.d.ts +35 -0
- package/lib/client/ProviderCard.js +240 -0
- package/lib/client/SpeedSelect.d.ts +72 -0
- package/lib/client/SpeedSelect.js +214 -0
- package/lib/client/Usage.d.ts +7 -0
- package/lib/client/Usage.js +83 -0
- package/lib/client/VideoGenerateToolview.d.ts +42 -0
- package/lib/client/VideoGenerateToolview.js +172 -0
- package/lib/client/context.d.ts +16 -0
- package/lib/client/context.js +11 -0
- package/lib/client/fast-command.d.ts +2 -0
- package/lib/client/fast-command.js +4 -0
- package/lib/client/hooks.d.ts +2 -0
- package/lib/client/hooks.js +10 -0
- package/lib/client/index.d.ts +3 -0
- package/lib/client/index.js +113 -0
- package/lib/client/locales.d.ts +139 -0
- package/lib/client/locales.js +267 -0
- package/lib/client/meter.d.ts +91 -0
- package/lib/client/meter.js +196 -0
- package/lib/client/prefs.d.ts +51 -0
- package/lib/client/prefs.js +71 -0
- package/lib/client/rpc.d.ts +161 -0
- package/lib/client/rpc.js +31 -0
- package/lib/client/store.d.ts +67 -0
- package/lib/client/store.js +129 -0
- package/lib/client/styles.d.ts +7 -0
- package/lib/client/styles.js +176 -0
- package/lib/client.js +3933 -0
- package/lib/client.js.map +1 -0
- package/lib/compat.d.ts +55 -0
- package/lib/compat.js +20 -0
- package/lib/http.d.ts +134 -0
- package/lib/http.js +431 -0
- package/lib/index.d.ts +121 -0
- package/lib/index.js +13210 -0
- package/lib/json-text.d.ts +2 -0
- package/lib/json-text.js +4 -0
- package/lib/model-defaults.d.ts +23 -0
- package/lib/model-defaults.js +238 -0
- package/lib/model-speeds.d.ts +10 -0
- package/lib/model-speeds.js +48 -0
- package/lib/models-directory.d.ts +17 -0
- package/lib/models-directory.js +25 -0
- package/lib/provider-settings.d.ts +55 -0
- package/lib/provider-settings.js +215 -0
- package/lib/providers/account-preferences.d.ts +46 -0
- package/lib/providers/account-preferences.js +188 -0
- package/lib/providers/accounts.d.ts +113 -0
- package/lib/providers/accounts.js +142 -0
- package/lib/providers/antigravity-oauth-client.d.ts +7 -0
- package/lib/providers/antigravity-oauth-client.js +7 -0
- package/lib/providers/antigravity.d.ts +119 -0
- package/lib/providers/antigravity.js +552 -0
- package/lib/providers/catalog-refresh.d.ts +4 -0
- package/lib/providers/catalog-refresh.js +30 -0
- package/lib/providers/catalog-store.d.ts +47 -0
- package/lib/providers/catalog-store.js +283 -0
- package/lib/providers/claude-cli-version.d.ts +15 -0
- package/lib/providers/claude-cli-version.js +24 -0
- package/lib/providers/claude.d.ts +212 -0
- package/lib/providers/claude.js +726 -0
- package/lib/providers/codex-client-version.d.ts +8 -0
- package/lib/providers/codex-client-version.js +17 -0
- package/lib/providers/codex-search.d.ts +29 -0
- package/lib/providers/codex-search.js +198 -0
- package/lib/providers/codex.d.ts +253 -0
- package/lib/providers/codex.js +930 -0
- package/lib/providers/common.d.ts +415 -0
- package/lib/providers/common.js +679 -0
- package/lib/providers/copilot.d.ts +365 -0
- package/lib/providers/copilot.js +956 -0
- package/lib/providers/grok.d.ts +214 -0
- package/lib/providers/grok.js +750 -0
- package/lib/providers/image-pool.d.ts +30 -0
- package/lib/providers/image-pool.js +89 -0
- package/lib/providers/npm-cli-version.d.ts +56 -0
- package/lib/providers/npm-cli-version.js +98 -0
- package/lib/providers/pool-family.d.ts +56 -0
- package/lib/providers/pool-family.js +45 -0
- package/lib/providers/pool-health.d.ts +91 -0
- package/lib/providers/pool-health.js +164 -0
- package/lib/providers/pool-usage.d.ts +106 -0
- package/lib/providers/pool-usage.js +302 -0
- package/lib/providers/pool.d.ts +115 -0
- package/lib/providers/pool.js +461 -0
- package/lib/providers/rate-limit.d.ts +192 -0
- package/lib/providers/rate-limit.js +338 -0
- package/lib/providers/replay.d.ts +4 -0
- package/lib/providers/replay.js +37 -0
- package/lib/providers/reset-redemption.d.ts +20 -0
- package/lib/providers/reset-redemption.js +70 -0
- package/lib/tools/image-generate.d.ts +128 -0
- package/lib/tools/image-generate.js +438 -0
- package/lib/tools/registration.d.ts +15 -0
- package/lib/tools/registration.js +24 -0
- package/lib/tools/video-generate.d.ts +89 -0
- package/lib/tools/video-generate.js +257 -0
- package/lib/tools/x-search.d.ts +58 -0
- package/lib/tools/x-search.js +197 -0
- package/lib/translate/anthropic.d.ts +180 -0
- package/lib/translate/anthropic.js +534 -0
- package/lib/translate/antigravity-images.d.ts +11 -0
- package/lib/translate/antigravity-images.js +62 -0
- package/lib/translate/antigravity-schema.d.ts +4 -0
- package/lib/translate/antigravity-schema.js +145 -0
- package/lib/translate/antigravity-thinking.d.ts +5 -0
- package/lib/translate/antigravity-thinking.js +44 -0
- package/lib/translate/antigravity.d.ts +120 -0
- package/lib/translate/antigravity.js +412 -0
- package/lib/translate/chat-completions.d.ts +120 -0
- package/lib/translate/chat-completions.js +382 -0
- package/lib/translate/resolved.d.ts +98 -0
- package/lib/translate/resolved.js +186 -0
- package/lib/translate/responses.d.ts +192 -0
- package/lib/translate/responses.js +443 -0
- package/lib/translate/sse.d.ts +21 -0
- package/lib/translate/sse.js +62 -0
- package/lib/usage/headers.d.ts +21 -0
- package/lib/usage/headers.js +64 -0
- package/lib/usage/pace.d.ts +53 -0
- package/lib/usage/pace.js +48 -0
- package/lib/usage/service.d.ts +64 -0
- package/lib/usage/service.js +104 -0
- package/lib/usage-providers/common.d.ts +23 -0
- package/lib/usage-providers/common.js +28 -0
- package/lib/usage-providers/index.d.ts +42 -0
- package/lib/usage-providers/index.js +71 -0
- package/lib/usage-providers/keys.d.ts +11 -0
- package/lib/usage-providers/keys.js +52 -0
- package/lib/usage-providers/kimi.d.ts +4 -0
- package/lib/usage-providers/kimi.js +52 -0
- package/lib/usage-providers/ollama-cloud.d.ts +4 -0
- package/lib/usage-providers/ollama-cloud.js +42 -0
- package/lib/usage-providers/zai.d.ts +5 -0
- package/lib/usage-providers/zai.js +53 -0
- package/locale/en.json +6 -0
- package/locale/zh.json +6 -0
- package/package.json +115 -4
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Translate between the harness message vocabulary and the Anthropic Messages
|
|
3
|
+
* API wire format used by the claude provider: request message assembly, tool
|
|
4
|
+
* schema mapping, and a push-model SSE-event → StreamChunk state machine
|
|
5
|
+
* ({@link AnthropicStreamTranslator}) so tests need no streams.
|
|
6
|
+
*/
|
|
7
|
+
import { LlmError } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
import type { StreamChunk, ToolSchema } from '@deepseek-ai/dsh-llm';
|
|
9
|
+
import type { TranslatableMessage } from './resolved.js';
|
|
10
|
+
/**
|
|
11
|
+
* The Claude Code identity block. The subscription endpoint rejects requests
|
|
12
|
+
* that do not present as Claude Code, so this block is REQUIRED as the first
|
|
13
|
+
* system entry on every request.
|
|
14
|
+
*/
|
|
15
|
+
export declare const CLAUDE_CODE_IDENTITY = "You are Claude Code, Anthropic's official CLI for Claude.";
|
|
16
|
+
/** Tags wrapping a mid-conversation system message where it sits in the history. */
|
|
17
|
+
export declare const SYSTEM_REMINDER_OPEN = "<system-reminder>";
|
|
18
|
+
export declare const SYSTEM_REMINDER_CLOSE = "</system-reminder>";
|
|
19
|
+
/**
|
|
20
|
+
* How far apart consecutive message breakpoints sit, in content blocks.
|
|
21
|
+
*
|
|
22
|
+
* A breakpoint looks back at most 20 blocks for an entry an earlier request
|
|
23
|
+
* wrote, so marks must stay closer than that: one agentic turn can append a
|
|
24
|
+
* dozen tool_use/tool_result blocks at once, and a single trailing mark would
|
|
25
|
+
* silently fall out of range and rebuild the whole prefix.
|
|
26
|
+
*/
|
|
27
|
+
export declare const CACHE_BLOCK_STRIDE = 15;
|
|
28
|
+
/**
|
|
29
|
+
* Message breakpoints per request. Anthropic allows four in total and the
|
|
30
|
+
* last `system` block takes the fourth, so three are left for the history —
|
|
31
|
+
* enough to tolerate a turn appending roughly {@link CACHE_BLOCK_STRIDE} × 3
|
|
32
|
+
* blocks before a read is lost.
|
|
33
|
+
*/
|
|
34
|
+
export declare const MESSAGE_CACHE_BREAKPOINTS = 3;
|
|
35
|
+
/**
|
|
36
|
+
* How long Anthropic keeps a cache entry after its last use: five minutes
|
|
37
|
+
* (the API default) or one hour. A one-hour entry is written at twice the base
|
|
38
|
+
* input price instead of 1.25×, and reads cost the same either way.
|
|
39
|
+
*/
|
|
40
|
+
export type PromptCacheTtl = '5m' | '1h';
|
|
41
|
+
/** The API default; a marker at this TTL carries no `ttl` field at all. */
|
|
42
|
+
export declare const DEFAULT_PROMPT_CACHE_TTL: PromptCacheTtl;
|
|
43
|
+
/**
|
|
44
|
+
* Build one `cache_control` marker.
|
|
45
|
+
*
|
|
46
|
+
* Five minutes is spelled by omitting `ttl`, so a request that does not opt in
|
|
47
|
+
* stays byte-identical to what earlier releases sent.
|
|
48
|
+
* @param ttl - cache lifetime; defaults to five minutes.
|
|
49
|
+
* @returns a fresh marker object (callers attach it to one block each).
|
|
50
|
+
*/
|
|
51
|
+
export declare function cacheControl(ttl?: PromptCacheTtl): Record<string, unknown>;
|
|
52
|
+
/** One Anthropic request message. */
|
|
53
|
+
export interface AnthropicMessage {
|
|
54
|
+
role: 'user' | 'assistant';
|
|
55
|
+
content: Record<string, unknown>[];
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Convert harness messages into Anthropic messages. Consecutive same-role
|
|
59
|
+
* messages merge into one message with multiple content blocks; tool results
|
|
60
|
+
* arrive as user messages with `tool_result` blocks, which a merged user
|
|
61
|
+
* message keeps in one leading run ({@link leadWithToolResults}); system-role
|
|
62
|
+
* messages before the conversation starts are handled by
|
|
63
|
+
* {@link toAnthropicSystem} and skipped here, while a later one rides in
|
|
64
|
+
* place as a user-role `<system-reminder>` block.
|
|
65
|
+
* Reasoning blocks are not replayed (v1). Images must arrive pre-resolved
|
|
66
|
+
* ({@link TranslatableMessage}); an unresolved ImageBlock is skipped because
|
|
67
|
+
* its bytes are unreachable here.
|
|
68
|
+
* @param messages - ordered conversation messages with resolved images.
|
|
69
|
+
* @returns Anthropic messages in conversation order.
|
|
70
|
+
*/
|
|
71
|
+
export declare function toAnthropicMessages(messages: readonly TranslatableMessage[]): AnthropicMessage[];
|
|
72
|
+
/**
|
|
73
|
+
* Mark the conversation's cache breakpoints in place: the last content block,
|
|
74
|
+
* then one every {@link CACHE_BLOCK_STRIDE} blocks backwards, {@link
|
|
75
|
+
* MESSAGE_CACHE_BREAKPOINTS} in total.
|
|
76
|
+
*
|
|
77
|
+
* The history is append-only, so the block one request marks last is
|
|
78
|
+
* byte-identical in the next — that entry is what the next request reads.
|
|
79
|
+
* Marks are counted across the flattened block sequence, not per message,
|
|
80
|
+
* because the lookback window Anthropic walks counts blocks the same way.
|
|
81
|
+
* @param messages - assembled Anthropic messages, marked in place.
|
|
82
|
+
* @param ttl - cache lifetime for every mark; defaults to five minutes.
|
|
83
|
+
*/
|
|
84
|
+
export declare function markMessageCache(messages: readonly AnthropicMessage[], ttl?: PromptCacheTtl): void;
|
|
85
|
+
/**
|
|
86
|
+
* Build the Anthropic `system` array: the mandatory Claude Code identity
|
|
87
|
+
* block, then the explicit system prompt, then any system-role messages.
|
|
88
|
+
* @param system - explicit system prompt, when set.
|
|
89
|
+
* @param messages - conversation messages; the system-role text preceding the
|
|
90
|
+
* conversation is appended, and a later one is left to {@link toAnthropicMessages}.
|
|
91
|
+
* @param ttl - cache lifetime for the tools+system mark; defaults to five minutes.
|
|
92
|
+
* @returns the system content blocks.
|
|
93
|
+
*/
|
|
94
|
+
export declare function toAnthropicSystem(system?: string, messages?: readonly TranslatableMessage[], ttl?: PromptCacheTtl): Record<string, unknown>[];
|
|
95
|
+
/**
|
|
96
|
+
* Map harness tool schemas to Anthropic tools, in name order.
|
|
97
|
+
*
|
|
98
|
+
* `tools` renders at position 0 of the cached prefix, so any reordering
|
|
99
|
+
* invalidates every cache entry behind it — `system` and the whole
|
|
100
|
+
* conversation included. Registration order belongs to the caller and plugin
|
|
101
|
+
* load order can differ between processes, so the wire order is fixed here
|
|
102
|
+
* instead. Anthropic selects a tool by name; the array order carries nothing.
|
|
103
|
+
* @param tools - tool schemas from the request.
|
|
104
|
+
* @returns Anthropic `tools` array entries, ordered by tool name.
|
|
105
|
+
*/
|
|
106
|
+
export declare function toAnthropicTools(tools: readonly ToolSchema[]): Record<string, unknown>[];
|
|
107
|
+
/** The subset of Anthropic SSE event shapes this translator reads. */
|
|
108
|
+
export interface AnthropicStreamEvent {
|
|
109
|
+
type: string;
|
|
110
|
+
index?: number;
|
|
111
|
+
message?: {
|
|
112
|
+
usage?: {
|
|
113
|
+
input_tokens?: number;
|
|
114
|
+
output_tokens?: number;
|
|
115
|
+
cache_read_input_tokens?: number;
|
|
116
|
+
cache_creation_input_tokens?: number;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
content_block?: {
|
|
120
|
+
type?: string;
|
|
121
|
+
id?: string;
|
|
122
|
+
name?: string;
|
|
123
|
+
};
|
|
124
|
+
delta?: {
|
|
125
|
+
type?: string;
|
|
126
|
+
text?: string;
|
|
127
|
+
thinking?: string;
|
|
128
|
+
partial_json?: string;
|
|
129
|
+
stop_reason?: string;
|
|
130
|
+
};
|
|
131
|
+
usage?: {
|
|
132
|
+
output_tokens?: number;
|
|
133
|
+
};
|
|
134
|
+
error?: {
|
|
135
|
+
type?: string;
|
|
136
|
+
message?: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Classify an Anthropic `error` event into a thrown LlmError.
|
|
141
|
+
* @param error - the wire error object.
|
|
142
|
+
* @returns the mapped error.
|
|
143
|
+
*/
|
|
144
|
+
export declare function anthropicFailure(error: {
|
|
145
|
+
type?: string;
|
|
146
|
+
message?: string;
|
|
147
|
+
} | undefined): LlmError;
|
|
148
|
+
/**
|
|
149
|
+
* Push-model Anthropic SSE translator: feed each parsed event object to
|
|
150
|
+
* {@link push} and collect the emitted harness StreamChunks. Block indexes
|
|
151
|
+
* are allocated in first-seen order; `usage` is emitted before the terminal
|
|
152
|
+
* `finish`, and nothing is emitted after it. `error` events throw
|
|
153
|
+
* {@link LlmError}.
|
|
154
|
+
*/
|
|
155
|
+
export declare class AnthropicStreamTranslator {
|
|
156
|
+
private blocks;
|
|
157
|
+
private nextIndex;
|
|
158
|
+
private sawAnyBlock;
|
|
159
|
+
private pendingUsage;
|
|
160
|
+
private outputTokens;
|
|
161
|
+
private stopReason;
|
|
162
|
+
private usageEmitted;
|
|
163
|
+
/** Set once `message_stop` produced the terminal finish chunk. */
|
|
164
|
+
terminated: boolean;
|
|
165
|
+
private open;
|
|
166
|
+
private emitUsage;
|
|
167
|
+
/**
|
|
168
|
+
* Process one parsed Anthropic SSE event.
|
|
169
|
+
* @param event - the parsed event object.
|
|
170
|
+
* @returns the StreamChunks this event produced (possibly none).
|
|
171
|
+
*/
|
|
172
|
+
push(event: AnthropicStreamEvent): StreamChunk[];
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Consume an Anthropic SSE byte stream and yield harness StreamChunks.
|
|
176
|
+
* @param stream - raw response body.
|
|
177
|
+
* @param onActivity - transport-activity callback for the idle watchdog.
|
|
178
|
+
* @returns the chunk stream; throws when the stream ends before `message_stop`.
|
|
179
|
+
*/
|
|
180
|
+
export declare function streamAnthropic(stream: ReadableStream<Uint8Array>, onActivity?: () => void): AsyncGenerator<StreamChunk>;
|