@happyvertical/smrt-template-sveltekit 0.74.7 → 0.75.1

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 (77) hide show
  1. package/AGENTS.md +22 -5
  2. package/README.md +49 -0
  3. package/agents/cookbook-host.md +10 -3
  4. package/cookbook-template/src/hooks.server.ts +4 -2
  5. package/cookbook-template/src/lib/server/cookbook.ts +1 -1
  6. package/cookbook-template/src/routes/+layout.server.ts +4 -2
  7. package/cookbook-template/src/routes/+layout.svelte +6 -0
  8. package/cookbook-template/src/routes/+page.server.ts +1 -1
  9. package/cookbook-template/src/routes/api/_runtime/owner-link/+server.ts +1 -1
  10. package/cookbook-template/src/routes/api/assistant/[...path]/+server.ts +1 -1
  11. package/cookbook-template/src/routes/api/connect-ai/+server.ts +1 -1
  12. package/cookbook-template/src/routes/api/cookbook/prebuilt/+server.ts +1 -1
  13. package/cookbook-template/src/routes/api/cookbook/preferences/+server.ts +1 -1
  14. package/cookbook-template/src/routes/api/onboarding/+server.ts +1 -1
  15. package/cookbook-template/src/routes/mcp/+server.ts +1 -1
  16. package/cookbook-template/src/routes/settings/+page.server.ts +1 -1
  17. package/cookbook-template/src/routes/settings/inference/+page.server.ts +1 -1
  18. package/cookbook-template/vite.config.ts +3 -1
  19. package/dist/host/server.d.ts +2 -1
  20. package/dist/host/server.js +18 -2
  21. package/dist/host/settings.d.ts +11 -0
  22. package/dist/host/settings.js +15 -0
  23. package/examples/notes/src/routes/notes/+page.server.ts +2 -2
  24. package/examples/notes/src/routes/notes/+page.svelte +1 -2
  25. package/host/InferenceSettingsPage.svelte +13 -2
  26. package/index.js +3 -3
  27. package/mcp-apps-template/package.dependencies.json +2 -2
  28. package/mcp-apps-template/src/routes/.well-known/oauth-protected-resource/api/mcp/+server.ts +1 -1
  29. package/mcp-apps-template/src/routes/api/mcp/+server.ts +2 -2
  30. package/package.json +50 -49
  31. package/template/README.md +38 -1
  32. package/template/gitignore.template +3 -0
  33. package/template/package.json +25 -19
  34. package/template/smrt.config.ts +1 -0
  35. package/template/src/app.d.ts +7 -1
  36. package/template/src/app.html +1 -1
  37. package/template/src/hooks.server.ts +6 -7
  38. package/template/src/lib/components/MaterializedReportDrilldown.svelte +1 -1
  39. package/template/src/lib/i18n/LanguageLayout.svelte +19 -0
  40. package/template/src/lib/i18n/LanguageSwitcher.svelte +17 -0
  41. package/template/src/lib/i18n/catalog.ts +27 -0
  42. package/template/src/lib/i18n/locale-tool.ts +19 -0
  43. package/template/src/lib/i18n/locales.ts +62 -0
  44. package/template/src/lib/i18n/messages.catalog.ts +39 -0
  45. package/template/src/lib/i18n/messages.ts +3 -0
  46. package/template/src/lib/i18n/shell-spanish.ts +173 -0
  47. package/template/src/lib/server/i18n.ts +48 -0
  48. package/template/src/lib/server/language-preference.ts +30 -0
  49. package/template/src/lib/server/languages.ts +67 -0
  50. package/template/src/lib/server/settings-registry.ts +2 -0
  51. package/template/src/params.ts +8 -0
  52. package/template/src/routes/+layout.server.ts +9 -5
  53. package/template/src/routes/+layout.svelte +10 -4
  54. package/template/src/routes/+page.svelte +7 -4
  55. package/template/src/routes/api/_reports/runtime/confirm/+server.ts +1 -1
  56. package/template/src/routes/api/_runtime/diagnostics/+server.ts +1 -1
  57. package/template/src/routes/api/_runtime/health/+server.ts +1 -1
  58. package/template/src/routes/api/languages/mcp/+server.ts +59 -0
  59. package/template/src/routes/api/settings/languages/+server.ts +32 -0
  60. package/template/src/routes/language/+server.ts +20 -0
  61. package/template/src/routes/reports/materialized/[id]/+page.server.ts +1 -1
  62. package/template/src/routes/reports/materialized/[id]/+page.svelte +2 -3
  63. package/template/src/routes/reports/materialized/[id]/drilldown/+server.ts +1 -1
  64. package/template/src/routes/settings/+page.svelte +11 -7
  65. package/template/src/routes/settings/[section=settingsSection]/+page.svelte +1 -1
  66. package/template/src/routes/settings/inference/+page.server.ts +1 -1
  67. package/template/src/routes/settings/languages/+page.server.ts +15 -0
  68. package/template/src/routes/settings/languages/+page.svelte +59 -0
  69. package/template/src/routes/settings/languages/+server.ts +20 -0
  70. package/template/src/routes/settings/prompts/+page.server.ts +1 -1
  71. package/template/src/routes/setup/+page.server.ts +2 -2
  72. package/template/src/routes/sign-out/+server.ts +1 -1
  73. package/template/tsconfig.json +3 -1
  74. package/template/vite.config.ts +3 -1
  75. package/template.config.js +21 -19
  76. package/template/src/params/settingsSection.ts +0 -4
  77. package/template/svelte.config.js +0 -16
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@happyvertical/smrt-template-sveltekit",
3
- "version": "0.74.7",
3
+ "version": "0.75.1",
4
4
  "description": "Minimal SvelteKit project template with s-m-r-t framework integration",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -86,54 +86,54 @@
