@nimiplatform/app-tools 0.1.3 → 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,19 @@
1
+ import type { StudioResultKind } from './module-registration.js';
2
+
3
+ export function hasStudioCapabilityRunInput(input: {
4
+ requiresPrompt: boolean;
5
+ prompt: string;
6
+ hasAlternativeInput: boolean;
7
+ }): boolean {
8
+ return !input.requiresPrompt || Boolean(input.prompt.trim()) || input.hasAlternativeInput;
9
+ }
10
+
11
+ export function canCancelStudioCapabilityRun(input: {
12
+ capabilityId: string;
13
+ resultKind: StudioResultKind;
14
+ }): boolean {
15
+ return input.capabilityId === 'chat.stream'
16
+ || input.resultKind === 'artifacts'
17
+ || input.resultKind === 'transcript'
18
+ || input.resultKind === 'voice-asset';
19
+ }
@@ -0,0 +1,291 @@
1
+ import { useEffect, useState, type ReactNode } from 'react';
2
+ import { Dialog, DialogContent, DialogTitle, IconButton, nimiToast, Tooltip } from '@nimiplatform/kit/ui';
3
+ import { Copy as CopyIcon, Download as DownloadIcon, Maximize2, X } from 'lucide-react';
4
+ import { useAIStudioHost } from './host-context.js';
5
+ import type { StudioCapabilityRunResult } from './runtime-types.js';
6
+ import { openNimiLocalAppAssetMediaUrl } from '@nimiplatform/kit/shell/renderer/bridge';
7
+ import { studioNonSuccessReasonTitle, type StudioTranslate } from './non-success-presentation.js';
8
+ import {
9
+ STUDIO_ARTIFACT_IMAGE_LOADING,
10
+ hasStudioArtifactMedia,
11
+ studioArtifactRenderBranch,
12
+ type StudioArtifactPreviewSource,
13
+ } from './section-ai-testing-artifact-preview.js';
14
+
15
+ export function formatTypedOutput(
16
+ result: StudioCapabilityRunResult & { ok: true },
17
+ translate: StudioTranslate,
18
+ ): string {
19
+ const output = result.output;
20
+ if (output.kind === 'text') {
21
+ return output.text || translate('StudioShell.emptyBody');
22
+ }
23
+ if (output.kind === 'embedding') {
24
+ return JSON.stringify({
25
+ vectors: output.vectorCount,
26
+ dimensions: output.dimensions,
27
+ sample: output.sample,
28
+ totalTokens: output.totalTokens,
29
+ }, null, 2);
30
+ }
31
+ if (output.kind === 'artifacts') {
32
+ return JSON.stringify({
33
+ jobId: output.jobId,
34
+ jobState: output.jobState,
35
+ artifactCount: output.artifactCount,
36
+ artifacts: output.artifacts,
37
+ firstArtifact: output.firstArtifact,
38
+ }, null, 2);
39
+ }
40
+ if (output.kind === 'transcript') {
41
+ return output.text || translate('StudioShell.emptyTranscript');
42
+ }
43
+ if (output.kind === 'voice-asset') {
44
+ return JSON.stringify({
45
+ jobId: output.jobId,
46
+ jobState: output.jobState,
47
+ voiceAssetId: output.voiceAssetId,
48
+ creationSource: output.creationSource,
49
+ assetStatus: output.assetStatus,
50
+ voiceReference: output.voiceReference,
51
+ }, null, 2);
52
+ }
53
+ return JSON.stringify({
54
+ voiceCount: output.voiceCount,
55
+ sample: output.sample,
56
+ }, null, 2);
57
+ }
58
+
59
+ export function formatNonSuccessOutput(
60
+ result: StudioCapabilityRunResult & { ok: false },
61
+ translate: StudioTranslate,
62
+ ): string {
63
+ return [
64
+ studioNonSuccessReasonTitle(result.reason, translate),
65
+ '',
66
+ `Capability: ${result.capabilityId}`,
67
+ `Reason: ${result.reason}`,
68
+ result.missingSurface ? `Missing surface: ${result.missingSurface}` : '',
69
+ '',
70
+ 'Message:',
71
+ result.message,
72
+ '',
73
+ 'Action:',
74
+ result.actionHint,
75
+ result.diagnostics ? 'Technical diagnostics:' : '',
76
+ result.diagnostics?.reasonCode ? `Reason code: ${result.diagnostics.reasonCode}` : '',
77
+ result.diagnostics?.actionHint ? `Owner action: ${result.diagnostics.actionHint}` : '',
78
+ result.diagnostics?.traceId ? `Trace: ${result.diagnostics.traceId}` : '',
79
+ result.diagnostics?.retryable !== undefined ? `Retryable: ${String(result.diagnostics.retryable)}` : '',
80
+ result.diagnostics?.source ? `Source: ${result.diagnostics.source}` : '',
81
+ ].filter(Boolean).join('\n');
82
+ }
83
+
84
+ // Plain-text projection used for Copy / Download. Text and transcript export the
85
+ // raw body; structured successes export their typed JSON summary; unavailable
86
+ // results export the fail-closed Runtime diagnostic without converting it into a
87
+ // success state.
88
+ export function resultPlainText(result: StudioCapabilityRunResult, translate: StudioTranslate): string {
89
+ if (!result.ok) return formatNonSuccessOutput(result, translate);
90
+ if (result.output.kind === 'text') return result.output.text;
91
+ if (result.output.kind === 'transcript') return result.output.text;
92
+ return formatTypedOutput(result, translate);
93
+ }
94
+
95
+ export function RuntimeDiagnosticsActions({
96
+ text,
97
+ filenameBase,
98
+ }: {
99
+ text: string;
100
+ filenameBase: string;
101
+ }) {
102
+ const rendererHost = useAIStudioHost();
103
+ const { translate: t } = useAIStudioHost();
104
+ const canExport = text.trim().length > 0;
105
+ function handleCopyDiagnostics() {
106
+ if (!canExport) return;
107
+ void rendererHost.app.commands.copyText(text)
108
+ .then((result) => {
109
+ if (result.ok) {
110
+ nimiToast.success(t('Common.copied'));
111
+ } else {
112
+ nimiToast.danger(t('Common.copyFailed'));
113
+ }
114
+ })
115
+ .catch(() => {
116
+ nimiToast.danger(t('Common.copyFailed'));
117
+ });
118
+ }
119
+ function handleDownloadDiagnostics() {
120
+ if (!canExport) return;
121
+ const stamp = new Date(rendererHost.clock.now()).toISOString().replace(/[:.]/g, '-');
122
+ void downloadTextFile(rendererHost.app.commands, `${filenameBase}-runtime-details-${stamp}.txt`, text);
123
+ }
124
+ return (
125
+ <div className="studio-diag__actions">
126
+ <Tooltip content={t('StudioShell.copyRuntimeDetails')} placement="top">
127
+ <IconButton type="button" className="studio-result__action" onClick={handleCopyDiagnostics} disabled={!canExport} aria-label={t('StudioShell.copyRuntimeDetails')} icon={<CopyIcon size={15} aria-hidden="true" />} />
128
+ </Tooltip>
129
+ <Tooltip content={t('StudioShell.downloadRuntimeDetails')} placement="top">
130
+ <IconButton type="button" className="studio-result__action" onClick={handleDownloadDiagnostics} disabled={!canExport} aria-label={t('StudioShell.downloadRuntimeDetails')} icon={<DownloadIcon size={15} aria-hidden="true" />} />
131
+ </Tooltip>
132
+ </div>
133
+ );
134
+ }
135
+
136
+ export type { StudioArtifactPreviewSource } from './section-ai-testing-artifact-preview.js';
137
+
138
+ export function hasPreviewableArtifact(artifact?: StudioArtifactPreviewSource): boolean {
139
+ return hasStudioArtifactMedia(artifact);
140
+ }
141
+
142
+ // Rich media preview for managed Runtime assets. The only URL exposed to the
143
+ // renderer is Kit's short-lived opaque handle; cleanup revokes it.
144
+ export function ArtifactMediaPreview({
145
+ artifact,
146
+ fallbackLabel,
147
+ }: {
148
+ artifact?: StudioArtifactPreviewSource;
149
+ fallbackLabel: string;
150
+ }) {
151
+ const relativePath = artifact?.relativePath;
152
+ const mimeType = artifact?.mediaType ?? '';
153
+ const branch = studioArtifactRenderBranch(artifact);
154
+ const { translate: t } = useAIStudioHost();
155
+ const [imagePreviewOpen, setImagePreviewOpen] = useState(false);
156
+ const [url, setUrl] = useState<string | null>(null);
157
+ useEffect(() => {
158
+ setImagePreviewOpen(false);
159
+ setUrl(null);
160
+ if (!relativePath || !hasPreviewableArtifact(artifact)) return undefined;
161
+ let active = true;
162
+ let revoke: (() => Promise<void>) | null = null;
163
+ void openNimiLocalAppAssetMediaUrl(relativePath)
164
+ .then((handle) => {
165
+ revoke = handle.revoke;
166
+ if (active) setUrl(handle.url);
167
+ else void handle.revoke();
168
+ })
169
+ .catch(() => {
170
+ if (active) setUrl(null);
171
+ });
172
+ return () => {
173
+ active = false;
174
+ setUrl(null);
175
+ if (revoke) void revoke();
176
+ };
177
+ }, [artifact, mimeType, relativePath]);
178
+ if (!hasPreviewableArtifact(artifact) || !url) return null;
179
+ const label = artifact?.displayName || relativePath || fallbackLabel;
180
+ const isImage = branch === 'image';
181
+ let media: ReactNode = null;
182
+ if (isImage) {
183
+ media = (
184
+ <div className="ai-result__media-frame">
185
+ <img src={url} alt={label} loading={STUDIO_ARTIFACT_IMAGE_LOADING} />
186
+ <Tooltip content={t('StudioShell.expandImage')} placement="top">
187
+ <IconButton
188
+ type="button"
189
+ className="ai-result__media-expand nimi-material-glass-thin backdrop-blur-[var(--nimi-backdrop-blur-thin)]"
190
+ data-nimi-material="glass-thin"
191
+ data-nimi-tone="overlay"
192
+ aria-label={t('StudioShell.expandGeneratedImage')}
193
+ onClick={() => setImagePreviewOpen(true)}
194
+ icon={<Maximize2 size={16} aria-hidden="true" />}
195
+ />
196
+ </Tooltip>
197
+ </div>
198
+ );
199
+ } else if (branch === 'audio') {
200
+ media = <audio controls src={url} />;
201
+ } else if (branch === 'video') {
202
+ media = <video controls src={url} />;
203
+ }
204
+ if (!media) return null;
205
+ return (
206
+ <>
207
+ <figure className="ai-result__media" data-mime={mimeType}>
208
+ {media}
209
+ </figure>
210
+ {isImage ? (
211
+ <Dialog open={imagePreviewOpen} onOpenChange={(open) => { if (!open) setImagePreviewOpen(false); }}>
212
+ <DialogContent
213
+ onClose={() => setImagePreviewOpen(false)}
214
+ overlayClassName="ai-result-preview-modal__overlay"
215
+ className="ai-result-preview-modal"
216
+ >
217
+ <DialogTitle className="ai-result-preview-modal__title">{t('StudioShell.imagePreview')}</DialogTitle>
218
+ <IconButton
219
+ type="button"
220
+ className="ai-result-preview-modal__close"
221
+ aria-label={t('StudioShell.closeImagePreview')}
222
+ onClick={() => setImagePreviewOpen(false)}
223
+ icon={<X size={20} aria-hidden="true" />}
224
+ />
225
+ <img src={url} alt={label} className="ai-result-preview-modal__image" />
226
+ </DialogContent>
227
+ </Dialog>
228
+ ) : null}
229
+ </>
230
+ );
231
+ }
232
+
233
+ export function ArtifactMediaResult({
234
+ artifact,
235
+ fallbackLabel,
236
+ }: {
237
+ artifact?: StudioArtifactPreviewSource;
238
+ fallbackLabel: string;
239
+ }) {
240
+ const { translate: t } = useAIStudioHost();
241
+ const branch = studioArtifactRenderBranch(artifact);
242
+ if (branch === 'image' || branch === 'audio' || branch === 'video') {
243
+ return <ArtifactMediaPreview artifact={artifact} fallbackLabel={fallbackLabel} />;
244
+ }
245
+ return (
246
+ <div className="studio-result__media-unavailable">
247
+ <p className="studio-result__plain">
248
+ {branch === 'unsupported'
249
+ ? t('StudioShell.mediaPreviewUnsupported')
250
+ : t('StudioShell.mediaPreviewMetadataOnly')}
251
+ </p>
252
+ <p className="studio-result__hint">{t('StudioShell.mediaMetadataDownloadHint')}</p>
253
+ </div>
254
+ );
255
+ }
256
+
257
+ function splitSubjectLine(text: string): { subject: string; body: string } | null {
258
+ const lines = text.replace(/\r\n/g, '\n').split('\n');
259
+ const [firstLine = '', ...rest] = lines;
260
+ const match = firstLine.match(/^Subject:\s*(.+)$/i);
261
+ if (!match) return null;
262
+ return {
263
+ subject: match[1].trim(),
264
+ body: rest.join('\n').replace(/^\n+/, '').trimEnd(),
265
+ };
266
+ }
267
+
268
+ export function TextStudioOutputBody({ text }: { text: string }) {
269
+ const { translate: t } = useAIStudioHost();
270
+ const emptyBody = t('StudioShell.emptyBody');
271
+ const value = text || emptyBody;
272
+ const subject = splitSubjectLine(value);
273
+ if (!subject) {
274
+ return <div className="studio-result__text">{value}</div>;
275
+ }
276
+ return (
277
+ <div className="studio-result__text studio-result__text--formatted">
278
+ <h2 className="studio-result__subject">{subject.subject}</h2>
279
+ <div className="studio-result__divider" aria-hidden="true" />
280
+ <div className="studio-result__text-body">{subject.body || emptyBody}</div>
281
+ </div>
282
+ );
283
+ }
284
+
285
+ export async function downloadTextFile(
286
+ commands: ReturnType<typeof useAIStudioHost>['app']['commands'],
287
+ filename: string,
288
+ body: string,
289
+ ) {
290
+ await commands.exportText({ filename, body });
291
+ }