@nimiplatform/app-tools 0.1.2 → 0.2.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 (120) 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 +401 -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 +194 -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/package.json +66 -3
  23. package/scripts/dev-shell.mjs +465 -0
  24. package/scripts/sync-app-source.mjs +300 -0
  25. package/scripts/sync-scaffold-versions.mjs +91 -0
  26. package/templates/app-source/LICENSE +21 -0
  27. package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
  28. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
  29. package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
  30. package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
  31. package/templates/app-source/src/ai-studio-core/history.ts +824 -0
  32. package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
  33. package/templates/app-source/src/ai-studio-core/index.ts +214 -0
  34. package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
  35. package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
  36. package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
  37. package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
  38. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
  39. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
  40. package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
  41. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
  42. package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
  43. package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
  44. package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
  45. package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
  58. package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
  59. package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
  60. package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
  61. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
  62. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
  63. package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
  64. package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
  65. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
  66. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
  67. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
  68. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
  69. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
  70. package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
  71. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
  72. package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
  73. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
  74. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
  75. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
  76. package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
  77. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
  78. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
  79. package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
  80. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
  81. package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
  82. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
  83. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
  84. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
  85. package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
  86. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
  87. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
  88. package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
  90. package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
  91. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
  92. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
  95. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
  96. package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
  97. package/templates/app-source/src/workbench-core/index.ts +17 -0
  98. package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
  99. package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
  100. package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
  101. package/templates/app-source.manifest.json +333 -0
  102. package/templates/default-starter/AGENTS.md +33 -0
  103. package/templates/default-starter/LICENSE +21 -0
  104. package/templates/default-starter/README.md +41 -0
  105. package/templates/default-starter/SECURITY.md +5 -0
  106. package/templates/default-starter/index.html +12 -0
  107. package/templates/default-starter/scripts/validate.mjs +26 -0
  108. package/templates/default-starter/src/shell/App.tsx +27 -0
  109. package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
  110. package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
  111. package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
  112. package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
  113. package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
  114. package/templates/default-starter/src/styles.css +26 -0
  115. package/templates/default-starter/src-tauri/Cargo.toml +17 -0
  116. package/templates/default-starter/src-tauri/build.rs +5 -0
  117. package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
  118. package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
  119. package/templates/default-starter/tsconfig.json +18 -0
  120. package/templates/default-starter.manifest.json +99 -0
