@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.
- package/LICENSE +198 -6
- package/README.md +83 -27
- package/bin/nimi-app.mjs +328 -45
- package/lib/app-access-declaration.mjs +49 -0
- package/lib/app-doctor-update.mjs +411 -149
- package/lib/app-pack.mjs +401 -0
- package/lib/app-project-lifecycle.mjs +1141 -0
- package/lib/app-scaffold-capabilities.mjs +769 -0
- package/lib/app-scaffold-default-source.mjs +21 -0
- package/lib/app-scaffold-profiles.mjs +1093 -0
- package/lib/app-scaffold.mjs +1266 -813
- package/lib/index.mjs +194 -42
- package/lib/simulator-conformance-ast.mjs +498 -0
- package/lib/simulator-conformance-css.mjs +116 -0
- package/lib/simulator-conformance-graph.mjs +757 -0
- package/lib/simulator-conformance.d.mts +14 -0
- package/lib/simulator-conformance.mjs +203 -0
- package/lib/simulator-css-profile.d.mts +27 -0
- package/lib/simulator-css-profile.mjs +531 -0
- package/lib/simulator-kit-export-resolution.mjs +70 -0
- package/lib/simulator-manifest.mjs +334 -0
- package/package.json +66 -3
- package/scripts/dev-shell.mjs +465 -0
- package/scripts/sync-app-source.mjs +300 -0
- package/scripts/sync-scaffold-versions.mjs +91 -0
- package/templates/app-source/LICENSE +21 -0
- package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
- package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
- package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
- package/templates/app-source/src/ai-studio-core/history.ts +824 -0
- package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
- package/templates/app-source/src/ai-studio-core/index.ts +214 -0
- package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
- package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
- package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
- package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
- package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
- package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
- package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
- package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
- package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
- package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
- package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
- package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
- package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
- package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
- package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
- package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
- package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
- package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
- package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
- package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
- package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
- package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
- package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
- package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
- package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
- package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
- package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
- package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
- package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
- package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
- package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
- package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
- package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
- package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
- package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
- package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
- package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
- package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
- package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
- package/templates/app-source/src/workbench-core/index.ts +17 -0
- package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
- package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
- package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
- package/templates/app-source.manifest.json +333 -0
- package/templates/default-starter/AGENTS.md +33 -0
- package/templates/default-starter/LICENSE +21 -0
- package/templates/default-starter/README.md +41 -0
- package/templates/default-starter/SECURITY.md +5 -0
- package/templates/default-starter/index.html +12 -0
- package/templates/default-starter/scripts/validate.mjs +26 -0
- package/templates/default-starter/src/shell/App.tsx +27 -0
- package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
- package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
- package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
- package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
- package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
- package/templates/default-starter/src/styles.css +26 -0
- package/templates/default-starter/src-tauri/Cargo.toml +17 -0
- package/templates/default-starter/src-tauri/build.rs +5 -0
- package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
- package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
- package/templates/default-starter/tsconfig.json +18 -0
- package/templates/default-starter.manifest.json +99 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
import { useState, type ReactNode } from 'react';
|
|
2
|
+
import { IconButton, nimiToast, StatusBadge, Tooltip } from '@nimiplatform/kit/ui';
|
|
3
|
+
import { AlertTriangle, ChevronRight, Copy as CopyIcon, Download as DownloadIcon, FileText, FolderOpen, MessageSquare, RefreshCw, SlidersHorizontal, SquarePen } from 'lucide-react';
|
|
4
|
+
import { useAIStudioHost } from './host-context.js';
|
|
5
|
+
import type { StudioCapabilityRegistration } from './module-registration.js';
|
|
6
|
+
import { formatStudioRunTimestamp, getStudioRunConfigParamRows, getStudioRunIntentLabel, getStudioRunPromptControlFacts, getStudioRunResultTags, getStudioRunStatusTone, type StudioRunConfigParamRow, type StudioRunHistoryRecord, type StudioRunHistoryResultSnapshot, type StudioRunPromptControlFact } from './history.js';
|
|
7
|
+
import { studioNonSuccessReasonTitle, studioNonSuccessReasonUserAction, studioNonSuccessReasonUserMessage } from './non-success-presentation.js';
|
|
8
|
+
import { ArtifactMediaResult, RuntimeDiagnosticsActions, StudioResult, TextStudioOutputBody, downloadTextFile, statusForCapability } from './section-ai-testing-surface.js';
|
|
9
|
+
import type { TextStudioActiveRun } from './section-ai-testing-run.js';
|
|
10
|
+
|
|
11
|
+
function TextStudioPromptControlFacts({ facts }: { facts: readonly StudioRunPromptControlFact[] }) {
|
|
12
|
+
if (facts.length === 0) return null;
|
|
13
|
+
return (
|
|
14
|
+
<dl className="studio-prompt-settings__facts">
|
|
15
|
+
{facts.map((fact) => (
|
|
16
|
+
<div key={`${fact.label}:${fact.value}`}>
|
|
17
|
+
<dt>{fact.label}</dt>
|
|
18
|
+
<dd>{fact.code ? <code>{fact.value}</code> : fact.value}</dd>
|
|
19
|
+
</div>
|
|
20
|
+
))}
|
|
21
|
+
</dl>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function TextStudioPromptSettings({ activeRun }: { activeRun: TextStudioActiveRun }) {
|
|
26
|
+
const { translate: t } = useAIStudioHost();
|
|
27
|
+
const runConfig = activeRun.record?.runConfig;
|
|
28
|
+
const facts = runConfig ? getStudioRunPromptControlFacts(runConfig) : [];
|
|
29
|
+
const context = (runConfig?.promptControls.context ?? activeRun.context).trim();
|
|
30
|
+
if (facts.length === 0 && !context) return null;
|
|
31
|
+
return (
|
|
32
|
+
<div className="studio-prompt-settings">
|
|
33
|
+
<TextStudioPromptControlFacts facts={facts} />
|
|
34
|
+
{context ? (
|
|
35
|
+
<div className="studio-prompt-settings__context">
|
|
36
|
+
<strong>{t('StudioShell.contextLabel')}</strong>
|
|
37
|
+
<p>{context}</p>
|
|
38
|
+
</div>
|
|
39
|
+
) : null}
|
|
40
|
+
</div>
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function groupParamRows(rows: readonly StudioRunConfigParamRow[]): Array<{ group: string; rows: StudioRunConfigParamRow[] }> {
|
|
45
|
+
const groups: Array<{ group: string; rows: StudioRunConfigParamRow[] }> = [];
|
|
46
|
+
for (const row of rows) {
|
|
47
|
+
const current = groups.find((entry) => entry.group === row.group);
|
|
48
|
+
if (current) {
|
|
49
|
+
current.rows.push(row);
|
|
50
|
+
} else {
|
|
51
|
+
groups.push({ group: row.group, rows: [row] });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return groups;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function TextStudioRequestSettings({ record }: { record: StudioRunHistoryRecord }) {
|
|
58
|
+
const { translate: t } = useAIStudioHost();
|
|
59
|
+
const runConfig = record.runConfig;
|
|
60
|
+
if (!runConfig) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const paramRows = getStudioRunConfigParamRows(runConfig);
|
|
65
|
+
const fallbackSummary = runConfig.target.paramsSummary.join(' / ');
|
|
66
|
+
if (paramRows.length === 0 && !fallbackSummary) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
const paramGroups = groupParamRows(paramRows);
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<section className="studio-history-settings" aria-label={t('StudioShell.requestSettings')}>
|
|
73
|
+
<div className="studio-history-settings__head">
|
|
74
|
+
<SlidersHorizontal size={14} aria-hidden="true" />
|
|
75
|
+
<strong>{t('StudioShell.requestSettings')}</strong>
|
|
76
|
+
</div>
|
|
77
|
+
{paramGroups.map((group) => (
|
|
78
|
+
<div key={group.group} className="studio-history-settings__group">
|
|
79
|
+
<strong className="studio-history-settings__group-title">{group.group}</strong>
|
|
80
|
+
<dl className="studio-history-settings__params">
|
|
81
|
+
{group.rows.map((row) => (
|
|
82
|
+
<div key={row.key}>
|
|
83
|
+
<dt>{row.label}</dt>
|
|
84
|
+
<dd>{row.code ? <code>{row.value}</code> : row.value}</dd>
|
|
85
|
+
</div>
|
|
86
|
+
))}
|
|
87
|
+
</dl>
|
|
88
|
+
</div>
|
|
89
|
+
))}
|
|
90
|
+
</section>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function hasTextStudioRequestSettings(record: StudioRunHistoryRecord): boolean {
|
|
95
|
+
const runConfig = record.runConfig;
|
|
96
|
+
if (!runConfig) return false;
|
|
97
|
+
return getStudioRunConfigParamRows(runConfig).length > 0 || Boolean(runConfig.target.paramsSummary.join(' / '));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function historyRecordPlainText(record: StudioRunHistoryRecord): string {
|
|
101
|
+
const snapshot = record.result;
|
|
102
|
+
if (!snapshot) return record.message;
|
|
103
|
+
if (!snapshot.ok) return snapshot.message;
|
|
104
|
+
if (snapshot.kind === 'text' || snapshot.kind === 'transcript') return snapshot.body;
|
|
105
|
+
return snapshot.summary;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function historyNonSuccessDiagnosticsText(snapshot: Extract<StudioRunHistoryResultSnapshot, { ok: false }>): string {
|
|
109
|
+
return [
|
|
110
|
+
`Reason: ${snapshot.reason}`,
|
|
111
|
+
snapshot.missingSurface ? `Missing surface: ${snapshot.missingSurface}` : '',
|
|
112
|
+
'',
|
|
113
|
+
'Message:',
|
|
114
|
+
snapshot.message,
|
|
115
|
+
'',
|
|
116
|
+
'Action:',
|
|
117
|
+
snapshot.actionHint,
|
|
118
|
+
snapshot.diagnostics ? 'Technical diagnostics:' : '',
|
|
119
|
+
snapshot.diagnostics?.reasonCode ? `Reason code: ${snapshot.diagnostics.reasonCode}` : '',
|
|
120
|
+
snapshot.diagnostics?.actionHint ? `Owner action: ${snapshot.diagnostics.actionHint}` : '',
|
|
121
|
+
snapshot.diagnostics?.traceId ? `Trace: ${snapshot.diagnostics.traceId}` : '',
|
|
122
|
+
snapshot.diagnostics?.retryable !== undefined ? `Retryable: ${String(snapshot.diagnostics.retryable)}` : '',
|
|
123
|
+
snapshot.diagnostics?.source ? `Source: ${snapshot.diagnostics.source}` : '',
|
|
124
|
+
].filter(Boolean).join('\n');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function historyResultToneClass(record: StudioRunHistoryRecord): string {
|
|
128
|
+
const tone = getStudioRunStatusTone(record.status);
|
|
129
|
+
return tone === 'danger' ? 'warning' : tone;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function TextStudioHistoryRecordResult({
|
|
133
|
+
record,
|
|
134
|
+
onRegenerate,
|
|
135
|
+
onUseAsDraft,
|
|
136
|
+
}: {
|
|
137
|
+
record: StudioRunHistoryRecord;
|
|
138
|
+
onRegenerate: () => void;
|
|
139
|
+
onUseAsDraft: (record: StudioRunHistoryRecord) => void;
|
|
140
|
+
}) {
|
|
141
|
+
const rendererHost = useAIStudioHost();
|
|
142
|
+
const { translate: t } = useAIStudioHost();
|
|
143
|
+
const snapshot = record.result;
|
|
144
|
+
const blocked = snapshot && !snapshot.ok ? snapshot : null;
|
|
145
|
+
const tags = blocked ? [studioNonSuccessReasonTitle(blocked.reason, t)] : getStudioRunResultTags(record);
|
|
146
|
+
const intentLabel = getStudioRunIntentLabel(record);
|
|
147
|
+
const toneClass = historyResultToneClass(record);
|
|
148
|
+
const exportText = historyRecordPlainText(record);
|
|
149
|
+
const managedArtifact = snapshot?.ok && snapshot.kind === 'artifacts'
|
|
150
|
+
? snapshot.artifacts?.[0] ?? snapshot.firstArtifact
|
|
151
|
+
: undefined;
|
|
152
|
+
const revealsManagedAsset = Boolean(managedArtifact?.relativePath);
|
|
153
|
+
const canExport = !blocked && (revealsManagedAsset || Boolean(exportText.trim()));
|
|
154
|
+
const hasRequestSettings = hasTextStudioRequestSettings(record);
|
|
155
|
+
const [requestSettingsOpen, setRequestSettingsOpen] = useState(false);
|
|
156
|
+
function handleCopy() {
|
|
157
|
+
if (!exportText.trim()) return;
|
|
158
|
+
void rendererHost.app.commands.copyText(exportText)
|
|
159
|
+
.then((result) => {
|
|
160
|
+
if (result.ok) {
|
|
161
|
+
nimiToast.success(t('Common.copied'));
|
|
162
|
+
} else {
|
|
163
|
+
nimiToast.danger(t('Common.copyFailed'));
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
.catch(() => {
|
|
167
|
+
nimiToast.danger(t('Common.copyFailed'));
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
function handleDownload() {
|
|
171
|
+
if (managedArtifact?.relativePath) {
|
|
172
|
+
void rendererHost.sdk.revealLocalAppAsset(managedArtifact.relativePath);
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const stamp = record.createdAt.replace(/[:.]/g, '-');
|
|
176
|
+
if (!exportText.trim()) return;
|
|
177
|
+
void downloadTextFile(rendererHost.app.commands, `${record.capabilityId}-${stamp}.txt`, exportText);
|
|
178
|
+
}
|
|
179
|
+
let body: ReactNode;
|
|
180
|
+
if (!snapshot) {
|
|
181
|
+
body = (
|
|
182
|
+
<>
|
|
183
|
+
<p>{record.message}</p>
|
|
184
|
+
<p className="studio-result__hint">
|
|
185
|
+
{t('StudioShell.legacyRecordHint')}
|
|
186
|
+
</p>
|
|
187
|
+
</>
|
|
188
|
+
);
|
|
189
|
+
} else if (!snapshot.ok) {
|
|
190
|
+
const diagnosticsText = historyNonSuccessDiagnosticsText(snapshot);
|
|
191
|
+
body = (
|
|
192
|
+
<div className="studio-result__blocked">
|
|
193
|
+
<div className="studio-result__blocked-line">
|
|
194
|
+
<AlertTriangle size={15} aria-hidden="true" />
|
|
195
|
+
<span>{studioNonSuccessReasonTitle(snapshot.reason, t)}</span>
|
|
196
|
+
</div>
|
|
197
|
+
<p>{studioNonSuccessReasonUserMessage(snapshot.reason, t)}</p>
|
|
198
|
+
<p className="studio-result__hint">{studioNonSuccessReasonUserAction(snapshot.reason, t)}</p>
|
|
199
|
+
<details className="studio-diag">
|
|
200
|
+
<summary>{t('StudioShell.runtimeDetails')}</summary>
|
|
201
|
+
<RuntimeDiagnosticsActions text={diagnosticsText} filenameBase={record.capabilityId} />
|
|
202
|
+
<pre className="studio-diag__json">{diagnosticsText}</pre>
|
|
203
|
+
</details>
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
} else {
|
|
207
|
+
body = <TextStudioHistorySnapshotBody snapshot={snapshot} />;
|
|
208
|
+
}
|
|
209
|
+
return (
|
|
210
|
+
<div className="studio-history-result" role="status">
|
|
211
|
+
<div className="studio-history-result__head">
|
|
212
|
+
<div className="studio-history-result__line">
|
|
213
|
+
<StatusBadge tone={getStudioRunStatusTone(record.status)} shape="dot">
|
|
214
|
+
{blocked ? studioNonSuccessReasonTitle(blocked.reason, t) : rendererHost.app.projection.runStatusLabel(record.status)}
|
|
215
|
+
</StatusBadge>
|
|
216
|
+
<span className="studio-history-result__title-stack">
|
|
217
|
+
<time dateTime={record.createdAt}>{t('StudioShell.runLabel')} / {formatStudioRunTimestamp(record.createdAt, new Date(rendererHost.clock.now()))}</time>
|
|
218
|
+
</span>
|
|
219
|
+
</div>
|
|
220
|
+
<div className="studio-result__actions studio-history-result__actions">
|
|
221
|
+
{!blocked ? (
|
|
222
|
+
<>
|
|
223
|
+
<Tooltip content={t('Common.copy')} placement="top">
|
|
224
|
+
<IconButton type="button" className="studio-result__action" onClick={handleCopy} disabled={!canExport} aria-label={t('StudioShell.copyGeneration')} icon={<CopyIcon size={16} aria-hidden="true" />} />
|
|
225
|
+
</Tooltip>
|
|
226
|
+
<Tooltip content={t(revealsManagedAsset ? 'StudioShell.revealAsset' : 'StudioShell.download')} placement="top">
|
|
227
|
+
<IconButton type="button" className="studio-result__action" onClick={handleDownload} disabled={!canExport} aria-label={t(revealsManagedAsset ? 'StudioShell.revealGeneration' : 'StudioShell.downloadGeneration')} icon={revealsManagedAsset ? <FolderOpen size={16} aria-hidden="true" /> : <DownloadIcon size={16} aria-hidden="true" />} />
|
|
228
|
+
</Tooltip>
|
|
229
|
+
</>
|
|
230
|
+
) : null}
|
|
231
|
+
<Tooltip content={t('StudioShell.useAsDraft')} placement="top">
|
|
232
|
+
<IconButton type="button" className="studio-result__action" onClick={() => onUseAsDraft(record)} aria-label={t('StudioShell.useAsDraft')} icon={<SquarePen size={16} aria-hidden="true" />} />
|
|
233
|
+
</Tooltip>
|
|
234
|
+
<Tooltip content={t('StudioShell.regenerate')} placement="top">
|
|
235
|
+
<IconButton type="button" className="studio-result__action" onClick={onRegenerate} aria-label={t('StudioShell.regenerate')} icon={<RefreshCw size={16} aria-hidden="true" />} />
|
|
236
|
+
</Tooltip>
|
|
237
|
+
</div>
|
|
238
|
+
</div>
|
|
239
|
+
<div className="studio-history-result__meta">
|
|
240
|
+
<div className="studio-history-result__tags">
|
|
241
|
+
{tags.map((tag, index) => <span key={tag} className={index === 0 ? `studio-history-result__tag--${toneClass}` : undefined}>{tag}</span>)}
|
|
242
|
+
</div>
|
|
243
|
+
<div className="studio-history-result__intent">
|
|
244
|
+
<span>{t('StudioShell.intentLabel')}</span>
|
|
245
|
+
<div className={hasRequestSettings ? 'studio-intent-pill__box' : 'studio-intent-pill__box studio-intent-pill__box--static'}>
|
|
246
|
+
<Tooltip content={intentLabel} placement="top" className="min-w-0">
|
|
247
|
+
<strong>{intentLabel}</strong>
|
|
248
|
+
</Tooltip>
|
|
249
|
+
{hasRequestSettings ? (
|
|
250
|
+
<Tooltip content={requestSettingsOpen ? t('StudioShell.hideRequestSettings') : t('StudioShell.showRequestSettings')} placement="top">
|
|
251
|
+
<IconButton
|
|
252
|
+
type="button"
|
|
253
|
+
className={requestSettingsOpen ? 'studio-intent-pill__trigger studio-intent-pill__trigger--open' : 'studio-intent-pill__trigger'}
|
|
254
|
+
aria-label={requestSettingsOpen ? t('StudioShell.hideRequestSettings') : t('StudioShell.showRequestSettings')}
|
|
255
|
+
aria-expanded={requestSettingsOpen}
|
|
256
|
+
onClick={() => setRequestSettingsOpen((value) => !value)}
|
|
257
|
+
icon={<ChevronRight size={15} aria-hidden="true" />}
|
|
258
|
+
/>
|
|
259
|
+
</Tooltip>
|
|
260
|
+
) : null}
|
|
261
|
+
</div>
|
|
262
|
+
</div>
|
|
263
|
+
</div>
|
|
264
|
+
{requestSettingsOpen && hasRequestSettings ? <TextStudioRequestSettings record={record} /> : null}
|
|
265
|
+
{body}
|
|
266
|
+
</div>
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function TextStudioHistorySnapshotBody({ snapshot }: { snapshot: Extract<StudioRunHistoryResultSnapshot, { ok: true }> }) {
|
|
271
|
+
const { translate: t } = useAIStudioHost();
|
|
272
|
+
if (snapshot.kind === 'text' || snapshot.kind === 'transcript') {
|
|
273
|
+
return <TextStudioOutputBody text={snapshot.body} />;
|
|
274
|
+
}
|
|
275
|
+
if (snapshot.kind === 'embedding') {
|
|
276
|
+
return (
|
|
277
|
+
<div className="studio-result__rich">
|
|
278
|
+
<p className="studio-result__plain">{t('StudioShell.embeddingSuccess')}</p>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
if (snapshot.kind === 'artifacts') {
|
|
283
|
+
const artifacts = snapshot.artifacts ?? (snapshot.firstArtifact ? [snapshot.firstArtifact] : []);
|
|
284
|
+
return (
|
|
285
|
+
<div className="studio-result__rich">
|
|
286
|
+
{artifacts.map((artifact, index) => (
|
|
287
|
+
<ArtifactMediaResult
|
|
288
|
+
key={artifact.relativePath}
|
|
289
|
+
artifact={artifact}
|
|
290
|
+
fallbackLabel={`${snapshot.jobId}:${index + 1}`}
|
|
291
|
+
/>
|
|
292
|
+
))}
|
|
293
|
+
</div>
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
if (snapshot.kind === 'voice-asset') {
|
|
297
|
+
return (
|
|
298
|
+
<div className="studio-result__rich">
|
|
299
|
+
<p className="studio-result__plain">{t('StudioShell.voiceAssetSuccess')}</p>
|
|
300
|
+
</div>
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return (
|
|
304
|
+
<ul className="studio-voice-list">
|
|
305
|
+
{snapshot.sample.map((voice) => (
|
|
306
|
+
<li key={voice.voiceId}>
|
|
307
|
+
<strong>{voice.voiceId}</strong>
|
|
308
|
+
<span>{voice.creationSource} / {voice.status}</span>
|
|
309
|
+
</li>
|
|
310
|
+
))}
|
|
311
|
+
{snapshot.sample.length === 0 ? <li><span>{t('StudioShell.noVoices')}</span></li> : null}
|
|
312
|
+
</ul>
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function TextStudioRunError({ message }: { message: string }) {
|
|
317
|
+
const { translate: t } = useAIStudioHost();
|
|
318
|
+
return (
|
|
319
|
+
<div className="studio-result__blocked" role="alert">
|
|
320
|
+
<div className="studio-result__blocked-line">
|
|
321
|
+
<AlertTriangle size={15} aria-hidden="true" />
|
|
322
|
+
<span>{t('StudioShell.generationFailed')}</span>
|
|
323
|
+
</div>
|
|
324
|
+
<p>{t('StudioShell.runStoppedEarly')}</p>
|
|
325
|
+
<p className="studio-result__hint">{t('StudioShell.noResultProduced')}</p>
|
|
326
|
+
<details className="studio-diag">
|
|
327
|
+
<summary>{t('StudioShell.runtimeDetails')}</summary>
|
|
328
|
+
<RuntimeDiagnosticsActions text={message} filenameBase="runtime-call" />
|
|
329
|
+
<pre className="studio-diag__json">{message}</pre>
|
|
330
|
+
</details>
|
|
331
|
+
</div>
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export function TextStudioResultState({
|
|
336
|
+
registration,
|
|
337
|
+
activeRun,
|
|
338
|
+
admission,
|
|
339
|
+
intentLabel,
|
|
340
|
+
running,
|
|
341
|
+
cancelRequested,
|
|
342
|
+
streamingText,
|
|
343
|
+
verboseConsole,
|
|
344
|
+
composer,
|
|
345
|
+
onCopy,
|
|
346
|
+
onDownload,
|
|
347
|
+
onRegenerate,
|
|
348
|
+
onCancel,
|
|
349
|
+
onUseAsDraft,
|
|
350
|
+
}: {
|
|
351
|
+
registration: StudioCapabilityRegistration;
|
|
352
|
+
activeRun: TextStudioActiveRun;
|
|
353
|
+
admission: ReturnType<typeof statusForCapability>;
|
|
354
|
+
intentLabel: string;
|
|
355
|
+
running: boolean;
|
|
356
|
+
cancelRequested: boolean;
|
|
357
|
+
streamingText: string | null;
|
|
358
|
+
verboseConsole: boolean;
|
|
359
|
+
composer: ReactNode;
|
|
360
|
+
onCopy: () => void;
|
|
361
|
+
onDownload: () => void;
|
|
362
|
+
onRegenerate: () => void;
|
|
363
|
+
onCancel?: () => void;
|
|
364
|
+
onUseAsDraft: (record: StudioRunHistoryRecord) => void;
|
|
365
|
+
}) {
|
|
366
|
+
const { translate: t } = useAIStudioHost();
|
|
367
|
+
const capability = registration.descriptor;
|
|
368
|
+
return (
|
|
369
|
+
<section className="studio-thread" aria-label={t('StudioShell.resultAriaLabel', { capability: t(capability.labelKey) })}>
|
|
370
|
+
<div className="studio-thread__scroll">
|
|
371
|
+
<article className="studio-turn studio-turn--user">
|
|
372
|
+
<div className="studio-turn__label">
|
|
373
|
+
<MessageSquare size={14} aria-hidden="true" />
|
|
374
|
+
<span>{t('StudioShell.promptLabel')}</span>
|
|
375
|
+
</div>
|
|
376
|
+
<p>{activeRun.prompt}</p>
|
|
377
|
+
<TextStudioPromptSettings activeRun={activeRun} />
|
|
378
|
+
</article>
|
|
379
|
+
<article className="studio-turn studio-turn--assistant">
|
|
380
|
+
<div className="studio-turn__label">
|
|
381
|
+
<FileText size={14} aria-hidden="true" />
|
|
382
|
+
<span>{t('StudioShell.generationLabel')}</span>
|
|
383
|
+
</div>
|
|
384
|
+
{activeRun.error ? (
|
|
385
|
+
<TextStudioRunError message={activeRun.error} />
|
|
386
|
+
) : activeRun.result || running ? (
|
|
387
|
+
<>
|
|
388
|
+
<StudioResult
|
|
389
|
+
result={activeRun.result}
|
|
390
|
+
running={running}
|
|
391
|
+
cancelRequested={cancelRequested}
|
|
392
|
+
registration={registration}
|
|
393
|
+
admission={admission}
|
|
394
|
+
createdAt={activeRun.createdAt}
|
|
395
|
+
intentLabel={intentLabel}
|
|
396
|
+
requestSettings={activeRun.record && hasTextStudioRequestSettings(activeRun.record) ? <TextStudioRequestSettings record={activeRun.record} /> : null}
|
|
397
|
+
streamingText={streamingText}
|
|
398
|
+
verboseConsole={verboseConsole}
|
|
399
|
+
onCopy={onCopy}
|
|
400
|
+
onDownload={onDownload}
|
|
401
|
+
onRegenerate={onRegenerate}
|
|
402
|
+
onCancel={onCancel}
|
|
403
|
+
/>
|
|
404
|
+
</>
|
|
405
|
+
) : activeRun.record ? (
|
|
406
|
+
<TextStudioHistoryRecordResult record={activeRun.record} onRegenerate={onRegenerate} onUseAsDraft={onUseAsDraft} />
|
|
407
|
+
) : null}
|
|
408
|
+
</article>
|
|
409
|
+
</div>
|
|
410
|
+
<div className="studio-thread__composer">{composer}</div>
|
|
411
|
+
</section>
|
|
412
|
+
);
|
|
413
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import type { NimiPortableAppAIConfig } from '@nimiplatform/sdk/ai';
|
|
3
|
+
|
|
4
|
+
import { useAIStudioHost } from './host-context.js';
|
|
5
|
+
import type { StudioCapabilityRegistration, CapabilityStudioProfile } from './module-registration.js';
|
|
6
|
+
import type { StudioCapabilityRunResult, StudioRuntimeInspection } from './runtime-types.js';
|
|
7
|
+
import {
|
|
8
|
+
getStudioRunIntentLabel,
|
|
9
|
+
type StudioRunConfigSnapshot,
|
|
10
|
+
type StudioRunHistoryRecord,
|
|
11
|
+
type StudioRunTargetSummary,
|
|
12
|
+
} from './history.js';
|
|
13
|
+
import {
|
|
14
|
+
composeStudioDirective,
|
|
15
|
+
DEFAULT_LENGTH_VALUE,
|
|
16
|
+
DEFAULT_TONE_VALUE,
|
|
17
|
+
LENGTH_OPTIONS,
|
|
18
|
+
TONE_OPTIONS,
|
|
19
|
+
} from './studio-directives.js';
|
|
20
|
+
import type { StudioTranslate } from './non-success-presentation.js';
|
|
21
|
+
|
|
22
|
+
export type TextStudioActiveRun = {
|
|
23
|
+
id: string;
|
|
24
|
+
prompt: string;
|
|
25
|
+
context: string;
|
|
26
|
+
createdAt: string;
|
|
27
|
+
result: StudioCapabilityRunResult | null;
|
|
28
|
+
record: StudioRunHistoryRecord | null;
|
|
29
|
+
error: string | null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function textStudioRuntimePrompt(prompt: string, context: string, directive?: string): string {
|
|
33
|
+
const trimmedContext = context.trim();
|
|
34
|
+
return [
|
|
35
|
+
directive?.trim() ? `Instructions:\n${directive.trim()}` : '',
|
|
36
|
+
trimmedContext ? `Context:\n${trimmedContext}` : '',
|
|
37
|
+
`Request:\n${prompt}`,
|
|
38
|
+
].filter(Boolean).join('\n\n');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function textStudioIntentSummary(
|
|
42
|
+
_result: StudioCapabilityRunResult | null,
|
|
43
|
+
runTarget: StudioRunTargetSummary,
|
|
44
|
+
record: StudioRunHistoryRecord | null,
|
|
45
|
+
translate: StudioTranslate,
|
|
46
|
+
): string {
|
|
47
|
+
const intent = record ? getStudioRunIntentLabel(record) : runTarget.intentLabel;
|
|
48
|
+
return translate('Studio.composer.intentSummary', { intent });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function textStudioRunTargetIntentSummary(
|
|
52
|
+
runTarget: StudioRunTargetSummary,
|
|
53
|
+
translate: StudioTranslate,
|
|
54
|
+
): string {
|
|
55
|
+
return translate('Studio.composer.intentSummary', { intent: runTarget.intentLabel });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function canConfigureRunTarget(runTarget: StudioRunTargetSummary): boolean {
|
|
59
|
+
return !runTarget.canDispatch && runTarget.status === 'blocked' && Boolean(runTarget.capabilityContract);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function useStudioRunTargetSummary(
|
|
63
|
+
registration: StudioCapabilityRegistration,
|
|
64
|
+
runtime: StudioRuntimeInspection | null,
|
|
65
|
+
): StudioRunTargetSummary {
|
|
66
|
+
const host = useAIStudioHost();
|
|
67
|
+
const [configProjection, setConfigProjection] = useState<{
|
|
68
|
+
state: 'loading' | 'loaded' | 'failed';
|
|
69
|
+
config: NimiPortableAppAIConfig | null;
|
|
70
|
+
error: string | null;
|
|
71
|
+
}>({ state: 'loading', config: null, error: null });
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
let cancelled = false;
|
|
75
|
+
let requestGeneration = 0;
|
|
76
|
+
const refresh = () => {
|
|
77
|
+
const generation = ++requestGeneration;
|
|
78
|
+
setConfigProjection({ state: 'loading', config: null, error: null });
|
|
79
|
+
void host.sdk.aiConfig.get()
|
|
80
|
+
.then((next) => {
|
|
81
|
+
if (!cancelled && generation === requestGeneration) {
|
|
82
|
+
setConfigProjection({ state: 'loaded', config: next, error: null });
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
.catch((cause) => {
|
|
86
|
+
if (!cancelled && generation === requestGeneration) {
|
|
87
|
+
setConfigProjection({
|
|
88
|
+
state: 'failed',
|
|
89
|
+
config: null,
|
|
90
|
+
error: cause instanceof Error ? cause.message : String(cause || host.translate('Studio.run.aiConfigLoadFailed')),
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
refresh();
|
|
96
|
+
const unsubscribe = host.app.events.subscribeAIConfigRefresh(refresh);
|
|
97
|
+
return () => {
|
|
98
|
+
cancelled = true;
|
|
99
|
+
requestGeneration += 1;
|
|
100
|
+
unsubscribe();
|
|
101
|
+
};
|
|
102
|
+
}, [host]);
|
|
103
|
+
|
|
104
|
+
return useMemo(() => host.app.projection.projectRunTarget({
|
|
105
|
+
capability: registration.descriptor,
|
|
106
|
+
runtime,
|
|
107
|
+
config: configProjection.config,
|
|
108
|
+
configState: configProjection.state,
|
|
109
|
+
configError: configProjection.error,
|
|
110
|
+
}), [configProjection, host, registration.descriptor, runtime]);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export type TextStudioPromptStyle = { tone: string; length: string };
|
|
114
|
+
|
|
115
|
+
function selectedStudioParamValue(
|
|
116
|
+
params: Readonly<Record<string, unknown>>,
|
|
117
|
+
key: string,
|
|
118
|
+
options: readonly { value: string }[],
|
|
119
|
+
fallback: string,
|
|
120
|
+
): string {
|
|
121
|
+
const raw = params[key];
|
|
122
|
+
const value = typeof raw === 'string' ? raw.trim() : '';
|
|
123
|
+
return options.some((option) => option.value === value) ? value : fallback;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function effectiveTextStudioPromptStyle(target: StudioRunTargetSummary): TextStudioPromptStyle {
|
|
127
|
+
return {
|
|
128
|
+
tone: selectedStudioParamValue(target.params, 'tone', TONE_OPTIONS, DEFAULT_TONE_VALUE),
|
|
129
|
+
length: selectedStudioParamValue(target.params, 'length', LENGTH_OPTIONS, DEFAULT_LENGTH_VALUE),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function textStudioDirectiveForTarget(
|
|
134
|
+
target: StudioRunTargetSummary,
|
|
135
|
+
profile: CapabilityStudioProfile,
|
|
136
|
+
): string | undefined {
|
|
137
|
+
if (!profile.controls.includes('tone') && !profile.controls.includes('length')) return undefined;
|
|
138
|
+
const style = effectiveTextStudioPromptStyle(target);
|
|
139
|
+
return composeStudioDirective(style.tone, style.length);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export function createRunConfigSnapshot(input: {
|
|
143
|
+
target: StudioRunTargetSummary;
|
|
144
|
+
promptStyle?: TextStudioPromptStyle | null;
|
|
145
|
+
context: string;
|
|
146
|
+
attachmentCount: number;
|
|
147
|
+
requestParameters?: Readonly<Record<string, unknown>>;
|
|
148
|
+
}): StudioRunConfigSnapshot {
|
|
149
|
+
const { target } = input;
|
|
150
|
+
const params = {
|
|
151
|
+
...target.params,
|
|
152
|
+
...(input.requestParameters ?? {}),
|
|
153
|
+
...(input.promptStyle ? { tone: input.promptStyle.tone, length: input.promptStyle.length } : {}),
|
|
154
|
+
};
|
|
155
|
+
return {
|
|
156
|
+
target: {
|
|
157
|
+
capabilityId: target.capabilityId,
|
|
158
|
+
capabilityContract: target.capabilityContract,
|
|
159
|
+
section: target.section,
|
|
160
|
+
status: target.status,
|
|
161
|
+
source: target.source,
|
|
162
|
+
intentLabel: target.intentLabel,
|
|
163
|
+
detail: target.detail,
|
|
164
|
+
params,
|
|
165
|
+
paramsSummary: [...target.paramsSummary],
|
|
166
|
+
profileOrigin: target.profileOrigin,
|
|
167
|
+
},
|
|
168
|
+
promptControls: {
|
|
169
|
+
contextAttached: Boolean(input.context.trim()),
|
|
170
|
+
context: input.context.trim(),
|
|
171
|
+
attachmentCount: input.attachmentCount,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|