@eiei114/pi-sub-shared 1.5.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.
Files changed (3) hide show
  1. package/README.md +58 -0
  2. package/index.ts +224 -0
  3. package/package.json +23 -0
package/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # @eiei114/pi-sub-shared
2
+
3
+ Shared types, metadata, and event contracts for the `sub-*` ecosystem.
4
+
5
+ This package is consumed by `sub-core` and `sub-bar` to keep provider metadata, usage types, and model multipliers consistent. For repo setup and extension installation, see the root [pi-sub README](../../README.md).
6
+
7
+ ## Overview
8
+
9
+ ### Installation
10
+
11
+ ```bash
12
+ npm install @eiei114/pi-sub-shared
13
+ ```
14
+
15
+ ### Usage
16
+
17
+ ```ts
18
+ import {
19
+ PROVIDERS,
20
+ ProviderName,
21
+ UsageSnapshot,
22
+ getDefaultCoreSettings,
23
+ } from "@eiei114/pi-sub-shared";
24
+
25
+ const defaults = getDefaultCoreSettings();
26
+ const provider: ProviderName = "anthropic";
27
+ const snapshot: UsageSnapshot = {
28
+ provider,
29
+ displayName: "Anthropic (Claude)",
30
+ windows: [],
31
+ };
32
+
33
+ console.log(PROVIDERS, defaults, snapshot);
34
+ ```
35
+
36
+ ### Exports
37
+
38
+ - `PROVIDERS`, `ProviderName`
39
+ - `RateWindow`, `UsageSnapshot`, `ProviderUsageEntry`
40
+ - `UsageError`, `UsageErrorCode`
41
+ - `ProviderStatus`, `StatusIndicator`
42
+ - `CoreSettings`, `CoreProviderSettings`, `CoreProviderSettingsMap`
43
+ - `BehaviorSettings`, `DEFAULT_BEHAVIOR_SETTINGS`
44
+ - `getDefaultCoreSettings`, `getDefaultCoreProviderSettings`
45
+ - `SubCoreState`, `SubCoreAllState`, `SubCoreEvents`
46
+ - `ProviderMetadata`, `ProviderDetectionConfig`, `ProviderStatusConfig`
47
+ - `PROVIDER_METADATA`, `PROVIDER_DISPLAY_NAMES`
48
+ - `MODEL_MULTIPLIERS`
49
+
50
+ ## Development
51
+
52
+ ```bash
53
+ npm run check
54
+ ```
55
+
56
+ ## Related docs
57
+
58
+ - Root README: [../../README.md](../../README.md)
package/index.ts ADDED
@@ -0,0 +1,224 @@
1
+ /**
2
+ * Shared types and metadata for sub-* extensions.
3
+ */
4
+
5
+ export const PROVIDERS = ["anthropic", "copilot", "gemini", "antigravity", "codex", "kiro", "zai"] as const;
6
+
7
+ export type ProviderName = (typeof PROVIDERS)[number];
8
+
9
+ export type StatusIndicator = "none" | "minor" | "major" | "critical" | "maintenance" | "unknown";
10
+
11
+ export interface ProviderStatus {
12
+ indicator: StatusIndicator;
13
+ description?: string;
14
+ }
15
+
16
+ export interface RateWindow {
17
+ label: string;
18
+ usedPercent: number;
19
+ resetDescription?: string;
20
+ resetAt?: string;
21
+ }
22
+
23
+ export interface UsageSnapshot {
24
+ provider: ProviderName;
25
+ displayName: string;
26
+ windows: RateWindow[];
27
+ extraUsageEnabled?: boolean;
28
+ fiveHourUsage?: number;
29
+ lastSuccessAt?: number;
30
+ error?: UsageError;
31
+ status?: ProviderStatus;
32
+ requestsSummary?: string;
33
+ requestsRemaining?: number;
34
+ requestsEntitlement?: number;
35
+ }
36
+
37
+ export type UsageErrorCode =
38
+ | "NO_CREDENTIALS"
39
+ | "NO_CLI"
40
+ | "NOT_LOGGED_IN"
41
+ | "FETCH_FAILED"
42
+ | "HTTP_ERROR"
43
+ | "API_ERROR"
44
+ | "TIMEOUT"
45
+ | "UNKNOWN";
46
+
47
+ export interface UsageError {
48
+ code: UsageErrorCode;
49
+ message: string;
50
+ httpStatus?: number;
51
+ }
52
+
53
+ export interface ProviderUsageEntry {
54
+ provider: ProviderName;
55
+ usage?: UsageSnapshot;
56
+ }
57
+
58
+ export type ProviderEnabledSetting = "auto" | "on" | "off" | boolean;
59
+
60
+ export interface CoreProviderSettings {
61
+ enabled: ProviderEnabledSetting;
62
+ displayName?: string;
63
+ fetchStatus: boolean;
64
+ extraUsageCurrencySymbol?: string;
65
+ extraUsageDecimalSeparator?: "." | ",";
66
+ }
67
+
68
+ export interface CoreProviderSettingsMap {
69
+ anthropic: CoreProviderSettings;
70
+ copilot: CoreProviderSettings;
71
+ gemini: CoreProviderSettings;
72
+ antigravity: CoreProviderSettings;
73
+ codex: CoreProviderSettings;
74
+ kiro: CoreProviderSettings;
75
+ zai: CoreProviderSettings;
76
+ }
77
+
78
+ export interface BehaviorSettings {
79
+ refreshInterval: number;
80
+ minRefreshInterval: number;
81
+ refreshOnTurnStart: boolean;
82
+ refreshOnToolResult: boolean;
83
+ }
84
+
85
+ export const DEFAULT_BEHAVIOR_SETTINGS: BehaviorSettings = {
86
+ refreshInterval: 60,
87
+ minRefreshInterval: 10,
88
+ refreshOnTurnStart: false,
89
+ refreshOnToolResult: false,
90
+ };
91
+
92
+ export function getDefaultCoreProviderSettings(): CoreProviderSettingsMap {
93
+ const defaults = {} as CoreProviderSettingsMap;
94
+ for (const provider of PROVIDERS) {
95
+ defaults[provider] = {
96
+ enabled: "auto" as ProviderEnabledSetting,
97
+ fetchStatus: Boolean(PROVIDER_METADATA[provider]?.status),
98
+ };
99
+ }
100
+ return defaults;
101
+ }
102
+
103
+ export function getDefaultCoreSettings(): CoreSettings {
104
+ return {
105
+ providers: getDefaultCoreProviderSettings(),
106
+ behavior: { ...DEFAULT_BEHAVIOR_SETTINGS },
107
+ statusRefresh: { ...DEFAULT_BEHAVIOR_SETTINGS },
108
+ providerOrder: [...PROVIDERS],
109
+ defaultProvider: null,
110
+ };
111
+ }
112
+
113
+ export interface CoreSettings {
114
+ providers: CoreProviderSettingsMap;
115
+ behavior: BehaviorSettings;
116
+ statusRefresh: BehaviorSettings;
117
+ providerOrder: ProviderName[];
118
+ defaultProvider: ProviderName | null;
119
+ }
120
+
121
+ export type SubCoreState = {
122
+ provider?: ProviderName;
123
+ usage?: UsageSnapshot;
124
+ };
125
+
126
+ export type SubCoreAllState = {
127
+ provider?: ProviderName;
128
+ entries: ProviderUsageEntry[];
129
+ };
130
+
131
+ export type SubCoreEvents =
132
+ | { type: "sub-core:ready"; state: SubCoreState }
133
+ | { type: "sub-core:update-current"; state: SubCoreState }
134
+ | { type: "sub-core:update-all"; state: SubCoreAllState };
135
+
136
+ export interface StatusPageComponentMatch {
137
+ id?: string;
138
+ name?: string;
139
+ }
140
+
141
+ export type ProviderStatusConfig =
142
+ | { type: "statuspage"; url: string; component?: StatusPageComponentMatch }
143
+ | { type: "google-workspace" };
144
+
145
+ export interface ProviderDetectionConfig {
146
+ providerTokens: string[];
147
+ modelTokens: string[];
148
+ }
149
+
150
+ export interface ProviderMetadata {
151
+ displayName: string;
152
+ detection?: ProviderDetectionConfig;
153
+ status?: ProviderStatusConfig;
154
+ }
155
+
156
+ export const PROVIDER_METADATA: Record<ProviderName, ProviderMetadata> = {
157
+ anthropic: {
158
+ displayName: "Anthropic (Claude)",
159
+ status: { type: "statuspage", url: "https://status.anthropic.com/api/v2/status.json" },
160
+ detection: { providerTokens: ["anthropic"], modelTokens: ["claude"] },
161
+ },
162
+ copilot: {
163
+ displayName: "GitHub Copilot",
164
+ status: { type: "statuspage", url: "https://www.githubstatus.com/api/v2/status.json" },
165
+ detection: { providerTokens: ["copilot", "github"], modelTokens: [] },
166
+ },
167
+ gemini: {
168
+ displayName: "Google Gemini",
169
+ status: { type: "google-workspace" },
170
+ detection: { providerTokens: ["google", "gemini"], modelTokens: ["gemini"] },
171
+ },
172
+ antigravity: {
173
+ displayName: "Antigravity",
174
+ status: { type: "google-workspace" },
175
+ detection: { providerTokens: ["antigravity"], modelTokens: ["antigravity"] },
176
+ },
177
+ codex: {
178
+ displayName: "OpenAI Codex",
179
+ status: {
180
+ type: "statuspage",
181
+ url: "https://status.openai.com/api/v2/status.json",
182
+ component: {
183
+ id: "01JVCV8YSWZFRSM1G5CVP253SK",
184
+ name: "Codex",
185
+ },
186
+ },
187
+ detection: { providerTokens: ["openai", "codex"], modelTokens: ["gpt", "o1", "o3"] },
188
+ },
189
+ kiro: {
190
+ displayName: "AWS Kiro",
191
+ detection: { providerTokens: ["kiro", "aws"], modelTokens: [] },
192
+ },
193
+ zai: {
194
+ displayName: "z.ai",
195
+ detection: { providerTokens: ["zai", "z.ai", "xai"], modelTokens: [] },
196
+ },
197
+ };
198
+
199
+ export const PROVIDER_DISPLAY_NAMES = Object.fromEntries(
200
+ PROVIDERS.map((provider) => [provider, PROVIDER_METADATA[provider].displayName])
201
+ ) as Record<ProviderName, string>;
202
+
203
+ export const MODEL_MULTIPLIERS: Record<string, number> = {
204
+ "Claude Haiku 4.5": 0.33,
205
+ "Claude Opus 4.1": 10,
206
+ "Claude Opus 4.5": 3,
207
+ "Claude Sonnet 4": 1,
208
+ "Claude Sonnet 4.5": 1,
209
+ "Gemini 2.5 Pro": 1,
210
+ "Gemini 3 Flash": 0.33,
211
+ "Gemini 3 Pro": 1,
212
+ "GPT-4.1": 0,
213
+ "GPT-4o": 0,
214
+ "GPT-5": 1,
215
+ "GPT-5 mini": 0,
216
+ "GPT-5-Codex": 1,
217
+ "GPT-5.1": 1,
218
+ "GPT-5.1-Codex": 1,
219
+ "GPT-5.1-Codex-Mini": 0.33,
220
+ "GPT-5.1-Codex-Max": 1,
221
+ "GPT-5.2": 1,
222
+ "Grok Code Fast 1": 0.25,
223
+ "Raptor mini": 0,
224
+ };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@eiei114/pi-sub-shared",
3
+ "version": "1.5.1",
4
+ "description": "Shared types and event contract for the sub-* ecosystem",
5
+ "type": "module",
6
+ "publishConfig": {
7
+ "access": "public",
8
+ "registry": "https://registry.npmjs.org"
9
+ },
10
+ "files": [
11
+ "index.ts",
12
+ "README.md"
13
+ ],
14
+ "main": "./index.ts",
15
+ "types": "./index.ts",
16
+ "scripts": {
17
+ "check": "tsc --noEmit",
18
+ "check:watch": "tsc --noEmit --watch"
19
+ },
20
+ "devDependencies": {
21
+ "typescript": "^5.8.0"
22
+ }
23
+ }