@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,381 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react';
|
|
2
|
+
import { nimiToast } from '@nimiplatform/kit/ui';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
StudioCapabilityParameterContext,
|
|
6
|
+
StudioHistoryActionsContext,
|
|
7
|
+
StudioHistoryLoadContext,
|
|
8
|
+
StudioHistoryPanelContext,
|
|
9
|
+
type StudioCapabilityParameterStore,
|
|
10
|
+
type StudioHistoryActions,
|
|
11
|
+
type StudioHistoryLoadState,
|
|
12
|
+
type StudioHistoryPanelScope,
|
|
13
|
+
type StudioHistoryPanelState,
|
|
14
|
+
type StudioMediaHistoryRecord,
|
|
15
|
+
} from './contexts.js';
|
|
16
|
+
import {
|
|
17
|
+
createStudioRunHistoryRecord,
|
|
18
|
+
type StudioRunConfigSnapshot,
|
|
19
|
+
type StudioRunHistory,
|
|
20
|
+
type StudioRunHistoryRecord,
|
|
21
|
+
} from './history.js';
|
|
22
|
+
import { studioHistoryClearOutcomeTone } from './history-policy.js';
|
|
23
|
+
import type { StudioCapabilityRegistration } from './module-registration.js';
|
|
24
|
+
import { createStudioNonSuccess } from './non-success-presentation.js';
|
|
25
|
+
import type { StudioParameterState } from './parameters.js';
|
|
26
|
+
import type { StudioCapabilityRunResult, StudioRuntimeInspection } from './runtime-types.js';
|
|
27
|
+
import { SectionAITesting } from './section-ai-testing.js';
|
|
28
|
+
import type { StudioAIConfigPanelRenderInput } from './section-ai-testing-surface.js';
|
|
29
|
+
import type { StudioTranslate } from './non-success-presentation.js';
|
|
30
|
+
|
|
31
|
+
export type AIStudioHistoryProjection = {
|
|
32
|
+
readonly runHistory: StudioRunHistory;
|
|
33
|
+
readonly mediaHistory: readonly StudioMediaHistoryRecord[];
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type AIStudioHistoryPersistOutcome =
|
|
37
|
+
| { readonly ok: true; readonly projection: AIStudioHistoryProjection }
|
|
38
|
+
| {
|
|
39
|
+
readonly ok: false;
|
|
40
|
+
readonly message: string;
|
|
41
|
+
readonly retryRecord: boolean;
|
|
42
|
+
readonly remainingCleanupPaths: readonly string[];
|
|
43
|
+
readonly displayFailure?: { readonly reason: 'runtime-call-failed'; readonly message: string };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export type AIStudioHistoryMutationIssue = {
|
|
47
|
+
readonly runId: string;
|
|
48
|
+
readonly step: 'asset' | 'history';
|
|
49
|
+
readonly message: string;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export type AIStudioHistoryMutationOutcome = {
|
|
53
|
+
readonly completed: number;
|
|
54
|
+
readonly skipped: number;
|
|
55
|
+
readonly failed: number;
|
|
56
|
+
readonly projection: AIStudioHistoryProjection;
|
|
57
|
+
readonly issues: readonly AIStudioHistoryMutationIssue[];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export type AIStudioArtifactCleanupOutcome = {
|
|
61
|
+
readonly failures: readonly string[];
|
|
62
|
+
readonly remainingCleanupPaths: readonly string[];
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type AIStudioHistoryPanelPreferences = {
|
|
66
|
+
readonly collapsed: boolean;
|
|
67
|
+
readonly scope: StudioHistoryPanelScope;
|
|
68
|
+
readonly hideFailures: boolean;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export type AIStudioHistoryRepository = {
|
|
72
|
+
readonly load: () => Promise<AIStudioHistoryProjection>;
|
|
73
|
+
readonly persist: (input: {
|
|
74
|
+
readonly result: StudioCapabilityRunResult;
|
|
75
|
+
readonly record: StudioRunHistoryRecord;
|
|
76
|
+
}) => Promise<AIStudioHistoryPersistOutcome>;
|
|
77
|
+
readonly appendRecord: (record: StudioRunHistoryRecord) => Promise<AIStudioHistoryProjection>;
|
|
78
|
+
readonly cleanupArtifacts: (relativePaths: readonly string[]) => Promise<AIStudioArtifactCleanupOutcome>;
|
|
79
|
+
readonly remove: (recordId: string, deleteAssets: boolean) => Promise<AIStudioHistoryMutationOutcome>;
|
|
80
|
+
readonly clear: (capabilityId: string | null, deleteAssets: boolean) => Promise<AIStudioHistoryMutationOutcome>;
|
|
81
|
+
readonly nextIdentity: () => Promise<{ readonly runId: string; readonly createdAt: string }>;
|
|
82
|
+
readonly statusForResult?: (result: StudioCapabilityRunResult) => string | undefined;
|
|
83
|
+
readonly loadPanelPreferences: () => AIStudioHistoryPanelPreferences;
|
|
84
|
+
readonly savePanelPreferences: (preferences: AIStudioHistoryPanelPreferences) => void | Promise<void>;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export type AIStudioWorkspaceProps = {
|
|
88
|
+
readonly registration: StudioCapabilityRegistration;
|
|
89
|
+
readonly registrations: readonly StudioCapabilityRegistration[];
|
|
90
|
+
readonly runtime: StudioRuntimeInspection | null;
|
|
91
|
+
readonly controller: AIStudioWorkspaceController;
|
|
92
|
+
readonly renderAIConfigPanel: (input: StudioAIConfigPanelRenderInput) => ReactNode;
|
|
93
|
+
readonly verboseConsole?: boolean;
|
|
94
|
+
readonly draftPersistence?: boolean;
|
|
95
|
+
readonly headerActions?: ReactNode;
|
|
96
|
+
readonly rootTestId?: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
export type AIStudioWorkspaceControllerOptions = {
|
|
100
|
+
readonly historyRepository: AIStudioHistoryRepository;
|
|
101
|
+
readonly registrations: readonly StudioCapabilityRegistration[];
|
|
102
|
+
readonly onSelectCapability: (capabilityId: string) => void;
|
|
103
|
+
readonly translate: StudioTranslate;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export type AIStudioWorkspaceController = {
|
|
107
|
+
readonly parameterStore: StudioCapabilityParameterStore;
|
|
108
|
+
readonly historyLoadState: StudioHistoryLoadState;
|
|
109
|
+
readonly historyActions: StudioHistoryActions;
|
|
110
|
+
readonly historyPanelState: StudioHistoryPanelState;
|
|
111
|
+
readonly handleResult: (
|
|
112
|
+
result: StudioCapabilityRunResult,
|
|
113
|
+
prompt: string,
|
|
114
|
+
runConfig?: StudioRunConfigSnapshot,
|
|
115
|
+
) => Promise<StudioRunHistoryRecord>;
|
|
116
|
+
readonly history: StudioRunHistory | null;
|
|
117
|
+
readonly lastResult: StudioCapabilityRunResult | null;
|
|
118
|
+
readonly historySelectionRequest: { readonly requestId: number; readonly record: StudioRunHistoryRecord } | null;
|
|
119
|
+
readonly selectHistoryRun: (record: StudioRunHistoryRecord) => void;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
type AIStudioHistoryIssue =
|
|
123
|
+
| { readonly kind: 'load'; readonly message: string }
|
|
124
|
+
| {
|
|
125
|
+
readonly kind: 'save';
|
|
126
|
+
readonly message: string;
|
|
127
|
+
readonly records: readonly StudioRunHistoryRecord[];
|
|
128
|
+
readonly cleanupPaths: readonly string[];
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export function useAIStudioWorkspaceController({
|
|
132
|
+
historyRepository,
|
|
133
|
+
registrations,
|
|
134
|
+
onSelectCapability,
|
|
135
|
+
translate,
|
|
136
|
+
}: AIStudioWorkspaceControllerOptions): AIStudioWorkspaceController {
|
|
137
|
+
const [projection, setProjection] = useState<AIStudioHistoryProjection | null>(null);
|
|
138
|
+
const [historyIssue, setHistoryIssue] = useState<AIStudioHistoryIssue | null>(null);
|
|
139
|
+
const [lastResult, setLastResult] = useState<StudioCapabilityRunResult | null>(null);
|
|
140
|
+
const [historySelectionRequest, setHistorySelectionRequest] = useState<{
|
|
141
|
+
requestId: number;
|
|
142
|
+
record: StudioRunHistoryRecord;
|
|
143
|
+
} | null>(null);
|
|
144
|
+
const [parameters, setParameters] = useState<StudioParameterState>(() => Object.freeze(Object.fromEntries(
|
|
145
|
+
registrations.map((entry) => [entry.descriptor.id, entry.parameters.initial()]),
|
|
146
|
+
)));
|
|
147
|
+
const [historyPanel, setHistoryPanel] = useState<AIStudioHistoryPanelPreferences>(
|
|
148
|
+
historyRepository.loadPanelPreferences,
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const refreshHistory = useCallback(async () => {
|
|
152
|
+
try {
|
|
153
|
+
setProjection(await historyRepository.load());
|
|
154
|
+
setHistoryIssue(null);
|
|
155
|
+
} catch (error) {
|
|
156
|
+
setHistoryIssue({ kind: 'load', message: errorMessage(error, 'History load failed.') });
|
|
157
|
+
}
|
|
158
|
+
}, [historyRepository]);
|
|
159
|
+
|
|
160
|
+
useEffect(() => { void refreshHistory(); }, [refreshHistory]);
|
|
161
|
+
|
|
162
|
+
const parameterStore = useMemo(() => ({
|
|
163
|
+
state: parameters,
|
|
164
|
+
setParameters: (capabilityId: string, value: Readonly<Record<string, unknown>>) => {
|
|
165
|
+
setParameters((current) => ({ ...current, [capabilityId]: value }));
|
|
166
|
+
},
|
|
167
|
+
}), [parameters]);
|
|
168
|
+
|
|
169
|
+
const updateHistoryPanel = useCallback((patch: Partial<AIStudioHistoryPanelPreferences>) => {
|
|
170
|
+
setHistoryPanel((current) => {
|
|
171
|
+
const next = { ...current, ...patch };
|
|
172
|
+
void Promise.resolve(historyRepository.savePanelPreferences(next));
|
|
173
|
+
return next;
|
|
174
|
+
});
|
|
175
|
+
}, [historyRepository]);
|
|
176
|
+
|
|
177
|
+
const historyActions = useMemo(() => ({
|
|
178
|
+
removeRecord: async (recordId: string, deleteAssets = false) => {
|
|
179
|
+
try {
|
|
180
|
+
const outcome = await historyRepository.remove(recordId, deleteAssets);
|
|
181
|
+
setProjection(outcome.projection);
|
|
182
|
+
if (outcome.skipped > 0) nimiToast.danger(translate('History.deleteAssetFailed'));
|
|
183
|
+
else if (outcome.failed > 0) nimiToast.danger(translate('History.deleteFailed'));
|
|
184
|
+
else nimiToast.success(translate(deleteAssets ? 'History.deletedRecordAndAsset' : 'History.deletedRecordOnly'));
|
|
185
|
+
} catch {
|
|
186
|
+
await refreshHistory();
|
|
187
|
+
nimiToast.danger(translate('History.deleteFailed'));
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
clearScope: async (capabilityId: string | null, deleteAssets: boolean) => {
|
|
191
|
+
try {
|
|
192
|
+
const outcome = await historyRepository.clear(capabilityId, deleteAssets);
|
|
193
|
+
setProjection(outcome.projection);
|
|
194
|
+
const message = deleteAssets
|
|
195
|
+
? translate('History.clearOutcome', {
|
|
196
|
+
completed: outcome.completed,
|
|
197
|
+
skipped: outcome.skipped,
|
|
198
|
+
failed: outcome.failed,
|
|
199
|
+
})
|
|
200
|
+
: translate(outcome.failed > 0 || outcome.skipped > 0
|
|
201
|
+
? 'History.clearFailed'
|
|
202
|
+
: 'History.clearedRecordsOnly');
|
|
203
|
+
const tone = studioHistoryClearOutcomeTone(outcome);
|
|
204
|
+
nimiToast[tone](message);
|
|
205
|
+
} catch {
|
|
206
|
+
await refreshHistory();
|
|
207
|
+
nimiToast.danger(translate('History.clearFailed'));
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
}), [historyRepository, refreshHistory, translate]);
|
|
211
|
+
|
|
212
|
+
const historyPanelState = useMemo(() => ({
|
|
213
|
+
...historyPanel,
|
|
214
|
+
imageRecords: projection?.mediaHistory ?? [],
|
|
215
|
+
setCollapsed: (collapsed: boolean) => updateHistoryPanel({ collapsed }),
|
|
216
|
+
setScope: (scope: StudioHistoryPanelScope) => updateHistoryPanel({ scope }),
|
|
217
|
+
setHideFailures: (hideFailures: boolean) => updateHistoryPanel({ hideFailures }),
|
|
218
|
+
}), [historyPanel, projection?.mediaHistory, updateHistoryPanel]);
|
|
219
|
+
|
|
220
|
+
const handleResult = useCallback(async (
|
|
221
|
+
result: StudioCapabilityRunResult,
|
|
222
|
+
prompt: string,
|
|
223
|
+
runConfig?: StudioRunConfigSnapshot,
|
|
224
|
+
) => {
|
|
225
|
+
setLastResult(result);
|
|
226
|
+
const identity = await historyRepository.nextIdentity();
|
|
227
|
+
const status = historyRepository.statusForResult?.(result);
|
|
228
|
+
const record = createStudioRunHistoryRecord({
|
|
229
|
+
result,
|
|
230
|
+
prompt,
|
|
231
|
+
runId: identity.runId,
|
|
232
|
+
createdAt: identity.createdAt,
|
|
233
|
+
runConfig,
|
|
234
|
+
...(status ? { status } : {}),
|
|
235
|
+
});
|
|
236
|
+
let outcome: AIStudioHistoryPersistOutcome;
|
|
237
|
+
try {
|
|
238
|
+
outcome = await historyRepository.persist({ result, record });
|
|
239
|
+
} catch (error) {
|
|
240
|
+
const message = errorMessage(error, 'History persistence failed.');
|
|
241
|
+
setHistoryIssue({ kind: 'save', message, records: [record], cleanupPaths: [] });
|
|
242
|
+
throw new Error(message);
|
|
243
|
+
}
|
|
244
|
+
if (outcome.ok) {
|
|
245
|
+
setProjection(outcome.projection);
|
|
246
|
+
setHistoryIssue((current) => {
|
|
247
|
+
if (!current || current.kind === 'load') return null;
|
|
248
|
+
const records = current.records.filter((pending) => pending.id !== record.id);
|
|
249
|
+
return records.length === 0 && current.cleanupPaths.length === 0
|
|
250
|
+
? null
|
|
251
|
+
: { ...current, records };
|
|
252
|
+
});
|
|
253
|
+
return record;
|
|
254
|
+
}
|
|
255
|
+
if (outcome.displayFailure) {
|
|
256
|
+
const capability = registrations.find((item) => item.descriptor.id === result.capabilityId)?.descriptor;
|
|
257
|
+
if (capability) {
|
|
258
|
+
setLastResult(createStudioNonSuccess(
|
|
259
|
+
capability,
|
|
260
|
+
outcome.displayFailure.reason,
|
|
261
|
+
outcome.displayFailure.message,
|
|
262
|
+
translate,
|
|
263
|
+
));
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
setHistoryIssue((current) => ({
|
|
267
|
+
kind: 'save',
|
|
268
|
+
message: outcome.message,
|
|
269
|
+
records: outcome.retryRecord
|
|
270
|
+
? [...(current?.kind === 'save' ? current.records.filter((item) => item.id !== record.id) : []), record]
|
|
271
|
+
: current?.kind === 'save' ? current.records : [],
|
|
272
|
+
cleanupPaths: [...new Set([
|
|
273
|
+
...(current?.kind === 'save' ? current.cleanupPaths : []),
|
|
274
|
+
...outcome.remainingCleanupPaths,
|
|
275
|
+
])],
|
|
276
|
+
}));
|
|
277
|
+
throw new Error(outcome.message);
|
|
278
|
+
}, [historyRepository, registrations, translate]);
|
|
279
|
+
|
|
280
|
+
const retryHistory = useCallback(async () => {
|
|
281
|
+
const issue = historyIssue;
|
|
282
|
+
if (!issue || issue.kind === 'load') {
|
|
283
|
+
await refreshHistory();
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
setHistoryIssue(null);
|
|
287
|
+
const cleanup = await historyRepository.cleanupArtifacts(issue.cleanupPaths);
|
|
288
|
+
const retryErrors = [...cleanup.failures];
|
|
289
|
+
let completed = 0;
|
|
290
|
+
let nextProjection: AIStudioHistoryProjection | null = null;
|
|
291
|
+
for (const record of issue.records) {
|
|
292
|
+
try {
|
|
293
|
+
nextProjection = await historyRepository.appendRecord(record);
|
|
294
|
+
completed += 1;
|
|
295
|
+
} catch (error) {
|
|
296
|
+
retryErrors.push(errorMessage(error, 'History persistence failed.'));
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (nextProjection) setProjection(nextProjection);
|
|
301
|
+
const records = issue.records.slice(completed);
|
|
302
|
+
if (retryErrors.length || records.length || cleanup.remainingCleanupPaths.length) {
|
|
303
|
+
setHistoryIssue({
|
|
304
|
+
kind: 'save',
|
|
305
|
+
message: retryErrors.join(' ') || 'History persistence retry is incomplete.',
|
|
306
|
+
records,
|
|
307
|
+
cleanupPaths: cleanup.remainingCleanupPaths,
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
}, [historyIssue, historyRepository, refreshHistory]);
|
|
311
|
+
|
|
312
|
+
const selectHistoryRun = useCallback((record: StudioRunHistoryRecord) => {
|
|
313
|
+
if (!registrations.some((entry) => entry.descriptor.id === record.capabilityId)) {
|
|
314
|
+
nimiToast.warning(translate('History.unsupportedCapability'));
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
onSelectCapability(record.capabilityId);
|
|
318
|
+
setHistorySelectionRequest((current) => ({
|
|
319
|
+
requestId: (current?.requestId ?? 0) + 1,
|
|
320
|
+
record,
|
|
321
|
+
}));
|
|
322
|
+
}, [onSelectCapability, registrations, translate]);
|
|
323
|
+
|
|
324
|
+
return {
|
|
325
|
+
parameterStore,
|
|
326
|
+
historyLoadState: {
|
|
327
|
+
title: translate(historyIssue?.kind === 'save' ? 'History.saveFailedTitle' : 'History.loadFailedTitle'),
|
|
328
|
+
error: historyIssue?.message ?? null,
|
|
329
|
+
retry: () => { void retryHistory(); },
|
|
330
|
+
},
|
|
331
|
+
historyActions,
|
|
332
|
+
historyPanelState,
|
|
333
|
+
handleResult,
|
|
334
|
+
history: projection?.runHistory ?? null,
|
|
335
|
+
lastResult,
|
|
336
|
+
historySelectionRequest,
|
|
337
|
+
selectHistoryRun,
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function AIStudioWorkspace({
|
|
342
|
+
registration,
|
|
343
|
+
registrations,
|
|
344
|
+
runtime,
|
|
345
|
+
controller,
|
|
346
|
+
renderAIConfigPanel,
|
|
347
|
+
verboseConsole = false,
|
|
348
|
+
draftPersistence = true,
|
|
349
|
+
headerActions,
|
|
350
|
+
rootTestId,
|
|
351
|
+
}: AIStudioWorkspaceProps) {
|
|
352
|
+
return (
|
|
353
|
+
<StudioCapabilityParameterContext.Provider value={controller.parameterStore}>
|
|
354
|
+
<StudioHistoryLoadContext.Provider value={controller.historyLoadState}>
|
|
355
|
+
<StudioHistoryActionsContext.Provider value={controller.historyActions}>
|
|
356
|
+
<StudioHistoryPanelContext.Provider value={controller.historyPanelState}>
|
|
357
|
+
<SectionAITesting
|
|
358
|
+
registration={registration}
|
|
359
|
+
registrations={registrations}
|
|
360
|
+
runtime={runtime}
|
|
361
|
+
onResult={controller.handleResult}
|
|
362
|
+
history={controller.history}
|
|
363
|
+
lastResult={controller.lastResult}
|
|
364
|
+
historySelectionRequest={controller.historySelectionRequest}
|
|
365
|
+
onSelectHistoryRun={controller.selectHistoryRun}
|
|
366
|
+
verboseConsole={verboseConsole}
|
|
367
|
+
draftPersistence={draftPersistence}
|
|
368
|
+
headerActions={headerActions}
|
|
369
|
+
renderAIConfigPanel={renderAIConfigPanel}
|
|
370
|
+
rootTestId={rootTestId}
|
|
371
|
+
/>
|
|
372
|
+
</StudioHistoryPanelContext.Provider>
|
|
373
|
+
</StudioHistoryActionsContext.Provider>
|
|
374
|
+
</StudioHistoryLoadContext.Provider>
|
|
375
|
+
</StudioCapabilityParameterContext.Provider>
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function errorMessage(error: unknown, fallback: string): string {
|
|
380
|
+
return error instanceof Error ? error.message : String(error || fallback);
|
|
381
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { NimiLocalAppClient } from '@nimiplatform/sdk/app';
|
|
3
|
+
import {
|
|
4
|
+
AppAgentCenterEntry,
|
|
5
|
+
createAgentCenterShellHostMechanics,
|
|
6
|
+
} from '@nimiplatform/kit/features/agent-center';
|
|
7
|
+
import {
|
|
8
|
+
createAgentCenterShellBridge,
|
|
9
|
+
hasElectronInvoke,
|
|
10
|
+
} from '@nimiplatform/kit/shell/renderer/bridge';
|
|
11
|
+
|
|
12
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
|
|
13
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-agid-014a
|
|
14
|
+
export function AgentCenterCapability(props: { readonly client: NimiLocalAppClient }) {
|
|
15
|
+
const hostMechanics = useMemo(() => (
|
|
16
|
+
hasElectronInvoke()
|
|
17
|
+
? createAgentCenterShellHostMechanics(createAgentCenterShellBridge())
|
|
18
|
+
: null
|
|
19
|
+
), []);
|
|
20
|
+
return (
|
|
21
|
+
<AppAgentCenterEntry
|
|
22
|
+
client={props.client}
|
|
23
|
+
hostMechanics={hostMechanics}
|
|
24
|
+
language={globalThis.document?.documentElement.lang || 'en'}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { NimiLocalAppClient } from '@nimiplatform/sdk/app';
|
|
3
|
+
import {
|
|
4
|
+
AppConversationEntry,
|
|
5
|
+
createBrowserAppConversationHostPort,
|
|
6
|
+
} from '@nimiplatform/kit/features/chat';
|
|
7
|
+
|
|
8
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
|
|
9
|
+
// @nimi-authority: rule.nimi.runtime.agent-participation.r093
|
|
10
|
+
export function AgentConversationCapability(props: { readonly client: NimiLocalAppClient }) {
|
|
11
|
+
const hostPort = useMemo(() => createBrowserAppConversationHostPort(), []);
|
|
12
|
+
return (
|
|
13
|
+
<AppConversationEntry
|
|
14
|
+
client={props.client}
|
|
15
|
+
hostPort={hostPort}
|
|
16
|
+
language={globalThis.document?.documentElement.lang || 'en'}
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import type { NimiLocalAppClient } from '@nimiplatform/sdk/app';
|
|
3
|
+
import {
|
|
4
|
+
AgentRealtimeEntry,
|
|
5
|
+
createBrowserAgentRealtimeHostMediaPort,
|
|
6
|
+
} from '@nimiplatform/kit/features/agent-realtime';
|
|
7
|
+
|
|
8
|
+
const INPUT_AUDIO = Object.freeze({
|
|
9
|
+
codec: 'pcm-s16le' as const,
|
|
10
|
+
sampleRateHz: 24_000,
|
|
11
|
+
channelCount: 1 as const,
|
|
12
|
+
frameDurationMs: 20,
|
|
13
|
+
maximumFrameBytes: 960,
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-017
|
|
17
|
+
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
|
|
18
|
+
export function AgentRealtimeCapability(props: { readonly client: NimiLocalAppClient }) {
|
|
19
|
+
const host = useMemo(() => createBrowserAgentRealtimeHostMediaPort(), []);
|
|
20
|
+
return (
|
|
21
|
+
<AgentRealtimeEntry
|
|
22
|
+
client={props.client}
|
|
23
|
+
inputAudio={INPUT_AUDIO}
|
|
24
|
+
turnDetection="server-vad"
|
|
25
|
+
host={host}
|
|
26
|
+
locale={globalThis.document?.documentElement.lang || 'en'}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { useMemo, useState } from 'react';
|
|
2
|
+
import { Button, IconButton, Surface } from '@nimiplatform/kit/ui';
|
|
3
|
+
import {
|
|
4
|
+
CheckSquare,
|
|
5
|
+
Copy,
|
|
6
|
+
Database,
|
|
7
|
+
FormInput,
|
|
8
|
+
Layers,
|
|
9
|
+
PanelsTopLeft,
|
|
10
|
+
Zap,
|
|
11
|
+
type LucideIcon,
|
|
12
|
+
} from 'lucide-react';
|
|
13
|
+
import {
|
|
14
|
+
CATEGORIES,
|
|
15
|
+
RECIPES,
|
|
16
|
+
type CategoryId,
|
|
17
|
+
} from './kit-component-gallery-recipes.js';
|
|
18
|
+
import {
|
|
19
|
+
FoundationsCanvas,
|
|
20
|
+
RecipeWorkspace,
|
|
21
|
+
countFor,
|
|
22
|
+
} from './kit-component-gallery-surface.js';
|
|
23
|
+
|
|
24
|
+
export type KitRecipesCopyText = (value: string) => void | Promise<unknown>;
|
|
25
|
+
|
|
26
|
+
const foundationCode = `@import "@nimiplatform/kit/ui/styles.css";
|
|
27
|
+
@import "@nimiplatform/kit/ui/themes/light.css";
|
|
28
|
+
@import "@nimiplatform/kit/ui/themes/nimi-accent.css";
|
|
29
|
+
|
|
30
|
+
.surface {
|
|
31
|
+
color: var(--nimi-text-primary);
|
|
32
|
+
background: var(--nimi-material-glass-thin-bg);
|
|
33
|
+
border: 1px solid var(--nimi-material-glass-thin-border);
|
|
34
|
+
}`;
|
|
35
|
+
|
|
36
|
+
const categoryIcons: Record<CategoryId, LucideIcon> = {
|
|
37
|
+
foundations: Layers,
|
|
38
|
+
actions: Zap,
|
|
39
|
+
inputs: FormInput,
|
|
40
|
+
selection: CheckSquare,
|
|
41
|
+
overlays: Layers,
|
|
42
|
+
layouts: PanelsTopLeft,
|
|
43
|
+
data: Database,
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function KitRecipesGallery({
|
|
47
|
+
copyText,
|
|
48
|
+
exampleAppId = 'example.app',
|
|
49
|
+
testId = 'kit-recipes-gallery',
|
|
50
|
+
}: {
|
|
51
|
+
copyText: KitRecipesCopyText;
|
|
52
|
+
exampleAppId?: string;
|
|
53
|
+
testId?: string;
|
|
54
|
+
}) {
|
|
55
|
+
const [category, setCategory] = useState<CategoryId>('foundations');
|
|
56
|
+
|
|
57
|
+
const recipesInCategory = useMemo(() => RECIPES.filter((recipe) => recipe.category === category), [category]);
|
|
58
|
+
const activeCategory = CATEGORIES.find((entry) => entry.id === category) ?? CATEGORIES[0];
|
|
59
|
+
|
|
60
|
+
const categoryCopyText = useMemo(() => {
|
|
61
|
+
if (category === 'foundations') return foundationCode;
|
|
62
|
+
const imports = Array.from(new Set(recipesInCategory.flatMap((recipe) => recipe.importNames))).sort();
|
|
63
|
+
return `import {\n ${imports.join(',\n ')}\n} from '@nimiplatform/kit/ui';`;
|
|
64
|
+
}, [category, recipesInCategory]);
|
|
65
|
+
|
|
66
|
+
function selectCategory(nextCategory: CategoryId) {
|
|
67
|
+
setCategory(nextCategory);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function copyImport() {
|
|
71
|
+
void copyText(categoryCopyText);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<div className="kit-doc grid h-full min-h-0 min-w-0 grid-cols-[260px_minmax(0,1fr)] items-stretch gap-4 overflow-x-hidden overflow-y-auto p-4 max-[880px]:grid-cols-1 max-[880px]:auto-rows-max" data-testid={testId}>
|
|
76
|
+
{/* Left — library nav. Sticky while the canvas to its right scrolls. */}
|
|
77
|
+
<Surface as="aside" material="glass-regular" padding="none" elevation="raised" className="kit-doc__library sticky top-0 flex h-[calc(100cqh-2rem)] min-h-0 max-h-none flex-col gap-4 self-stretch overflow-hidden p-4 max-[880px]:static max-[880px]:h-auto max-[880px]:overflow-visible" aria-label="Kit library navigation">
|
|
78
|
+
<div className="kit-doc__intro min-w-0">
|
|
79
|
+
<p className="eyebrow">Nimi UI Kit</p>
|
|
80
|
+
<h1 className="m-0 text-2xl font-bold tracking-tight">UI Recipes</h1>
|
|
81
|
+
</div>
|
|
82
|
+
<div className="flex min-h-0 flex-1 flex-col gap-2 max-[880px]:flex-none">
|
|
83
|
+
<p className="kit-doc__browse-label px-1 text-[10px] font-bold uppercase tracking-wider text-[var(--nimi-text-muted)]">Browse</p>
|
|
84
|
+
<nav className="kit-doc__taxonomy grid min-h-0 flex-1 content-start gap-1.5 overflow-auto max-[880px]:flex-none" aria-label="Recipe categories">
|
|
85
|
+
{CATEGORIES.map((entry) => {
|
|
86
|
+
const isActive = entry.id === category;
|
|
87
|
+
return (
|
|
88
|
+
<Button
|
|
89
|
+
key={entry.id}
|
|
90
|
+
type="button"
|
|
91
|
+
tone="ghost"
|
|
92
|
+
size="sm"
|
|
93
|
+
className={`kit-tax grid grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-3 rounded-2xl border p-2 text-left transition-all [&>span]:contents ${isActive ? 'kit-tax--active border-transparent bg-[var(--nimi-sidebar-item-active)] text-[var(--nimi-text-primary)] shadow-[var(--nimi-elevation-base)]' : 'border-transparent bg-transparent text-[var(--nimi-text-secondary)] hover:bg-[var(--nimi-sidebar-item-hover)] hover:text-[var(--nimi-text-primary)]'}`}
|
|
94
|
+
onClick={() => selectCategory(entry.id)}
|
|
95
|
+
aria-current={isActive ? 'page' : undefined}
|
|
96
|
+
>
|
|
97
|
+
<span className={`kit-tax__symbol grid h-10 w-10 place-items-center rounded-xl border text-sm font-bold transition-colors ${isActive ? 'border-[color-mix(in_srgb,var(--nimi-action-primary-bg)_34%,transparent)] bg-[var(--nimi-surface-active)] text-[var(--nimi-action-primary-bg)]' : 'border-[var(--nimi-border-subtle)] bg-[color-mix(in_srgb,var(--nimi-text-muted)_14%,transparent)] text-[var(--nimi-text-secondary)]'}`}>
|
|
98
|
+
{(() => {
|
|
99
|
+
const Icon = categoryIcons[entry.id];
|
|
100
|
+
return <Icon size={18} strokeWidth={1.8} aria-hidden="true" />;
|
|
101
|
+
})()}
|
|
102
|
+
</span>
|
|
103
|
+
<span className="kit-tax__copy min-w-0">
|
|
104
|
+
<strong className="truncate text-sm">{entry.label}</strong>
|
|
105
|
+
</span>
|
|
106
|
+
<span className={`kit-tax__count rounded-full px-2 py-0.5 text-xs font-bold ${isActive ? 'bg-[var(--nimi-surface-active)] text-[var(--nimi-action-primary-bg)]' : 'bg-[color-mix(in_srgb,var(--nimi-text-muted)_14%,transparent)] text-[var(--nimi-text-secondary)]'}`}>{countFor(entry.id)}</span>
|
|
107
|
+
</Button>
|
|
108
|
+
);
|
|
109
|
+
})}
|
|
110
|
+
</nav>
|
|
111
|
+
</div>
|
|
112
|
+
</Surface>
|
|
113
|
+
|
|
114
|
+
{/* Main — hero + canvas. Flows in natural height so the whole column scrolls. */}
|
|
115
|
+
<section className="kit-doc__main grid min-w-0 content-start gap-4">
|
|
116
|
+
<div className="kit-doc__header flex min-w-0 items-center justify-between gap-4 px-1 py-1 max-[720px]:flex-col max-[720px]:items-stretch">
|
|
117
|
+
<div className="grid min-w-0 gap-2">
|
|
118
|
+
<h2 className="m-0 truncate text-3xl font-bold tracking-tight">{activeCategory.label}</h2>
|
|
119
|
+
</div>
|
|
120
|
+
<div className="kit-doc__header-actions flex min-w-0 shrink-0 flex-wrap items-center gap-2">
|
|
121
|
+
<IconButton
|
|
122
|
+
tone="ghost"
|
|
123
|
+
size="sm"
|
|
124
|
+
aria-label={category === 'foundations' ? 'Copy CSS setup' : 'Copy imports'}
|
|
125
|
+
className="kit-doc__copy-action bg-[color-mix(in_srgb,var(--nimi-surface-card)_32%,transparent)] border-[color-mix(in_srgb,var(--nimi-border-subtle)_45%,transparent)] shadow-none hover:bg-[var(--nimi-action-primary-bg)] hover:border-[var(--nimi-action-primary-bg)] hover:text-[var(--nimi-action-primary-text)] hover:shadow-none"
|
|
126
|
+
icon={<Copy size={14} aria-hidden="true" />}
|
|
127
|
+
onClick={copyImport}
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
</div>
|
|
131
|
+
|
|
132
|
+
<div className="kit-doc__canvas min-w-0">
|
|
133
|
+
{category === 'foundations' ? (
|
|
134
|
+
<FoundationsCanvas />
|
|
135
|
+
) : (
|
|
136
|
+
<RecipeWorkspace recipes={recipesInCategory} copyText={copyText} exampleAppId={exampleAppId} />
|
|
137
|
+
)}
|
|
138
|
+
</div>
|
|
139
|
+
</section>
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { KitRecipesGallery } from './gallery.js';
|
|
2
|
+
|
|
3
|
+
async function copyText(value: string): Promise<void> {
|
|
4
|
+
if (!globalThis.navigator?.clipboard?.writeText) {
|
|
5
|
+
throw new Error('Clipboard write is unavailable.');
|
|
6
|
+
}
|
|
7
|
+
await globalThis.navigator.clipboard.writeText(value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function KitRecipesCapability({
|
|
11
|
+
exampleAppId = 'example.app',
|
|
12
|
+
}: {
|
|
13
|
+
readonly exampleAppId?: string;
|
|
14
|
+
}) {
|
|
15
|
+
return <KitRecipesGallery copyText={copyText} exampleAppId={exampleAppId} />;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { KitRecipesGallery } from './gallery.js';
|
|
19
|
+
export type { KitRecipesCopyText } from './gallery.js';
|