@nimiplatform/app-tools 0.1.3 → 0.2.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 (121) hide show
  1. package/LICENSE +198 -6
  2. package/README.md +83 -27
  3. package/bin/nimi-app.mjs +328 -45
  4. package/lib/app-access-declaration.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +411 -149
  6. package/lib/app-pack.mjs +402 -0
  7. package/lib/app-project-lifecycle.mjs +1141 -0
  8. package/lib/app-scaffold-capabilities.mjs +769 -0
  9. package/lib/app-scaffold-default-source.mjs +21 -0
  10. package/lib/app-scaffold-profiles.mjs +1093 -0
  11. package/lib/app-scaffold.mjs +1266 -813
  12. package/lib/index.mjs +195 -42
  13. package/lib/simulator-conformance-ast.mjs +498 -0
  14. package/lib/simulator-conformance-css.mjs +116 -0
  15. package/lib/simulator-conformance-graph.mjs +757 -0
  16. package/lib/simulator-conformance.d.mts +14 -0
  17. package/lib/simulator-conformance.mjs +203 -0
  18. package/lib/simulator-css-profile.d.mts +27 -0
  19. package/lib/simulator-css-profile.mjs +531 -0
  20. package/lib/simulator-kit-export-resolution.mjs +70 -0
  21. package/lib/simulator-manifest.mjs +334 -0
  22. package/lib/windows-powershell.mjs +7 -0
  23. package/package.json +66 -3
  24. package/scripts/dev-shell.mjs +465 -0
  25. package/scripts/sync-app-source.mjs +300 -0
  26. package/scripts/sync-scaffold-versions.mjs +91 -0
  27. package/templates/app-source/LICENSE +21 -0
  28. package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
  29. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
  30. package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
  31. package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
  32. package/templates/app-source/src/ai-studio-core/history.ts +824 -0
  33. package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
  34. package/templates/app-source/src/ai-studio-core/index.ts +214 -0
  35. package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
  36. package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
  37. package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
  38. package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
  39. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
  40. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
  41. package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
  42. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
  43. package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
  44. package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
  45. package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
  46. package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
  58. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
  59. package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
  60. package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
  61. package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
  62. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
  63. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
  64. package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
  65. package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
  66. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
  67. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
  68. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
  69. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
  70. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
  71. package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
  72. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
  73. package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
  74. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
  75. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
  76. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
  77. package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
  78. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
  79. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
  80. package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
  81. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
  82. package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
  83. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
  84. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
  85. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
  86. package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
  87. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
  88. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
  90. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
  91. package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
  92. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
  95. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
  96. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
  97. package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
  98. package/templates/app-source/src/workbench-core/index.ts +17 -0
  99. package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
  100. package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
  101. package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
  102. package/templates/app-source.manifest.json +333 -0
  103. package/templates/default-starter/AGENTS.md +33 -0
  104. package/templates/default-starter/LICENSE +21 -0
  105. package/templates/default-starter/README.md +41 -0
  106. package/templates/default-starter/SECURITY.md +5 -0
  107. package/templates/default-starter/index.html +12 -0
  108. package/templates/default-starter/scripts/validate.mjs +26 -0
  109. package/templates/default-starter/src/shell/App.tsx +27 -0
  110. package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
  111. package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
  112. package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
  113. package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
  114. package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
  115. package/templates/default-starter/src/styles.css +26 -0
  116. package/templates/default-starter/src-tauri/Cargo.toml +17 -0
  117. package/templates/default-starter/src-tauri/build.rs +5 -0
  118. package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
  119. package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
  120. package/templates/default-starter/tsconfig.json +18 -0
  121. package/templates/default-starter.manifest.json +99 -0
