pi-spark 0.11.2 → 0.13.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/README.md +76 -57
- package/assets/cover.png +0 -0
- package/index.ts +31 -0
- package/package.json +24 -9
- package/{extensions/shared → src}/components/inline-text.ts +1 -1
- package/{extensions/shared → src}/config/index.ts +37 -12
- package/src/config/schema.ts +30 -0
- package/{extensions/shared → src}/events/auto-collect-events.ts +1 -1
- package/src/events/index.ts +3 -0
- package/src/features/credits/config.ts +3 -0
- package/src/features/credits/index.ts +49 -0
- package/src/features/credits/manager.ts +64 -0
- package/src/features/credits/providers/deepseek.ts +36 -0
- package/src/features/credits/providers/fireworks.proto +42 -0
- package/src/features/credits/providers/fireworks.ts +111 -0
- package/src/features/credits/providers/index.ts +22 -0
- package/src/features/credits/providers/moonshot.ts +39 -0
- package/src/features/credits/providers/openai-codex.ts +62 -0
- package/src/features/credits/providers/openrouter.ts +35 -0
- package/src/features/credits/providers/vercel-ai-gateway.ts +30 -0
- package/src/features/credits/status.ts +43 -0
- package/src/features/credits/types.ts +24 -0
- package/{extensions → src/features}/editor/index.ts +8 -11
- package/{extensions → src/features}/footer/index.ts +7 -9
- package/{extensions → src/features}/fullscreen/index.ts +6 -9
- package/src/features/model/config.ts +3 -0
- package/{extensions/models → src/features/model}/index.ts +5 -5
- package/{extensions → src/features}/name/index.ts +6 -8
- package/{extensions → src/features}/presets/config.ts +1 -1
- package/{extensions → src/features}/presets/index.ts +4 -4
- package/{extensions → src/features}/presets/manager.ts +2 -2
- package/{extensions → src/features}/recap/config.ts +1 -1
- package/{extensions → src/features}/recap/index.ts +4 -6
- package/{extensions → src/features}/recap/manager.ts +5 -5
- package/{extensions → src/features}/recap/model.ts +2 -2
- package/{extensions/shared/format/index.ts → src/utils/format.ts} +29 -0
- package/{extensions/shared/usage/index.ts → src/utils/usage.ts} +0 -18
- package/extensions/models/config.ts +0 -3
- package/extensions/shared/config/schema.ts +0 -22
- package/extensions/shared/events/index.ts +0 -3
- /package/{extensions/shared → src}/components/split-line.ts +0 -0
- /package/{extensions/shared → src}/config/model.ts +0 -0
- /package/{extensions/shared → src}/events/preset.ts +0 -0
- /package/{extensions → src/features}/editor/config.ts +0 -0
- /package/{extensions → src/features}/editor/spinner.ts +0 -0
- /package/{extensions → src/features}/footer/config.ts +0 -0
- /package/{extensions → src/features}/fullscreen/config.ts +0 -0
- /package/{extensions → src/features}/fullscreen/filler.ts +0 -0
- /package/{extensions → src/features}/name/config.ts +0 -0
- /package/{extensions → src/features}/presets/selector.ts +0 -0
- /package/{extensions → src/features}/recap/idle.ts +0 -0
- /package/{extensions → src/features}/recap/widget.ts +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { clampThinkingLevel } from "@earendil-works/pi-ai";
|
|
2
2
|
|
|
3
|
-
import { formatModel } from "
|
|
3
|
+
import { formatModel } from "../../utils/format";
|
|
4
4
|
|
|
5
5
|
import type { Api, Model, ModelThinkingLevel } from "@earendil-works/pi-ai";
|
|
6
6
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
7
|
-
import type { OptionalModelConfig } from "
|
|
7
|
+
import type { OptionalModelConfig } from "../../config/model";
|
|
8
8
|
|
|
9
9
|
const DEFAULT_THINKING_LEVEL: ModelThinkingLevel = "off";
|
|
10
10
|
|
|
@@ -61,3 +61,32 @@ export function sanitizeText(text: string): string {
|
|
|
61
61
|
.replace(/ +/g, " ")
|
|
62
62
|
.trim();
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
/** Coerce a possibly-stringified numeric value to a finite number, or `undefined`. */
|
|
66
|
+
export function toNumber(value?: string | number | null): number | undefined {
|
|
67
|
+
if (value === undefined || value === null) return undefined;
|
|
68
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
69
|
+
return Number.isFinite(parsed) ? parsed : undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const FRANKFURTER_API = "https://api.frankfurter.dev/v2/rate";
|
|
73
|
+
|
|
74
|
+
interface FrankfurterRateResponse {
|
|
75
|
+
rate?: string | number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Convert an amount in the given currency to USD via the Frankfurter API. */
|
|
79
|
+
export async function convertToUSD(amount: number | undefined, currency: string | undefined, signal: AbortSignal): Promise<number | undefined> {
|
|
80
|
+
if (amount === undefined) return undefined;
|
|
81
|
+
if (!currency || currency === "USD") return amount;
|
|
82
|
+
|
|
83
|
+
const url = `${FRANKFURTER_API}/${encodeURIComponent(currency)}/USD`;
|
|
84
|
+
const response = await fetch(url, { headers: { Accept: "application/json" }, signal });
|
|
85
|
+
if (!response.ok) throw new Error("currency conversion failed");
|
|
86
|
+
|
|
87
|
+
const payload = (await response.json()) as FrankfurterRateResponse;
|
|
88
|
+
const rate = toNumber(payload.rate);
|
|
89
|
+
if (rate === undefined) throw new Error("currency conversion failed");
|
|
90
|
+
|
|
91
|
+
return amount * rate;
|
|
92
|
+
}
|
|
@@ -25,24 +25,6 @@ export function isUsage(value: unknown): value is Usage {
|
|
|
25
25
|
);
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
/** Sum two `Usage` values into a new one. */
|
|
29
|
-
export function addUsage(a: Usage, b: Usage): Usage {
|
|
30
|
-
return {
|
|
31
|
-
input: a.input + b.input,
|
|
32
|
-
output: a.output + b.output,
|
|
33
|
-
cacheRead: a.cacheRead + b.cacheRead,
|
|
34
|
-
cacheWrite: a.cacheWrite + b.cacheWrite,
|
|
35
|
-
totalTokens: a.totalTokens + b.totalTokens,
|
|
36
|
-
cost: {
|
|
37
|
-
input: a.cost.input + b.cost.input,
|
|
38
|
-
output: a.cost.output + b.cost.output,
|
|
39
|
-
cacheRead: a.cost.cacheRead + b.cost.cacheRead,
|
|
40
|
-
cacheWrite: a.cost.cacheWrite + b.cost.cacheWrite,
|
|
41
|
-
total: a.cost.total + b.cost.total,
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
28
|
/**
|
|
47
29
|
* Extract usage from a session entry.
|
|
48
30
|
*
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as z from "zod";
|
|
2
|
-
|
|
3
|
-
import { editorConfigSchema } from "../../editor/config";
|
|
4
|
-
import { footerConfigSchema } from "../../footer/config";
|
|
5
|
-
import { fullscreenConfigSchema } from "../../fullscreen/config";
|
|
6
|
-
import { modelsConfigSchema } from "../../models/config";
|
|
7
|
-
import { nameConfigSchema } from "../../name/config";
|
|
8
|
-
import { presetsConfigSchema } from "../../presets/config";
|
|
9
|
-
import { recapConfigSchema } from "../../recap/config";
|
|
10
|
-
|
|
11
|
-
export const configSchemas = {
|
|
12
|
-
editor: editorConfigSchema,
|
|
13
|
-
footer: footerConfigSchema,
|
|
14
|
-
fullscreen: fullscreenConfigSchema,
|
|
15
|
-
models: modelsConfigSchema,
|
|
16
|
-
name: nameConfigSchema,
|
|
17
|
-
presets: presetsConfigSchema,
|
|
18
|
-
recap: recapConfigSchema,
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export type ConfigField = keyof typeof configSchemas;
|
|
22
|
-
export type ConfigValue<Field extends ConfigField> = z.infer<(typeof configSchemas)[Field]>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|