86
86
  "directory": "packages/template-sveltekit"
87
87
  },
88
88
  "peerDependencies": {
89
- "@happyvertical/smrt-core": "0.74.7",
90
- "@happyvertical/smrt-agents": "0.74.7",
91
- "@happyvertical/smrt-app-runtime": "0.74.7",
92
- "@happyvertical/smrt-app-mcp": "0.74.7",
93
- "@happyvertical/smrt-chat": "0.74.7",
94
- "@happyvertical/smrt-inference": "0.74.7",
95
- "@happyvertical/smrt-preferences": "0.74.7",
96
- "@happyvertical/smrt-svelte": "0.74.7",
97
- "@happyvertical/smrt-tenancy": "0.74.7",
98
- "@happyvertical/smrt-types": "0.74.7",
99
- "@happyvertical/smrt-ui": "0.74.7",
100
- "@happyvertical/smrt-users": "0.74.7",
101
- "@sveltejs/kit": "^2.70.3",
89
+ "@happyvertical/smrt-core": "0.75.1",
90
+ "@happyvertical/smrt-agents": "0.75.1",
91
+ "@happyvertical/smrt-app-runtime": "0.75.1",
92
+ "@happyvertical/smrt-app-mcp": "0.75.1",
93
+ "@happyvertical/smrt-chat": "0.75.1",
94
+ "@happyvertical/smrt-inference": "0.75.1",
95
+ "@happyvertical/smrt-preferences": "0.75.1",
96
+ "@happyvertical/smrt-svelte": "0.75.1",
97
+ "@happyvertical/smrt-tenancy": "0.75.1",
98
+ "@happyvertical/smrt-types": "0.75.1",
99
+ "@happyvertical/smrt-ui": "0.75.1",
100
+ "@happyvertical/smrt-users": "0.75.1",
101
+ "@sveltejs/kit": "^3.4.1",
102
102
  "svelte": "^5.57.1",
103
103
  "@happyvertical/sql": ">=0.89.12",
104
- "@happyvertical/smrt-jobs": "0.74.7",
105
- "@happyvertical/smrt-prompts": "0.74.7",
106
- "@happyvertical/smrt-workflows": "0.74.7"
104
+ "@happyvertical/smrt-jobs": "0.75.1",
105
+ "@happyvertical/smrt-prompts": "0.75.1",
106
+ "@happyvertical/smrt-workflows": "0.75.1"
107
107
  },
