@nimiplatform/app-tools 0.1.3 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +198 -6
  2. package/README.md +83 -27
  3. package/bin/nimi-app.mjs +328 -45
  4. package/lib/app-access-declaration.mjs +49 -0
  5. package/lib/app-doctor-update.mjs +411 -149
  6. package/lib/app-pack.mjs +401 -0
  7. package/lib/app-project-lifecycle.mjs +1141 -0
  8. package/lib/app-scaffold-capabilities.mjs +769 -0
  9. package/lib/app-scaffold-default-source.mjs +21 -0
  10. package/lib/app-scaffold-profiles.mjs +1093 -0
  11. package/lib/app-scaffold.mjs +1266 -813
  12. package/lib/index.mjs +194 -42
  13. package/lib/simulator-conformance-ast.mjs +498 -0
  14. package/lib/simulator-conformance-css.mjs +116 -0
  15. package/lib/simulator-conformance-graph.mjs +757 -0
  16. package/lib/simulator-conformance.d.mts +14 -0
  17. package/lib/simulator-conformance.mjs +203 -0
  18. package/lib/simulator-css-profile.d.mts +27 -0
  19. package/lib/simulator-css-profile.mjs +531 -0
  20. package/lib/simulator-kit-export-resolution.mjs +70 -0
  21. package/lib/simulator-manifest.mjs +334 -0
  22. package/package.json +66 -3
  23. package/scripts/dev-shell.mjs +465 -0
  24. package/scripts/sync-app-source.mjs +300 -0
  25. package/scripts/sync-scaffold-versions.mjs +91 -0
  26. package/templates/app-source/LICENSE +21 -0
  27. package/templates/app-source/src/ai-studio-core/ai-config.ts +100 -0
  28. package/templates/app-source/src/ai-studio-core/ai-studio-core.css +338 -0
  29. package/templates/app-source/src/ai-studio-core/contexts.tsx +61 -0
  30. package/templates/app-source/src/ai-studio-core/history-policy.ts +447 -0
  31. package/templates/app-source/src/ai-studio-core/history.ts +824 -0
  32. package/templates/app-source/src/ai-studio-core/host-context.tsx +79 -0
  33. package/templates/app-source/src/ai-studio-core/index.ts +214 -0
  34. package/templates/app-source/src/ai-studio-core/messages/en.json +310 -0
  35. package/templates/app-source/src/ai-studio-core/messages/index.ts +47 -0
  36. package/templates/app-source/src/ai-studio-core/messages/zh.json +310 -0
  37. package/templates/app-source/src/ai-studio-core/module-registration.ts +109 -0
  38. package/templates/app-source/src/ai-studio-core/non-success-presentation.ts +65 -0
  39. package/templates/app-source/src/ai-studio-core/parameter-fields.tsx +247 -0
  40. package/templates/app-source/src/ai-studio-core/parameters.ts +110 -0
  41. package/templates/app-source/src/ai-studio-core/prompt-drafts.ts +69 -0
  42. package/templates/app-source/src/ai-studio-core/run-target.ts +123 -0
  43. package/templates/app-source/src/ai-studio-core/runtime-dispatcher.ts +35 -0
  44. package/templates/app-source/src/ai-studio-core/runtime-types.ts +86 -0
  45. package/templates/app-source/src/ai-studio-core/runtime.ts +306 -0
  46. package/templates/app-source/src/ai-studio-core/section-ai-testing-admission.ts +38 -0
  47. package/templates/app-source/src/ai-studio-core/section-ai-testing-ai-config.tsx +30 -0
  48. package/templates/app-source/src/ai-studio-core/section-ai-testing-artifact-preview.ts +40 -0
  49. package/templates/app-source/src/ai-studio-core/section-ai-testing-composer.tsx +257 -0
  50. package/templates/app-source/src/ai-studio-core/section-ai-testing-history.tsx +676 -0
  51. package/templates/app-source/src/ai-studio-core/section-ai-testing-input.ts +19 -0
  52. package/templates/app-source/src/ai-studio-core/section-ai-testing-output.tsx +291 -0
  53. package/templates/app-source/src/ai-studio-core/section-ai-testing-result.tsx +413 -0
  54. package/templates/app-source/src/ai-studio-core/section-ai-testing-run.ts +174 -0
  55. package/templates/app-source/src/ai-studio-core/section-ai-testing-studio-result.tsx +449 -0
  56. package/templates/app-source/src/ai-studio-core/section-ai-testing-surface.tsx +45 -0
  57. package/templates/app-source/src/ai-studio-core/section-ai-testing.tsx +494 -0
  58. package/templates/app-source/src/ai-studio-core/studio-directives.ts +33 -0
  59. package/templates/app-source/src/ai-studio-core/workspace.tsx +381 -0
  60. package/templates/app-source/src/product-modules/agent-center/index.tsx +27 -0
  61. package/templates/app-source/src/product-modules/agent-conversation/index.tsx +19 -0
  62. package/templates/app-source/src/product-modules/agent-realtime/index.tsx +29 -0
  63. package/templates/app-source/src/product-modules/kit-recipes/gallery.tsx +142 -0
  64. package/templates/app-source/src/product-modules/kit-recipes/index.tsx +19 -0
  65. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-data-recipes.tsx +336 -0
  66. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-demos.tsx +165 -0
  67. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-recipes.tsx +682 -0
  68. package/templates/app-source/src/product-modules/kit-recipes/kit-component-gallery-surface.tsx +341 -0
  69. package/templates/app-source/src/studio-modules/studio-create/descriptors.ts +26 -0
  70. package/templates/app-source/src/studio-modules/studio-create/index.ts +14 -0
  71. package/templates/app-source/src/studio-modules/studio-create/messages/en.json +67 -0
  72. package/templates/app-source/src/studio-modules/studio-create/messages/index.ts +5 -0
  73. package/templates/app-source/src/studio-modules/studio-create/messages/zh.json +67 -0
  74. package/templates/app-source/src/studio-modules/studio-create/parameter-panel.tsx +153 -0
  75. package/templates/app-source/src/studio-modules/studio-create/parameters.ts +70 -0
  76. package/templates/app-source/src/studio-modules/studio-create/registration.ts +46 -0
  77. package/templates/app-source/src/studio-modules/studio-create/runtime.ts +339 -0
  78. package/templates/app-source/src/studio-modules/studio-media/descriptors.ts +22 -0
  79. package/templates/app-source/src/studio-modules/studio-media/index.ts +12 -0
  80. package/templates/app-source/src/studio-modules/studio-media/messages/en.json +82 -0
  81. package/templates/app-source/src/studio-modules/studio-media/messages/index.ts +5 -0
  82. package/templates/app-source/src/studio-modules/studio-media/messages/zh.json +82 -0
  83. package/templates/app-source/src/studio-modules/studio-media/parameter-panel.tsx +283 -0
  84. package/templates/app-source/src/studio-modules/studio-media/parameters.ts +94 -0
  85. package/templates/app-source/src/studio-modules/studio-media/registration.ts +44 -0
  86. package/templates/app-source/src/studio-modules/studio-media/runtime.ts +113 -0
  87. package/templates/app-source/src/studio-modules/studio-voice/descriptors.ts +28 -0
  88. package/templates/app-source/src/studio-modules/studio-voice/index.ts +16 -0
  89. package/templates/app-source/src/studio-modules/studio-voice/messages/en.json +99 -0
  90. package/templates/app-source/src/studio-modules/studio-voice/messages/index.ts +5 -0
  91. package/templates/app-source/src/studio-modules/studio-voice/messages/zh.json +99 -0
  92. package/templates/app-source/src/studio-modules/studio-voice/parameter-panel.tsx +284 -0
  93. package/templates/app-source/src/studio-modules/studio-voice/parameters.ts +116 -0
  94. package/templates/app-source/src/studio-modules/studio-voice/registration.ts +59 -0
  95. package/templates/app-source/src/studio-modules/studio-voice/runtime.ts +347 -0
  96. package/templates/app-source/src/workbench-core/empty-state.tsx +31 -0
  97. package/templates/app-source/src/workbench-core/index.ts +17 -0
  98. package/templates/app-source/src/workbench-core/runtime-gate.tsx +131 -0
  99. package/templates/app-source/src/workbench-core/workbench-core.css +255 -0
  100. package/templates/app-source/src/workbench-core/workbench-core.tsx +140 -0
  101. package/templates/app-source.manifest.json +333 -0
  102. package/templates/default-starter/AGENTS.md +33 -0
  103. package/templates/default-starter/LICENSE +21 -0
  104. package/templates/default-starter/README.md +41 -0
  105. package/templates/default-starter/SECURITY.md +5 -0
  106. package/templates/default-starter/index.html +12 -0
  107. package/templates/default-starter/scripts/validate.mjs +26 -0
  108. package/templates/default-starter/src/shell/App.tsx +27 -0
  109. package/templates/default-starter/src/shell/auth/app-identity.ts +3 -0
  110. package/templates/default-starter/src/shell/auth/local-app-client.ts +18 -0
  111. package/templates/default-starter/src/shell/auth/runtime-platform.ts +110 -0
  112. package/templates/default-starter/src/shell/authenticated-shell.tsx +20 -0
  113. package/templates/default-starter/src/shell/workbench-target-adapter.ts +40 -0
  114. package/templates/default-starter/src/styles.css +26 -0
  115. package/templates/default-starter/src-tauri/Cargo.toml +17 -0
  116. package/templates/default-starter/src-tauri/build.rs +5 -0
  117. package/templates/default-starter/src-tauri/capabilities/default.json +7 -0
  118. package/templates/default-starter/src-tauri/tauri.conf.json +26 -0
  119. package/templates/default-starter/tsconfig.json +18 -0
  120. package/templates/default-starter.manifest.json +99 -0