@@ -0,0 +1,283 @@
1
+ import { useRef, useState, type ChangeEvent } from 'react';
2
+ import { Button, SelectField, TextareaField } from '@nimiplatform/kit/ui';
3
+ import { Trash2, Upload } from 'lucide-react';
4
+
5
+ import {
6
+ StudioBooleanParameter,
7
+ StudioNumberParameter,
8
+ StudioParameterField,
9
+ StudioParameterPanelFrame,
10
+ StudioRouteAwareParameterFields,
11
+ StudioTextParameter,
12
+ type StudioParameterFieldDefinition,
13
+ type StudioParameterPanelProps,
14
+ type StudioParameterTranslate,
15
+ } from '../../ai-studio-core/parameter-fields.js';
16
+ import { useAIStudioHost } from '../../ai-studio-core/host-context.js';
17
+ import {
18
+ MAX_STUDIO_ARTIFACT_UPLOAD_BYTES,
19
+ type StudioImageGenerationParameters,
20
+ type StudioMusicGenerationParameters,
21
+ type StudioVideoGenerationParameters,
22
+ } from './parameters.js';
23
+
24
+ const STUDIO_IMAGE_MIME_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/gif'] as const;
25
+ type StudioImageMimeType = typeof STUDIO_IMAGE_MIME_TYPES[number];
26
+
27
+ function isStudioImageMimeType(value: string): value is StudioImageMimeType {
28
+ return STUDIO_IMAGE_MIME_TYPES.includes(value as StudioImageMimeType);
29
+ }
30
+
31
+ function MusicFields(props: StudioParameterPanelProps) {
32
+ const { translate: t } = useAIStudioHost();
33
+ const parameters = props.parameters as StudioMusicGenerationParameters;
34
+ const update = props.onChange as (next: StudioMusicGenerationParameters) => void;
35
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
36
+ const fields: StudioParameterFieldDefinition[] = [{
37
+ field: 'lyrics',
38
+ label: t('Studio.parameters.fields.lyrics'),
39
+ render: (routeDisabled) => (
40
+ <StudioParameterField label={t('Studio.parameters.fields.lyrics')}>
41
+ <TextareaField
42
+ value={parameters.lyrics ?? ''}
43
+ disabled={props.disabled || routeDisabled}
44
+ textareaClassName="min-h-36 font-mono"
45
+ onChange={(event) => update({ ...parameters, lyrics: event.currentTarget.value })}
46
+ />
47
+ </StudioParameterField>
48
+ ),
49
+ }];
50
+ return <StudioRouteAwareParameterFields contract={props.contract} source={props.source} fields={fields} translate={translate} />;
51
+ }
52
+
53
+ function ImageFields(props: StudioParameterPanelProps) {
54
+ const host = useAIStudioHost();
55
+ const { translate: t } = useAIStudioHost();
56
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
57
+ const parameters = props.parameters as StudioImageGenerationParameters;
58
+ const update = props.onChange as (next: StudioImageGenerationParameters) => void;
59
+ const inputRef = useRef<HTMLInputElement>(null);
60
+ const [uploading, setUploading] = useState(false);
61
+ const [uploadError, setUploadError] = useState('');
62
+ const [uploadedFileName, setUploadedFileName] = useState('');
63
+ async function selectReferenceImage(event: ChangeEvent<HTMLInputElement>) {
64
+ const file = event.currentTarget.files?.[0];
65
+ event.currentTarget.value = '';
66
+ if (!file) return;
67
+ if (file.size === 0 || file.size > MAX_STUDIO_ARTIFACT_UPLOAD_BYTES) {
68
+ setUploadError(t('Studio.parameters.imageFileTooLarge'));
69
+ return;
70
+ }
71
+ if (!isStudioImageMimeType(file.type)) {
72
+ setUploadError(t('Studio.parameters.imageFileMimeUnsupported'));
73
+ return;
74
+ }
75
+ setUploading(true);
76
+ setUploadError('');
77
+ try {
78
+ const result = await host.sdk.uploadLocalAppArtifact({
79
+ bytes: new Uint8Array(await file.arrayBuffer()),
80
+ mimeType: file.type,
81
+ });
82
+ const next = { ...parameters, referenceImageArtifactId: result.artifactId };
83
+ delete next.referenceImage;
84
+ setUploadedFileName(file.name);
85
+ update(next);
86
+ } catch (error) {
87
+ setUploadError(error instanceof Error ? error.message : String(error));
88
+ } finally {
89
+ setUploading(false);
90
+ }
91
+ }
92
+ const updateReferenceUrl = (next: StudioImageGenerationParameters) => {
93
+ const normalized = { ...next };
94
+ delete normalized.referenceImageArtifactId;
95
+ setUploadedFileName('');
96
+ update(normalized);
97
+ };
98
+ const clearReferenceArtifact = () => {
99
+ const normalized = { ...parameters };
100
+ delete normalized.referenceImageArtifactId;
101
+ setUploadedFileName('');
102
+ setUploadError('');
103
+ update(normalized);
104
+ };
105
+ const textField = (field: keyof StudioImageGenerationParameters, label: string, placeholder?: string): StudioParameterFieldDefinition => ({
106
+ field,
107
+ label,
108
+ render: (routeDisabled) => <StudioTextParameter current={parameters} field={field} label={label} placeholder={placeholder} onChange={update} disabled={props.disabled || routeDisabled} />,
109
+ });
110
+ const fields: StudioParameterFieldDefinition[] = [
111
+ textField('negativePrompt', t('Studio.parameters.fields.negativePrompt')),
112
+ {
113
+ field: 'count',
114
+ label: t('Studio.parameters.fields.count'),
115
+ render: (routeDisabled) => <StudioNumberParameter current={parameters} field="count" label={t('Studio.parameters.fields.count')} onChange={update} disabled={props.disabled || routeDisabled} min={1} step={1} />,
116
+ },
117
+ textField('size', t('Studio.parameters.fields.size'), '1024x1024'),
118
+ {
119
+ field: 'seed',
120
+ label: t('Studio.parameters.fields.seed'),
121
+ render: (routeDisabled) => <StudioNumberParameter current={parameters} field="seed" label={t('Studio.parameters.fields.seed')} onChange={update} disabled={props.disabled || routeDisabled} step={1} />,
122
+ },
123
+ textField('aspectRatio', t('Studio.parameters.fields.aspectRatio')),
124
+ textField('quality', t('Studio.parameters.fields.quality')),
125
+ textField('style', t('Studio.parameters.fields.style')),
126
+ {
127
+ field: 'referenceImage',
128
+ label: t('Studio.parameters.fields.referenceImage'),
129
+ render: (routeDisabled) => <StudioTextParameter current={parameters} field="referenceImage" label={t('Studio.parameters.fields.referenceImage')} placeholder="https://…" onChange={updateReferenceUrl} disabled={props.disabled || routeDisabled || uploading} />,
130
+ },
131
+ {
132
+ field: 'referenceImageArtifactId',
133
+ label: t('Studio.parameters.fields.referenceImageFile'),
134
+ render: (routeDisabled) => (
135
+ <StudioParameterField label={t('Studio.parameters.fields.referenceImageFile')}>
136
+ <input ref={inputRef} className="studio-parameters__file-input" type="file" accept="image/png,image/jpeg,image/webp,image/gif" disabled={props.disabled || routeDisabled || uploading} onChange={(event) => void selectReferenceImage(event)} />
137
+ <div className="studio-parameters__file-row">
138
+ <Button type="button" tone="ghost" size="sm" disabled={props.disabled || routeDisabled || uploading} leadingIcon={<Upload size={14} aria-hidden="true" />} onClick={() => inputRef.current?.click()}>
139
+ {uploading ? t('Studio.parameters.uploadingImage') : t('Studio.parameters.chooseImageFile')}
140
+ </Button>
141
+ {uploadedFileName ? <span>{uploadedFileName}</span> : null}
142
+ {parameters.referenceImageArtifactId ? (
143
+ <Button type="button" tone="ghost" size="sm" disabled={props.disabled || routeDisabled || uploading} leadingIcon={<Trash2 size={14} aria-hidden="true" />} onClick={clearReferenceArtifact}>
144
+ {t('Studio.parameters.clearReferenceImage')}
145
+ </Button>
146
+ ) : null}
147
+ </div>
148
+ {uploadError ? <small>{uploadError}</small> : null}
149
+ </StudioParameterField>
150
+ ),
151
+ },
152
+ textField('mask', t('Studio.parameters.fields.mask'), 'https://…'),
153
+ ];
154
+ return <StudioRouteAwareParameterFields contract={props.contract} source={props.source} fields={fields} translate={translate} />;
155
+ }
156
+
157
+ function VideoFields(props: StudioParameterPanelProps) {
158
+ const host = useAIStudioHost();
159
+ const { translate: t } = useAIStudioHost();
160
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
161
+ const parameters = props.parameters as StudioVideoGenerationParameters;
162
+ const update = props.onChange as (next: StudioVideoGenerationParameters) => void;
163
+ const inputRef = useRef<HTMLInputElement>(null);
164
+ const [uploading, setUploading] = useState(false);
165
+ const [uploadError, setUploadError] = useState('');
166
+ const [uploadedFileName, setUploadedFileName] = useState('');
167
+ async function selectReferenceImage(event: ChangeEvent<HTMLInputElement>) {
168
+ const file = event.currentTarget.files?.[0];
169
+ event.currentTarget.value = '';
170
+ if (!file) return;
171
+ if (file.size === 0 || file.size > MAX_STUDIO_ARTIFACT_UPLOAD_BYTES) {
172
+ setUploadError(t('Studio.parameters.imageFileTooLarge'));
173
+ return;
174
+ }
175
+ if (!isStudioImageMimeType(file.type)) {
176
+ setUploadError(t('Studio.parameters.imageFileMimeUnsupported'));
177
+ return;
178
+ }
179
+ setUploading(true);
180
+ setUploadError('');
181
+ try {
182
+ const result = await host.sdk.uploadLocalAppArtifact({
183
+ bytes: new Uint8Array(await file.arrayBuffer()),
184
+ mimeType: file.type,
185
+ });
186
+ setUploadedFileName(file.name);
187
+ update({ ...parameters, mode: 'i2v-reference', referenceArtifactId: result.artifactId });
188
+ } catch (error) {
189
+ setUploadError(error instanceof Error ? error.message : String(error));
190
+ } finally {
191
+ setUploading(false);
192
+ }
193
+ }
194
+ const textField = (field: keyof StudioVideoGenerationParameters, label: string, placeholder?: string): StudioParameterFieldDefinition => ({
195
+ field,
196
+ label,
197
+ render: (routeDisabled) => <StudioTextParameter current={parameters} field={field} label={label} placeholder={placeholder} onChange={update} disabled={props.disabled || routeDisabled} />,
198
+ });
199
+ const numberField = (field: keyof StudioVideoGenerationParameters, label: string, min?: number): StudioParameterFieldDefinition => ({
200
+ field,
201
+ label,
202
+ render: (routeDisabled) => <StudioNumberParameter current={parameters} field={field} label={label} onChange={update} disabled={props.disabled || routeDisabled} min={min} step={1} />,
203
+ });
204
+ const booleanField = (field: keyof StudioVideoGenerationParameters, label: string): StudioParameterFieldDefinition => ({
205
+ field,
206
+ label,
207
+ render: (routeDisabled) => <StudioBooleanParameter current={parameters} field={field} label={label} onChange={update} disabled={props.disabled || routeDisabled} />,
208
+ });
209
+ const modeLabel = t('Studio.parameters.fields.mode');
210
+ const referenceLabel = t('Studio.parameters.fields.referenceArtifactId');
211
+ const fields: StudioParameterFieldDefinition[] = [
212
+ {
213
+ field: 'mode',
214
+ label: modeLabel,
215
+ render: (routeDisabled) => (
216
+ <StudioParameterField label={modeLabel}>
217
+ <SelectField
218
+ value={parameters.mode ?? 't2v'}
219
+ disabled={props.disabled || routeDisabled}
220
+ options={[
221
+ { value: 't2v', label: t('Studio.parameters.videoModeT2v') },
222
+ { value: 'i2v-reference', label: t('Studio.parameters.videoModeReference') },
223
+ ]}
224
+ onValueChange={(value) => update({ ...parameters, mode: value as StudioVideoGenerationParameters['mode'] })}
225
+ />
226
+ </StudioParameterField>
227
+ ),
228
+ },
229
+ ...(parameters.mode === 'i2v-reference' ? [{
230
+ field: 'referenceArtifactId',
231
+ label: referenceLabel,
232
+ render: (routeDisabled: boolean) => (
233
+ <div className="studio-parameters__reference-fields">
234
+ <StudioTextParameter current={parameters} field="referenceArtifactId" label={referenceLabel} placeholder="artifact_…" onChange={update} disabled={props.disabled || routeDisabled || uploading} />
235
+ <StudioParameterField label={t('Studio.parameters.fields.referenceImageFile')}>
236
+ <input ref={inputRef} className="studio-parameters__file-input" type="file" accept="image/png,image/jpeg,image/webp,image/gif" disabled={props.disabled || routeDisabled || uploading} onChange={(event) => void selectReferenceImage(event)} />
237
+ <div className="studio-parameters__file-row">
238
+ <Button type="button" tone="ghost" size="sm" disabled={props.disabled || routeDisabled || uploading} leadingIcon={<Upload size={14} aria-hidden="true" />} onClick={() => inputRef.current?.click()}>
239
+ {uploading ? t('Studio.parameters.uploadingImage') : t('Studio.parameters.chooseImageFile')}
240
+ </Button>
241
+ {uploadedFileName ? <span>{uploadedFileName}</span> : null}
242
+ </div>
243
+ {uploadError ? <small>{uploadError}</small> : null}
244
+ </StudioParameterField>
245
+ </div>
246
+ ),
247
+ }] : []),
248
+ textField('negativePrompt', t('Studio.parameters.fields.negativePrompt')),
249
+ textField('resolution', t('Studio.parameters.fields.resolution'), '720p'),
250
+ numberField('frames', t('Studio.parameters.fields.frames'), 1),
251
+ numberField('seed', t('Studio.parameters.fields.seed')),
252
+ booleanField('generateAudio', t('Studio.parameters.fields.generateAudio')),
253
+ textField('ratio', t('Studio.parameters.fields.ratio')),
254
+ numberField('durationSec', t('Studio.parameters.fields.durationSec'), 0),
255
+ numberField('fps', t('Studio.parameters.fields.fps'), 1),
256
+ booleanField('cameraFixed', t('Studio.parameters.fields.cameraFixed')),
257
+ booleanField('watermark', t('Studio.parameters.fields.watermark')),
258
+ booleanField('draft', t('Studio.parameters.fields.draft')),
259
+ booleanField('returnLastFrame', t('Studio.parameters.fields.returnLastFrame')),
260
+ textField('serviceTier', t('Studio.parameters.fields.serviceTier')),
261
+ numberField('executionExpiresAfterSec', t('Studio.parameters.fields.executionExpiresAfterSec'), 0),
262
+ ];
263
+ return <StudioRouteAwareParameterFields contract={props.contract} source={props.source} fields={fields} translate={translate} />;
264
+ }
265
+
266
+ export function StudioMediaParameterPanel(props: StudioParameterPanelProps) {
267
+ const { translate: t } = useAIStudioHost();
268
+ const translate: StudioParameterTranslate = (key, values) => t(key, values);
269
+ const fields = props.capabilityId === 'image.generate'
270
+ ? <ImageFields {...props} />
271
+ : props.capabilityId === 'video.generate'
272
+ ? <VideoFields {...props} />
273
+ : <MusicFields {...props} />;
274
+ return (
275
+ <StudioParameterPanelFrame
276
+ translate={translate}
277
+ disabled={props.disabled}
278
+ onReset={() => props.onChange(props.contract.initial())}
279
+ >
280
+ {fields}
281
+ </StudioParameterPanelFrame>
282
+ );
283
+ }
@@ -0,0 +1,94 @@
1
+ import {
2
+ CLOUD_ONLY_STUDIO_PARAMETER,
3
+ LOCAL_AND_CLOUD_STUDIO_PARAMETER,
4
+ LOCAL_ONLY_STUDIO_PARAMETER,
5
+ SUPPORTED_STUDIO_PARAMETER,
6
+ UNSUPPORTED_STUDIO_PARAMETER,
7
+ defineStudioParameters,
8
+ } from '../../ai-studio-core/parameters.js';
9
+
10
+ export type StudioImageGenerationParameters = {
11
+ negativePrompt?: string;
12
+ count?: number;
13
+ size?: string;
14
+ seed?: number;
15
+ aspectRatio?: string;
16
+ quality?: string;
17
+ style?: string;
18
+ referenceImage?: string;
19
+ referenceImageArtifactId?: string;
20
+ mask?: string;
21
+ };
22
+
23
+ export type StudioVideoGenerationParameters = {
24
+ mode?: 't2v' | 'i2v-reference';
25
+ referenceArtifactId?: string;
26
+ negativePrompt?: string;
27
+ resolution?: string;
28
+ frames?: number;
29
+ seed?: number;
30
+ generateAudio?: boolean;
31
+ ratio?: string;
32
+ durationSec?: number;
33
+ fps?: number;
34
+ cameraFixed?: boolean;
35
+ watermark?: boolean;
36
+ draft?: boolean;
37
+ returnLastFrame?: boolean;
38
+ serviceTier?: string;
39
+ executionExpiresAfterSec?: number;
40
+ };
41
+
42
+ export type StudioMusicGenerationParameters = {
43
+ lyrics?: string;
44
+ };
45
+
46
+ const LOCAL_APP_UNAVAILABLE = Object.freeze({
47
+ local: UNSUPPORTED_STUDIO_PARAMETER,
48
+ cloud: UNSUPPORTED_STUDIO_PARAMETER,
49
+ });
50
+
51
+ export const MAX_STUDIO_ARTIFACT_UPLOAD_BYTES = 32 * 1024 * 1024;
52
+
53
+ export const studioImageGenerateParameters = defineStudioParameters<StudioImageGenerationParameters>({
54
+ initial: () => ({}),
55
+ routeMatrix: {
56
+ negativePrompt: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
57
+ count: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
58
+ size: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
59
+ seed: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
60
+ aspectRatio: CLOUD_ONLY_STUDIO_PARAMETER,
61
+ quality: CLOUD_ONLY_STUDIO_PARAMETER,
62
+ style: CLOUD_ONLY_STUDIO_PARAMETER,
63
+ referenceImage: CLOUD_ONLY_STUDIO_PARAMETER,
64
+ referenceImageArtifactId: LOCAL_ONLY_STUDIO_PARAMETER,
65
+ mask: CLOUD_ONLY_STUDIO_PARAMETER,
66
+ },
67
+ });
68
+
69
+ export const studioVideoGenerateParameters = defineStudioParameters<StudioVideoGenerationParameters>({
70
+ initial: () => ({ mode: 't2v', generateAudio: true }),
71
+ routeMatrix: {
72
+ mode: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
73
+ referenceArtifactId: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
74
+ negativePrompt: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
75
+ resolution: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
76
+ frames: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
77
+ seed: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
78
+ generateAudio: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
79
+ ratio: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
80
+ durationSec: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
81
+ fps: { local: { kind: 'fixed', value: 24 }, cloud: SUPPORTED_STUDIO_PARAMETER },
82
+ cameraFixed: CLOUD_ONLY_STUDIO_PARAMETER,
83
+ watermark: CLOUD_ONLY_STUDIO_PARAMETER,
84
+ draft: CLOUD_ONLY_STUDIO_PARAMETER,
85
+ returnLastFrame: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
86
+ serviceTier: LOCAL_APP_UNAVAILABLE,
87
+ executionExpiresAfterSec: LOCAL_APP_UNAVAILABLE,
88
+ },
89
+ });
90
+
91
+ export const studioMusicGenerateParameters = defineStudioParameters<StudioMusicGenerationParameters>({
92
+ initial: () => ({ lyrics: '[Verse]\n\n[Chorus]\n' }),
93
+ routeMatrix: { lyrics: LOCAL_ONLY_STUDIO_PARAMETER },
94
+ });
@@ -0,0 +1,44 @@
1
+ import { Image as ImageIcon, Music2, Video } from 'lucide-react';
2
+ import type { AIStudioModuleRegistration } from '../../ai-studio-core/module-registration.js';
3
+ import { studioMediaDescriptors, type StudioMediaCapabilityId } from './descriptors.js';
4
+ import { studioImageGenerateParameters, studioMusicGenerateParameters, studioVideoGenerateParameters } from './parameters.js';
5
+ import { StudioMediaParameterPanel } from './parameter-panel.js';
6
+
7
+ export const studioMediaModule = Object.freeze({
8
+ id: 'studio-media', navigationLabel: 'Media', order: 20,
9
+ capabilities: [
10
+ {
11
+ descriptor: studioMediaDescriptors[0],
12
+ icon: ImageIcon,
13
+ profile: {
14
+ studioTag: 'Image', inputTitleKey: 'Studio.profiles.imageGenerate.inputTitle', inputPlaceholderKey: 'Studio.profiles.imageGenerate.inputPlaceholder', inputKind: 'prompt', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.imageGenerate.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.imageGenerate.primaryRunningLabel', resultTitle: 'Generated image', emptyTitleKey: 'Studio.profiles.imageGenerate.emptyTitle', emptyHintKey: 'Studio.profiles.imageGenerate.emptyHint', resultKind: 'artifacts', footnoteKey: 'Studio.profiles.imageGenerate.footnote',
15
+ },
16
+ preset: { id: 'ui-preview', label: 'UI preview', prompt: 'Generate a product-grade UI inspection image for a Nimi App workbench.' },
17
+ runtimeMethod: 'runtime.ai.submitScenarioJob:image_generate',
18
+ parameters: studioImageGenerateParameters,
19
+ parameterPanel: StudioMediaParameterPanel,
20
+ },
21
+ {
22
+ descriptor: studioMediaDescriptors[1],
23
+ icon: Video,
24
+ profile: {
25
+ studioTag: 'Video', inputTitleKey: 'Studio.profiles.videoGenerate.inputTitle', inputPlaceholderKey: 'Studio.profiles.videoGenerate.inputPlaceholder', inputKind: 'prompt', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.videoGenerate.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.videoGenerate.primaryRunningLabel', resultTitle: 'Generated clip', emptyTitleKey: 'Studio.profiles.videoGenerate.emptyTitle', emptyHintKey: 'Studio.profiles.videoGenerate.emptyHint', resultKind: 'artifacts', footnoteKey: 'Studio.profiles.videoGenerate.footnote',
26
+ },
27
+ preset: { id: 'clip-sample', label: 'Clip sample', prompt: 'Create a short inspection clip for a Nimi App glass UI workflow.' },
28
+ runtimeMethod: 'kit.generation.runRuntimeVideoGenerate',
29
+ parameters: studioVideoGenerateParameters,
30
+ parameterPanel: StudioMediaParameterPanel,
31
+ },
32
+ {
33
+ descriptor: studioMediaDescriptors[2],
34
+ icon: Music2,
35
+ profile: {
36
+ studioTag: 'Music', inputTitleKey: 'Studio.profiles.musicGenerate.inputTitle', inputPlaceholderKey: 'Studio.profiles.musicGenerate.inputPlaceholder', inputKind: 'prompt', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.musicGenerate.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.musicGenerate.primaryRunningLabel', resultTitle: 'Generated music', emptyTitleKey: 'Studio.profiles.musicGenerate.emptyTitle', emptyHintKey: 'Studio.profiles.musicGenerate.emptyHint', resultKind: 'artifacts', footnoteKey: 'Studio.profiles.musicGenerate.footnote',
37
+ },
38
+ preset: { id: 'music-sample', label: 'Music sample', prompt: 'Upbeat synth-pop with bright arpeggios, driving drums, and a soaring female vocal.' },
39
+ runtimeMethod: 'kit.generation.runRuntimeMusicGenerate',
40
+ parameters: studioMusicGenerateParameters,
41
+ parameterPanel: StudioMediaParameterPanel,
42
+ },
43
+ ],
44
+ } as const satisfies AIStudioModuleRegistration<'studio-media', StudioMediaCapabilityId>);
@@ -0,0 +1,113 @@
1
+ import type { StudioCapabilityRuntimeHandlers } from '../../ai-studio-core/runtime-dispatcher.js';
2
+ import {
3
+ createStudioScenarioJobClient,
4
+ projectStudioArtifactRunnerResult,
5
+ type StudioCapabilityRuntimeContext,
6
+ } from '../../ai-studio-core/runtime.js';
7
+ import type {
8
+ StudioImageGenerationParameters,
9
+ StudioMusicGenerationParameters,
10
+ StudioVideoGenerationParameters,
11
+ } from './parameters.js';
12
+
13
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
14
+
15
+ export const studioMediaRuntimeHandlers: StudioCapabilityRuntimeHandlers = Object.freeze({
16
+ 'image.generate': runImageGenerate,
17
+ 'video.generate': runVideoGenerate,
18
+ 'music.generate': runMusicGenerate,
19
+ });
20
+
21
+ async function runImageGenerate(context: StudioCapabilityRuntimeContext) {
22
+ if (!context.prompt) return inputRequired(context);
23
+ const parameters = context.input.parameters as StudioImageGenerationParameters | undefined;
24
+ const result = await context.host.runners.imageGenerate({
25
+ runtime: { ai: createStudioScenarioJobClient(context) },
26
+ appId: context.host.appId,
27
+ prompt: context.prompt,
28
+ ...(parameters?.negativePrompt !== undefined ? { negativePrompt: parameters.negativePrompt } : {}),
29
+ ...(parameters?.count !== undefined ? { count: parameters.count } : {}),
30
+ ...(parameters?.size !== undefined ? { size: parameters.size } : {}),
31
+ ...(parameters?.seed !== undefined ? { seed: parameters.seed } : {}),
32
+ ...(parameters?.aspectRatio !== undefined ? { aspectRatio: parameters.aspectRatio } : {}),
33
+ ...(parameters?.quality !== undefined ? { quality: parameters.quality } : {}),
34
+ ...(parameters?.style !== undefined ? { style: parameters.style } : {}),
35
+ ...(parameters?.referenceImage !== undefined ? { referenceImages: [parameters.referenceImage] } : {}),
36
+ ...(parameters?.referenceImageArtifactId !== undefined ? { referenceImageArtifactId: parameters.referenceImageArtifactId } : {}),
37
+ ...(parameters?.mask !== undefined ? { mask: parameters.mask } : {}),
38
+ scenarioId: context.scenarioId,
39
+ surfaceId: context.host.surfaceId,
40
+ ...(context.input.signal ? {
41
+ signal: context.input.signal,
42
+ abortReason: context.host.abortReason,
43
+ } : {}),
44
+ });
45
+ return projectStudioArtifactRunnerResult(context, result);
46
+ }
47
+
48
+ async function runMusicGenerate(context: StudioCapabilityRuntimeContext) {
49
+ const parameters = context.input.parameters as StudioMusicGenerationParameters | undefined;
50
+ const lyrics = parameters?.lyrics?.trim() ?? '';
51
+ if (!context.prompt || !lyrics) return inputRequired(context);
52
+ const result = await context.host.runners.musicGenerate({
53
+ runtime: { ai: createStudioScenarioJobClient(context) },
54
+ appId: context.host.appId,
55
+ prompt: context.prompt,
56
+ lyrics,
57
+ scenarioId: context.scenarioId,
58
+ surfaceId: context.host.surfaceId,
59
+ ...(context.input.signal ? { signal: context.input.signal, abortReason: context.host.abortReason } : {}),
60
+ });
61
+ return projectStudioArtifactRunnerResult(context, result);
62
+ }
63
+
64
+ async function runVideoGenerate(context: StudioCapabilityRuntimeContext) {
65
+ if (!context.prompt) return inputRequired(context);
66
+ const parameters = context.input.parameters as StudioVideoGenerationParameters | undefined;
67
+ const mode = parameters?.mode ?? 't2v';
68
+ const result = await context.host.runners.videoGenerate({
69
+ runtime: { ai: createStudioScenarioJobClient(context) },
70
+ appId: context.host.appId,
71
+ mode,
72
+ prompt: context.prompt,
73
+ ...(parameters?.negativePrompt !== undefined ? { negativePrompt: parameters.negativePrompt } : {}),
74
+ ...(mode === 'i2v-reference' && parameters?.referenceArtifactId ? {
75
+ content: [{ type: 'artifact-ref', role: 'reference-image', artifactId: parameters.referenceArtifactId }],
76
+ } : {}),
77
+ options: videoGenerationOptions(parameters),
78
+ scenarioId: context.scenarioId,
79
+ surfaceId: context.host.surfaceId,
80
+ ...(context.input.signal ? {
81
+ signal: context.input.signal,
82
+ abortReason: context.host.abortReason,
83
+ } : {}),
84
+ });
85
+ return projectStudioArtifactRunnerResult(context, result);
86
+ }
87
+
88
+ function inputRequired(context: StudioCapabilityRuntimeContext) {
89
+ return context.host.nonSuccess(
90
+ context.capability,
91
+ 'input-invalid',
92
+ `${context.capability.label} requires non-empty input.`,
93
+ );
94
+ }
95
+
96
+ function videoGenerationOptions(parameters: StudioVideoGenerationParameters | undefined) {
97
+ if (!parameters) return undefined;
98
+ return {
99
+ ...(parameters.resolution !== undefined ? { resolution: parameters.resolution } : {}),
100
+ ...(parameters.ratio !== undefined ? { ratio: parameters.ratio } : {}),
101
+ ...(parameters.durationSec !== undefined ? { durationSec: parameters.durationSec } : {}),
102
+ ...(parameters.frames !== undefined ? { frames: parameters.frames } : {}),
103
+ ...(parameters.fps !== undefined ? { fps: parameters.fps } : {}),
104
+ ...(parameters.seed !== undefined ? { seed: parameters.seed } : {}),
105
+ ...(parameters.cameraFixed !== undefined ? { cameraFixed: parameters.cameraFixed } : {}),
106
+ ...(parameters.watermark !== undefined ? { watermark: parameters.watermark } : {}),
107
+ ...(parameters.generateAudio !== undefined ? { generateAudio: parameters.generateAudio } : {}),
108
+ ...(parameters.draft !== undefined ? { draft: parameters.draft } : {}),
109
+ ...(parameters.serviceTier !== undefined ? { serviceTier: parameters.serviceTier } : {}),
110
+ ...(parameters.executionExpiresAfterSec !== undefined ? { executionExpiresAfterSec: parameters.executionExpiresAfterSec } : {}),
111
+ ...(parameters.returnLastFrame !== undefined ? { returnLastFrame: parameters.returnLastFrame } : {}),
112
+ };
113
+ }
@@ -0,0 +1,28 @@
1
+ export type StudioVoiceCapabilityId = 'audio.synthesize' | 'audio.transcribe' | 'voice.create' | 'speech.bundle';
2
+
3
+ export const studioVoiceDescriptors = Object.freeze([
4
+ {
5
+ id: 'audio.synthesize', label: 'Speech Synthesis', labelKey: 'Capabilities.audioSynthesize.label', group: 'audio',
6
+ section: 'tts',
7
+ summary: 'Text → audio.synthesize Scenario Job → typed audio artifact result.', summaryKey: 'Capabilities.audioSynthesize.summary',
8
+ surface: 'kit.runRuntimeSpeechSynthesize → sdk.localApp.ai.scenarioJobs + artifacts', execution: 'runtime-sdk', capabilityContract: 'audio.synthesize',
9
+ },
10
+ {
11
+ id: 'audio.transcribe', label: 'Speech Transcribe', labelKey: 'Capabilities.audioTranscribe.label', group: 'audio',
12
+ section: 'stt',
13
+ summary: 'Audio URL → audio.transcribe Scenario Job → typed transcript result.', summaryKey: 'Capabilities.audioTranscribe.summary',
14
+ surface: 'kit.runRuntimeSpeechTranscribe → sdk.localApp.ai.scenarioJobs + artifacts', execution: 'runtime-sdk', capabilityContract: 'audio.transcribe',
15
+ },
16
+ {
17
+ id: 'voice.create', label: 'Voice Create', labelKey: 'Capabilities.voiceCreate.label', group: 'audio',
18
+ section: 'voice',
19
+ summary: 'Typed reference audio or text description → voice.create Scenario Job → VoiceAsset.', summaryKey: 'Capabilities.voiceCreate.summary',
20
+ surface: 'sdk.localApp.ai.scenarioJobs.submit:voice-create', execution: 'runtime-sdk', capabilityContract: 'voice.create',
21
+ },
22
+ {
23
+ id: 'speech.bundle', label: 'Voice Catalog', labelKey: 'Capabilities.speechBundle.label', group: 'audio',
24
+ section: 'voice',
25
+ summary: 'Inspect owner-scoped voice references through the protected Runtime voice catalog.', summaryKey: 'Capabilities.speechBundle.summary',
26
+ surface: 'kit.runRuntimeVoiceCatalog → sdk.localApp.ai.voiceAssets.list', execution: 'runtime-sdk', capabilityContract: 'audio.synthesize',
27
+ },
28
+ ] as const);
@@ -0,0 +1,16 @@
1
+ export { studioVoiceDescriptors, type StudioVoiceCapabilityId } from './descriptors.js';
2
+ export { studioVoiceMessageBundles } from './messages/index.js';
3
+ export { StudioVoiceParameterPanel } from './parameter-panel.js';
4
+ export {
5
+ MAX_STUDIO_AUDIO_UPLOAD_BYTES,
6
+ MAX_STUDIO_VOICE_REFERENCE_AUDIO_BYTES,
7
+ studioSpeechSynthesizeParameters,
8
+ studioSpeechTranscribeParameters,
9
+ studioVoiceCreateParameters,
10
+ type StudioAudioFile,
11
+ type StudioSpeechSynthesizeParameters,
12
+ type StudioSpeechTranscribeParameters,
13
+ type StudioVoiceCreateParameters,
14
+ } from './parameters.js';
15
+ export { studioVoiceModule } from './registration.js';
16
+ export { studioVoiceRuntimeHandlers } from './runtime.js';