@0xkahi/pi-qol 0.0.1 → 0.0.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 +93 -12
- package/assets/config.schema.json +190 -2
- package/package.json +1 -1
- package/src/config-loader.ts +8 -4
- package/src/constants.ts +20 -0
- package/src/extensions/auto-session-name/index.ts +1 -1
- package/src/extensions/custom-footer/constants.ts +4 -0
- package/src/extensions/custom-footer/footer-component.ts +179 -0
- package/src/extensions/custom-footer/index.ts +18 -0
- package/src/extensions/custom-footer/progress-bar.ts +16 -0
- package/src/extensions/custom-footer/subscription-usage-manager.ts +91 -0
- package/src/extensions/custom-footer/token-stats.ts +144 -0
- package/src/extensions/custom-footer/types.ts +40 -0
- package/src/extensions/model-select/constants.ts +8 -0
- package/src/extensions/model-select/index.ts +119 -0
- package/src/extensions/model-select/model-formatter.ts +60 -0
- package/src/extensions/model-select/model-lists.ts +63 -0
- package/src/extensions/model-select/model-select-dialog.ts +340 -0
- package/src/extensions/model-select/types.ts +31 -0
- package/src/index.ts +4 -0
- package/src/libs/subscription-usage/strategy/anthropic-oauth-usage.strategy.ts +41 -0
- package/src/libs/subscription-usage/strategy/openai-codex-usage.strategy.ts +75 -0
- package/src/libs/subscription-usage/subscription-usage-api.util.ts +78 -0
- package/src/schemas/auto-session-name.config.schema.ts +2 -2
- package/src/schemas/config.schema.ts +11 -0
- package/src/schemas/custom-footer-config.schema.ts +64 -0
- package/src/schemas/model-select.config.schema.ts +18 -0
- package/src/schemas/shared-config.schema.ts +5 -2
- package/src/types.ts +1 -0
- package/src/utils/crayon.util.ts +58 -0
- package/src/utils/model-resolver.util.ts +2 -0
- package/src/utils/path.util.ts +4 -0
- package/src/utils/raw-data-parser.util.ts +14 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
import { ModelConfigSchema } from './shared-config.schema';
|
|
3
|
+
|
|
4
|
+
const FavouriteModelSchema = ModelConfigSchema.omit({ reasoning: true });
|
|
5
|
+
|
|
6
|
+
const ModelSelectLayoutSchema = z.enum(['inline', 'overlay']);
|
|
7
|
+
export type ModelSelectLayout = z.infer<typeof ModelSelectLayoutSchema>;
|
|
8
|
+
|
|
9
|
+
export const ModelSelectConfigSchema = z.object({
|
|
10
|
+
enabled: z.boolean().default(false),
|
|
11
|
+
favourite: z.array(FavouriteModelSchema).default([]),
|
|
12
|
+
provider_filter: z.array(z.string().min(1)).default([]),
|
|
13
|
+
layout: ModelSelectLayoutSchema.default('inline'),
|
|
14
|
+
});
|
|
15
|
+
export type ModelSelectConfig = z.infer<typeof ModelSelectConfigSchema>;
|
|
16
|
+
|
|
17
|
+
export const PartialModelSelectConfigSchema = ModelSelectConfigSchema.partial();
|
|
18
|
+
export type PartialModelSelectConfig = z.infer<typeof PartialModelSelectConfigSchema>;
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
+
import { COLOR_HEX_REGEX } from '../constants';
|
|
2
3
|
|
|
3
4
|
export const ReasoningLevelSchema = z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh']);
|
|
4
5
|
export type ReasoningLevel = z.infer<typeof ReasoningLevelSchema>;
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
+
export const ModelConfigSchema = z.object({
|
|
7
8
|
provider: z.string(),
|
|
8
9
|
modelId: z.string(),
|
|
9
10
|
reasoning: ReasoningLevelSchema,
|
|
10
11
|
});
|
|
11
|
-
export type ModelConfig = z.infer<typeof
|
|
12
|
+
export type ModelConfig = z.infer<typeof ModelConfigSchema>;
|
|
13
|
+
|
|
14
|
+
export const ColorHexSchema = z.string().regex(COLOR_HEX_REGEX, { message: 'Invalid color format. Must be a 7-character hex code (e.g., #RRGGBB).' });
|
package/src/types.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type ObjectValues<T> = T[keyof T];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { COLOR_HEX_REGEX } from '../constants';
|
|
2
|
+
|
|
3
|
+
type ColorizeOptions = {
|
|
4
|
+
bg?: string;
|
|
5
|
+
fg?: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
function hexToRgb(hex: string): { r: number; g: number; b: number } {
|
|
9
|
+
return {
|
|
10
|
+
r: Number.parseInt(hex.slice(1, 3), 16),
|
|
11
|
+
g: Number.parseInt(hex.slice(3, 5), 16),
|
|
12
|
+
b: Number.parseInt(hex.slice(5, 7), 16),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function fgAnsi(hex: string): string {
|
|
17
|
+
const { r, g, b } = hexToRgb(hex);
|
|
18
|
+
return `\x1b[38;2;${r};${g};${b}m`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function bgAnsi(hex: string): string {
|
|
22
|
+
const { r, g, b } = hexToRgb(hex);
|
|
23
|
+
return `\x1b[48;2;${r};${g};${b}m`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function colorize(text: string, { bg, fg }: ColorizeOptions = {}): string {
|
|
27
|
+
const hasFg = fg !== undefined && COLOR_HEX_REGEX.test(fg);
|
|
28
|
+
const hasBg = bg !== undefined && COLOR_HEX_REGEX.test(bg);
|
|
29
|
+
|
|
30
|
+
if (!hasFg && !hasBg) {
|
|
31
|
+
return text;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const prefix = `${hasBg ? bgAnsi(bg) : ''}${hasFg ? fgAnsi(fg) : ''}`;
|
|
35
|
+
const suffix = `${hasFg ? '\x1b[39m' : ''}${hasBg ? '\x1b[49m' : ''}`;
|
|
36
|
+
|
|
37
|
+
return `${prefix}${text}${suffix}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const ANSI_ESCAPE_REGEX = new RegExp(`${String.fromCharCode(27)}\\[[0-?]*[ -/]*[@-~]`, 'g');
|
|
41
|
+
|
|
42
|
+
function stripAnsi(text: string): string {
|
|
43
|
+
return text.replace(ANSI_ESCAPE_REGEX, '');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const crayon = {
|
|
47
|
+
colorize(text: string, opts: ColorizeOptions = {}): string {
|
|
48
|
+
return colorize(text, opts);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
reverseVideo(text: string): string {
|
|
52
|
+
return `\x1b[7m${text}\x1b[27m`;
|
|
53
|
+
},
|
|
54
|
+
|
|
55
|
+
stripAnsi(text: string): string {
|
|
56
|
+
return stripAnsi(text);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -7,6 +7,7 @@ export type ResolvedModel = {
|
|
|
7
7
|
apiKey?: string;
|
|
8
8
|
headers?: Record<string, string>;
|
|
9
9
|
reasoning?: ModelConfig['reasoning'];
|
|
10
|
+
isOauth?: boolean;
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
export type ResolveModelResult = {
|
|
@@ -50,6 +51,7 @@ export class ModelResolver {
|
|
|
50
51
|
apiKey: auth.apiKey,
|
|
51
52
|
headers: auth.headers,
|
|
52
53
|
reasoning: candidate.reasoning,
|
|
54
|
+
isOauth: this.ctx.modelRegistry.isUsingOAuth(model),
|
|
53
55
|
},
|
|
54
56
|
};
|
|
55
57
|
}
|
package/src/utils/path.util.ts
CHANGED
|
@@ -31,6 +31,10 @@ export class PathUtil {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
static findPiAuthConfig(): FileSearchResult {
|
|
35
|
+
return PathUtil.findFile(path.join(getAgentDir(), 'auth.json'));
|
|
36
|
+
}
|
|
37
|
+
|
|
34
38
|
private static getExtensionConfig(paths: string[]): string {
|
|
35
39
|
return path.join(...paths, 'extensions', EXTENSION_ID, 'config.json');
|
|
36
40
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class RawDataParser {
|
|
2
|
+
static asRecord(value: unknown): Record<string, unknown> | undefined {
|
|
3
|
+
return value && typeof value === 'object' && !Array.isArray(value) ? (value as Record<string, unknown>) : undefined;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
static stringValue(value: unknown): string | undefined {
|
|
7
|
+
return typeof value === 'string' && value.trim() ? value.trim() : undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static numberValue(value: unknown): number | undefined {
|
|
11
|
+
const number = typeof value === 'number' ? value : Number(value);
|
|
12
|
+
return Number.isFinite(number) ? number : undefined;
|
|
13
|
+
}
|
|
14
|
+
}
|