@@ -0,0 +1,341 @@
1
+ import { useRef, useState, type RefObject } from 'react';
2
+ import { AppCardSurface, Button, IconButton, NimiText, ScrollShell, StatusBadge, Surface } from '@nimiplatform/kit/ui';
3
+ import {
4
+ Check,
5
+ Code2,
6
+ Copy,
7
+ X,
8
+ } from 'lucide-react';
9
+ import {
10
+ COLOR_TOKENS,
11
+ RECIPES,
12
+ SCALE_TOKENS,
13
+ TYPE_ROLES,
14
+ type CategoryId,
15
+ type KitRecipeExampleContext,
16
+ type Recipe,
17
+ } from './kit-component-gallery-recipes.js';
18
+ import type { KitRecipesCopyText } from './gallery.js';
19
+
20
+ export function countFor(category: CategoryId): number {
21
+ if (category === 'foundations') return COLOR_TOKENS.length + TYPE_ROLES.length + SCALE_TOKENS.length;
22
+ return RECIPES.filter((recipe) => recipe.category === category).length;
23
+ }
24
+
25
+ const fallbackAccessChecks = [
26
+ 'Use the exported Kit primitive instead of app-local visual copies.',
27
+ 'Preserve caller-owned labels, names, and state instead of hiding them behind local wrappers.',
28
+ 'Do not treat this recipe as Runtime or Realm conformance evidence.',
29
+ ];
30
+
31
+ function fallbackTokenFootprint(recipe: Recipe): NonNullable<Recipe['tokenFootprint']> {
32
+ return [
33
+ { token: '--nimi-text-primary', role: `${recipe.exportsLabel} text color`, source: 'tables/nimi-ui-tokens.yaml' },
34
+ { token: '--nimi-border-subtle', role: `${recipe.exportsLabel} boundary treatment`, source: 'tables/nimi-ui-tokens.yaml' },
35
+ { token: '--nimi-surface-card', role: `${recipe.exportsLabel} host surface`, source: 'tables/nimi-ui-themes.yaml' },
36
+ ];
37
+ }
38
+
39
+ function recipeAccessChecks(recipe: Recipe): string[] {
40
+ return recipe.accessChecks ?? fallbackAccessChecks;
41
+ }
42
+
43
+ function recipeTokenFootprint(recipe: Recipe): NonNullable<Recipe['tokenFootprint']> {
44
+ return recipe.tokenFootprint ?? fallbackTokenFootprint(recipe);
45
+ }
46
+
47
+ function recipeImportBlock(recipe: Recipe): string {
48
+ return [
49
+ `import {\n ${recipe.importNames.join(',\n ')}\n} from '@nimiplatform/kit/ui';`,
50
+ ...(recipe.extraImports ?? []),
51
+ ].join('\n');
52
+ }
53
+
54
+ function recipeCopyText(recipe: Recipe, context: KitRecipeExampleContext): string {
55
+ const snippet = typeof recipe.snippet === 'function' ? recipe.snippet(context) : recipe.snippet;
56
+ return `${recipeImportBlock(recipe)}\n\n${snippet}`;
57
+ }
58
+
59
+ function RecipePreview({ recipe, context, compact = false }: { recipe: Recipe; context: KitRecipeExampleContext; compact?: boolean }) {
60
+ const stage = typeof recipe.stage === 'function' ? recipe.stage(context) : recipe.stage;
61
+ return (
62
+ <div
63
+ className={[
64
+ 'kit-recipe-preview grid min-w-0 place-items-center overflow-hidden rounded-2xl border border-[var(--nimi-border-subtle)]',
65
+ 'bg-[radial-gradient(circle_at_1px_1px,color-mix(in_srgb,var(--nimi-text-muted)_14%,transparent)_1px,transparent_0)] bg-[length:18px_18px]',
66
+ compact ? 'min-h-36 h-full p-4' : 'min-h-64 p-7',
67
+ ].join(' ')}
68
+ data-recipe-preview={recipe.id}
69
+ >
70
+ <div className="flex min-w-0 flex-wrap items-center justify-center gap-3">
71
+ {stage}
72
+ </div>
73
+ </div>
74
+ );
75
+ }
76
+
77
+ function RecipeTile({
78
+ recipe,
79
+ context,
80
+ active,
81
+ onInspect,
82
+ }: {
83
+ recipe: Recipe;
84
+ context: KitRecipeExampleContext;
85
+ active: boolean;
86
+ onInspect: () => void;
87
+ }) {
88
+ return (
89
+ <AppCardSurface
90
+ as="article"
91
+ kind="operational-solid"
92
+ active={active}
93
+ className="kit-recipe-tile grid h-full min-w-0 grid-rows-[auto_minmax(9rem,1fr)] gap-4 p-4 min-[1700px]:grid-cols-[minmax(0,1fr)_184px]"
94
+ >
95
+ <div className="grid min-w-0 content-start gap-3">
96
+ <div className="flex min-w-0 items-start justify-between gap-3">
97
+ <strong className="min-w-0 truncate text-base">{recipe.name}</strong>
98
+ <Button
99
+ tone="secondary"
100
+ size="sm"
101
+ active={active}
102
+ aria-pressed={active}
103
+ leadingIcon={<Code2 size={14} strokeWidth={2.2} aria-hidden="true" />}
104
+ aria-label={`Inspect ${recipe.name}`}
105
+ className="kit-recipe-inspect-action min-h-10 rounded-full border-[color-mix(in_srgb,var(--nimi-action-primary-bg)_44%,var(--nimi-border-strong))] bg-[var(--nimi-surface-card)] px-4 text-[var(--nimi-text-primary)] shadow-[var(--nimi-elevation-raised)] hover:border-[var(--nimi-action-primary-bg)] hover:bg-[color-mix(in_srgb,var(--nimi-action-primary-bg)_10%,var(--nimi-surface-card))] hover:shadow-[0_12px_26px_rgba(44,184,154,0.18)] data-[active]:border-[var(--nimi-action-primary-bg)] data-[active]:bg-[color-mix(in_srgb,var(--nimi-action-primary-bg)_16%,var(--nimi-surface-card))] data-[active]:text-[var(--nimi-text-primary)]"
106
+ onClick={onInspect}
107
+ >
108
+ Inspect
109
+ </Button>
110
+ </div>
111
+ </div>
112
+ <RecipePreview recipe={recipe} context={context} compact />
113
+ </AppCardSurface>
114
+ );
115
+ }
116
+
117
+ function RecipeInspector({
118
+ recipe,
119
+ context,
120
+ onClose,
121
+ panelRef,
122
+ copyText,
123
+ }: {
124
+ recipe: Recipe;
125
+ context: KitRecipeExampleContext;
126
+ onClose: () => void;
127
+ panelRef: RefObject<HTMLDivElement | null>;
128
+ copyText: KitRecipesCopyText;
129
+ }) {
130
+ const importBlock = recipeImportBlock(recipe);
131
+ const checks = recipeAccessChecks(recipe);
132
+ const tokenFootprint = recipeTokenFootprint(recipe);
133
+ return (
134
+ <div ref={panelRef} className="min-w-0">
135
+ <Surface
136
+ as="aside"
137
+ material="glass-regular"
138
+ tone="panel"
139
+ elevation="floating"
140
+ padding="none"
141
+ className="kit-doc__inspector sticky top-0 grid max-h-[calc(100cqh-2rem)] min-w-0 content-start gap-5 overflow-y-auto rounded-3xl p-5"
142
+ aria-label={`${recipe.name} Recipe Inspector`}
143
+ >
144
+ <div className="flex min-w-0 items-start justify-between gap-3">
145
+ <div className="grid min-w-0 gap-1">
146
+ <p className="m-0 text-[10px] font-bold uppercase tracking-wider text-[var(--nimi-text-muted)]">Recipe Inspector</p>
147
+ <h3 className="m-0 truncate text-xl font-bold">{recipe.name}</h3>
148
+ </div>
149
+ <IconButton
150
+ type="button"
151
+ aria-label="Close recipe inspector"
152
+ className="grid h-10 w-10 shrink-0 place-items-center rounded-full border border-[var(--nimi-border-subtle)] bg-[var(--nimi-surface-card)] text-[var(--nimi-text-secondary)] transition-colors hover:bg-[var(--nimi-action-ghost-hover)] hover:text-[var(--nimi-text-primary)]"
153
+ onClick={onClose}
154
+ icon={<X size={18} strokeWidth={2.2} aria-hidden="true" />}
155
+ />
156
+ </div>
157
+
158
+ <div className="h-px bg-[var(--nimi-border-subtle)]" />
159
+
160
+ <section className="grid min-w-0 gap-3">
161
+ <div className="flex items-center justify-between gap-3">
162
+ <h4 className="m-0 text-sm font-bold">Use</h4>
163
+ <IconButton
164
+ tone="ghost"
165
+ size="sm"
166
+ aria-label="Copy recipe imports"
167
+ icon={<Copy size={14} aria-hidden="true" />}
168
+ onClick={() => void copyText(importBlock)}
169
+ />
170
+ </div>
171
+ <ScrollShell className="max-h-44 rounded-2xl border border-[var(--nimi-border-subtle)] bg-[var(--nimi-surface-canvas)] p-3">
172
+ <pre className="m-0 whitespace-pre-wrap text-[11px] leading-5 text-[var(--nimi-text-secondary)]">{importBlock}</pre>
173
+ </ScrollShell>
174
+ </section>
175
+
176
+ <div className="h-px bg-[var(--nimi-border-subtle)]" />
177
+
178
+ <section className="grid min-w-0 gap-3">
179
+ <h4 className="m-0 text-sm font-bold">Key props</h4>
180
+ <div className="overflow-hidden rounded-2xl border border-[var(--nimi-border-subtle)]">
181
+ {recipe.props.map((row) => (
182
+ <div key={row.name} className="grid grid-cols-[112px_minmax(0,1fr)] border-b border-[color-mix(in_srgb,var(--nimi-text-primary)_7%,transparent)] last:border-b-0">
183
+ <b className="bg-[color-mix(in_srgb,var(--nimi-surface-card)_70%,transparent)] p-3 text-[11px]">{row.name}</b>
184
+ <span className="p-3 text-[11px] leading-5 text-[var(--nimi-text-secondary)]">{row.desc}</span>
185
+ </div>
186
+ ))}
187
+ </div>
188
+ </section>
189
+
190
+ <div className="h-px bg-[var(--nimi-border-subtle)]" />
191
+
192
+ <section className="grid min-w-0 gap-3">
193
+ <h4 className="m-0 text-sm font-bold">Access</h4>
194
+ <div className="grid gap-3">
195
+ {checks.map((rule) => (
196
+ <div key={rule} className="grid grid-cols-[22px_minmax(0,1fr)] items-start gap-3 text-xs leading-5 text-[var(--nimi-text-secondary)]">
197
+ <span className="mt-0.5 grid h-5 w-5 place-items-center rounded-full bg-[var(--nimi-status-success-soft-bg)] text-[var(--nimi-status-success-soft-text)]">
198
+ <Check size={12} aria-hidden="true" />
199
+ </span>
200
+ <span>{rule}</span>
201
+ </div>
202
+ ))}
203
+ </div>
204
+ </section>
205
+
206
+ <div className="h-px bg-[var(--nimi-border-subtle)]" />
207
+
208
+ <section className="grid min-w-0 gap-3">
209
+ <h4 className="m-0 text-sm font-bold">Design tokens</h4>
210
+ <div className="flex min-w-0 flex-wrap gap-2">
211
+ {tokenFootprint.map((row) => (
212
+ <code key={`${row.token}-${row.role}`} className="rounded-full bg-[color-mix(in_srgb,var(--nimi-status-info-soft-bg)_72%,var(--nimi-surface-card))] px-3 py-2 text-[11px] text-[var(--nimi-text-secondary)]">
213
+ {row.token}
214
+ </code>
215
+ ))}
216
+ </div>
217
+ </section>
218
+
219
+ <Button tone="primary" fullWidth leadingIcon={<Copy size={15} aria-hidden="true" />} onClick={() => void copyText(recipeCopyText(recipe, context))}>
220
+ Copy selected recipe
221
+ </Button>
222
+ </Surface>
223
+ </div>
224
+ );
225
+ }
226
+
227
+ export function RecipeWorkspace({ recipes, copyText, exampleAppId }: { recipes: Recipe[]; copyText: KitRecipesCopyText; exampleAppId: string }) {
228
+ const [selectedRecipeId, setSelectedRecipeId] = useState(recipes[0]?.id ?? '');
229
+ const [inspectorOpen, setInspectorOpen] = useState(false);
230
+ const inspectorPanelRef = useRef<HTMLDivElement | null>(null);
231
+ const selectedRecipe = recipes.find((recipe) => recipe.id === selectedRecipeId) ?? recipes[0];
232
+
233
+ if (!selectedRecipe) return null;
234
+
235
+ function closeInspector() {
236
+ setInspectorOpen(false);
237
+ }
238
+
239
+ function inspectRecipe(recipe: Recipe) {
240
+ setSelectedRecipeId(recipe.id);
241
+ setInspectorOpen(true);
242
+ }
243
+
244
+ return (
245
+ <div
246
+ className={inspectorOpen ? 'kit-recipe-workspace grid min-w-0 gap-5 lg:grid-cols-[minmax(0,1fr)_340px]' : 'kit-recipe-workspace grid min-w-0 gap-5'}
247
+ onBlur={(event) => {
248
+ if (!inspectorOpen || event.currentTarget.contains(event.relatedTarget)) return;
249
+ closeInspector();
250
+ }}
251
+ >
252
+ <div className="grid min-w-0 content-start gap-4">
253
+ <div className={inspectorOpen ? 'grid min-w-0 items-stretch gap-4 2xl:grid-cols-2' : 'grid min-w-0 items-stretch gap-4 lg:grid-cols-2'}>
254
+ {recipes.map((recipe) => (
255
+ <RecipeTile
256
+ key={recipe.id}
257
+ recipe={recipe}
258
+ context={{ appId: exampleAppId }}
259
+ active={recipe.id === selectedRecipe.id}
260
+ onInspect={() => inspectRecipe(recipe)}
261
+ />
262
+ ))}
263
+ </div>
264
+ </div>
265
+
266
+ {inspectorOpen ? (
267
+ <RecipeInspector
268
+ recipe={selectedRecipe}
269
+ context={{ appId: exampleAppId }}
270
+ onClose={closeInspector}
271
+ panelRef={inspectorPanelRef}
272
+ copyText={copyText}
273
+ />
274
+ ) : null}
275
+ </div>
276
+ );
277
+ }
278
+
279
+ export function FoundationsCanvas() {
280
+ return (
281
+ <div className="kit-foundations grid min-w-0 grid-cols-2 gap-4 overflow-hidden max-[980px]:grid-cols-1">
282
+ {/* Color roles */}
283
+ <Surface className="kit-found-card grid min-w-0 overflow-hidden content-start gap-4 p-5" material="glass-thin" tone="panel" elevation="base">
284
+ <div className="kit-found-head flex min-w-0 items-start justify-between gap-3">
285
+ <div className="grid min-w-0 gap-1">
286
+ <strong className="text-base">Color roles</strong>
287
+ </div>
288
+ <StatusBadge tone="success" shape="soft">Theme-aware</StatusBadge>
289
+ </div>
290
+ <div className="kit-token-grid grid grid-cols-3 gap-3 max-[520px]:grid-cols-2">
291
+ {COLOR_TOKENS.map((entry) => (
292
+ <div key={entry.token} className="kit-token grid min-w-0 gap-1.5">
293
+ <span
294
+ className="kit-token__chip block h-14 rounded-xl border border-[color-mix(in_srgb,var(--nimi-text-primary)_8%,transparent)]"
295
+ style={{ background: `var(${entry.token})` }}
296
+ aria-hidden="true"
297
+ />
298
+ <b className="block truncate text-xs">{entry.label}</b>
299
+ </div>
300
+ ))}
301
+ </div>
302
+ </Surface>
303
+
304
+ {/* Text roles */}
305
+ <Surface className="kit-found-card grid min-w-0 overflow-hidden content-start gap-4 p-5" material="glass-thin" tone="panel" elevation="base">
306
+ <div className="kit-found-head flex min-w-0 items-start justify-between gap-3">
307
+ <div className="grid min-w-0 gap-1">
308
+ <strong className="text-base">Text roles</strong>
309
+ </div>
310
+ <StatusBadge tone="info" shape="soft">NimiText</StatusBadge>
311
+ </div>
312
+ <div className="kit-type-stack grid gap-3">
313
+ {TYPE_ROLES.map((entry) => (
314
+ <div key={entry.role} className="kit-type-row flex min-w-0 overflow-hidden border-b border-[color-mix(in_srgb,var(--nimi-text-primary)_7%,transparent)] pb-2 last:border-b-0 last:pb-0">
315
+ <NimiText role={entry.role} className="min-w-0 break-words">{entry.sample}</NimiText>
316
+ </div>
317
+ ))}
318
+ </div>
319
+ </Surface>
320
+
321
+ {/* Corner radius */}
322
+ <Surface className="kit-found-card col-span-2 grid min-w-0 overflow-hidden content-start gap-4 p-5 max-[980px]:col-span-1" material="glass-thin" tone="panel" elevation="base">
323
+ <div className="kit-found-head grid gap-1">
324
+ <strong className="text-base">Corner radius</strong>
325
+ </div>
326
+ <div className="kit-scale-row flex flex-wrap items-end gap-5">
327
+ {SCALE_TOKENS.map((entry) => (
328
+ <div key={entry.token} className="grid justify-items-center gap-2">
329
+ <span
330
+ className="kit-scale-chip grid h-16 w-16 place-items-center border border-[var(--nimi-border-strong)] bg-[color-mix(in_srgb,var(--nimi-action-primary-bg)_8%,transparent)]"
331
+ style={{ borderRadius: `var(${entry.token})` }}
332
+ aria-hidden="true"
333
+ />
334
+ <b className="text-xs">{entry.label}</b>
335
+ </div>
336
+ ))}
337
+ </div>
338
+ </Surface>
339
+ </div>
340
+ );
341
+ }
@@ -0,0 +1,26 @@
1
+ export type StudioCreateCapabilityId = 'text.generate' | 'chat.stream' | 'text.embed';
2
+
3
+ export const studioCreateDescriptors = Object.freeze([
4
+ {
5
+ id: 'text.generate', label: 'Text Studio', labelKey: 'Capabilities.textGenerate.label', group: 'text',
6
+ section: 'chat',
7
+ summary: 'Prompt → text.generate CapabilityContract → typed Runtime result.',
8
+ summaryKey: 'Capabilities.textGenerate.summary',
9
+ surface: 'sdk.localApp.ai.text.generateCandidate → RuntimeAiService.GenerateLocalAppTextCandidate',
10
+ execution: 'runtime-sdk', capabilityContract: 'text.generate',
11
+ },
12
+ {
13
+ id: 'chat.stream', label: 'Chat Stream', labelKey: 'Capabilities.chatStream.label', group: 'text',
14
+ section: 'chat',
15
+ summary: 'Conversation turn → protected text.generate stream → incremental typed Runtime result.',
16
+ summaryKey: 'Capabilities.chatStream.summary', surface: 'kit.runRuntimeAIConsumeCapability → sdk.localApp.ai.text.streamTurn',
17
+ execution: 'runtime-sdk', capabilityContract: 'text.generate',
18
+ },
19
+ {
20
+ id: 'text.embed', label: 'Embeddings', labelKey: 'Capabilities.textEmbed.label', group: 'text',
21
+ section: 'embed',
22
+ summary: 'Input string → protected scenario.execute text.embed → typed vector result.',
23
+ summaryKey: 'Capabilities.textEmbed.summary', surface: 'sdk.localApp.ai.scenario.execute:text-embed',
24
+ execution: 'runtime-sdk', capabilityContract: 'text.embed',
25
+ },
26
+ ] as const);
@@ -0,0 +1,14 @@
1
+ export { studioCreateDescriptors, type StudioCreateCapabilityId } from './descriptors.js';
2
+ export { studioCreateMessageBundles } from './messages/index.js';
3
+ export { StudioCreateParameterPanel } from './parameter-panel.js';
4
+ export {
5
+ nonEmptyEmbeddingInputs,
6
+ studioChatStreamParameters,
7
+ studioTextEmbedParameters,
8
+ studioTextGenerateParameters,
9
+ type StudioEmbeddingParameters,
10
+ type StudioTextCandidateParameters,
11
+ type StudioTextTurnParameters,
12
+ } from './parameters.js';
13
+ export { studioCreateModule } from './registration.js';
14
+ export { studioCreateRuntimeHandlers } from './runtime.js';
@@ -0,0 +1,67 @@
1
+ {
2
+ "Capabilities": {
3
+ "textGenerate": {
4
+ "label": "Text Studio",
5
+ "summary": "Prompt → text.generate CapabilityContract → typed Runtime result."
6
+ },
7
+ "chatStream": {
8
+ "label": "Chat Stream",
9
+ "summary": "Conversation turn → protected text.generate stream → incremental typed Runtime result."
10
+ },
11
+ "textEmbed": {
12
+ "label": "Embeddings",
13
+ "summary": "Input string → protected scenario.execute text.embed → typed vector result."
14
+ }
15
+ },
16
+ "Studio": {
17
+ "profiles": {
18
+ "textGenerate": {
19
+ "inputTitle": "Test text generation",
20
+ "inputPlaceholder": "Describe what you want Nimi to write…",
21
+ "primaryLabel": "Generate text",
22
+ "primaryRunningLabel": "Generating…",
23
+ "emptyTitle": "Waiting for generation",
24
+ "emptyHint": "Your generated text will appear here.",
25
+ "footnote": "Your request will be sent to the runtime to generate content."
26
+ },
27
+ "chatStream": {
28
+ "inputTitle": "Test chat streaming",
29
+ "inputPlaceholder": "Type a message for Nimi to continue…",
30
+ "primaryLabel": "Stream reply",
31
+ "primaryRunningLabel": "Streaming…",
32
+ "emptyTitle": "Waiting for stream",
33
+ "emptyHint": "Streamed tokens will appear here as they arrive from the runtime.",
34
+ "footnote": "Deltas stream live from the runtime; nothing is fabricated locally."
35
+ },
36
+ "textEmbed": {
37
+ "inputTitle": "Test embeddings",
38
+ "inputPlaceholder": "Enter the text to convert into an embedding vector…",
39
+ "primaryLabel": "Generate embedding",
40
+ "primaryRunningLabel": "Embedding…",
41
+ "emptyTitle": "Waiting for embedding",
42
+ "emptyHint": "The runtime result will appear here after generation.",
43
+ "footnote": "Runtime technical output is available in diagnostics when needed."
44
+ }
45
+ },
46
+ "composer": {
47
+ "textGeneratePlaceholder": "Ask Nimi to draft, rewrite, summarize, or structure something..."
48
+ },
49
+ "parameters": {
50
+ "stopPlaceholder": "One stop sequence per line",
51
+ "embeddingInput": "Embedding input {{index}}",
52
+ "embeddingInputPlaceholder": "Text to embed",
53
+ "addInput": "Add input",
54
+ "removeInput": "Remove input {{index}}",
55
+ "fields": {
56
+ "inputs": "Embedding inputs",
57
+ "temperature": "Temperature",
58
+ "topP": "Top P",
59
+ "maxTokens": "Max tokens",
60
+ "topK": "Top K",
61
+ "presencePenalty": "Presence penalty",
62
+ "frequencyPenalty": "Frequency penalty",
63
+ "stop": "Stop sequences"
64
+ }
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,5 @@
1
+ import type { AIStudioMessageBundles } from '../../../ai-studio-core/messages/index.js';
2
+ import en from './en.json' with { type: 'json' };
3
+ import zh from './zh.json' with { type: 'json' };
4
+
5
+ export const studioCreateMessageBundles = Object.freeze({ en, zh }) satisfies AIStudioMessageBundles;
@@ -0,0 +1,67 @@
1
+ {
2
+ "Capabilities": {
3
+ "textGenerate": {
4
+ "label": "文本工作室",
5
+ "summary": "提示词 → text.generate 能力契约 → 类型化 Runtime 结果。"
6
+ },
7
+ "chatStream": {
8
+ "label": "聊天流",
9
+ "summary": "会话轮次 → 受保护的 text.generate 流 → 增量类型化 Runtime 结果。"
10
+ },
11
+ "textEmbed": {
12
+ "label": "向量嵌入",
13
+ "summary": "输入字符串 → 受保护的 scenario.execute text.embed → 类型化向量结果。"
14
+ }
15
+ },
16
+ "Studio": {
17
+ "profiles": {
18
+ "textGenerate": {
19
+ "inputTitle": "测试文本生成",
20
+ "inputPlaceholder": "描述你想让 Nimi 写的内容…",
21
+ "primaryLabel": "生成文本",
22
+ "primaryRunningLabel": "生成中…",
23
+ "emptyTitle": "等待生成",
24
+ "emptyHint": "生成的文本会显示在这里。",
25
+ "footnote": "你的请求会发送到 Runtime 以生成内容。"
26
+ },
27
+ "chatStream": {
28
+ "inputTitle": "测试聊天流式输出",
29
+ "inputPlaceholder": "输入一条消息让 Nimi 继续…",
30
+ "primaryLabel": "流式回复",
31
+ "primaryRunningLabel": "流式输出中…",
32
+ "emptyTitle": "等待流式输出",
33
+ "emptyHint": "来自 Runtime 的流式 token 会实时显示在这里。",
34
+ "footnote": "增量数据实时来自 Runtime;本地不做任何伪造。"
35
+ },
36
+ "textEmbed": {
37
+ "inputTitle": "测试向量嵌入",
38
+ "inputPlaceholder": "输入要转换为嵌入向量的文本…",
39
+ "primaryLabel": "生成嵌入",
40
+ "primaryRunningLabel": "嵌入生成中…",
41
+ "emptyTitle": "等待嵌入",
42
+ "emptyHint": "生成完成后,Runtime 结果会显示在这里。",
43
+ "footnote": "需要时可在诊断中查看 Runtime 技术输出。"
44
+ }
45
+ },
46
+ "composer": {
47
+ "textGeneratePlaceholder": "让 Nimi 起草、改写、总结或组织一些内容……"
48
+ },
49
+ "parameters": {
50
+ "stopPlaceholder": "每行一个停止序列",
51
+ "embeddingInput": "嵌入输入 {{index}}",
52
+ "embeddingInputPlaceholder": "要生成嵌入的文本",
53
+ "addInput": "添加输入",
54
+ "removeInput": "移除输入 {{index}}",
55
+ "fields": {
56
+ "inputs": "嵌入输入",
57
+ "temperature": "Temperature",
58
+ "topP": "Top P",
59
+ "maxTokens": "最大 Token 数",
60
+ "topK": "Top K",
61
+ "presencePenalty": "存在惩罚",
62
+ "frequencyPenalty": "频率惩罚",
63
+ "stop": "停止序列"
64
+ }
65
+ }
66
+ }
67
+ }
@@ -0,0 +1,153 @@
1
+ import { Button, TextareaField } from '@nimiplatform/kit/ui';
2
+ import { Plus, Trash2 } from 'lucide-react';
3
+
4
+ import {
5
+ StudioNumberParameter,
6
+ StudioParameterField,
7
+ StudioParameterPanelFrame,
8
+ StudioRouteAwareParameterFields,
9
+ type StudioParameterFieldDefinition,
10
+ type StudioParameterPanelProps,
11
+ type StudioParameterTranslate,
12
+ } from '../../ai-studio-core/parameter-fields.js';
13
+ import { useAIStudioHost } from '../../ai-studio-core/host-context.js';
14
+ import type {
15
+ StudioEmbeddingParameters,
16
+ StudioTextTurnParameters,
17
+ } from './parameters.js';
18
+
19
+ function TextGenerationFields(props: StudioParameterPanelProps) {
20
+ const { translate: t } = useAIStudioHost();
21
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
22
+ const parameters = props.parameters as StudioTextTurnParameters;
23
+ const update = props.onChange as (next: StudioTextTurnParameters) => void;
24
+ const numberField = (
25
+ field: keyof StudioTextTurnParameters,
26
+ label: string,
27
+ options: { min?: number; max?: number; step?: number | 'any' } = {},
28
+ ): StudioParameterFieldDefinition => ({
29
+ field,
30
+ label,
31
+ render: (routeDisabled) => (
32
+ <StudioNumberParameter
33
+ current={parameters}
34
+ field={field}
35
+ label={label}
36
+ onChange={update}
37
+ disabled={props.disabled || routeDisabled}
38
+ {...options}
39
+ />
40
+ ),
41
+ });
42
+ const fields: StudioParameterFieldDefinition[] = [
43
+ numberField('temperature', t('Studio.parameters.fields.temperature')),
44
+ numberField('topP', t('Studio.parameters.fields.topP'), { min: 0, max: 1 }),
45
+ numberField('maxTokens', t('Studio.parameters.fields.maxTokens'), { min: 0, step: 1 }),
46
+ ];
47
+ if (props.capabilityId === 'chat.stream') {
48
+ const stopLabel = t('Studio.parameters.fields.stop');
49
+ fields.push(
50
+ numberField('topK', t('Studio.parameters.fields.topK'), { min: 0, step: 1 }),
51
+ numberField('presencePenalty', t('Studio.parameters.fields.presencePenalty')),
52
+ numberField('frequencyPenalty', t('Studio.parameters.fields.frequencyPenalty')),
53
+ {
54
+ field: 'stop',
55
+ label: stopLabel,
56
+ render: (routeDisabled) => (
57
+ <StudioParameterField label={stopLabel}>
58
+ <TextareaField
59
+ rows={3}
60
+ value={parameters.stop?.join('\n') ?? ''}
61
+ placeholder={t('Studio.parameters.stopPlaceholder')}
62
+ disabled={props.disabled || routeDisabled}
63
+ onChange={(event) => {
64
+ const values = event.currentTarget.value.split(/\r?\n/u).map((value) => value.trim()).filter(Boolean);
65
+ if (values.length > 0) update({ ...parameters, stop: values });
66
+ else {
67
+ const next = { ...parameters };
68
+ delete next.stop;
69
+ update(next);
70
+ }
71
+ }}
72
+ />
73
+ </StudioParameterField>
74
+ ),
75
+ },
76
+ numberField('seed', t('Studio.parameters.fields.seed'), { step: 1 }),
77
+ );
78
+ }
79
+ return (
80
+ <StudioRouteAwareParameterFields
81
+ contract={props.contract}
82
+ source={props.source}
83
+ fields={fields}
84
+ translate={translate}
85
+ />
86
+ );
87
+ }
88
+
89
+ function EmbeddingFields(props: StudioParameterPanelProps) {
90
+ const { translate: t } = useAIStudioHost();
91
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
92
+ const parameters = props.parameters as StudioEmbeddingParameters;
93
+ const values = parameters.inputs?.length ? parameters.inputs : [''];
94
+ const updateValues = (nextValues: string[]) => {
95
+ if (nextValues.some((value) => value.trim())) props.onChange({ inputs: nextValues });
96
+ else props.onChange({});
97
+ };
98
+ const label = t('Studio.parameters.fields.inputs');
99
+ const fields: StudioParameterFieldDefinition[] = [{
100
+ field: 'inputs',
101
+ label,
102
+ render: (routeDisabled) => (
103
+ <div className="studio-parameters__stack">
104
+ {values.map((value, index) => (
105
+ <div className="studio-parameters__repeat" key={index}>
106
+ <TextareaField
107
+ rows={2}
108
+ value={value}
109
+ disabled={props.disabled || routeDisabled}
110
+ aria-label={t('Studio.parameters.embeddingInput', { index: index + 1 })}
111
+ placeholder={t('Studio.parameters.embeddingInputPlaceholder')}
112
+ onChange={(event) => updateValues(values.map((entry, itemIndex) => itemIndex === index ? event.currentTarget.value : entry))}
113
+ />
114
+ {values.length > 1 ? (
115
+ <Button type="button" tone="ghost" size="sm" disabled={props.disabled || routeDisabled} onClick={() => updateValues(values.filter((_, itemIndex) => itemIndex !== index))} aria-label={t('Studio.parameters.removeInput', { index: index + 1 })}>
116
+ <Trash2 size={14} aria-hidden="true" />
117
+ </Button>
118
+ ) : null}
119
+ </div>
120
+ ))}
121
+ <Button type="button" tone="ghost" size="sm" disabled={props.disabled || routeDisabled} leadingIcon={<Plus size={14} aria-hidden="true" />} onClick={() => updateValues([...values, ''])}>
122
+ {t('Studio.parameters.addInput')}
123
+ </Button>
124
+ </div>
125
+ ),
126
+ }];
127
+ return (
128
+ <StudioRouteAwareParameterFields
129
+ contract={props.contract}
130
+ source={props.source}
131
+ fields={fields}
132
+ translate={translate}
133
+ contentClassName="studio-parameters__stack"
134
+ />
135
+ );
136
+ }
137
+
138
+ export function StudioCreateParameterPanel(props: StudioParameterPanelProps) {
139
+ const { translate: t } = useAIStudioHost();
140
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
141
+ const fields = props.capabilityId === 'text.embed'
142
+ ? <EmbeddingFields {...props} />
143
+ : <TextGenerationFields {...props} />;
144
+ return (
145
+ <StudioParameterPanelFrame
146
+ translate={translate}
147
+ disabled={props.disabled}
148
+ onReset={() => props.onChange(props.contract.initial())}
149
+ >
150
+ {fields}
151
+ </StudioParameterPanelFrame>
152
+ );
153
+ }