@nimiplatform/app-tools 0.2.9 → 0.4.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/README.md +89 -4
- package/lib/app-doctor-update.mjs +12 -3
- package/lib/app-info.mjs +142 -0
- package/lib/app-pack.mjs +53 -16
- package/lib/app-project-lifecycle.mjs +10 -15
- package/lib/app-scaffold-profiles.mjs +28 -13
- package/lib/app-scaffold.mjs +31 -3
- package/lib/macos-native.mjs +96 -0
- package/lib/payload-links.mjs +41 -0
- package/package.json +8 -7
- package/scripts/sync-scaffold-versions.mjs +3 -16
- package/templates/app-source/src/ai-studio-core/ai-studio-core.css +31 -0
- package/templates/app-source/src/ai-studio-core/history-policy.ts +23 -1
- package/templates/app-source/src/ai-studio-core/history.ts +7 -1
- package/templates/app-source/src/ai-studio-core/host-context.tsx +5 -3
- package/templates/app-source/src/ai-studio-core/messages/en.json +1 -0
- package/templates/app-source/src/ai-studio-core/messages/zh.json +1 -0
- package/templates/app-source/src/ai-studio-core/module-registration.ts +2 -2
- package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +6 -2
- package/templates/app-source/src/ai-studio-core/run-target.ts +1 -1
- package/templates/app-source/src/ai-studio-core/runtime-types.ts +4 -0
- package/templates/app-source/src/ai-studio-core/runtime.ts +13 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +3 -3
- package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +41 -13
- package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +1 -1
- package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +1 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +26 -1
- package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +14 -4
- package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +3 -1
- package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +12 -3
- package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-input.tsx +56 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing-vision-result.tsx +22 -0
- package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +54 -29
- package/templates/app-source/src/product-modules/agent-realtime/index.tsx +2 -2
- package/templates/app-source/src/studio-modules/studio-create/runtime.ts +1 -0
- package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +6 -1
- package/templates/app-source/src/studio-modules/studio-media/messages/en.json +19 -0
- package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +19 -0
- package/templates/app-source/src/studio-modules/studio-media/registration.ts +10 -1
- package/templates/app-source/src/studio-modules/studio-media/runtime.ts +2 -0
- package/templates/app-source/src/studio-modules/studio-media/vision-parameters.tsx +18 -0
- package/templates/app-source/src/studio-modules/studio-media/vision-runtime.ts +58 -0
- package/templates/app-source/src/workbench-core/workbench-core.css +5 -0
- package/templates/app-source.manifest.json +16 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Suspense, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
|
-
import { IconButton, LoadingSkeleton, nimiToast, OverlayShell, StatusBadge, Tooltip } from '@nimiplatform/kit/ui';
|
|
2
|
+
import { Button, IconButton, LoadingSkeleton, nimiToast, OverlayShell, StatusBadge, Tooltip } from '@nimiplatform/kit/ui';
|
|
3
3
|
import { PanelRight, SquarePen } from 'lucide-react';
|
|
4
4
|
import { createBrowserDataUrlAttachmentAdapter, useChatComposer, type BrowserDataUrlAttachment } from '@nimiplatform/kit/features/chat/headless';
|
|
5
5
|
import { useAIStudioHost } from './host-context.js';
|
|
@@ -8,6 +8,7 @@ import type { StudioCapabilityRunResult, StudioRuntimeInspection } from './runti
|
|
|
8
8
|
import { getStudioRunIntentLabel, restoreStudioCapabilityRunResult, type StudioRunConfigSnapshot, type StudioRunHistory, type StudioRunHistoryRecord } from './history.js';
|
|
9
9
|
import { CapabilityRunHistory, DrawerErrorBoundary, downloadTextFile, resultPlainText, statusForCapability, type CapabilityStatus, type SectionAITestingProps } from './section-ai-testing-surface.js';
|
|
10
10
|
import { TextStudioComposer, TextStudioStartState } from './section-ai-testing-composer.js';
|
|
11
|
+
import { ScenarioJobStatus } from '@nimiplatform/sdk/runtime/generated';
|
|
11
12
|
import {
|
|
12
13
|
canCancelStudioCapabilityRun,
|
|
13
14
|
hasStudioCapabilityRunInput,
|
|
@@ -35,6 +36,7 @@ function TextStudioShell({
|
|
|
35
36
|
verboseConsole,
|
|
36
37
|
draftPersistence,
|
|
37
38
|
onOpenConfig,
|
|
39
|
+
configOpen,
|
|
38
40
|
history,
|
|
39
41
|
historySelectionRequest,
|
|
40
42
|
onSelectHistoryRun,
|
|
@@ -48,6 +50,7 @@ function TextStudioShell({
|
|
|
48
50
|
verboseConsole: boolean;
|
|
49
51
|
draftPersistence: boolean;
|
|
50
52
|
onOpenConfig?: () => void;
|
|
53
|
+
configOpen: boolean;
|
|
51
54
|
history: StudioRunHistory | null;
|
|
52
55
|
historySelectionRequest: { requestId: number; record: StudioRunHistoryRecord } | null;
|
|
53
56
|
onSelectHistoryRun: (record: StudioRunHistoryRecord) => void;
|
|
@@ -69,7 +72,7 @@ function TextStudioShell({
|
|
|
69
72
|
}, draftPersistence).prompt ?? preset.prompt
|
|
70
73
|
));
|
|
71
74
|
const [context, setContext] = useState('');
|
|
72
|
-
const [
|
|
75
|
+
const [executingRun, setExecutingRun] = useState<TextStudioActiveRun | null>(null);
|
|
73
76
|
const [cancelRequested, setCancelRequested] = useState(false);
|
|
74
77
|
const [streamingText, setStreamingText] = useState<string | null>(null);
|
|
75
78
|
const [activeRun, setActiveRun] = useState<TextStudioActiveRun | null>(null);
|
|
@@ -77,11 +80,14 @@ function TextStudioShell({
|
|
|
77
80
|
const historyPanel = useContext(StudioHistoryPanelContext);
|
|
78
81
|
const historyCollapsed = historyPanel?.collapsed ?? true;
|
|
79
82
|
const runSeqRef = useRef(0);
|
|
80
|
-
const abortControllerRef = useRef<AbortController | null>(null);
|
|
83
|
+
const abortControllerRef = useRef<{ runId: string; controller: AbortController } | null>(null);
|
|
84
|
+
const running = executingRun !== null;
|
|
85
|
+
const displayingExecution = executingRun !== null && activeRun?.id === executingRun.id;
|
|
86
|
+
const displayedRun = displayingExecution ? executingRun : activeRun;
|
|
81
87
|
const expandedHistoryErrorRef = useRef<string | null>(null);
|
|
82
88
|
const attachmentAdapter = useMemo(
|
|
83
|
-
() => createBrowserDataUrlAttachmentAdapter({ idPrefix: 'studio-attachment' }),
|
|
84
|
-
[],
|
|
89
|
+
() => createBrowserDataUrlAttachmentAdapter({ idPrefix: 'studio-attachment', ...(capability.id === 'vision.locate' ? { maxAttachments: 1, accept: ['image/png','image/jpeg','image/webp','image/gif'] } : {}) }),
|
|
90
|
+
[capability.id],
|
|
85
91
|
);
|
|
86
92
|
const composerState = useChatComposer<BrowserDataUrlAttachment>({
|
|
87
93
|
adapter: { submit: async () => {} },
|
|
@@ -90,16 +96,18 @@ function TextStudioShell({
|
|
|
90
96
|
onTextChange: updatePrompt,
|
|
91
97
|
disabled: running,
|
|
92
98
|
});
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
99
|
+
const hasRequiredImage = capability.id !== 'vision.locate'
|
|
100
|
+
|| (composerState.attachments.length === 1 && composerState.attachments[0]?.kind === 'image');
|
|
101
|
+
const hasActiveRun = Boolean(displayedRun);
|
|
102
|
+
const currentResult = displayedRun
|
|
103
|
+
? displayedRun.result ?? (displayedRun.record
|
|
104
|
+
? restoreStudioCapabilityRunResult(displayedRun.record, (id) => (
|
|
97
105
|
registrations.find((item) => item.descriptor.id === id)?.descriptor.label ?? null
|
|
98
106
|
))
|
|
99
107
|
: null)
|
|
100
108
|
: lastResult?.capabilityId === capability.id ? lastResult : null;
|
|
101
109
|
const headerResult = hasActiveRun ? currentResult : null;
|
|
102
|
-
const runTarget = useStudioRunTargetSummary(registration, runtime);
|
|
110
|
+
const runTarget = useStudioRunTargetSummary(registration, runtime, configOpen);
|
|
103
111
|
const admission = statusForCapability(registration, runTarget, headerResult, t);
|
|
104
112
|
const requiresPrompt = profile.inputKind !== 'none';
|
|
105
113
|
const supportsMedia = profile.supportsAttachments;
|
|
@@ -132,7 +140,7 @@ function TextStudioShell({
|
|
|
132
140
|
}
|
|
133
141
|
|
|
134
142
|
useEffect(() => {
|
|
135
|
-
abortControllerRef.current?.abort('studio-capability-changed');
|
|
143
|
+
abortControllerRef.current?.controller.abort('studio-capability-changed');
|
|
136
144
|
abortControllerRef.current = null;
|
|
137
145
|
const draft = rendererHost.app.projection.promptDraft({
|
|
138
146
|
surfaceId: 'ai-capabilities',
|
|
@@ -144,19 +152,20 @@ function TextStudioShell({
|
|
|
144
152
|
setContext('');
|
|
145
153
|
setActiveRun(null);
|
|
146
154
|
setSessionRuns({});
|
|
147
|
-
|
|
155
|
+
setExecutingRun(null);
|
|
148
156
|
setCancelRequested(false);
|
|
149
157
|
setStreamingText(null);
|
|
150
158
|
}, [capability.id, draftPersistence, preset, rendererHost]);
|
|
151
159
|
|
|
152
160
|
async function run(nextPrompt = prompt, nextContext = context) {
|
|
161
|
+
if (abortControllerRef.current) return;
|
|
153
162
|
const displayPrompt = nextPrompt.trim();
|
|
154
163
|
if (!hasStudioCapabilityRunInput({ requiresPrompt, prompt: displayPrompt, hasAlternativeInput })) return;
|
|
164
|
+
if (!hasRequiredImage) return;
|
|
155
165
|
if (!runTarget.canDispatch) return;
|
|
156
166
|
const runSeq = runSeqRef.current + 1;
|
|
157
167
|
runSeqRef.current = runSeq;
|
|
158
168
|
const abortController = new AbortController();
|
|
159
|
-
abortControllerRef.current = abortController;
|
|
160
169
|
const startedAt = rendererHost.clock.now();
|
|
161
170
|
const pendingRun: TextStudioActiveRun = {
|
|
162
171
|
id: `pending-${startedAt}`,
|
|
@@ -167,8 +176,9 @@ function TextStudioShell({
|
|
|
167
176
|
record: null,
|
|
168
177
|
error: null,
|
|
169
178
|
};
|
|
179
|
+
abortControllerRef.current = { runId: pendingRun.id, controller: abortController };
|
|
170
180
|
setActiveRun(pendingRun);
|
|
171
|
-
|
|
181
|
+
setExecutingRun(pendingRun);
|
|
172
182
|
setCancelRequested(false);
|
|
173
183
|
try {
|
|
174
184
|
let result: StudioCapabilityRunResult;
|
|
@@ -178,14 +188,21 @@ function TextStudioShell({
|
|
|
178
188
|
const directive = textStudioDirectiveForTarget(runTarget, profile);
|
|
179
189
|
result = await rendererHost.sdk.runCapability({
|
|
180
190
|
capabilityId: capability.id,
|
|
181
|
-
prompt: capability.id === 'audio.transcribe'
|
|
191
|
+
prompt: capability.id === 'audio.transcribe' || capability.id === 'vision.locate'
|
|
182
192
|
? displayPrompt
|
|
183
193
|
: textStudioRuntimePrompt(displayPrompt, nextContext, directive),
|
|
184
194
|
scenarioId: preset.id,
|
|
185
|
-
onPartial: isStreaming ?
|
|
195
|
+
onPartial: isStreaming ? (text) => {
|
|
196
|
+
if (runSeqRef.current === runSeq) setStreamingText(text);
|
|
197
|
+
} : undefined,
|
|
186
198
|
attachments: supportsMedia ? [...composerState.attachments] : undefined,
|
|
187
199
|
parameters: effectiveCapabilityParameters,
|
|
188
200
|
signal: abortController.signal,
|
|
201
|
+
onJobUpdate: job => {
|
|
202
|
+
if (runSeqRef.current !== runSeq) return;
|
|
203
|
+
const jobStatus = job.status === ScenarioJobStatus.QUEUED || job.status === ScenarioJobStatus.SUBMITTED ? 'queued' : job.status === ScenarioJobStatus.RUNNING ? 'running' : undefined;
|
|
204
|
+
if (jobStatus) setExecutingRun(current => current?.id === pendingRun.id ? { ...current, jobStatus } : current);
|
|
205
|
+
},
|
|
189
206
|
});
|
|
190
207
|
} catch (error) {
|
|
191
208
|
const message = error instanceof Error ? error.message : String(error || t('NonSuccess.title.runtimeCallFailed'));
|
|
@@ -227,8 +244,8 @@ function TextStudioShell({
|
|
|
227
244
|
setActiveRun({ ...pendingRun, error: message });
|
|
228
245
|
} finally {
|
|
229
246
|
if (runSeq === runSeqRef.current) {
|
|
230
|
-
if (abortControllerRef.current === abortController) abortControllerRef.current = null;
|
|
231
|
-
|
|
247
|
+
if (abortControllerRef.current?.controller === abortController) abortControllerRef.current = null;
|
|
248
|
+
setExecutingRun(null);
|
|
232
249
|
setCancelRequested(false);
|
|
233
250
|
setStreamingText(null);
|
|
234
251
|
}
|
|
@@ -341,9 +358,10 @@ function TextStudioShell({
|
|
|
341
358
|
}
|
|
342
359
|
|
|
343
360
|
function handleCancel() {
|
|
344
|
-
|
|
361
|
+
const execution = abortControllerRef.current;
|
|
362
|
+
if (!execution || cancelRequested || !displayingExecution || execution.runId !== displayedRun?.id) return;
|
|
345
363
|
setCancelRequested(true);
|
|
346
|
-
|
|
364
|
+
execution.controller.abort('studio-user-canceled');
|
|
347
365
|
}
|
|
348
366
|
|
|
349
367
|
return (
|
|
@@ -360,6 +378,11 @@ function TextStudioShell({
|
|
|
360
378
|
</div>
|
|
361
379
|
<div className="studio__head-actions">
|
|
362
380
|
{headerActions}
|
|
381
|
+
{executingRun && !displayingExecution ? (
|
|
382
|
+
<Button size="sm" tone="secondary" onClick={() => setActiveRun(executingRun)}>
|
|
383
|
+
{t('StudioShell.returnToRunning')}
|
|
384
|
+
</Button>
|
|
385
|
+
) : null}
|
|
363
386
|
{hasActiveRun ? (
|
|
364
387
|
<Tooltip content={t('StudioShell.newRun')} placement="bottom">
|
|
365
388
|
<IconButton
|
|
@@ -388,21 +411,22 @@ function TextStudioShell({
|
|
|
388
411
|
</div>
|
|
389
412
|
</header>
|
|
390
413
|
<main className="studio__stage">
|
|
391
|
-
{hasActiveRun &&
|
|
414
|
+
{hasActiveRun && displayedRun ? (
|
|
392
415
|
<TextStudioResultState
|
|
393
416
|
registration={registration}
|
|
394
|
-
activeRun={
|
|
417
|
+
activeRun={displayedRun}
|
|
395
418
|
admission={admission}
|
|
396
|
-
intentLabel={
|
|
397
|
-
running={
|
|
398
|
-
|
|
399
|
-
|
|
419
|
+
intentLabel={displayedRun.record ? getStudioRunIntentLabel(displayedRun.record) : runTarget.intentLabel}
|
|
420
|
+
running={displayingExecution}
|
|
421
|
+
canRegenerate={!running && hasRequiredImage}
|
|
422
|
+
cancelRequested={displayingExecution && cancelRequested}
|
|
423
|
+
streamingText={displayingExecution ? streamingText : null}
|
|
400
424
|
verboseConsole={verboseConsole}
|
|
401
425
|
composer={composer}
|
|
402
426
|
onCopy={handleCopy}
|
|
403
427
|
onDownload={handleDownload}
|
|
404
|
-
onRegenerate={() => void run(
|
|
405
|
-
onCancel={canCancelStudioCapabilityRun({
|
|
428
|
+
onRegenerate={() => void run(displayedRun.prompt, displayedRun.context)}
|
|
429
|
+
onCancel={displayingExecution && canCancelStudioCapabilityRun({
|
|
406
430
|
capabilityId: capability.id,
|
|
407
431
|
resultKind: profile.resultKind,
|
|
408
432
|
})
|
|
@@ -420,7 +444,7 @@ function TextStudioShell({
|
|
|
420
444
|
</div>
|
|
421
445
|
<CapabilityRunHistory
|
|
422
446
|
history={history}
|
|
423
|
-
activeRunId={
|
|
447
|
+
activeRunId={displayedRun?.id ?? null}
|
|
424
448
|
onSelectRun={onSelectHistoryRun}
|
|
425
449
|
collapsed={historyCollapsed}
|
|
426
450
|
currentCapabilityId={capability.id}
|
|
@@ -466,6 +490,7 @@ export function SectionAITesting({
|
|
|
466
490
|
verboseConsole={verboseConsole}
|
|
467
491
|
draftPersistence={draftPersistence}
|
|
468
492
|
onOpenConfig={renderAIConfigPanel ? () => setConfigOpen(true) : undefined}
|
|
493
|
+
configOpen={configOpen}
|
|
469
494
|
history={history}
|
|
470
495
|
historySelectionRequest={historySelectionRequest}
|
|
471
496
|
onSelectHistoryRun={onSelectHistoryRun}
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
|
|
8
8
|
const INPUT_AUDIO = Object.freeze({
|
|
9
9
|
codec: 'pcm-s16le' as const,
|
|
10
|
-
sampleRateHz:
|
|
10
|
+
sampleRateHz: 16_000,
|
|
11
11
|
channelCount: 1 as const,
|
|
12
12
|
frameDurationMs: 20,
|
|
13
|
-
maximumFrameBytes:
|
|
13
|
+
maximumFrameBytes: 640,
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-017
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type StudioMediaCapabilityId = 'image.generate' | 'video.generate' | 'music.generate';
|
|
1
|
+
export type StudioMediaCapabilityId = 'image.generate' | 'video.generate' | 'music.generate' | 'vision.locate';
|
|
2
2
|
|
|
3
3
|
export const studioMediaDescriptors = Object.freeze([
|
|
4
4
|
{
|
|
@@ -19,4 +19,9 @@ export const studioMediaDescriptors = Object.freeze([
|
|
|
19
19
|
summary: 'Prompt + lyrics → protected music.generate Scenario Job → adopted WAV.', summaryKey: 'Capabilities.musicGenerate.summary',
|
|
20
20
|
surface: 'kit.runRuntimeMusicGenerate → sdk.localApp.ai.scenarioJobs + artifact adoption', execution: 'runtime-sdk', capabilityContract: 'music.generate',
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
id: 'vision.locate', label: 'Visual localization', labelKey: 'Capabilities.visionLocate.label', group: 'media', section: 'image',
|
|
24
|
+
summary: 'Locate objects or controls in one image using boxes or points.', summaryKey: 'Capabilities.visionLocate.summary',
|
|
25
|
+
surface: 'sdk.localApp.ai.scenarioJobs + artifact upload', execution: 'runtime-sdk', capabilityContract: 'vision.locate',
|
|
26
|
+
},
|
|
22
27
|
] as const);
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
+
"VisionLocate": {
|
|
3
|
+
"chooseImage": "Choose image",
|
|
4
|
+
"replaceImage": "Replace image",
|
|
5
|
+
"draftImage": "Image to locate in",
|
|
6
|
+
"imageHint": "One static image · PNG, JPEG, WebP or GIF · Up to 32 MiB",
|
|
7
|
+
"queryLabel": "Describe the target",
|
|
8
|
+
"modelSelectionRequired": "No model configuration is selected for visual localization.",
|
|
9
|
+
"selectModelAction": "In Nimi Desktop, open Runtime → Model configuration and select a visual localization configuration, then locate again.",
|
|
10
|
+
"invalidInput": "The image or target description does not meet the localization requirements.",
|
|
11
|
+
"correctInput": "Use one readable, static JPEG, PNG, WebP or GIF (multi-frame images are unsupported), up to 32 MiB and about 67 million pixels. Enter a nonempty target description of at most 8 KiB in UTF-8, then locate again.",
|
|
12
|
+
"historySummaryOnly": "This large result's history keeps its summary and Job ID. Export full coordinates during the original run.",
|
|
13
|
+
"stoppedBeforeSubmit": "Stopped before submitting a Locate job.",
|
|
14
|
+
"geometry": "Result shape", "box": "Bounding boxes", "point": "Points", "localOnly": "Runs locally. Choose a model using the configuration control below.",
|
|
15
|
+
"inputRequired": "Attach one static image and describe the target to locate.", "imageTooLarge": "Choose a static image of at most 32 MiB.", "resultMissing": "Runtime returned no typed Locate result.",
|
|
16
|
+
"found": "Found {{count}} matching targets", "noMatch": "No matching targets found", "sourceImage": "Image used for this task", "overlay": "Locations on the task image", "target": "Target {{index}}",
|
|
17
|
+
"previewUnavailable": "The input image preview is no longer available. The coordinates below still refer to the recorded image.", "coordinates": "Image identity and coordinates", "matches": "Matches", "queued": "Queued for localization…", "running": "Loading the model or locating targets…"
|
|
18
|
+
},
|
|
2
19
|
"Capabilities": {
|
|
20
|
+
"visionLocate": { "label": "Visual localization", "summary": "Describe an object or control in one image to get boxes or points." },
|
|
3
21
|
"imageGenerate": {
|
|
4
22
|
"label": "Image Generate",
|
|
5
23
|
"summary": "Prompt → image.generate Scenario Job → typed artifact preview result."
|
|
@@ -15,6 +33,7 @@
|
|
|
15
33
|
},
|
|
16
34
|
"Studio": {
|
|
17
35
|
"profiles": {
|
|
36
|
+
"visionLocate": { "inputTitle": "Test visual localization", "inputPlaceholder": "For example: the search button at the top right, or the red cup on the desk…", "primaryLabel": "Locate targets", "primaryRunningLabel": "Locating…", "emptyTitle": "Locate objects or controls", "emptyHint": "Choose one static image, describe the target, then choose boxes or points.", "footnote": "Coordinates refer to the complete image after applying its orientation." },
|
|
18
37
|
"imageGenerate": {
|
|
19
38
|
"inputTitle": "Test image generation",
|
|
20
39
|
"inputPlaceholder": "Describe the image you want the runtime to render…",
|
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
+
"VisionLocate": {
|
|
3
|
+
"chooseImage": "选择图片",
|
|
4
|
+
"replaceImage": "更换图片",
|
|
5
|
+
"draftImage": "待定位的图片",
|
|
6
|
+
"imageHint": "一张静态图片 · PNG、JPEG、WebP 或 GIF · 不超过 32 MiB",
|
|
7
|
+
"queryLabel": "描述目标",
|
|
8
|
+
"modelSelectionRequired": "尚未选择图像定位的模型配置。",
|
|
9
|
+
"selectModelAction": "在 Nimi Desktop 的“运行时 → 模型配置”中选择图像定位配置,然后重新定位。",
|
|
10
|
+
"invalidInput": "图片或目标描述不符合定位要求。",
|
|
11
|
+
"correctInput": "请使用一张能正常打开的静态 JPEG、PNG、WebP 或 GIF(不支持多帧图片),不超过 32 MiB、约 6700 万像素。填写非空的目标描述,UTF-8 编码不超过 8 KiB,然后重新定位。",
|
|
12
|
+
"historySummaryOnly": "此定位结果较大,历史仅保留摘要和任务编号。完整坐标请在当次运行中导出。",
|
|
13
|
+
"stoppedBeforeSubmit": "定位请求已停止,尚未提交任务。",
|
|
14
|
+
"geometry": "结果形态", "box": "边界框", "point": "定位点", "localOnly": "使用本地图像定位,可通过下方配置入口选择模型。",
|
|
15
|
+
"inputRequired": "请附上一张静态图片,并描述要定位的目标。", "imageTooLarge": "请选择不超过 32 MiB 的静态图片。", "resultMissing": "Runtime 未返回完整的定位结果。",
|
|
16
|
+
"found": "找到 {{count}} 个匹配目标", "noMatch": "未找到匹配目标", "sourceImage": "本次任务使用的图片", "overlay": "任务图片上的定位结果", "target": "目标 {{index}}",
|
|
17
|
+
"previewUnavailable": "输入图片的预览已不可用。下方坐标仍对应记录中的原图。", "coordinates": "图片标识与坐标", "matches": "匹配目标", "queued": "正在排队等待定位…", "running": "正在加载模型或定位目标…"
|
|
18
|
+
},
|
|
2
19
|
"Capabilities": {
|
|
20
|
+
"visionLocate": { "label": "图像定位", "summary": "描述单张图片中的物体或控件,获取边界框或定位点。" },
|
|
3
21
|
"imageGenerate": {
|
|
4
22
|
"label": "图像生成",
|
|
5
23
|
"summary": "提示词 → image.generate 场景任务 → 类型化产物预览结果。"
|
|
@@ -15,6 +33,7 @@
|
|
|
15
33
|
},
|
|
16
34
|
"Studio": {
|
|
17
35
|
"profiles": {
|
|
36
|
+
"visionLocate": { "inputTitle": "测试图像定位", "inputPlaceholder": "例如:右上角的搜索按钮,或桌上的红色杯子…", "primaryLabel": "定位目标", "primaryRunningLabel": "正在定位…", "emptyTitle": "定位图片中的物体或控件", "emptyHint": "选择一张静态图片,描述目标,再选择边界框或定位点。", "footnote": "坐标以应用方向后的完整原图为基准。" },
|
|
18
37
|
"imageGenerate": {
|
|
19
38
|
"inputTitle": "测试图像生成",
|
|
20
39
|
"inputPlaceholder": "描述你希望 Runtime 渲染的图像…",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Image as ImageIcon, Music2, Video } from 'lucide-react';
|
|
1
|
+
import { Image as ImageIcon, Music2, Video, ScanSearch } from 'lucide-react';
|
|
2
|
+
import { StudioVisionParameterPanel, studioVisionLocateParameters } from './vision-parameters.js';
|
|
2
3
|
import type { AIStudioModuleRegistration } from '../../ai-studio-core/module-registration.js';
|
|
3
4
|
import { studioMediaDescriptors, type StudioMediaCapabilityId } from './descriptors.js';
|
|
4
5
|
import { studioImageGenerateParameters, studioMusicGenerateParameters, studioVideoGenerateParameters } from './parameters.js';
|
|
@@ -7,6 +8,14 @@ import { StudioMediaParameterPanel } from './parameter-panel.js';
|
|
|
7
8
|
export const studioMediaModule = Object.freeze({
|
|
8
9
|
id: 'studio-media', navigationLabel: 'Media', order: 20,
|
|
9
10
|
capabilities: [
|
|
11
|
+
{
|
|
12
|
+
descriptor: studioMediaDescriptors[3], icon: ScanSearch,
|
|
13
|
+
profile: {
|
|
14
|
+
studioTag: 'Vision', inputTitleKey: 'Studio.profiles.visionLocate.inputTitle', inputPlaceholderKey: 'Studio.profiles.visionLocate.inputPlaceholder', inputKind: 'prompt', supportsAttachments: true, controls: [], primaryLabelKey: 'Studio.profiles.visionLocate.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.visionLocate.primaryRunningLabel', resultTitle: 'Locations', emptyTitleKey: 'Studio.profiles.visionLocate.emptyTitle', emptyHintKey: 'Studio.profiles.visionLocate.emptyHint', resultKind: 'vision-locate', footnoteKey: 'Studio.profiles.visionLocate.footnote',
|
|
15
|
+
},
|
|
16
|
+
preset: { id: 'locate-object', label: 'Locate an object', prompt: '' },
|
|
17
|
+
runtimeMethod: 'runtime.ai.submitScenarioJob:vision_locate', parameters: studioVisionLocateParameters, parameterPanel: StudioVisionParameterPanel,
|
|
18
|
+
},
|
|
10
19
|
{
|
|
11
20
|
descriptor: studioMediaDescriptors[0],
|
|
12
21
|
icon: ImageIcon,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { StudioCapabilityRuntimeHandlers } from '../../ai-studio-core/runtime-dispatcher.js';
|
|
2
|
+
import { runVisionLocate } from './vision-runtime.js';
|
|
2
3
|
import {
|
|
3
4
|
createStudioScenarioJobClient,
|
|
4
5
|
projectStudioArtifactRunnerResult,
|
|
@@ -13,6 +14,7 @@ import type {
|
|
|
13
14
|
// @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
|
|
14
15
|
|
|
15
16
|
export const studioMediaRuntimeHandlers: StudioCapabilityRuntimeHandlers = Object.freeze({
|
|
17
|
+
'vision.locate': runVisionLocate,
|
|
16
18
|
'image.generate': runImageGenerate,
|
|
17
19
|
'video.generate': runVideoGenerate,
|
|
18
20
|
'music.generate': runMusicGenerate,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SelectField } from '@nimiplatform/kit/ui';
|
|
2
|
+
import { defineStudioParameters, LOCAL_ONLY_STUDIO_PARAMETER } from '../../ai-studio-core/parameters.js';
|
|
3
|
+
import { StudioParameterField, type StudioParameterPanelProps } from '../../ai-studio-core/parameter-fields.js';
|
|
4
|
+
import { useAIStudioHost } from '../../ai-studio-core/host-context.js';
|
|
5
|
+
|
|
6
|
+
export const studioVisionLocateParameters = defineStudioParameters<{ geometry: 'box' | 'point' }>({
|
|
7
|
+
initial: () => ({ geometry: 'box' }), routeMatrix: { geometry: LOCAL_ONLY_STUDIO_PARAMETER },
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
export function StudioVisionParameterPanel(props: StudioParameterPanelProps) {
|
|
11
|
+
const { translate: t } = useAIStudioHost();
|
|
12
|
+
return <div className="studio-parameters">
|
|
13
|
+
<StudioParameterField label={t('VisionLocate.geometry')}>
|
|
14
|
+
<SelectField value={props.parameters.geometry === 'point' ? 'point' : 'box'} disabled={props.disabled || props.source === 'cloud'} onChange={event => props.onChange({ geometry: event.currentTarget.value })} options={[{value:'box',label:t('VisionLocate.box')},{value:'point',label:t('VisionLocate.point')}]} />
|
|
15
|
+
</StudioParameterField>
|
|
16
|
+
<p>{t('VisionLocate.localOnly')}</p>
|
|
17
|
+
</div>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { runNimiRuntimeScenarioJob } from '@nimiplatform/sdk/runtime';
|
|
2
|
+
import { ExecutionMode, ScenarioType, VisionLocateGeometry, type VisionLocateResult } from '@nimiplatform/sdk/runtime/generated';
|
|
3
|
+
import type { NimiLocalAppVisionLocateResult } from '@nimiplatform/sdk/app';
|
|
4
|
+
import { createStudioScenarioJobClient, type StudioCapabilityRuntimeContext } from '../../ai-studio-core/runtime.js';
|
|
5
|
+
|
|
6
|
+
function localVisionResult(result: VisionLocateResult): NimiLocalAppVisionLocateResult {
|
|
7
|
+
return { imageArtifactId: result.imageArtifactId, width: result.width, height: result.height,
|
|
8
|
+
locations: result.locations.map(location => {
|
|
9
|
+
const label = location.label === undefined ? {} : { label: location.label };
|
|
10
|
+
const geometry = location.geometry;
|
|
11
|
+
if (geometry.oneofKind === 'box' && 'box' in geometry) return { type: 'box', ...geometry.box, ...label };
|
|
12
|
+
if (geometry.oneofKind === 'point' && 'point' in geometry) return { type: 'point', ...geometry.point, ...label };
|
|
13
|
+
throw new Error('Locate result geometry is missing');
|
|
14
|
+
}),
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// @nimi-authority: rule.nimi.sdks.feature-clients.r102
|
|
19
|
+
export async function runVisionLocate(context: StudioCapabilityRuntimeContext) {
|
|
20
|
+
const t = context.host.translate;
|
|
21
|
+
const abortedBeforeSubmit = () => context.host.nonSuccess(context.capability, 'operation-aborted', t('VisionLocate.stoppedBeforeSubmit'));
|
|
22
|
+
const images = context.input.attachments ?? [];
|
|
23
|
+
const image = images[0];
|
|
24
|
+
if (!context.prompt || images.length !== 1 || !image || image.kind !== 'image' || !['image/png','image/jpeg','image/webp','image/gif'].includes(image.mimeType)) {
|
|
25
|
+
return context.host.nonSuccess(context.capability, 'input-invalid', t('VisionLocate.inputRequired'));
|
|
26
|
+
}
|
|
27
|
+
const prefix = `data:${image.mimeType};base64,`;
|
|
28
|
+
if (!image.dataUrl.startsWith(prefix) || image.dataUrl.length > 4 * Math.ceil(32 * 1024 * 1024 / 3) + prefix.length) {
|
|
29
|
+
return context.host.nonSuccess(context.capability, 'input-invalid', t('VisionLocate.imageTooLarge'));
|
|
30
|
+
}
|
|
31
|
+
if (context.input.signal?.aborted) return abortedBeforeSubmit();
|
|
32
|
+
const bytes = Uint8Array.from(atob(image.dataUrl.slice(prefix.length)), char => char.charCodeAt(0));
|
|
33
|
+
let upload;
|
|
34
|
+
try {
|
|
35
|
+
upload = await context.host.client.ai.artifacts.upload({ bytes, mimeType: image.mimeType as Parameters<typeof context.host.client.ai.artifacts.upload>[0]['mimeType'] });
|
|
36
|
+
} catch (error) {
|
|
37
|
+
if (context.input.signal?.aborted) return abortedBeforeSubmit();
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
if (context.input.signal?.aborted) return abortedBeforeSubmit();
|
|
41
|
+
const result = await runNimiRuntimeScenarioJob({
|
|
42
|
+
ai: createStudioScenarioJobClient(context),
|
|
43
|
+
request: {
|
|
44
|
+
head: { appId: context.host.appId, subjectUserId: '', timeoutMs: 0 }, scenarioType: ScenarioType.VISION_LOCATE, executionMode: ExecutionMode.ASYNC_JOB,
|
|
45
|
+
spec: { spec: { oneofKind: 'visionLocate', visionLocate: { imageArtifactId: upload.artifactId, query: context.prompt, geometry: context.input.parameters?.geometry === 'point' ? VisionLocateGeometry.POINT : VisionLocateGeometry.BOX } } },
|
|
46
|
+
requestId: '', idempotencyKey: '', labels: {}, extensions: [],
|
|
47
|
+
},
|
|
48
|
+
signal: context.input.signal, abortReason: context.host.abortReason, onJobUpdate: context.input.onJobUpdate,
|
|
49
|
+
});
|
|
50
|
+
if (!result.visionLocate) throw new Error(t('VisionLocate.resultMissing'));
|
|
51
|
+
const locate = localVisionResult(result.visionLocate);
|
|
52
|
+
return {
|
|
53
|
+
ok: true as const, capabilityId: context.capability.id, capabilityLabel: context.capability.label,
|
|
54
|
+
message: t(locate.locations.length ? 'VisionLocate.found' : 'VisionLocate.noMatch', { count: locate.locations.length }),
|
|
55
|
+
output: { kind: 'vision-locate' as const, jobId: result.job.jobId, result: locate, imagePreviewUrl: image.dataUrl },
|
|
56
|
+
trace: { traceId: result.traceId },
|
|
57
|
+
};
|
|
58
|
+
}
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
.workbench__body {
|
|
45
45
|
display: grid;
|
|
46
46
|
grid-template-columns: 72px minmax(0, 1fr);
|
|
47
|
+
grid-template-rows: minmax(0, 1fr);
|
|
47
48
|
height: 100%;
|
|
48
49
|
min-height: 0;
|
|
49
50
|
}
|
|
@@ -71,6 +72,10 @@
|
|
|
71
72
|
justify-items: center;
|
|
72
73
|
width: 72px;
|
|
73
74
|
min-width: 72px;
|
|
75
|
+
min-height: 0;
|
|
76
|
+
overflow-y: auto;
|
|
77
|
+
overflow-x: hidden;
|
|
78
|
+
scrollbar-width: thin;
|
|
74
79
|
padding: 24px 14px 18px;
|
|
75
80
|
}
|
|
76
81
|
|
|
@@ -153,6 +153,14 @@
|
|
|
153
153
|
"path": "src/ai-studio-core/section-ai-testing-surface.tsx",
|
|
154
154
|
"class": "app-owned product code"
|
|
155
155
|
},
|
|
156
|
+
{
|
|
157
|
+
"path": "src/ai-studio-core/section-ai-testing-vision-input.tsx",
|
|
158
|
+
"class": "app-owned product code"
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"path": "src/ai-studio-core/section-ai-testing-vision-result.tsx",
|
|
162
|
+
"class": "app-owned product code"
|
|
163
|
+
},
|
|
156
164
|
{
|
|
157
165
|
"path": "src/ai-studio-core/section-ai-testing.tsx",
|
|
158
166
|
"class": "app-owned product code"
|
|
@@ -273,6 +281,14 @@
|
|
|
273
281
|
"path": "src/studio-modules/studio-media/runtime.ts",
|
|
274
282
|
"class": "app-owned product code"
|
|
275
283
|
},
|
|
284
|
+
{
|
|
285
|
+
"path": "src/studio-modules/studio-media/vision-parameters.tsx",
|
|
286
|
+
"class": "app-owned product code"
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"path": "src/studio-modules/studio-media/vision-runtime.ts",
|
|
290
|
+
"class": "app-owned product code"
|
|
291
|
+
},
|
|
276
292
|
{
|
|
277
293
|
"path": "src/studio-modules/studio-voice/descriptors.ts",
|
|
278
294
|
"class": "app-owned product code"
|