@brglng/pi-currency-cost 0.3.0 → 0.4.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 +5 -2
- package/README.zh.md +5 -2
- package/package.json +1 -1
- package/src/config.ts +4 -5
- package/src/settings-config.ts +2 -0
- package/src/store.ts +3 -4
package/README.md
CHANGED
|
@@ -17,14 +17,14 @@ pi install npm:@brglng/pi-currency-cost
|
|
|
17
17
|
|
|
18
18
|
### Rates in Pi's settings.json
|
|
19
19
|
|
|
20
|
-
Add the `
|
|
20
|
+
Add the `currency-cost` namespace to Pi's global `<agentDir>/settings.json`
|
|
21
21
|
(default: `~/.pi/agent/settings.json`). Use strict JSON (no comments or
|
|
22
22
|
trailing commas). The extension ignores this namespace in project settings
|
|
23
23
|
and in `models.json`.
|
|
24
24
|
|
|
25
25
|
```json
|
|
26
26
|
{
|
|
27
|
-
"
|
|
27
|
+
"currency-cost": {
|
|
28
28
|
"currencies": {
|
|
29
29
|
"CNY": { "usdRate": 0.147 }
|
|
30
30
|
},
|
|
@@ -36,6 +36,9 @@ and in `models.json`.
|
|
|
36
36
|
Valid rates and rate-source settings here take precedence over the merged
|
|
37
37
|
legacy configuration.
|
|
38
38
|
|
|
39
|
+
If your `settings.json` uses `pi-currency-cost`, rename it to `currency-cost`.
|
|
40
|
+
The old namespace is ignored.
|
|
41
|
+
|
|
39
42
|
Upgrading from 0.2.0: rename `currencyExchangeRateSource` to
|
|
40
43
|
`exchangeRateSource` in `settings.json`. The old key is ignored.
|
|
41
44
|
|
package/README.zh.md
CHANGED
|
@@ -16,13 +16,13 @@ pi install npm:@brglng/pi-currency-cost
|
|
|
16
16
|
|
|
17
17
|
### 在 Pi 的 settings.json 中配置汇率
|
|
18
18
|
|
|
19
|
-
将 `
|
|
19
|
+
将 `currency-cost` 命名空间添加到 Pi 的全局 `<agentDir>/settings.json`
|
|
20
20
|
(默认为 `~/.pi/agent/settings.json`)。请使用严格的 JSON,不要添加注释或
|
|
21
21
|
尾随逗号。扩展会忽略项目设置和 `models.json` 中的此命名空间。
|
|
22
22
|
|
|
23
23
|
```json
|
|
24
24
|
{
|
|
25
|
-
"
|
|
25
|
+
"currency-cost": {
|
|
26
26
|
"currencies": {
|
|
27
27
|
"CNY": { "usdRate": 0.147 }
|
|
28
28
|
},
|
|
@@ -33,6 +33,9 @@ pi install npm:@brglng/pi-currency-cost
|
|
|
33
33
|
|
|
34
34
|
此处有效的汇率及汇率来源设置优先于合并后的旧版配置。
|
|
35
35
|
|
|
36
|
+
如果 `settings.json` 中仍使用 `pi-currency-cost`,请将其改为 `currency-cost`。
|
|
37
|
+
扩展会忽略旧命名空间。
|
|
38
|
+
|
|
36
39
|
从 0.2.0 升级时,请在 `settings.json` 中将 `currencyExchangeRateSource`
|
|
37
40
|
改为 `exchangeRateSource`。扩展会忽略旧键。
|
|
38
41
|
|
package/package.json
CHANGED
package/src/config.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { readFile } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
|
-
import { EXTENSION_ID } from "./config-paths";
|
|
4
3
|
import {
|
|
5
4
|
getModelsConfigPath,
|
|
6
5
|
isPositiveFinite,
|
|
7
6
|
isRecord,
|
|
8
7
|
readModelsConfig,
|
|
9
8
|
} from "./models-config";
|
|
10
|
-
import { readSettingsConfig } from "./settings-config";
|
|
9
|
+
import { readSettingsConfig, SETTINGS_KEY } from "./settings-config";
|
|
11
10
|
|
|
12
11
|
/**
|
|
13
12
|
* One currency entry. `usdRate` is the sole conversion rate (USD per one
|
|
@@ -462,7 +461,7 @@ export async function loadConfigWithSources(agentDir: string, cwd: string) {
|
|
|
462
461
|
}),
|
|
463
462
|
readSettingsConfig(agentDir).catch(() => {
|
|
464
463
|
inlineWarnings.push(
|
|
465
|
-
|
|
464
|
+
`Could not read a valid settings.json; ignoring ${SETTINGS_KEY} settings`,
|
|
466
465
|
);
|
|
467
466
|
return undefined;
|
|
468
467
|
}),
|
|
@@ -473,7 +472,7 @@ export async function loadConfigWithSources(agentDir: string, cwd: string) {
|
|
|
473
472
|
global.config,
|
|
474
473
|
);
|
|
475
474
|
const inlineRateKeys = new Map<string, string>();
|
|
476
|
-
const settings = settingsRaw?.[
|
|
475
|
+
const settings = settingsRaw?.[SETTINGS_KEY];
|
|
477
476
|
|
|
478
477
|
if (isRecord(settings)) {
|
|
479
478
|
if (isRecord(settings.currencies)) {
|
|
@@ -528,7 +527,7 @@ export async function loadConfigWithSources(agentDir: string, cwd: string) {
|
|
|
528
527
|
}
|
|
529
528
|
} else if (settings !== undefined) {
|
|
530
529
|
inlineWarnings.push(
|
|
531
|
-
|
|
530
|
+
`settings.json: ${SETTINGS_KEY} must be an object; ignoring`,
|
|
532
531
|
);
|
|
533
532
|
}
|
|
534
533
|
|
package/src/settings-config.ts
CHANGED
|
@@ -2,6 +2,8 @@ import { readFile } from "node:fs/promises";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { isRecord } from "./models-config";
|
|
4
4
|
|
|
5
|
+
export const SETTINGS_KEY = "currency-cost";
|
|
6
|
+
|
|
5
7
|
export function getSettingsConfigPath(agentDir: string): string {
|
|
6
8
|
return join(agentDir, "settings.json");
|
|
7
9
|
}
|
package/src/store.ts
CHANGED
|
@@ -14,9 +14,8 @@ import {
|
|
|
14
14
|
import { dirname, join } from "node:path";
|
|
15
15
|
import { applyEdits, modify, type Node, parseTree } from "jsonc-parser";
|
|
16
16
|
import { normalizeCurrencyCode } from "./config";
|
|
17
|
-
import { EXTENSION_ID } from "./config-paths";
|
|
18
17
|
import { isPositiveFinite, isRecord } from "./models-config";
|
|
19
|
-
import { parseSettingsConfig } from "./settings-config";
|
|
18
|
+
import { parseSettingsConfig, SETTINGS_KEY } from "./settings-config";
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* Read a raw config JSON file. Returns undefined when the file does not
|
|
@@ -128,7 +127,7 @@ export async function updateInlineRate(
|
|
|
128
127
|
if (!info.isFile()) throw new Error();
|
|
129
128
|
const text = await readFile(target, "utf8");
|
|
130
129
|
const raw = parseSettingsConfig(text);
|
|
131
|
-
const settings = raw[
|
|
130
|
+
const settings = raw[SETTINGS_KEY];
|
|
132
131
|
const currencies = isRecord(settings) ? settings.currencies : undefined;
|
|
133
132
|
if (!isRecord(currencies)) throw new Error();
|
|
134
133
|
const effective = Object.entries(currencies).findLast(
|
|
@@ -143,7 +142,7 @@ export async function updateInlineRate(
|
|
|
143
142
|
const source = text.slice(bomLength);
|
|
144
143
|
const tree = parseTree(source);
|
|
145
144
|
const entry = propertyValue(
|
|
146
|
-
propertyValue(propertyValue(tree,
|
|
145
|
+
propertyValue(propertyValue(tree, SETTINGS_KEY), "currencies"),
|
|
147
146
|
key,
|
|
148
147
|
);
|
|
149
148
|
const rate = propertyValue(entry, "usdRate");
|