108
108
  "devDependencies": {
109
- "@happyvertical/smrt-app-cli": "0.74.7",
110
- "@happyvertical/smrt-app-mcp": "0.74.7",
111
- "@happyvertical/smrt-app-runtime": "0.74.7",
112
- "@happyvertical/smrt-assets": "0.74.7",
113
- "@happyvertical/smrt-chat": "0.74.7",
114
- "@happyvertical/smrt-cli": "0.74.7",
115
- "@happyvertical/smrt-config": "0.74.7",
116
- "@happyvertical/smrt-inference": "0.74.7",
117
- "@happyvertical/smrt-jobs": "0.74.7",
118
- "@happyvertical/smrt-mcp-openai": "0.74.7",
119
- "@happyvertical/smrt-playbooks": "0.74.7",
120
- "@happyvertical/smrt-preferences": "0.74.7",
121
- "@happyvertical/smrt-profiles": "0.74.7",
122
- "@happyvertical/smrt-prompts": "0.74.7",
123
- "@happyvertical/smrt-scanner": "0.74.7",
124
- "@happyvertical/smrt-secrets": "0.74.7",
125
- "@happyvertical/smrt-svelte": "0.74.7",
126
- "@happyvertical/smrt-tenancy": "0.74.7",
127
- "@happyvertical/smrt-ui": "0.74.7",
128
- "@happyvertical/smrt-users": "0.74.7",
129
- "@happyvertical/smrt-web": "0.74.7",
130
- "@happyvertical/smrt-workflows": "0.74.7",
109
+ "@happyvertical/smrt-app-cli": "0.75.1",
110
+ "@happyvertical/smrt-app-mcp": "0.75.1",
111
+ "@happyvertical/smrt-app-runtime": "0.75.1",
112
+ "@happyvertical/smrt-assets": "0.75.1",
113
+ "@happyvertical/smrt-chat": "0.75.1",
114
+ "@happyvertical/smrt-cli": "0.75.1",
115
+ "@happyvertical/smrt-config": "0.75.1",
116
+ "@happyvertical/smrt-inference": "0.75.1",
117
+ "@happyvertical/smrt-jobs": "0.75.1",
118
+ "@happyvertical/smrt-mcp-openai": "0.75.1",
119
+ "@happyvertical/smrt-playbooks": "0.75.1",
120
+ "@happyvertical/smrt-preferences": "0.75.1",
121
+ "@happyvertical/smrt-profiles": "0.75.1",
122
+ "@happyvertical/smrt-prompts": "0.75.1",
123
+ "@happyvertical/smrt-scanner": "0.75.1",
124
+ "@happyvertical/smrt-secrets": "0.75.1",
125
+ "@happyvertical/smrt-svelte": "0.75.1",
126
+ "@happyvertical/smrt-tenancy": "0.75.1",
127
+ "@happyvertical/smrt-ui": "0.75.1",
128
+ "@happyvertical/smrt-users": "0.75.1",
129
+ "@happyvertical/smrt-web": "0.75.1",
130
+ "@happyvertical/smrt-workflows": "0.75.1",
131
131
  "@happyvertical/sql": "^0.89.12",
132
132
  "@modelcontextprotocol/client": "2.3.1",
133
133
  "@modelcontextprotocol/server": "^2.3.1",
134
134
  "@playwright/test": "^1.63.0",
135
- "@sveltejs/adapter-node": "^5.5.7",
136
- "@sveltejs/kit": "2.70.3",
135
+ "@sveltejs/adapter-node": "^6.0.6",
136
+ "@sveltejs/kit": "3.4.1",
137
137
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
138
138
  "@types/node": "24.13.6",
139
139
  "svelte": "^5.57.1",
@@ -141,20 +141,21 @@
141
141
  "typescript": "6.0.3",
142
142
  "vite": "8.1.6",
143
143
  "vitest": "4.1.10",
144
- "@happyvertical/smrt-reports": "0.74.7",
145
- "@happyvertical/smrt-agents": "0.74.7",
146
- "@happyvertical/smrt-types": "0.74.7",
147
- "@happyvertical/smrt-commerce": "0.74.7",
148
- "@happyvertical/smrt-events": "0.74.7",
149
- "@happyvertical/smrt-inventory": "0.74.7"
144
+ "@happyvertical/smrt-reports": "0.75.1",
145
+ "@happyvertical/smrt-agents": "0.75.1",
146
+ "@happyvertical/smrt-types": "0.75.1",
147
+ "@happyvertical/smrt-commerce": "0.75.1",
148
+ "@happyvertical/smrt-events": "0.75.1",
149
+ "@happyvertical/smrt-inventory": "0.75.1",
150
+ "@happyvertical/smrt-languages": "0.75.1"
150
151
  },
151
152
  "publishConfig": {
152
153
  "registry": "https://registry.npmjs.org",
153
154
  "access": "public"
154
155
  },
155
156
  "dependencies": {
156
- "@happyvertical/smrt-app-cli": "0.74.7",
157
- "@happyvertical/smrt-desktop": "0.74.7",
157
+ "@happyvertical/smrt-app-cli": "0.75.1",
158
+ "@happyvertical/smrt-desktop": "0.75.1",
158
159
  "ajv": "^8.20.0"
159
160
  },
