@juicesharp/rpiv-ask-user-question 1.1.3 → 1.1.4
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 +3 -3
- package/index.ts +28 -14
- package/package.json +6 -1
- package/state/i18n-bridge.ts +28 -4
package/README.md
CHANGED
|
@@ -42,15 +42,15 @@ pi install npm:@juicesharp/rpiv-ask-user-question
|
|
|
42
42
|
|
|
43
43
|
Then restart your Pi session.
|
|
44
44
|
|
|
45
|
-
### Optional:
|
|
45
|
+
### Optional: localization
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
`rpiv-ask-user-question` works standalone — install only this package and you get the full English UI. Install `@juicesharp/rpiv-i18n` alongside it to flip sentinel labels, dialog hints, review-tab heading, and chat-summary lines to your active locale:
|
|
48
48
|
|
|
49
49
|
```bash
|
|
50
50
|
pi install npm:@juicesharp/rpiv-i18n
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
With the SDK present, locale resolves from `--locale <code>` → `~/.config/rpiv-i18n/locale.json` → `LANG` / `LC_ALL` → English. The `/languages` interactive picker and `pi --locale <code>` startup flag are also enabled. Without the SDK, the dialog stays online and renders English at every call site — no warning, no crash. Users who installed via `pi install npm:@juicesharp/rpiv-pi` + `/rpiv-setup` get the SDK automatically.
|
|
54
54
|
|
|
55
55
|
## Tool
|
|
56
56
|
|
package/index.ts
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
* rpiv-ask-user-question — Pi extension. Registers the `ask_user_question`
|
|
3
3
|
* tool: a structured option selector with a free-text "Other" fallback.
|
|
4
4
|
*
|
|
5
|
-
* Sentinel labels
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Sentinel labels and TUI chrome strings localize at render time via the i18n
|
|
6
|
+
* bridge. Strings are registered with rpiv-i18n here, once, at module init —
|
|
7
|
+
* but only when the SDK is actually installed. If `@juicesharp/rpiv-i18n` is
|
|
8
|
+
* missing (standalone install of just this package), the dynamic-load shim
|
|
9
|
+
* no-ops and the bridge's `t(key, fallback)` returns the inline English literal
|
|
10
|
+
* at every call site. The extension stays online either way.
|
|
8
11
|
*
|
|
9
12
|
* Adding a locale: drop `locales/<code>.json` next to en.json (mirroring the
|
|
10
13
|
* key set), then add the load + entry to the `registerStrings` call below.
|
|
@@ -14,11 +17,13 @@
|
|
|
14
17
|
|
|
15
18
|
import { readFileSync } from "node:fs";
|
|
16
19
|
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { registerStrings, type TranslationMap } from "@juicesharp/rpiv-i18n";
|
|
18
20
|
import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
|
|
19
21
|
import { registerAskUserQuestionTool } from "./ask-user-question.js";
|
|
20
22
|
import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
|
|
21
23
|
|
|
24
|
+
type TranslationMap = Readonly<Record<string, string>>;
|
|
25
|
+
type I18nSDK = { registerStrings: (namespace: string, byLocale: Record<string, TranslationMap>) => void };
|
|
26
|
+
|
|
22
27
|
function loadLocale(code: string): TranslationMap {
|
|
23
28
|
// A missing or malformed locale file degrades gracefully: registerStrings
|
|
24
29
|
// records an empty map for the locale, so render-time `tr(key, fallback)`
|
|
@@ -37,16 +42,25 @@ function loadLocale(code: string): TranslationMap {
|
|
|
37
42
|
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
// Dynamic import keeps `@juicesharp/rpiv-i18n` a soft optional peer: when the
|
|
46
|
+
// SDK is installed alongside this package the strings register and
|
|
47
|
+
// `/languages` flips them live; when it isn't, the import rejects here, we
|
|
48
|
+
// no-op, and the bridge's English-fallback shim keeps the extension online.
|
|
49
|
+
try {
|
|
50
|
+
const sdk = (await import("@juicesharp/rpiv-i18n")) as I18nSDK;
|
|
51
|
+
sdk.registerStrings(I18N_NAMESPACE, {
|
|
52
|
+
de: loadLocale("de"),
|
|
53
|
+
en: loadLocale("en"),
|
|
54
|
+
es: loadLocale("es"),
|
|
55
|
+
fr: loadLocale("fr"),
|
|
56
|
+
pt: loadLocale("pt"),
|
|
57
|
+
"pt-BR": loadLocale("pt-BR"),
|
|
58
|
+
ru: loadLocale("ru"),
|
|
59
|
+
uk: loadLocale("uk"),
|
|
60
|
+
});
|
|
61
|
+
} catch {
|
|
62
|
+
// SDK absent — extension still loads with English-only UI.
|
|
63
|
+
}
|
|
50
64
|
|
|
51
65
|
export default function (pi: ExtensionAPI) {
|
|
52
66
|
registerAskUserQuestionTool(pi);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juicesharp/rpiv-ask-user-question",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Pi extension: lets the model ask you a clarifying question with structured options instead of guessing",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -75,5 +75,10 @@
|
|
|
75
75
|
"@mariozechner/pi-coding-agent": "*",
|
|
76
76
|
"@mariozechner/pi-tui": "*",
|
|
77
77
|
"typebox": "*"
|
|
78
|
+
},
|
|
79
|
+
"peerDependenciesMeta": {
|
|
80
|
+
"@juicesharp/rpiv-i18n": {
|
|
81
|
+
"optional": true
|
|
82
|
+
}
|
|
78
83
|
}
|
|
79
84
|
}
|
package/state/i18n-bridge.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* i18n bridge for rpiv-ask-user-question — single thin import surface so every
|
|
3
|
-
* call site routes through one place. Backed by `@juicesharp/rpiv-i18n`'s SDK
|
|
3
|
+
* call site routes through one place. Backed by `@juicesharp/rpiv-i18n`'s SDK
|
|
4
|
+
* when available; degrades to canonical-English fallbacks when not.
|
|
4
5
|
*
|
|
5
|
-
* - `t(key, fallback)` is `scope("@juicesharp/rpiv-ask-user-question")
|
|
6
|
+
* - `t(key, fallback)` is `scope("@juicesharp/rpiv-ask-user-question")` if the
|
|
7
|
+
* SDK is installed (live `/languages` updates propagate). If the SDK is
|
|
8
|
+
* missing (standalone install without rpiv-i18n), `t` is an identity
|
|
9
|
+
* passthrough that returns the inline English fallback at every call site,
|
|
10
|
+
* so the extension stays online with English UI.
|
|
6
11
|
* - `displayLabel(kind)` resolves a sentinel kind to its locale-aware label,
|
|
7
12
|
* with the canonical English `ROW_INTENT_META[kind].label` as fallback so
|
|
8
13
|
* nothing renders blank if the namespace isn't registered.
|
|
@@ -15,12 +20,31 @@
|
|
|
15
20
|
* the canonical `ROW_INTENT_META[kind].label`, never `displayLabel(kind)`.
|
|
16
21
|
*/
|
|
17
22
|
|
|
18
|
-
import { scope } from "@juicesharp/rpiv-i18n";
|
|
19
23
|
import { ROW_INTENT_META, type SentinelKind } from "./row-intent.js";
|
|
20
24
|
|
|
21
25
|
export const I18N_NAMESPACE = "@juicesharp/rpiv-ask-user-question";
|
|
22
26
|
|
|
23
|
-
|
|
27
|
+
type ScopeFn = (key: string, fallback: string) => string;
|
|
28
|
+
type I18nSDK = { scope: (namespace: string) => ScopeFn };
|
|
29
|
+
|
|
30
|
+
// Prefer the live SDK if installed: closures it returns track the active
|
|
31
|
+
// locale, so /languages picker propagates to our render call sites. If the
|
|
32
|
+
// SDK isn't installed (standalone install of this extension without
|
|
33
|
+
// rpiv-i18n), the dynamic import fails, every t(key, fallback) returns the
|
|
34
|
+
// canonical English literal, and the extension stays online.
|
|
35
|
+
//
|
|
36
|
+
// Top-level await is required so a synchronous `t(...)` call from any
|
|
37
|
+
// downstream module sees the resolved scope; ESM module loading awaits this
|
|
38
|
+
// before evaluating any importer.
|
|
39
|
+
let scopeImpl: ScopeFn;
|
|
40
|
+
try {
|
|
41
|
+
const sdk = (await import("@juicesharp/rpiv-i18n")) as I18nSDK;
|
|
42
|
+
scopeImpl = sdk.scope(I18N_NAMESPACE);
|
|
43
|
+
} catch {
|
|
44
|
+
scopeImpl = (_key, fallback) => fallback;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const t: ScopeFn = scopeImpl;
|
|
24
48
|
|
|
25
49
|
export function displayLabel(kind: SentinelKind): string {
|
|
26
50
|
return t(`sentinel.${kind}`, ROW_INTENT_META[kind].label);
|