@@ -0,0 +1,70 @@
1
+ import {
2
+ CLOUD_ONLY_STUDIO_PARAMETER,
3
+ LOCAL_AND_CLOUD_STUDIO_PARAMETER,
4
+ defineStudioParameters,
5
+ } from '../../ai-studio-core/parameters.js';
6
+
7
+ export type StudioTextCandidateParameters = {
8
+ temperature?: number;
9
+ topP?: number;
10
+ maxTokens?: number;
11
+ };
12
+
13
+ export type StudioTextTurnParameters = StudioTextCandidateParameters & {
14
+ topK?: number;
15
+ presencePenalty?: number;
16
+ frequencyPenalty?: number;
17
+ stop?: string[];
18
+ seed?: number;
19
+ };
20
+
21
+ export type StudioEmbeddingParameters = {
22
+ inputs?: string[];
23
+ };
24
+
25
+ const TEXT_CANDIDATE_ROUTE_MATRIX = {
26
+ temperature: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
27
+ topP: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
28
+ maxTokens: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
29
+ } as const;
30
+
31
+ const TEXT_TURN_ROUTE_MATRIX = {
32
+ ...TEXT_CANDIDATE_ROUTE_MATRIX,
33
+ topK: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
34
+ presencePenalty: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
35
+ frequencyPenalty: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
36
+ stop: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
37
+ seed: LOCAL_AND_CLOUD_STUDIO_PARAMETER,
38
+ } as const;
39
+
40
+ const studioTextGenerateParameterContract = defineStudioParameters<StudioTextCandidateParameters>({
41
+ initial: () => ({}),
42
+ routeMatrix: TEXT_CANDIDATE_ROUTE_MATRIX,
43
+ });
44
+
45
+ export const studioTextGenerateParameters = Object.freeze({
46
+ ...studioTextGenerateParameterContract,
47
+ project: (source: Parameters<typeof studioTextGenerateParameterContract.project>[0], parameters: Parameters<typeof studioTextGenerateParameterContract.project>[1]) => (
48
+ studioTextGenerateParameterContract.project(
49
+ source,
50
+ Object.fromEntries(
51
+ Object.entries(parameters).filter(([field]) => Object.hasOwn(TEXT_CANDIDATE_ROUTE_MATRIX, field)),
52
+ ),
53
+ )
54
+ ),
55
+ });
56
+
57
+ export const studioChatStreamParameters = defineStudioParameters<StudioTextTurnParameters>({
58
+ initial: () => ({}),
59
+ routeMatrix: TEXT_TURN_ROUTE_MATRIX,
60
+ });
61
+
62
+ export const studioTextEmbedParameters = defineStudioParameters<StudioEmbeddingParameters>({
63
+ initial: () => ({}),
64
+ routeMatrix: { inputs: CLOUD_ONLY_STUDIO_PARAMETER },
65
+ hasAlternativeInput: (parameters) => nonEmptyEmbeddingInputs(parameters).length > 0,
66
+ });
67
+
68
+ export function nonEmptyEmbeddingInputs(parameters: StudioEmbeddingParameters | undefined): string[] {
69
+ return (parameters?.inputs ?? []).map((value) => value.trim()).filter(Boolean);
70
+ }
@@ -0,0 +1,46 @@
1
+ import { MessageSquareText, Sparkles, TextCursorInput } from 'lucide-react';
2
+ import type { AIStudioModuleRegistration } from '../../ai-studio-core/module-registration.js';
3
+ import { studioCreateDescriptors, type StudioCreateCapabilityId } from './descriptors.js';
4
+ import { studioChatStreamParameters, studioTextEmbedParameters, studioTextGenerateParameters } from './parameters.js';
5
+ import { StudioCreateParameterPanel } from './parameter-panel.js';
6
+
7
+ export const studioCreateModule = Object.freeze({
8
+ id: 'studio-create',
9
+ navigationLabel: 'Create',
10
+ order: 10,
11
+ capabilities: [
12
+ {
13
+ descriptor: studioCreateDescriptors[0],
14
+ icon: Sparkles,
15
+ profile: {
16
+ studioTag: 'Text', inputTitleKey: 'Studio.profiles.textGenerate.inputTitle', inputPlaceholderKey: 'Studio.profiles.textGenerate.inputPlaceholder', inputKind: 'prompt', supportsAttachments: false, controls: ['tone', 'length'], primaryLabelKey: 'Studio.profiles.textGenerate.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.textGenerate.primaryRunningLabel', resultTitle: 'Generated result', emptyTitleKey: 'Studio.profiles.textGenerate.emptyTitle', emptyHintKey: 'Studio.profiles.textGenerate.emptyHint', resultKind: 'text', footnoteKey: 'Studio.profiles.textGenerate.footnote',
17
+ },
18
+ preset: { id: 'acceptance-note', label: 'Acceptance note', prompt: 'Write a concise acceptance note for a Runtime-backed Nimi App that can generate helpful content.' },
19
+ runtimeMethod: 'sdk.localApp.ai.text.generateCandidate',
20
+ parameters: studioTextGenerateParameters,
21
+ parameterPanel: StudioCreateParameterPanel,
22
+ },
23
+ {
24
+ descriptor: studioCreateDescriptors[1],
25
+ icon: MessageSquareText,
26
+ profile: {
27
+ studioTag: 'Chat', inputTitleKey: 'Studio.profiles.chatStream.inputTitle', inputPlaceholderKey: 'Studio.profiles.chatStream.inputPlaceholder', inputKind: 'prompt', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.chatStream.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.chatStream.primaryRunningLabel', resultTitle: 'Streamed reply', emptyTitleKey: 'Studio.profiles.chatStream.emptyTitle', emptyHintKey: 'Studio.profiles.chatStream.emptyHint', resultKind: 'text', footnoteKey: 'Studio.profiles.chatStream.footnote',
28
+ },
29
+ preset: { id: 'stream-sample', label: 'Stream sample', prompt: 'Continue this conversation through the text.generate stream contract.' },
30
+ runtimeMethod: 'runtime.ai.streamScenario:text_generate',
31
+ parameters: studioChatStreamParameters,
32
+ parameterPanel: StudioCreateParameterPanel,
33
+ },
34
+ {
35
+ descriptor: studioCreateDescriptors[2],
36
+ icon: TextCursorInput,
37
+ profile: {
38
+ studioTag: 'Embeddings', inputTitleKey: 'Studio.profiles.textEmbed.inputTitle', inputPlaceholderKey: 'Studio.profiles.textEmbed.inputPlaceholder', inputKind: 'prompt', supportsAttachments: false, controls: [], primaryLabelKey: 'Studio.profiles.textEmbed.primaryLabel', primaryRunningLabelKey: 'Studio.profiles.textEmbed.primaryRunningLabel', resultTitle: 'Embedding result', emptyTitleKey: 'Studio.profiles.textEmbed.emptyTitle', emptyHintKey: 'Studio.profiles.textEmbed.emptyHint', resultKind: 'embedding', footnoteKey: 'Studio.profiles.textEmbed.footnote',
39
+ },
40
+ preset: { id: 'embedding-sample', label: 'Embedding sample', prompt: 'Identity-neutral App embedding sample.' },
41
+ runtimeMethod: 'runtime.ai.executeScenario:text_embed',
42
+ parameters: studioTextEmbedParameters,
43
+ parameterPanel: StudioCreateParameterPanel,
44
+ },
45
+ ],
46
+ } as const satisfies AIStudioModuleRegistration<'studio-create', StudioCreateCapabilityId>);
@@ -0,0 +1,339 @@
1
+ import type { RuntimeAIConsumeRuntime } from '@nimiplatform/kit/features/generation/runtime';
2
+ import type { NimiRuntimeAIScenarioClient } from '@nimiplatform/sdk/ai';
3
+ import type { NimiLocalAppTextTurnEvent } from '@nimiplatform/sdk/app';
4
+ import { ExecutionMode, FinishReason, ScenarioType } from '@nimiplatform/sdk/runtime/generated';
5
+ import type { StudioCapabilityRuntimeHandlers } from '../../ai-studio-core/runtime-dispatcher.js';
6
+ import {
7
+ projectStudioRunnerNonSuccess,
8
+ studioAbortError,
9
+ type StudioCapabilityRuntimeContext,
10
+ } from '../../ai-studio-core/runtime.js';
11
+ import {
12
+ nonEmptyEmbeddingInputs,
13
+ type StudioEmbeddingParameters,
14
+ type StudioTextCandidateParameters,
15
+ type StudioTextTurnParameters,
16
+ } from './parameters.js';
17
+
18
+ // @nimi-authority: rule.nimi.platform.app-ecosystem.p-scaf-019c
19
+
20
+ type RuntimeStreamEvent = ReturnType<NimiRuntimeAIScenarioClient['streamScenario']> extends AsyncIterable<infer TEvent>
21
+ ? TEvent
22
+ : never;
23
+
24
+ export const studioCreateRuntimeHandlers: StudioCapabilityRuntimeHandlers = Object.freeze({
25
+ 'text.generate': runTextGenerate,
26
+ 'chat.stream': runChatStream,
27
+ 'text.embed': runTextEmbed,
28
+ });
29
+
30
+ async function runTextGenerate(context: StudioCapabilityRuntimeContext) {
31
+ if (!context.prompt) return inputRequired(context);
32
+ const parameters = context.input.parameters as StudioTextCandidateParameters | undefined;
33
+ const result = await context.host.client.ai.text.generateCandidate({
34
+ messages: [{ role: 'user', text: context.prompt }],
35
+ ...textCandidateParameters(parameters),
36
+ });
37
+ return {
38
+ ok: true as const,
39
+ capabilityId: context.capability.id,
40
+ capabilityLabel: context.capability.label,
41
+ message: 'Runtime completed the protected foreground text candidate request.',
42
+ output: {
43
+ kind: 'text' as const,
44
+ text: result.text,
45
+ finishReason: result.finishReason,
46
+ streamed: false,
47
+ },
48
+ trace: result.traceId ? { traceId: result.traceId } : undefined,
49
+ };
50
+ }
51
+
52
+ async function runChatStream(context: StudioCapabilityRuntimeContext) {
53
+ if (!context.prompt) return inputRequired(context);
54
+ if (context.input.attachments?.length) {
55
+ return context.host.nonSuccess(
56
+ context.capability,
57
+ 'input-invalid',
58
+ 'The protected Local App text stream currently accepts text messages only.',
59
+ );
60
+ }
61
+ const result = await context.host.runners.aiConsume({
62
+ runtime: createLocalAppTextScenarioRuntime(context),
63
+ appId: context.host.appId,
64
+ capabilityId: 'chat.stream',
65
+ prompt: context.prompt,
66
+ ...(context.input.directive?.trim() ? { directive: context.input.directive.trim() } : {}),
67
+ ...(context.input.parameters ? {
68
+ parameters: textTurnParameters(
69
+ context.input.parameters as StudioTextTurnParameters,
70
+ ),
71
+ } : {}),
72
+ scenarioId: context.scenarioId,
73
+ surfaceId: context.host.surfaceId,
74
+ ...(context.input.onPartial ? { onPartial: context.input.onPartial } : {}),
75
+ ...(context.input.signal ? { signal: context.input.signal } : {}),
76
+ });
77
+ if (result.ok === false) return projectStudioRunnerNonSuccess(context, result);
78
+ if (result.output.kind !== 'text') {
79
+ return context.host.nonSuccess(
80
+ context.capability,
81
+ 'runtime-call-failed',
82
+ 'Runtime stream returned a non-text output.',
83
+ );
84
+ }
85
+ return {
86
+ ok: true as const,
87
+ capabilityId: context.capability.id,
88
+ capabilityLabel: context.capability.label,
89
+ message: result.message,
90
+ output: { ...result.output },
91
+ ...(result.trace?.traceId ? { trace: { traceId: result.trace.traceId } } : {}),
92
+ };
93
+ }
94
+
95
+ async function runTextEmbed(context: StudioCapabilityRuntimeContext) {
96
+ const embeddingInputs = nonEmptyEmbeddingInputs(
97
+ context.input.parameters as StudioEmbeddingParameters | undefined,
98
+ );
99
+ if (!context.prompt && embeddingInputs.length === 0) return inputRequired(context);
100
+ const result = await context.host.client.ai.scenario.execute({
101
+ type: 'text-embed',
102
+ inputs: embeddingInputs.length > 0 ? embeddingInputs : [context.prompt],
103
+ });
104
+ if (result.output.type !== 'text-embed') {
105
+ return context.host.nonSuccess(
106
+ context.capability,
107
+ 'runtime-call-failed',
108
+ 'Runtime embedding returned an unexpected output type.',
109
+ );
110
+ }
111
+ const first = result.output.vectors[0] ?? [];
112
+ return {
113
+ ok: true as const,
114
+ capabilityId: context.capability.id,
115
+ capabilityLabel: context.capability.label,
116
+ message: `Runtime completed text.embed with ${result.output.vectors.length} vector(s).`,
117
+ output: {
118
+ kind: 'embedding' as const,
119
+ vectorCount: result.output.vectors.length,
120
+ dimensions: first.length,
121
+ sample: [...first.slice(0, 8)],
122
+ },
123
+ ...(result.traceId ? { trace: { traceId: result.traceId } } : {}),
124
+ };
125
+ }
126
+
127
+ function inputRequired(context: StudioCapabilityRuntimeContext) {
128
+ return context.host.nonSuccess(
129
+ context.capability,
130
+ 'input-invalid',
131
+ `${context.capability.label} requires non-empty input.`,
132
+ );
133
+ }
134
+
135
+ function createLocalAppTextScenarioRuntime(
136
+ context: StudioCapabilityRuntimeContext,
137
+ ): RuntimeAIConsumeRuntime {
138
+ const ai: NimiRuntimeAIScenarioClient = {
139
+ async executeScenario() {
140
+ throw Object.assign(new Error('Local App text execution is stream-only on this adapter.'), {
141
+ reasonCode: 'SDK_RUNTIME_METHOD_UNAVAILABLE',
142
+ });
143
+ },
144
+ streamScenario(request, options) {
145
+ return streamLocalAppTextEvents(context, request, options?.signal);
146
+ },
147
+ };
148
+ return { ai };
149
+ }
150
+
151
+ async function* streamLocalAppTextEvents(
152
+ context: StudioCapabilityRuntimeContext,
153
+ request: Parameters<NimiRuntimeAIScenarioClient['streamScenario']>[0],
154
+ signal?: AbortSignal,
155
+ ): AsyncIterable<RuntimeStreamEvent> {
156
+ const spec = request.spec?.spec;
157
+ if (
158
+ request.scenarioType !== ScenarioType.TEXT_GENERATE
159
+ || request.executionMode !== ExecutionMode.STREAM
160
+ || request.extensions.length > 0
161
+ || spec?.oneofKind !== 'textGenerate'
162
+ ) {
163
+ throw Object.assign(new Error('Local App text stream requires the closed textGenerate Scenario shape.'), {
164
+ reasonCode: 'SDK_AI_INPUT_INVALID',
165
+ });
166
+ }
167
+ const textSpec = spec.textGenerate;
168
+ if (
169
+ textSpec.tools.length > 0
170
+ || textSpec.toolChoiceName
171
+ || textSpec.input.some((message) => message.role !== 'user')
172
+ ) {
173
+ throw Object.assign(new Error('Local App text stream does not admit tools or advanced generation controls.'), {
174
+ reasonCode: 'SDK_AI_INPUT_INVALID',
175
+ });
176
+ }
177
+ const messages = [
178
+ ...(textSpec.systemPrompt ? [{ role: 'system' as const, text: textSpec.systemPrompt }] : []),
179
+ ...textSpec.input.map((message) => ({ role: 'user' as const, text: message.content })),
180
+ ];
181
+ const seed = localTextSeed(textSpec.seed);
182
+ const subscription = await context.host.client.ai.text.streamTurn({
183
+ messages,
184
+ ...(textSpec.temperature !== undefined ? { temperature: textSpec.temperature } : {}),
185
+ ...(textSpec.topP !== undefined ? { topP: textSpec.topP } : {}),
186
+ ...(textSpec.maxTokens !== undefined ? { maxTokens: textSpec.maxTokens } : {}),
187
+ ...(textSpec.topK !== undefined ? { topK: textSpec.topK } : {}),
188
+ ...(textSpec.presencePenalty !== undefined ? { presencePenalty: textSpec.presencePenalty } : {}),
189
+ ...(textSpec.frequencyPenalty !== undefined ? { frequencyPenalty: textSpec.frequencyPenalty } : {}),
190
+ ...(textSpec.stop.length > 0 ? { stop: [...textSpec.stop] } : {}),
191
+ ...(seed !== undefined ? { seed } : {}),
192
+ });
193
+ let canceled = false;
194
+ const cancel = () => {
195
+ if (canceled) return;
196
+ canceled = true;
197
+ void subscription.cancel().catch(() => undefined);
198
+ };
199
+ signal?.addEventListener('abort', cancel, { once: true });
200
+ try {
201
+ if (signal?.aborted) throw studioAbortError();
202
+ let started = false;
203
+ let textItemOpened = false;
204
+ for await (const event of subscription) {
205
+ if (!started) {
206
+ started = true;
207
+ yield {
208
+ eventType: 1,
209
+ sequence: event.sequence,
210
+ traceId: event.traceId,
211
+ payload: {
212
+ oneofKind: 'started',
213
+ started: { modelResolved: '', routeDecision: 0, voiceOutputMode: 0 },
214
+ },
215
+ };
216
+ }
217
+ if (event.type === 'delta') {
218
+ textItemOpened = true;
219
+ yield localTextDeltaEvent(event);
220
+ continue;
221
+ }
222
+ if (event.type === 'failed') {
223
+ throw Object.assign(new Error(event.actionHint || 'Runtime Scenario stream failed.'), {
224
+ reasonCode: event.reasonCode,
225
+ actionHint: event.actionHint,
226
+ });
227
+ }
228
+ if (textItemOpened) {
229
+ yield localTextCompletionDeltaEvent(event);
230
+ }
231
+ yield {
232
+ eventType: 6,
233
+ sequence: event.sequence,
234
+ traceId: event.traceId,
235
+ payload: {
236
+ oneofKind: 'completed',
237
+ completed: {
238
+ finishReason: localFinishReason(event.finishReason),
239
+ streamSimulated: false,
240
+ },
241
+ },
242
+ };
243
+ return;
244
+ }
245
+ } finally {
246
+ signal?.removeEventListener('abort', cancel);
247
+ cancel();
248
+ }
249
+ }
250
+
251
+ function localTextSeed(value: string | undefined): number | undefined {
252
+ if (value === undefined) return undefined;
253
+ const seed = Number(value);
254
+ if (!Number.isSafeInteger(seed)) {
255
+ throw Object.assign(new Error('Local App text seed must be a safe integer.'), {
256
+ reasonCode: 'SDK_AI_INPUT_INVALID',
257
+ });
258
+ }
259
+ return seed;
260
+ }
261
+
262
+ function localTextDeltaEvent(
263
+ event: Extract<NimiLocalAppTextTurnEvent, { type: 'delta' }>,
264
+ ): RuntimeStreamEvent {
265
+ return {
266
+ eventType: 2,
267
+ sequence: event.sequence,
268
+ traceId: event.traceId,
269
+ payload: {
270
+ oneofKind: 'delta',
271
+ delta: {
272
+ delta: {
273
+ oneofKind: 'textOutputItem',
274
+ textOutputItem: {
275
+ itemIndex: 0,
276
+ delta: { oneofKind: 'text', text: { text: event.text } },
277
+ itemCompleted: false,
278
+ },
279
+ },
280
+ },
281
+ },
282
+ };
283
+ }
284
+
285
+ function localTextCompletionDeltaEvent(
286
+ event: Extract<NimiLocalAppTextTurnEvent, { type: 'completed' }>,
287
+ ): RuntimeStreamEvent {
288
+ return {
289
+ eventType: 2,
290
+ sequence: event.sequence,
291
+ traceId: event.traceId,
292
+ payload: {
293
+ oneofKind: 'delta',
294
+ delta: {
295
+ delta: {
296
+ oneofKind: 'textOutputItem',
297
+ textOutputItem: {
298
+ itemIndex: 0,
299
+ delta: { oneofKind: undefined },
300
+ itemCompleted: true,
301
+ },
302
+ },
303
+ },
304
+ },
305
+ };
306
+ }
307
+
308
+ function localFinishReason(
309
+ reason: Extract<NimiLocalAppTextTurnEvent, { type: 'completed' }>['finishReason'],
310
+ ): FinishReason {
311
+ if (reason === 'length') return FinishReason.LENGTH;
312
+ if (reason === 'content-filter') return FinishReason.CONTENT_FILTER;
313
+ return FinishReason.STOP;
314
+ }
315
+
316
+ function textCandidateParameters(
317
+ parameters: StudioTextCandidateParameters | undefined,
318
+ ): StudioTextCandidateParameters {
319
+ if (!parameters) return {};
320
+ return {
321
+ ...(parameters.temperature !== undefined ? { temperature: parameters.temperature } : {}),
322
+ ...(parameters.topP !== undefined ? { topP: parameters.topP } : {}),
323
+ ...(parameters.maxTokens !== undefined ? { maxTokens: parameters.maxTokens } : {}),
324
+ };
325
+ }
326
+
327
+ function textTurnParameters(
328
+ parameters: StudioTextTurnParameters | undefined,
329
+ ): StudioTextTurnParameters {
330
+ if (!parameters) return {};
331
+ return {
332
+ ...textCandidateParameters(parameters),
333
+ ...(parameters.topK !== undefined ? { topK: parameters.topK } : {}),
334
+ ...(parameters.presencePenalty !== undefined ? { presencePenalty: parameters.presencePenalty } : {}),
335
+ ...(parameters.frequencyPenalty !== undefined ? { frequencyPenalty: parameters.frequencyPenalty } : {}),
336
+ ...(parameters.stop !== undefined ? { stop: [...parameters.stop] } : {}),
337
+ ...(parameters.seed !== undefined ? { seed: parameters.seed } : {}),
338
+ };
339
+ }
@@ -0,0 +1,22 @@
1
+ export type StudioMediaCapabilityId = 'image.generate' | 'video.generate' | 'music.generate';
2
+
3
+ export const studioMediaDescriptors = Object.freeze([
4
+ {
5
+ id: 'image.generate', label: 'Image Generate', labelKey: 'Capabilities.imageGenerate.label', group: 'media',
6
+ section: 'image',
7
+ summary: 'Prompt → image.generate Scenario Job → typed artifact preview result.', summaryKey: 'Capabilities.imageGenerate.summary',
8
+ surface: 'kit.runRuntimeImageGenerate → sdk.localApp.ai.scenarioJobs + artifacts', execution: 'runtime-sdk', capabilityContract: 'image.generate',
9
+ },
10
+ {
11
+ id: 'video.generate', label: 'Video Generate', labelKey: 'Capabilities.videoGenerate.label', group: 'media',
12
+ section: 'video',
13
+ summary: 'Prompt → video.generate Scenario Job → typed artifact preview result.', summaryKey: 'Capabilities.videoGenerate.summary',
14
+ surface: 'kit.runRuntimeVideoGenerate → sdk.localApp.ai.scenarioJobs + artifacts', execution: 'runtime-sdk', capabilityContract: 'video.generate',
15
+ },
16
+ {
17
+ id: 'music.generate', label: 'Music Generate', labelKey: 'Capabilities.musicGenerate.label', group: 'media',
18
+ section: 'music',
19
+ summary: 'Prompt + lyrics → protected music.generate Scenario Job → adopted WAV.', summaryKey: 'Capabilities.musicGenerate.summary',
20
+ surface: 'kit.runRuntimeMusicGenerate → sdk.localApp.ai.scenarioJobs + artifact adoption', execution: 'runtime-sdk', capabilityContract: 'music.generate',
21
+ },
22
+ ] as const);
@@ -0,0 +1,12 @@
1
+ export { studioMediaDescriptors, type StudioMediaCapabilityId } from './descriptors.js';
2
+ export { studioMediaMessageBundles } from './messages/index.js';
3
+ export { StudioMediaParameterPanel } from './parameter-panel.js';
4
+ export {
5
+ MAX_STUDIO_ARTIFACT_UPLOAD_BYTES,
6
+ studioImageGenerateParameters,
7
+ studioVideoGenerateParameters,
8
+ type StudioImageGenerationParameters,
9
+ type StudioVideoGenerationParameters,
10
+ } from './parameters.js';
11
+ export { studioMediaModule } from './registration.js';
12
+ export { studioMediaRuntimeHandlers } from './runtime.js';
@@ -0,0 +1,82 @@
1
+ {
2
+ "Capabilities": {
3
+ "imageGenerate": {
4
+ "label": "Image Generate",
5
+ "summary": "Prompt → image.generate Scenario Job → typed artifact preview result."
6
+ },
7
+ "videoGenerate": {
8
+ "label": "Video Generate",
9
+ "summary": "Prompt → video.generate Scenario Job → typed artifact preview result."
10
+ },
11
+ "musicGenerate": {
12
+ "label": "Music Generate",
13
+ "summary": "Prompt and lyrics → protected music.generate Scenario Job → adopted WAV."
14
+ }
15
+ },
16
+ "Studio": {
17
+ "profiles": {
18
+ "imageGenerate": {
19
+ "inputTitle": "Test image generation",
20
+ "inputPlaceholder": "Describe the image you want the runtime to render…",
21
+ "primaryLabel": "Generate image",
22
+ "primaryRunningLabel": "Generating…",
23
+ "emptyTitle": "Waiting for render",
24
+ "emptyHint": "The generated image will appear here once the job returns.",
25
+ "footnote": "The runtime queues a render job and returns typed artifacts."
26
+ },
27
+ "videoGenerate": {
28
+ "inputTitle": "Test video generation",
29
+ "inputPlaceholder": "Describe the short clip you want to generate…",
30
+ "primaryLabel": "Generate video",
31
+ "primaryRunningLabel": "Generating…",
32
+ "emptyTitle": "Waiting for render",
33
+ "emptyHint": "The generated clip will appear here once the job returns.",
34
+ "footnote": "Text-to-video runs as a runtime job; typed artifacts are returned."
35
+ },
36
+ "musicGenerate": {
37
+ "inputTitle": "Test music generation",
38
+ "inputPlaceholder": "Describe the song, genre, instrumentation, and vocal style…",
39
+ "primaryLabel": "Generate music",
40
+ "primaryRunningLabel": "Generating…",
41
+ "emptyTitle": "Waiting for music",
42
+ "emptyHint": "The Runtime-custodied WAV will be adopted here after the job completes.",
43
+ "footnote": "Progress is unavailable for MiniMax-Music3 Preview; cancel stops the active CLI process."
44
+ }
45
+ },
46
+ "parameters": {
47
+ "videoModeT2v": "Text to video",
48
+ "videoModeReference": "Single reference image",
49
+ "chooseImageFile": "Choose and upload image",
50
+ "clearReferenceImage": "Clear reference image",
51
+ "uploadingImage": "Uploading image…",
52
+ "imageFileTooLarge": "Image files must be non-empty and not exceed 32 MiB.",
53
+ "imageFileMimeUnsupported": "Choose a PNG, JPEG, WebP, or GIF image.",
54
+ "fields": {
55
+ "negativePrompt": "Negative prompt",
56
+ "count": "Count",
57
+ "size": "Size",
58
+ "aspectRatio": "Aspect ratio",
59
+ "quality": "Quality",
60
+ "style": "Style",
61
+ "referenceImage": "Reference image URL",
62
+ "mask": "Mask URL",
63
+ "mode": "Mode",
64
+ "referenceArtifactId": "Reference artifact ID",
65
+ "referenceImageFile": "Local reference image",
66
+ "resolution": "Resolution",
67
+ "frames": "Frames",
68
+ "generateAudio": "Generate audio",
69
+ "ratio": "Ratio",
70
+ "durationSec": "Duration (seconds)",
71
+ "fps": "FPS",
72
+ "cameraFixed": "Fixed camera",
73
+ "watermark": "Watermark",
74
+ "draft": "Draft",
75
+ "returnLastFrame": "Return last frame",
76
+ "serviceTier": "Service tier",
77
+ "executionExpiresAfterSec": "Execution expiry (seconds)",
78
+ "lyrics": "Lyrics"
79
+ }
80
+ }
81
+ }
82
+ }
@@ -0,0 +1,5 @@
1
+ import type { AIStudioMessageBundles } from '../../../ai-studio-core/messages/index.js';
2
+ import en from './en.json' with { type: 'json' };
3
+ import zh from './zh.json' with { type: 'json' };
4
+
5
+ export const studioMediaMessageBundles = Object.freeze({ en, zh }) satisfies AIStudioMessageBundles;
@@ -0,0 +1,82 @@
1
+ {
2
+ "Capabilities": {
3
+ "imageGenerate": {
4
+ "label": "图像生成",
5
+ "summary": "提示词 → image.generate 场景任务 → 类型化产物预览结果。"
6
+ },
7
+ "videoGenerate": {
8
+ "label": "视频生成",
9
+ "summary": "提示词 → video.generate 场景任务 → 类型化产物预览结果。"
10
+ },
11
+ "musicGenerate": {
12
+ "label": "音乐生成",
13
+ "summary": "提示词与歌词 → 受保护 music.generate 场景任务 → 采用 WAV。"
14
+ }
15
+ },
16
+ "Studio": {
17
+ "profiles": {
18
+ "imageGenerate": {
19
+ "inputTitle": "测试图像生成",
20
+ "inputPlaceholder": "描述你希望 Runtime 渲染的图像…",
21
+ "primaryLabel": "生成图像",
22
+ "primaryRunningLabel": "生成中…",
23
+ "emptyTitle": "等待渲染",
24
+ "emptyHint": "任务返回后,生成的图像会显示在这里。",
25
+ "footnote": "Runtime 会排队一个渲染任务并返回类型化产物。"
26
+ },
27
+ "videoGenerate": {
28
+ "inputTitle": "测试视频生成",
29
+ "inputPlaceholder": "描述你想生成的短片…",
30
+ "primaryLabel": "生成视频",
31
+ "primaryRunningLabel": "生成中…",
32
+ "emptyTitle": "等待渲染",
33
+ "emptyHint": "任务返回后,生成的短片会显示在这里。",
34
+ "footnote": "文生视频以 Runtime 任务运行;返回类型化产物。"
35
+ },
36
+ "musicGenerate": {
37
+ "inputTitle": "测试音乐生成",
38
+ "inputPlaceholder": "描述歌曲、流派、配器与演唱风格…",
39
+ "primaryLabel": "生成音乐",
40
+ "primaryRunningLabel": "生成中…",
41
+ "emptyTitle": "等待音乐",
42
+ "emptyHint": "任务完成后会在此采用 Runtime 托管的 WAV。",
43
+ "footnote": "MiniMax-Music3 Preview 暂无可信进度;取消会终止当前 CLI 进程。"
44
+ }
45
+ },
46
+ "parameters": {
47
+ "videoModeT2v": "文生视频",
48
+ "videoModeReference": "单参考图",
49
+ "chooseImageFile": "选择并上传图片",
50
+ "clearReferenceImage": "清除参考图片",
51
+ "uploadingImage": "正在上传图片…",
52
+ "imageFileTooLarge": "图片文件必须非空且不超过 32 MiB。",
53
+ "imageFileMimeUnsupported": "请选择 PNG、JPEG、WebP 或 GIF 图片。",
54
+ "fields": {
55
+ "negativePrompt": "负向提示词",
56
+ "count": "数量",
57
+ "size": "尺寸",
58
+ "aspectRatio": "宽高比",
59
+ "quality": "质量",
60
+ "style": "风格",
61
+ "referenceImage": "参考图 URL",
62
+ "mask": "蒙版 URL",
63
+ "mode": "模式",
64
+ "referenceArtifactId": "参考产物 ID",
65
+ "referenceImageFile": "本地参考图片",
66
+ "resolution": "分辨率",
67
+ "frames": "帧数",
68
+ "generateAudio": "生成音频",
69
+ "ratio": "画面比例",
70
+ "durationSec": "时长(秒)",
71
+ "fps": "帧率",
72
+ "cameraFixed": "固定镜头",
73
+ "watermark": "水印",
74
+ "draft": "草稿模式",
75
+ "returnLastFrame": "返回末帧",
76
+ "serviceTier": "服务等级",
77
+ "executionExpiresAfterSec": "执行过期时间(秒)",
78
+ "lyrics": "歌词"
79
+ }
80
+ }
81
+ }
82
+ }