160
161
  "scripts": {
@@ -202,7 +202,7 @@ import {
202
202
  RoleCollection,
203
203
  syncPermissionCatalog,
204
204
  } from '@happyvertical/smrt-users';
205
- import { runtime } from '$lib/server/smrt';
205
+ import { runtime } from '#lib/server/smrt.js';
206
206
 
207
207
  await syncPermissionCatalog(runtime.classOptions('Permission'));
208
208
  const roles = await RoleCollection.create(runtime.classOptions('Role'));
@@ -485,3 +485,40 @@ identities are denied. To use a different lookup, pass the route an explicit
485
485
  `auth` built with `createHostedMcpResourceAuth({ ..., resolvePrincipal })`. The route never derives tenant authority from
486
486
  JWT claims, request headers, or tool arguments. Missing configuration fails
487
487
  closed before MCP dispatch.
488
+
489
+ ### Interface languages
490
+
491
+ The starter ships English and Spanish. Its root server load resolves the active
492
+ language after the runtime verifies the session: an enabled `?lang=` preference,
493
+ then the `smrt-locale` cookie, then weighted `Accept-Language`, then the stored
494
+ application/workspace default. Regional preferences fall back to an enabled base
495
+ language (`es-MX` → `es`). Invalid or disabled languages are ignored. The native
496
+ language form posts to `/language`, stores an HTTP-only, same-site cookie for one
497
+ year, and reloads the current page with a new server snapshot. Disabling a locale
498
+ does not delete its translations.
499
+
500
+ `src/lib/i18n/messages.catalog.ts` contains the starter's reviewed English/Spanish wording; `messages.ts` registers its keys for component fallbacks.
501
+ `catalog.ts` explicitly assembles shipped package and app catalogs; add catalogs
502
+ for every feature, including lazy routes, here. Preserve `applicationCatalogs`
503
+ when calling the settings service so inventory retains package attribution.
504
+ Pass the merged catalog to `buildI18nSnapshot` and the resulting request-local
505
+ snapshot to `AppShell i18n`. Never retain a tenant snapshot or a request database
506
+ handle at module scope. The shell and child stock components read the same
507
+ snapshot synchronously during SSR and hydration.
508
+
509
+ `app.html` language/direction placeholders are filled during SSR; the root
510
+ layout keeps document `lang` and script-aware `dir` synchronized after navigation. The load explicitly tracks the `lang` query parameter, so
511
+ client `goto` language changes refresh the snapshot without reloading. API and
512
+ other nonpage requests perform no snapshot resolution. Bulk scoped override reads
513
+ are bounded to one app and one tenant list regardless of catalog size.
514
+ English and Spanish are LTR. Enabling an RTL language also sets document RTL;
515
+ provide reviewed translations for that language before advertising support.
516
+
517
+ Settings → Languages mounts the reusable languages package panel. Its explicit
518
+ app/workspace views use server-bound scope; workspace identity comes only from
519
+ the verified session. `languages.customize` permits workspace writes;
520
+ `languages.customize_app` permits writes across the application. The service
521
+ validates placeholders. Local application-wide authority is the installation
522
+ owner identity checked against a persisted session. Hosted apps deny it until a
523
+ trusted `applicationPermissionAuthorizer` is configured in the server runtime;
524
+ tenant roles do not establish this authority. Browsing the catalog does not enqueue translations.
@@ -21,6 +21,9 @@ dist
21
21
  # SMRT auto-generated
22
22
  .smrt/
23
23
  src/routes/api/**/+server.ts
24
+ # Authored, session-bound language operation adapters (generated CRUD stays closed).
25
+ !src/routes/api/settings/languages/+server.ts
26
+ !src/routes/api/languages/mcp/+server.ts
24
27
  !src/routes/api/_runtime/diagnostics/+server.ts
25
28
  # The runtime readiness endpoint is authored infrastructure, not generated API
26
29
  # output, and must remain in the installable scaffold.
@@ -33,34 +33,40 @@
33
33
  "docs:agents": "smrt docs:agents"
34
34
  },
35
35
  "devDependencies": {
36
- "@sveltejs/adapter-node": "^5.5.7",
37
- "@sveltejs/kit": "2.70.3",
36
+ "@sveltejs/adapter-node": "^6.0.6",
37
+ "@sveltejs/kit": "3.4.1",
38
38
  "@sveltejs/vite-plugin-svelte": "^7.3.0",
39
39
  "@types/node": "^24.13.6",
40
40
  "svelte": "^5.57.1",
41
41
  "svelte-check": "^4.7.6",
42
42
  "typescript": "6.0.3",
43
43
  "vite": "8.3.3",
44
- "@happyvertical/smrt-cli": "^0.74.7"
44
+ "@happyvertical/smrt-cli": "^0.75.1"
45
45
  },
