@juicesharp/rpiv-ask-user-question 1.9.1 → 1.10.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.
Files changed (2) hide show
  1. package/index.ts +11 -36
  2. package/package.json +2 -2
package/index.ts CHANGED
@@ -10,54 +10,29 @@
10
10
  * at every call site. The extension stays online either way.
11
11
  *
12
12
  * Adding a locale: drop `locales/<code>.json` next to en.json (mirroring the
13
- * key set), then add the load + entry to the `registerStrings` call below.
14
- * See `@juicesharp/rpiv-i18n` README → "Contributing translations" for the
15
- * full convention.
13
+ * key set). No edit needed here — `registerLocalesFromDir` iterates
14
+ * `SUPPORTED_LOCALES` from the SDK. See `@juicesharp/rpiv-i18n` README →
15
+ * "Contributing translations" for the full convention.
16
16
  */
17
17
 
18
- import { readFileSync } from "node:fs";
19
- import { fileURLToPath } from "node:url";
20
18
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
21
19
  import { registerAskUserQuestionTool } from "./ask-user-question.js";
22
20
  import { I18N_NAMESPACE } from "./state/i18n-bridge.js";
23
21
 
24
- type TranslationMap = Readonly<Record<string, string>>;
25
- type I18nSDK = { registerStrings: (namespace: string, byLocale: Record<string, TranslationMap>) => void };
26
-
27
- function loadLocale(code: string): TranslationMap {
28
- // A missing or malformed locale file degrades gracefully: registerStrings
29
- // records an empty map for the locale, so render-time `tr(key, fallback)`
30
- // returns the canonical English literal at the call site. Crashing here
31
- // would take the entire ask_user_question tool offline at module init —
32
- // publish-manifest miss would brick the extension.
33
- try {
34
- return JSON.parse(
35
- readFileSync(fileURLToPath(new URL(`./locales/${code}.json`, import.meta.url)), "utf-8"),
36
- ) as TranslationMap;
37
- } catch (err) {
38
- console.warn(
39
- `rpiv-ask-user-question: failed to load locales/${code}.json — falling back to English (${(err as Error).message})`,
40
- );
41
- return {};
42
- }
43
- }
22
+ type I18nLoader = {
23
+ registerLocalesFromDir: (namespace: string, packageUrl: string, options?: { label?: string }) => void;
24
+ };
44
25
 
45
26
  // Dynamic import keeps `@juicesharp/rpiv-i18n` a soft optional peer: when the
46
27
  // SDK is installed alongside this package the strings register and
47
28
  // `/languages` flips them live; when it isn't, the import rejects here, we
48
29
  // no-op, and the bridge's English-fallback shim keeps the extension online.
30
+ //
31
+ // The `/loader` subpath is used instead of the SDK entry so the i18n-ui +
32
+ // pi-tui modules are not pulled into our load graph just to register strings.
49
33
  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
- });
34
+ const sdk = (await import("@juicesharp/rpiv-i18n/loader")) as I18nLoader;
35
+ sdk.registerLocalesFromDir(I18N_NAMESPACE, import.meta.url, { label: "rpiv-ask-user-question" });
61
36
  } catch {
62
37
  // SDK absent — extension still loads with English-only UI.
63
38
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juicesharp/rpiv-ask-user-question",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
4
4
  "description": "Pi extension. A structured questionnaire the model can put to you when it would otherwise guess, with typed options instead of free-form replies.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -82,6 +82,6 @@
82
82
  }
83
83
  },
84
84
  "dependencies": {
85
- "@juicesharp/rpiv-config": "^1.9.1"
85
+ "@juicesharp/rpiv-config": "^1.10.0"
86
86
  }
87
87
  }