46
46
  "dependencies": {
47
- "@happyvertical/smrt-app-runtime": "^0.74.7",
48
- "@happyvertical/smrt-config": "^0.74.7",
49
- "@happyvertical/smrt-core": "^0.74.7",
50
- "@happyvertical/smrt-inference": "^0.74.7",
51
- "@happyvertical/smrt-jobs": "^0.74.7",
52
- "@happyvertical/smrt-preferences": "^0.74.7",
53
- "@happyvertical/smrt-profiles": "^0.74.7",
54
- "@happyvertical/smrt-prompts": "^0.74.7",
55
- "@happyvertical/smrt-svelte": "^0.74.7",
56
- "@happyvertical/smrt-tenancy": "^0.74.7",
57
- "@happyvertical/smrt-ui": "^0.74.7",
58
- "@happyvertical/smrt-users": "^0.74.7",
59
- "@happyvertical/smrt-web": "^0.74.7",
47
+ "@happyvertical/smrt-app-runtime": "^0.75.1",
48
+ "@happyvertical/smrt-config": "^0.75.1",
49
+ "@happyvertical/smrt-core": "^0.75.1",
50
+ "@happyvertical/smrt-inference": "^0.75.1",
51
+ "@happyvertical/smrt-jobs": "^0.75.1",
52
+ "@happyvertical/smrt-preferences": "^0.75.1",
53
+ "@happyvertical/smrt-profiles": "^0.75.1",
54
+ "@happyvertical/smrt-prompts": "^0.75.1",
55
+ "@happyvertical/smrt-svelte": "^0.75.1",
56
+ "@happyvertical/smrt-tenancy": "^0.75.1",
57
+ "@happyvertical/smrt-ui": "^0.75.1",
58
+ "@happyvertical/smrt-users": "^0.75.1",
59
+ "@happyvertical/smrt-web": "^0.75.1",
60
60
  "@happyvertical/sql": "^0.89.12",
61
61
  "@modelcontextprotocol/server": "^2.3.1",
62
- "@happyvertical/smrt-reports": "^0.74.7",
63
- "@happyvertical/smrt-secrets": "^0.74.7",
64
- "@happyvertical/smrt-template-sveltekit": "^0.74.7"
62
+ "@happyvertical/smrt-reports": "^0.75.1",
63
+ "@happyvertical/smrt-secrets": "^0.75.1",
64
+ "@happyvertical/smrt-template-sveltekit": "^0.75.1",
65
+ "@happyvertical/smrt-languages": "^0.75.1",
66
+ "@happyvertical/smrt-app-mcp": "^0.75.1"
67
+ },
68
+ "imports": {
69
+ "#lib": "./src/lib/index.js",
70
+ "#lib/*": "./src/lib/*"
65
71
  }
66
72
  }
@@ -26,6 +26,7 @@ export default {
26
26
  '@happyvertical/smrt-preferences',
27
27
  '@happyvertical/smrt-inference',
28
28
  '@happyvertical/smrt-prompts',
29
+ '@happyvertical/smrt-languages',
29
30
  '@happyvertical/smrt-tenancy',
30
31
  '@happyvertical/smrt-users',
31
32
  '@happyvertical/smrt-reports',
@@ -1,6 +1,8 @@
1
1
  // See https://svelte.dev/docs/kit/types#app.d.ts
2
2
  // for information about these interfaces
3
3
 
4
+ import type { I18nSnapshot } from '@happyvertical/smrt-ui/i18n';
5
+ import type { LanguageConfiguration } from '#lib/i18n/locales.js';
4
6
  import type { SmrtRuntimeLocals } from '@happyvertical/smrt-app-runtime/sveltekit';
5
7
 
6
8
  declare global {
@@ -8,7 +10,11 @@ declare global {
8
10
  // interface Error {}
9
11
  // Session user, permissions, the authorized `tenantId`/`tenantContext`,
10
12
  // and the URL-selected tenant candidate (never authorization).
11
- interface Locals extends SmrtRuntimeLocals {}
13
+ interface Locals extends SmrtRuntimeLocals {
14
+ i18n?: I18nSnapshot;
15
+ direction?: 'ltr' | 'rtl';
16
+ languageConfiguration?: LanguageConfiguration;
17
+ }
12
18
  // interface PageData {}
13
19
  // interface PageState {}
14
20
  // interface Platform {}
@@ -1,5 +1,5 @@
1
1
  <!doctype html>
2
- <html lang="en">
2
+ <html lang="%smrt.locale%" dir="%smrt.direction%">
3
3
  <head>
4
4
  <meta charset="utf-8" />
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
@@ -7,14 +7,13 @@
7
7
  *
8
8
  * Membership-gated tenant switching belongs in an explicit action using
9
9
  * `switchSessionTenant()` from `@happyvertical/smrt-users/sveltekit`.
10
- * Configure the runtime in `$lib/server/smrt`.
10
+ * Configure the runtime in `#lib/server/smrt`.
11
11
  */
12
12
 
13
- import { installInferenceOverrides } from '$lib/server/settings';
14
- import { runtime } from '$lib/server/smrt';
13
+ import { withLanguageDocument } from '#lib/server/i18n.js';
14
+ import { installInferenceOverrides } from '#lib/server/settings.js';
15
+ import { runtime } from '#lib/server/smrt.js';
15
16
 
16
- export const { handle, init } = runtime;
17
-
18
- // Tier bindings, aliases and fusions saved on the Inference settings page
19
- // apply to every inference call (lazy: the database resolves in `init`).
17
+ export const { init } = runtime;
18
+ export const handle = withLanguageDocument(runtime.handle);
20
19
  installInferenceOverrides();
@@ -4,7 +4,7 @@
4
4
  import { DataTable, type DataTableColumn } from '@happyvertical/smrt-ui/data';
5
5
  import { Alert } from '@happyvertical/smrt-ui/feedback';
6
6
  import { Badge, Card } from '@happyvertical/smrt-ui/ui';
7
- import { parseMaterializedReportDrilldown } from '$lib/materialized-report-drilldown';
7
+ import { parseMaterializedReportDrilldown } from '#lib/materialized-report-drilldown.js';
8
8
 
9
9
  interface ContributorRow {
10
10
  id: string;
@@ -0,0 +1,19 @@
1
+ <script lang="ts">
2
+ import { createI18nContext, setI18nContext, type I18nSnapshot } from '@happyvertical/smrt-ui/i18n';
3
+ import { untrack, type Snippet } from 'svelte';
4
+ import { goto } from '$app/navigation';
5
+ import { registerLocaleTool } from '#lib/i18n/locale-tool.js';
6
+
7
+ let { snapshot, direction, children }: { snapshot: I18nSnapshot; direction: 'ltr' | 'rtl'; children: Snippet } = $props();
8
+ // The cookbook shell itself reads translations before its nested AppShell Provider.
9
+ // Locale-only context avoids a second app-state/WebMCP Provider.
10
+ const i18n = setI18nContext(createI18nContext(untrack(() => snapshot)));
11
+ $effect(() => { i18n.snapshot = snapshot; });
12
+ $effect(() => {
13
+ document.documentElement.lang = snapshot.locale;
14
+ document.documentElement.dir = direction;
15
+ });
16
+ $effect(() => registerLocaleTool((location) => goto(location, { refreshAll: true })));
17
+ </script>
18
+
19
+ {@render children()}
@@ -0,0 +1,17 @@
1
+ <script lang="ts">
2
+ import { Form, Select } from '@happyvertical/smrt-ui/forms';
3
+ import { Button } from '@happyvertical/smrt-ui/ui';
4
+ import type { I18nSnapshot } from '@happyvertical/smrt-ui/i18n';
5
+ import { M } from './messages.js';
6
+ let { snapshot, enabledLocales }: { snapshot: I18nSnapshot; enabledLocales: readonly string[] } = $props();
7
+ const label = (key: string) => snapshot.messages[key] ?? key;
8
+ </script>
9
+
10
+ <Form action="/language" method="POST" preventDefault={false}>
11
+ <Select name="locale" value={snapshot.locale} aria-label={label(M['app.language.label'])}>
12
+ {#each enabledLocales as locale}
13
+ <option value={locale} lang={locale}>{new Intl.DisplayNames([locale], { type: 'language' }).of(locale) ?? locale}</option>
14
+ {/each}
15
+ </Select>
16
+ <Button type="submit">{label(M['app.language.apply'])}</Button>
17
+ </Form>
@@ -0,0 +1,27 @@
1
+ /** Explicit server-safe inventory, including packages used only by lazy routes. */
2
+ import { assembleApplicationCatalog, messageCatalog as ui } from '@happyvertical/smrt-ui/i18n/catalog';
3
+ import { messageCatalog as shell } from '@happyvertical/smrt-svelte/i18n/catalog';
4
+ import { messageCatalog as inference } from '@happyvertical/smrt-inference/i18n/catalog';
5
+ import { messageCatalog as prompts } from '@happyvertical/smrt-prompts/i18n/catalog';
6
+ import { messageCatalog as languages } from '@happyvertical/smrt-languages/i18n/catalog';
7
+ import { messageCatalog as users } from '@happyvertical/smrt-users/i18n/catalog';
8
+ import { english, spanish } from './messages.catalog';
9
+ import { shellSpanish } from './shell-spanish.js';
10
+
11
+ export const applicationCatalogs = [
12
+ ui,
13
+ languages,
14
+ users,
15
+ inference,
16
+ prompts,
17
+ shell,
18
+ { packageName: shell.packageName, messages: Object.entries(shellSpanish).map(([key, template]) => ({ key, locale: 'es', template })) },
19
+ {
20
+ packageName: 'app',
21
+ messages: [
22
+ ...Object.entries(english).map(([key, template]) => ({ key, locale: 'en', template })),
23
+ ...Object.entries(spanish).map(([key, template]) => ({ key, locale: 'es', template })),
24
+ ],
25
+ },
26
+ ];
27
+ export const applicationCatalog = assembleApplicationCatalog(applicationCatalogs);
@@ -0,0 +1,19 @@
1
+ import { registerWebMcpBespokeTool } from '@happyvertical/smrt-web/webmcp';
2
+
3
+ /** Root-owned browser preference tool; native form and tool use the identical cookie endpoint. */
4
+ export function registerLocaleTool(navigate: (location: string) => Promise<unknown>, request: typeof fetch = fetch) {
5
+ return registerWebMcpBespokeTool({
6
+ name: 'languages_locale_set',
7
+ description: 'Set the active browser interface language to an enabled locale and refresh the current page.',
8
+ inputSchema: { type: 'object', properties: { locale: { type: 'string', minLength: 1, maxLength: 100 } }, required: ['locale'], additionalProperties: false },
9
+ annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
10
+ execute: async (args) => {
11
+ const response = await request('/language', { method: 'POST', credentials: 'same-origin',
12
+ headers: { 'content-type': 'application/json' }, body: JSON.stringify(args) });
13
+ if (!response.ok) throw new Error('Unable to change interface language');
14
+ const result = await response.json() as { locale: string; location: string };
15
+ await navigate(result.location);
16
+ return JSON.stringify({ locale: result.locale });
17
+ },
18
+ }, { effects: ['write'] });
19
+ }
@@ -0,0 +1,62 @@
1
+ /** App policy. Stored settings may replace these shipped defaults. */
2
+ export const defaultLanguageConfiguration = {
3
+ defaultLocale: 'en',
4
+ enabledLocales: ['en', 'es'],
5
+ };
6
+ export const languageCookie = 'smrt-locale';
7
+ export interface LanguageConfiguration {
8
+ defaultLocale: string;
9
+ enabledLocales: readonly string[];
10
+ }
11
+
12
+ export function canonicalLocale(value: string): string | undefined {
13
+ try {
14
+ return Intl.getCanonicalLocales(value)[0];
15
+ } catch {
16
+ return undefined;
17
+ }
18
+ }
19
+
20
+ /** A regional preference can use its enabled base language; never enables a locale. */
21
+ export function enabledLocale(value: string, config: LanguageConfiguration): string | undefined {
22
+ let candidate = canonicalLocale(value);
23
+ const enabled = new Map(config.enabledLocales.map((locale) => [canonicalLocale(locale), locale]));
24
+ while (candidate) {
25
+ const match = enabled.get(candidate);
26
+ if (match) return canonicalLocale(match);
27
+ const separator = candidate.lastIndexOf('-');
28
+ candidate = separator < 0 ? undefined : candidate.slice(0, separator);
29
+ }
30
+ return undefined;
31
+ }
32
+
33
+ /** Explicit URL > persisted cookie > weighted browser preferences > app default. */
34
+ export function resolveRequestLocale(
35
+ input: { explicit?: string | null; cookie?: string; acceptLanguage?: string | null },
36
+ config: LanguageConfiguration = defaultLanguageConfiguration,
37
+ ): string {
38
+ for (const preference of [input.explicit, input.cookie]) {
39
+ const locale = preference && enabledLocale(preference, config);
40
+ if (locale) return locale;
41
+ }
42
+ const preferences = (input.acceptLanguage ?? '').split(',').map((entry, index) => {
43
+ const [locale, ...parameters] = entry.trim().split(';');
44
+ const quality = parameters.find((parameter) => parameter.trim().startsWith('q='));
45
+ const weight = quality ? Number(quality.trim().slice(2)) : 1;
46
+ return { locale, weight, index };
47
+ }).filter(({ weight }) => Number.isFinite(weight) && weight > 0 && weight <= 1)
48
+ .sort((a, b) => b.weight - a.weight || a.index - b.index);
49
+ for (const { locale } of preferences) {
50
+ const match = enabledLocale(locale, config);
51
+ if (match) return match;
52
+ }
53
+ const fallback = enabledLocale(config.defaultLocale, config) ?? config.enabledLocales.map(canonicalLocale).find((locale) => locale !== undefined);
54
+ if (!fallback) throw new Error('Configure at least one valid enabled language');
55
+ return fallback;
56
+ }
57
+
58
+ export function localeDirection(locale: string): 'ltr' | 'rtl' {
59
+ // Script-aware: e.g. az-Arab is RTL while az-Latn is LTR.
60
+ const script = new Intl.Locale(canonicalLocale(locale) ?? 'en').maximize().script;
61
+ return ['Arab', 'Hebr', 'Thaa', 'Nkoo', 'Adlm', 'Rohg', 'Syrc', 'Samr', 'Mand'].includes(script ?? '') ? 'rtl' : 'ltr';
62
+ }
@@ -0,0 +1,39 @@
1
+ /** Pure starter defaults: safe to inventory without a Svelte loader. */
2
+ export const english = {
3
+ 'app.settings.title': 'Settings · {application}',
4
+ 'app.settings.languageSaveFailed': 'Unable to save language settings.',
5
+ 'app.settings.allWorkspaces': 'All workspaces',
6
+ 'app.settings.thisWorkspace': 'This workspace',
7
+ 'app.home.title': 'Home',
8
+ 'app.home.empty': 'Nothing here yet',
9
+ 'app.home.description': 'Add your first object in src/lib/objects, then build pages for it here.',
10
+ 'app.nav.settings': 'Settings',
11
+ 'app.nav.settingsDescription': 'Appearance, account and layout',
12
+ 'app.language.label': 'Language',
13
+ 'app.language.apply': 'Change language',
14
+ 'app.settings.inference': 'Inference',
15
+ 'app.settings.inferenceDescription': 'Provider, model tiers, aliases, fusions and usage.',
16
+ 'app.settings.prompts': 'Prompts',
17
+ 'app.settings.promptsDescription': 'Review and override the prompt text the app uses.',
18
+ 'app.settings.languages': 'Languages',
19
+ 'app.settings.languagesDescription': 'Manage languages and interface translations.',
20
+ };
21
+ export const spanish: Record<keyof typeof english, string> = {
22
+ 'app.settings.title': 'Configuración · {application}',
23
+ 'app.settings.languageSaveFailed': 'No se ha podido guardar la configuración de idiomas.',
24
+ 'app.settings.allWorkspaces': 'Todos los espacios de trabajo',
25
+ 'app.settings.thisWorkspace': 'Este espacio de trabajo',
26
+ 'app.home.title': 'Inicio',
27
+ 'app.home.empty': 'Todavía no hay nada aquí',
28
+ 'app.home.description': 'Añade tu primer objeto en src/lib/objects y crea sus páginas aquí.',
29
+ 'app.nav.settings': 'Configuración',
30
+ 'app.nav.settingsDescription': 'Apariencia, cuenta y diseño',
31
+ 'app.language.label': 'Idioma',
32
+ 'app.language.apply': 'Cambiar idioma',
33
+ 'app.settings.inference': 'Inferencia',
34
+ 'app.settings.inferenceDescription': 'Proveedor, niveles de modelos, alias, fusiones y uso.',
35
+ 'app.settings.prompts': 'Instrucciones',
36
+ 'app.settings.promptsDescription': 'Revisa y personaliza las instrucciones que utiliza la aplicación.',
37
+ 'app.settings.languages': 'Idiomas',
38
+ 'app.settings.languagesDescription': 'Gestiona los idiomas y las traducciones de la interfaz.',
39
+ };
@@ -0,0 +1,3 @@
1
+ import { defineMessages } from '@happyvertical/smrt-ui/i18n';
2
+ import { english } from './messages.catalog';
3
+ export const M = defineMessages(english);