@nimiplatform/sdk 0.10.0 → 0.12.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/dist/core/ai/index.d.ts +1 -0
- package/dist/core/ai/index.d.ts.map +1 -1
- package/dist/core/ai/index.js +1 -0
- package/dist/core/ai/index.js.map +1 -1
- package/dist/core/ai/local-app-model.d.ts +8 -0
- package/dist/core/ai/local-app-model.d.ts.map +1 -0
- package/dist/core/ai/local-app-model.js +117 -0
- package/dist/core/ai/local-app-model.js.map +1 -0
- package/dist/core/app/index.d.ts +8 -1
- package/dist/core/app/index.d.ts.map +1 -1
- package/dist/core/app/index.js +5 -0
- package/dist/core/app/index.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai.d.ts +52 -7
- package/dist/core/app/local-app-runtime-platform-ai.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai.js +178 -86
- package/dist/core/app/local-app-runtime-platform-ai.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-direct-realtime-shared.d.ts +1 -1
- package/dist/core/app/local-app-runtime-platform-validation.d.ts +1 -1
- package/dist/core/app/local-app-runtime-platform-validation.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-validation.js +4 -4
- package/dist/core/app/local-app-runtime-platform-validation.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-video.d.ts +58 -0
- package/dist/core/app/local-app-runtime-platform-video.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-video.js +155 -0
- package/dist/core/app/local-app-runtime-platform-video.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-world-creator.d.ts +50 -0
- package/dist/core/app/local-app-runtime-platform-world-creator.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-world-creator.js +246 -0
- package/dist/core/app/local-app-runtime-platform-world-creator.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform.d.ts +9 -10
- package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform.js +8 -3
- package/dist/core/app/local-app-runtime-platform.js.map +1 -1
- package/dist/core/app/local-app-text.d.ts +51 -0
- package/dist/core/app/local-app-text.d.ts.map +1 -0
- package/dist/core/app/local-app-text.js +228 -0
- package/dist/core/app/local-app-text.js.map +1 -0
- package/dist/core-generated/realm-client.js +6 -6
- package/dist/core-generated/realm-client.js.map +1 -1
- package/dist/core-generated/realm-typed-client.d.ts +12 -12
- package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
- package/dist/core-generated/realm-typed-client.js +13 -13
- package/dist/core-generated/realm-typed-client.js.map +1 -1
- package/dist/core-generated/runtime-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-client.js +96 -0
- package/dist/core-generated/runtime-client.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts +725 -6
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js +1758 -261
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts +579 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.js +1306 -37
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +37 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.js +36 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
- package/dist/core-generated/runtime-public-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-public-client.js +96 -0
- package/dist/core-generated/runtime-public-client.js.map +1 -1
- package/dist/core-generated/runtime-public-rpc-auth-posture.d.ts.map +1 -1
- package/dist/core-generated/runtime-public-rpc-auth-posture.js +12 -0
- package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
- package/dist/core-generated/runtime-public-wire-codecs.d.ts +14 -2
- package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
- package/dist/core-generated/runtime-public-wire-codecs.js +14 -2
- package/dist/core-generated/runtime-public-wire-codecs.js.map +1 -1
- package/dist/core-generated/runtime-rpc-auth-posture.d.ts.map +1 -1
- package/dist/core-generated/runtime-rpc-auth-posture.js +12 -0
- package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
- package/dist/core-generated/runtime-typed-client.d.ts +17 -5
- package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-typed-client.js +121 -1
- package/dist/core-generated/runtime-typed-client.js.map +1 -1
- package/dist/core-generated/runtime-wire-codecs.d.ts +14 -2
- package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
- package/dist/core-generated/runtime-wire-codecs.js +14 -2
- package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
- package/dist/realm/index.d.ts +1 -1
- package/dist/realm/index.d.ts.map +1 -1
- package/dist/realm/index.js +1 -1
- package/dist/realm/index.js.map +1 -1
- package/dist/runtime/desktop-first-party-runtime.d.ts +1 -1
- package/dist/runtime/desktop-first-party-runtime.d.ts.map +1 -1
- package/dist/runtime/desktop-first-party-runtime.js +8 -0
- package/dist/runtime/desktop-first-party-runtime.js.map +1 -1
- package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +67 -3
- package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
- package/dist/runtime/first-party-protected-runtime-profiles.generated.js +19 -3
- package/dist/runtime/first-party-protected-runtime-profiles.generated.js.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts +12 -1
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.js +13 -0
- package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-types.d.ts +2 -2
- package/dist/runtime/wire-types/ai-scenario-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/identity-app-enums.d.ts +2 -1
- package/dist/runtime/wire-types/identity-app-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/identity-app-enums.js +1 -0
- package/dist/runtime/wire-types/identity-app-enums.js.map +1 -1
- package/dist/runtime/wire-types/identity-app-types.d.ts +2 -2
- package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.d.ts +10 -1
- package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.js +9 -0
- package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ExecutionMode, FinishReason, ReasonCode as RuntimeReasonCode, RoutePolicy, ScenarioJobEventType, ScenarioJobStatus, ScenarioType, SpeechTimingMode, VideoContentRole, VideoContentType, VideoMode, VoiceAssetStatus, VoiceCreationSource, VoiceReferenceKind, VisionLocateGeometry, } from '../../core-generated/runtime-typed-client.js';
|
|
1
|
+
import { ExecutionMode, FaceSwapNoFacePolicy, FinishReason, ResponseFormatKind, ToolChoiceMode, ReasonCode as RuntimeReasonCode, RoutePolicy, ScenarioJobEventType, ScenarioJobStatus, ScenarioType, SpeechTimingMode, VideoContentRole, VideoContentType, VideoMode, VoiceAssetStatus, VoiceCreationSource, VoiceReferenceKind, VisionLocateGeometry, } from '../../core-generated/runtime-typed-client.js';
|
|
2
|
+
import { toRuntimeMessages, toRuntimeTools, toRuntimeStruct, toNimiToolCall, toNimiTextOutputItems } from '../ai/runtime-model-text-projection.js';
|
|
3
|
+
import { validateLocalAppTextInput, projectLocalAppToolCall, projectLocalAppTextItems, projectLocalAppContinuity, modelTextOutputToLocalApp, localAppTextOutputToModel, } from './local-app-text.js';
|
|
2
4
|
import { asRecord, assertExactKeys, assertExactProjectionKeys, assertNoAuthorityMaterial, assertSafeProjection, localAppError, localAppProjectionError, projectionText, requireText, } from './local-app-runtime-platform-validation.js';
|
|
3
5
|
import { projectVisionLocateResult, localVisionLocateFromRuntime, runtimeVisionLocateFromLocal, localLocateGeometry, projectLocalExecutionInterruption, localInterruptionFromRuntime, runtimeInterruptionFromLocal, } from './local-app-runtime-platform-vision.js';
|
|
4
6
|
const MAX_RESULT_BYTES = 256 * 1024;
|
|
@@ -11,15 +13,43 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
|
|
|
11
13
|
const client = {
|
|
12
14
|
text: Object.freeze({
|
|
13
15
|
streamTurn: async (input) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
const stream = projectSubscription(await shell.text.streamTurn(validateLocalAppTextInput(input)), projectTextTurnEvent);
|
|
17
|
+
let canceled = false;
|
|
18
|
+
let closing;
|
|
19
|
+
const cancel = () => { canceled = true; return closing ??= stream.cancel(); };
|
|
20
|
+
return Object.freeze({
|
|
21
|
+
async *[Symbol.asyncIterator]() {
|
|
22
|
+
let sequence = 0n;
|
|
23
|
+
let terminal = false;
|
|
24
|
+
let hasPrimary = false;
|
|
25
|
+
const toolIds = new Set();
|
|
26
|
+
try {
|
|
27
|
+
for await (const event of stream) {
|
|
28
|
+
if (canceled)
|
|
29
|
+
break;
|
|
30
|
+
if (terminal || BigInt(event.sequence) !== ++sequence)
|
|
31
|
+
localAppProjectionError('text-turn event sequence');
|
|
32
|
+
if (event.type === 'delta')
|
|
33
|
+
hasPrimary = true;
|
|
34
|
+
if (event.type === 'tool-call') {
|
|
35
|
+
hasPrimary = true;
|
|
36
|
+
if (toolIds.has(event.toolCall.id))
|
|
37
|
+
localAppProjectionError('duplicate text tool call');
|
|
38
|
+
toolIds.add(event.toolCall.id);
|
|
39
|
+
}
|
|
40
|
+
if (event.type === 'completed' && !hasPrimary)
|
|
41
|
+
localAppProjectionError('missing primary text output');
|
|
42
|
+
terminal = event.type === 'completed' || event.type === 'failed';
|
|
43
|
+
yield event;
|
|
44
|
+
}
|
|
45
|
+
if (!terminal && !canceled)
|
|
46
|
+
localAppProjectionError('text-turn missing terminal event');
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
await cancel();
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
cancel,
|
|
23
53
|
});
|
|
24
54
|
},
|
|
25
55
|
}),
|
|
@@ -43,7 +73,7 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
|
|
|
43
73
|
assertExactKeys(input, ['bytes', 'mimeType'], 'artifact upload input');
|
|
44
74
|
assertNoAuthorityMaterial(input);
|
|
45
75
|
if (!(input.bytes instanceof Uint8Array) || input.bytes.byteLength === 0
|
|
46
|
-
|| input.bytes.byteLength > MAX_ARTIFACT_BYTES || !
|
|
76
|
+
|| input.bytes.byteLength > MAX_ARTIFACT_BYTES || !isArtifactUploadMime(input.mimeType)) {
|
|
47
77
|
invalidAIInput('artifact upload is invalid');
|
|
48
78
|
}
|
|
49
79
|
return projectArtifactUpload(await shell.artifacts.upload({ bytes: [...input.bytes], mimeType: input.mimeType }), input.bytes.byteLength, input.mimeType);
|
|
@@ -236,65 +266,36 @@ export function createNimiLocalAppRuntimeScenarioJobClient(ai) {
|
|
|
236
266
|
};
|
|
237
267
|
return Object.freeze(client);
|
|
238
268
|
}
|
|
239
|
-
function validateTextTurnInput(input) {
|
|
240
|
-
assertExactKeys(input, [
|
|
241
|
-
'messages', 'temperature', 'topP', 'maxTokens', 'topK',
|
|
242
|
-
'presencePenalty', 'frequencyPenalty', 'stop', 'seed',
|
|
243
|
-
], 'text-turn input');
|
|
244
|
-
assertNoAuthorityMaterial(input);
|
|
245
|
-
if (!Array.isArray(input.messages) || input.messages.length === 0 || input.messages.length > 8) {
|
|
246
|
-
invalidAIInput('text-turn messages are invalid');
|
|
247
|
-
}
|
|
248
|
-
let totalBytes = 0;
|
|
249
|
-
let sawSystem = false;
|
|
250
|
-
let sawUser = false;
|
|
251
|
-
const messages = input.messages.map((message, index) => {
|
|
252
|
-
assertExactKeys(message, ['role', 'text'], `text-turn message ${index}`);
|
|
253
|
-
if (message.role === 'system') {
|
|
254
|
-
if (sawSystem || sawUser)
|
|
255
|
-
invalidAIInput('text-turn system message order is invalid');
|
|
256
|
-
sawSystem = true;
|
|
257
|
-
}
|
|
258
|
-
else if (message.role === 'user')
|
|
259
|
-
sawUser = true;
|
|
260
|
-
else
|
|
261
|
-
invalidAIInput(`text-turn message ${index} role is invalid`);
|
|
262
|
-
const text = boundedContent(message.text, `text-turn message ${index}`, 32 * 1024);
|
|
263
|
-
totalBytes += utf8Length(message.role) + utf8Length(text);
|
|
264
|
-
if (totalBytes > 64 * 1024)
|
|
265
|
-
invalidAIInput('text-turn prompt is too large');
|
|
266
|
-
return Object.freeze({ role: message.role, text });
|
|
267
|
-
});
|
|
268
|
-
if (!sawUser)
|
|
269
|
-
invalidAIInput('text-turn requires a user message');
|
|
270
|
-
optionalBoundedNumber(input.temperature, 'text-turn temperature', 0, 2);
|
|
271
|
-
optionalBoundedNumber(input.topP, 'text-turn topP', 0, 1);
|
|
272
|
-
optionalBoundedInteger(input.maxTokens, 'text-turn maxTokens', 0, 4096);
|
|
273
|
-
optionalBoundedInteger(input.topK, 'text-turn topK', 0, Number.MAX_SAFE_INTEGER);
|
|
274
|
-
optionalBoundedNumber(input.presencePenalty, 'text-turn presencePenalty', -2, 2);
|
|
275
|
-
optionalBoundedNumber(input.frequencyPenalty, 'text-turn frequencyPenalty', -2, 2);
|
|
276
|
-
optionalBoundedInteger(input.seed, 'text-turn seed', Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
|
|
277
|
-
if (input.stop !== undefined && (!Array.isArray(input.stop)
|
|
278
|
-
|| input.stop.some((entry) => typeof entry !== 'string' || !entry.trim())))
|
|
279
|
-
invalidAIInput('text-turn stop is invalid');
|
|
280
|
-
return Object.freeze({
|
|
281
|
-
messages: Object.freeze(messages),
|
|
282
|
-
...(input.temperature !== undefined ? { temperature: input.temperature } : {}),
|
|
283
|
-
...(input.topP !== undefined ? { topP: input.topP } : {}),
|
|
284
|
-
...(input.maxTokens !== undefined ? { maxTokens: input.maxTokens } : {}),
|
|
285
|
-
...(input.topK !== undefined ? { topK: input.topK } : {}),
|
|
286
|
-
...(input.presencePenalty !== undefined ? { presencePenalty: input.presencePenalty } : {}),
|
|
287
|
-
...(input.frequencyPenalty !== undefined ? { frequencyPenalty: input.frequencyPenalty } : {}),
|
|
288
|
-
...(input.stop !== undefined ? { stop: Object.freeze([...input.stop]) } : {}),
|
|
289
|
-
...(input.seed !== undefined ? { seed: input.seed } : {}),
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
269
|
function validateScenarioSpec(spec, execute) {
|
|
293
270
|
const record = asRecord(spec);
|
|
294
271
|
if (!record || typeof record.type !== 'string')
|
|
295
272
|
invalidAIInput('scenario spec is invalid');
|
|
273
|
+
if (record.type === 'text-generate') {
|
|
274
|
+
if (!execute)
|
|
275
|
+
invalidAIInput('text-generate is a single synchronous model step');
|
|
276
|
+
const { type: _type, ...input } = record;
|
|
277
|
+
return Object.freeze({ type: 'text-generate', ...validateLocalAppTextInput(input) });
|
|
278
|
+
}
|
|
296
279
|
assertNoAuthorityMaterial(record);
|
|
297
280
|
switch (record.type) {
|
|
281
|
+
// @nimi-authority: rule.nimi.runtime.ai-provider.face-swap-video-job
|
|
282
|
+
case 'video-face-swap':
|
|
283
|
+
if (execute)
|
|
284
|
+
invalidAIInput('video-face-swap requires an async Job');
|
|
285
|
+
assertExactKeys(record, ['type', 'referenceImageArtifactId', 'targetVideoArtifactId', 'noFacePolicy'], 'video face replacement spec');
|
|
286
|
+
boundedIdentifier(record.referenceImageArtifactId, 'referenceImageArtifactId');
|
|
287
|
+
boundedIdentifier(record.targetVideoArtifactId, 'targetVideoArtifactId');
|
|
288
|
+
if (record.noFacePolicy !== 'fail' && record.noFacePolicy !== 'preserve-frame')
|
|
289
|
+
invalidAIInput('video face replacement requires an explicit no-face policy');
|
|
290
|
+
break;
|
|
291
|
+
// @nimi-authority: rule.nimi.runtime.ai-provider.face-swap-image-job
|
|
292
|
+
case 'image-face-swap':
|
|
293
|
+
if (execute)
|
|
294
|
+
invalidAIInput('image-face-swap requires an async Job');
|
|
295
|
+
assertExactKeys(record, ['type', 'referenceImageArtifactId', 'targetImageArtifactId'], 'image face replacement spec');
|
|
296
|
+
boundedIdentifier(record.referenceImageArtifactId, 'referenceImageArtifactId');
|
|
297
|
+
boundedIdentifier(record.targetImageArtifactId, 'targetImageArtifactId');
|
|
298
|
+
break;
|
|
298
299
|
case 'vision-locate':
|
|
299
300
|
if (execute)
|
|
300
301
|
invalidAIInput('vision-locate requires an async Job');
|
|
@@ -373,9 +374,12 @@ function validateScenarioSpec(spec, execute) {
|
|
|
373
374
|
case 'music-generate':
|
|
374
375
|
if (execute)
|
|
375
376
|
invalidAIInput('music-generate is not a synchronous spec');
|
|
376
|
-
assertExactKeys(record, ['type', 'prompt', 'lyrics'], 'music spec');
|
|
377
|
+
assertExactKeys(record, ['type', 'prompt', 'lyrics', 'durationSeconds'], 'music spec');
|
|
377
378
|
boundedContent(record.prompt, 'music prompt', 32 * 1024);
|
|
378
379
|
boundedContent(record.lyrics, 'music lyrics', 32 * 1024);
|
|
380
|
+
if (record.durationSeconds !== undefined && (!Number.isSafeInteger(record.durationSeconds)
|
|
381
|
+
|| Number(record.durationSeconds) < 1 || Number(record.durationSeconds) > 180))
|
|
382
|
+
invalidAIInput('music durationSeconds must be an integer from 1 through 180');
|
|
379
383
|
break;
|
|
380
384
|
case 'world-generate':
|
|
381
385
|
if (execute)
|
|
@@ -541,31 +545,49 @@ function projectTextTurnEvent(value) {
|
|
|
541
545
|
localAppProjectionError('text-turn event');
|
|
542
546
|
const base = { sequence: String(record.sequence), traceId: boundedProjectionText(record.traceId, 'text-turn traceId', 512) };
|
|
543
547
|
if (record.type === 'delta') {
|
|
544
|
-
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'text'], 'text-turn delta');
|
|
545
|
-
return Object.freeze({ ...base, type: 'delta', text: boundedProjectionContent(record.text, 'text-turn text', 64 * 1024) });
|
|
548
|
+
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'text', 'itemIndex'], 'text-turn delta');
|
|
549
|
+
return Object.freeze({ ...base, type: 'delta', text: boundedProjectionContent(record.text, 'text-turn text', 64 * 1024), itemIndex: projectionInteger(record.itemIndex, 'text item index', 0, 4_294_967_295) });
|
|
550
|
+
}
|
|
551
|
+
if (record.type === 'tool-call') {
|
|
552
|
+
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'toolCall'], 'text tool call');
|
|
553
|
+
return Object.freeze({ ...base, type: 'tool-call', itemIndex: projectionInteger(record.itemIndex, 'tool item index', 0, 4_294_967_295), toolCall: projectLocalAppToolCall(record.toolCall) });
|
|
554
|
+
}
|
|
555
|
+
if (record.type === 'reasoning-continuity') {
|
|
556
|
+
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'carrier'], 'text continuity');
|
|
557
|
+
return Object.freeze({ ...base, type: 'reasoning-continuity', itemIndex: projectionInteger(record.itemIndex, 'continuity item index', 0, 4_294_967_295), carrier: projectLocalAppContinuity(record.carrier) });
|
|
546
558
|
}
|
|
547
559
|
if (record.type === 'completed') {
|
|
548
560
|
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'finishReason'], 'text-turn completed');
|
|
549
|
-
if (!['stop', 'length', 'content-filter'].includes(String(record.finishReason)))
|
|
561
|
+
if (!['stop', 'length', 'tool-calls', 'content-filter'].includes(String(record.finishReason)))
|
|
550
562
|
localAppProjectionError('text-turn finishReason');
|
|
551
563
|
return Object.freeze({ ...base, type: 'completed', finishReason: record.finishReason });
|
|
552
564
|
}
|
|
553
565
|
if (record.type === 'failed') {
|
|
554
|
-
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'reasonCode', 'actionHint'], 'text-turn failed');
|
|
555
|
-
|
|
566
|
+
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'reasonCode', 'actionHint', ...(Object.hasOwn(record, 'interruption') ? ['interruption'] : [])], 'text-turn failed');
|
|
567
|
+
const interruption = projectLocalExecutionInterruption(record.interruption ?? undefined, record.reasonCode, 'failed');
|
|
568
|
+
return Object.freeze({ ...base, type: 'failed', reasonCode: boundedProjectionText(record.reasonCode, 'text-turn reasonCode', 128), actionHint: optionalProjectionText(record.actionHint, 'text-turn actionHint', 512), ...(interruption ? { interruption } : {}) });
|
|
556
569
|
}
|
|
557
570
|
return localAppProjectionError('text-turn event type');
|
|
558
571
|
}
|
|
559
572
|
function projectScenarioExecute(value) {
|
|
560
573
|
const record = asRecord(value);
|
|
561
574
|
assertExactProjectionKeys(record, ['output', 'traceId'], 'scenario execute');
|
|
562
|
-
assertSafeProjection(record);
|
|
563
575
|
const output = asRecord(record.output);
|
|
564
576
|
if (!output)
|
|
565
577
|
localAppProjectionError('scenario execute output');
|
|
566
578
|
const traceId = boundedProjectionText(record.traceId, 'scenario execute traceId', 512);
|
|
579
|
+
if (output.type === 'text-generate') {
|
|
580
|
+
assertExactProjectionKeys(output, ['type', 'items', 'finishReason'], 'text generate output');
|
|
581
|
+
const items = projectLocalAppTextItems(output.items);
|
|
582
|
+
if (!['stop', 'length', 'tool-calls', 'content-filter'].includes(String(output.finishReason))
|
|
583
|
+
|| (output.finishReason === 'tool-calls' && !items.some((item) => item.type === 'tool-call')))
|
|
584
|
+
localAppProjectionError('text finish reason');
|
|
585
|
+
return Object.freeze({ output: Object.freeze({ type: 'text-generate', items, finishReason: output.finishReason }), traceId });
|
|
586
|
+
}
|
|
587
|
+
assertSafeProjection(record);
|
|
567
588
|
if (output.type === 'text-embed') {
|
|
568
|
-
assertExactProjectionKeys(output, ['type', 'vectors'], 'text embed output');
|
|
589
|
+
assertExactProjectionKeys(output, ['type', 'vectors', 'spaceId'], 'text embed output');
|
|
590
|
+
const spaceId = boundedProjectionText(output.spaceId, 'embedding spaceId', 128);
|
|
569
591
|
if (!Array.isArray(output.vectors) || output.vectors.length === 0 || output.vectors.length > 16)
|
|
570
592
|
localAppProjectionError('text embed vectors');
|
|
571
593
|
const vectors = output.vectors.map((vector) => {
|
|
@@ -574,7 +596,7 @@ function projectScenarioExecute(value) {
|
|
|
574
596
|
localAppProjectionError('text embed vector');
|
|
575
597
|
return Object.freeze([...vector]);
|
|
576
598
|
});
|
|
577
|
-
return Object.freeze({ output: Object.freeze({ type: 'text-embed', vectors: Object.freeze(vectors) }), traceId });
|
|
599
|
+
return Object.freeze({ output: Object.freeze({ type: 'text-embed', vectors: Object.freeze(vectors), spaceId }), traceId });
|
|
578
600
|
}
|
|
579
601
|
if (output.type === 'image-generate') {
|
|
580
602
|
assertExactProjectionKeys(output, ['type', 'artifacts'], 'image execute output');
|
|
@@ -615,7 +637,7 @@ function projectScenarioJobEnvelope(value) {
|
|
|
615
637
|
}
|
|
616
638
|
function projectScenarioJob(value) {
|
|
617
639
|
const record = asRecord(value);
|
|
618
|
-
assertExactProjectionKeys(record, ['jobId', 'scenarioType', 'status', 'progressPercent', 'progressCurrentStep', 'progressTotalSteps', 'reasonCode', 'reasonDetail', 'artifacts', 'traceId', 'createdAt', 'updatedAt', 'transcriptionText', ...(record && Object.hasOwn(record, 'interruption') ? ['interruption'] : [])], 'scenario Job');
|
|
640
|
+
assertExactProjectionKeys(record, ['jobId', 'scenarioType', 'status', 'progressPercent', 'progressCurrentStep', 'progressTotalSteps', 'reasonCode', 'reasonDetail', 'artifacts', 'traceId', 'createdAt', 'updatedAt', 'transcriptionText', ...(record && Object.hasOwn(record, 'interruption') ? ['interruption'] : []), ...(record && Object.hasOwn(record, 'videoFaceSwapSummary') ? ['videoFaceSwapSummary'] : [])], 'scenario Job');
|
|
619
641
|
assertSafeProjection(record);
|
|
620
642
|
if (!LOCAL_SCENARIO_TYPES.includes(record.scenarioType) || !LOCAL_JOB_STATUSES.includes(record.status))
|
|
621
643
|
localAppProjectionError('scenario Job enum');
|
|
@@ -624,7 +646,12 @@ function projectScenarioJob(value) {
|
|
|
624
646
|
if (current > total)
|
|
625
647
|
localAppProjectionError('scenario Job progress');
|
|
626
648
|
const interruption = projectLocalExecutionInterruption(record.interruption, record.reasonCode, record.status);
|
|
649
|
+
const hasVideoSummary = record.videoFaceSwapSummary !== undefined;
|
|
650
|
+
if (hasVideoSummary !== (record.scenarioType === 'video-face-swap' && record.status === 'completed'))
|
|
651
|
+
localAppProjectionError('video face replacement summary state');
|
|
652
|
+
const videoFaceSwapSummary = hasVideoSummary ? projectVideoFaceSwapSummary(record.videoFaceSwapSummary) : undefined;
|
|
627
653
|
return Object.freeze({
|
|
654
|
+
...(videoFaceSwapSummary ? { videoFaceSwapSummary } : {}),
|
|
628
655
|
...(interruption ? { interruption } : {}),
|
|
629
656
|
jobId: boundedProjectionText(record.jobId, 'scenario Job id', MAX_IDENTIFIER_BYTES),
|
|
630
657
|
scenarioType: record.scenarioType,
|
|
@@ -641,6 +668,17 @@ function projectScenarioJob(value) {
|
|
|
641
668
|
transcriptionText: optionalProjectionText(record.transcriptionText, 'scenario Job transcriptionText', MAX_RESULT_BYTES),
|
|
642
669
|
});
|
|
643
670
|
}
|
|
671
|
+
function projectVideoFaceSwapSummary(value) {
|
|
672
|
+
const record = asRecord(value);
|
|
673
|
+
assertExactProjectionKeys(record, ['totalFrames', 'transformedFrames', 'preservedFrames', 'durationUs', 'frameRate', 'audioPreserved'], 'video face replacement summary');
|
|
674
|
+
const totalFrames = projectionInteger(record.totalFrames, 'video total frames', 1, 9000);
|
|
675
|
+
const transformedFrames = projectionInteger(record.transformedFrames, 'video transformed frames', 0, totalFrames);
|
|
676
|
+
const preservedFrames = projectionInteger(record.preservedFrames, 'video preserved frames', 0, totalFrames);
|
|
677
|
+
const frameRate = projectionInteger(record.frameRate, 'video frame rate', 24, 30);
|
|
678
|
+
if (transformedFrames + preservedFrames !== totalFrames || ![24, 25, 30].includes(frameRate) || typeof record.audioPreserved !== 'boolean')
|
|
679
|
+
localAppProjectionError('video face replacement counts or format');
|
|
680
|
+
return Object.freeze({ totalFrames, transformedFrames, preservedFrames, durationUs: projectionInteger(record.durationUs, 'video duration', 1, 300000000), frameRate: frameRate, audioPreserved: record.audioPreserved });
|
|
681
|
+
}
|
|
644
682
|
function projectArtifacts(value) {
|
|
645
683
|
if (!Array.isArray(value) || value.length > 16)
|
|
646
684
|
localAppProjectionError('scenario artifacts');
|
|
@@ -684,13 +722,13 @@ function projectArtifactUpload(value, expectedSize, expectedMimeType) {
|
|
|
684
722
|
if (utf8Length(artifactId) > MAX_IDENTIFIER_BYTES
|
|
685
723
|
|| !Number.isSafeInteger(record.sizeBytes) || record.sizeBytes !== expectedSize
|
|
686
724
|
|| record.sizeBytes < 1 || record.sizeBytes > MAX_ARTIFACT_BYTES
|
|
687
|
-
|| record.mimeType !== expectedMimeType || !
|
|
725
|
+
|| record.mimeType !== expectedMimeType || !isArtifactUploadMime(record.mimeType)) {
|
|
688
726
|
localAppProjectionError('artifact upload result');
|
|
689
727
|
}
|
|
690
728
|
return Object.freeze({ artifactId, sizeBytes: record.sizeBytes, mimeType: record.mimeType });
|
|
691
729
|
}
|
|
692
|
-
function
|
|
693
|
-
return value === 'image/png' || value === 'image/jpeg' || value === 'image/webp' || value === 'image/gif';
|
|
730
|
+
function isArtifactUploadMime(value) {
|
|
731
|
+
return value === 'image/png' || value === 'image/jpeg' || value === 'image/webp' || value === 'image/gif' || value === 'audio/wav' || value === 'audio/mpeg' || value === 'video/mp4';
|
|
694
732
|
}
|
|
695
733
|
function projectArtifactRead(value) {
|
|
696
734
|
const record = asRecord(value);
|
|
@@ -758,8 +796,26 @@ function projectRuntimeLocalAppVoiceAsset(asset) {
|
|
|
758
796
|
};
|
|
759
797
|
}
|
|
760
798
|
function runtimeTextTurnRequest(input) {
|
|
799
|
+
const messages = toRuntimeMessages(input.messages.map((message) => ({
|
|
800
|
+
role: message.role,
|
|
801
|
+
content: message.turnItems?.length || message.role === 'assistant' ? [] : [{ type: 'text', text: message.text }],
|
|
802
|
+
turnItems: message.turnItems?.length ? message.turnItems.map((item) => item.type === 'output'
|
|
803
|
+
? { ...item, output: localAppTextOutputToModel(item.output) } : item) : message.role === 'assistant'
|
|
804
|
+
? [{ type: 'output', output: { type: 'text', text: message.text } }] : undefined,
|
|
805
|
+
})));
|
|
806
|
+
const choice = input.toolChoice;
|
|
807
|
+
const format = input.responseFormat;
|
|
761
808
|
return {
|
|
762
|
-
messages:
|
|
809
|
+
messages: messages.map((message) => ({ role: message.role, text: message.content, turnItems: message.turnItems })),
|
|
810
|
+
tools: toRuntimeTools(input.tools),
|
|
811
|
+
toolChoice: choice === 'none' ? ToolChoiceMode.NONE : choice === 'auto' ? ToolChoiceMode.AUTO
|
|
812
|
+
: choice === 'required' ? ToolChoiceMode.REQUIRED : choice ? ToolChoiceMode.TOOL : ToolChoiceMode.UNSPECIFIED,
|
|
813
|
+
toolChoiceName: typeof choice === 'object' ? choice.name : '',
|
|
814
|
+
responseFormat: format ? {
|
|
815
|
+
kind: format.type === 'json-schema' ? ResponseFormatKind.JSON_SCHEMA : format.type === 'json-object' ? ResponseFormatKind.JSON_OBJECT : ResponseFormatKind.TEXT,
|
|
816
|
+
jsonSchema: format.schema ? toRuntimeStruct(format.schema) : undefined,
|
|
817
|
+
schemaName: format.name ?? '', schemaDescription: format.description ?? '', strict: format.strict ?? false,
|
|
818
|
+
} : undefined,
|
|
763
819
|
...(input.temperature === undefined ? {} : { temperature: input.temperature }),
|
|
764
820
|
...(input.topP === undefined ? {} : { topP: input.topP }),
|
|
765
821
|
...(input.maxTokens === undefined ? {} : { maxTokens: input.maxTokens }),
|
|
@@ -771,6 +827,8 @@ function runtimeTextTurnRequest(input) {
|
|
|
771
827
|
};
|
|
772
828
|
}
|
|
773
829
|
function runtimeExecuteRequest(spec) {
|
|
830
|
+
if (spec.type === 'text-generate')
|
|
831
|
+
return { spec: { oneofKind: 'textGenerate', textGenerate: runtimeTextTurnRequest(spec) } };
|
|
774
832
|
if (spec.type === 'text-embed') {
|
|
775
833
|
return { spec: { oneofKind: 'textEmbed', textEmbed: { inputs: [...spec.inputs] } } };
|
|
776
834
|
}
|
|
@@ -778,6 +836,10 @@ function runtimeExecuteRequest(spec) {
|
|
|
778
836
|
}
|
|
779
837
|
function runtimeLocalJobSpec(spec) {
|
|
780
838
|
switch (spec.type) {
|
|
839
|
+
case 'video-face-swap':
|
|
840
|
+
return { oneofKind: 'videoFaceSwap', videoFaceSwap: { referenceImageArtifactId: spec.referenceImageArtifactId, targetVideoArtifactId: spec.targetVideoArtifactId, noFacePolicy: spec.noFacePolicy === 'fail' ? FaceSwapNoFacePolicy.FAIL : FaceSwapNoFacePolicy.PRESERVE_FRAME } };
|
|
841
|
+
case 'image-face-swap':
|
|
842
|
+
return { oneofKind: 'imageFaceSwap', imageFaceSwap: { referenceImageArtifactId: spec.referenceImageArtifactId, targetImageArtifactId: spec.targetImageArtifactId } };
|
|
781
843
|
case 'vision-locate':
|
|
782
844
|
return { oneofKind: 'visionLocate', visionLocate: { imageArtifactId: spec.imageArtifactId, query: spec.query, geometry: spec.geometry === 'box' ? VisionLocateGeometry.BOX : VisionLocateGeometry.POINT } };
|
|
783
845
|
case 'image-generate':
|
|
@@ -886,7 +948,7 @@ function runtimeLocalJobSpec(spec) {
|
|
|
886
948
|
case 'music-generate':
|
|
887
949
|
return {
|
|
888
950
|
oneofKind: 'musicGenerate',
|
|
889
|
-
musicGenerate: { prompt: spec.prompt, lyrics: spec.lyrics },
|
|
951
|
+
musicGenerate: { prompt: spec.prompt, lyrics: spec.lyrics, durationSeconds: spec.durationSeconds ?? 0 },
|
|
890
952
|
};
|
|
891
953
|
case 'world-generate':
|
|
892
954
|
return { oneofKind: 'worldGenerate', worldGenerate: { prompt: spec.prompt, displayName: spec.displayName } };
|
|
@@ -954,8 +1016,19 @@ function runtimeVoiceReference(value) {
|
|
|
954
1016
|
function projectRuntimeTextTurnEvent(event) {
|
|
955
1017
|
const base = { sequence: event.sequence, traceId: event.traceId };
|
|
956
1018
|
switch (event.payload.oneofKind) {
|
|
1019
|
+
case 'reasoningContinuity': {
|
|
1020
|
+
const carrier = event.payload.reasoningContinuity.carrier;
|
|
1021
|
+
if (!carrier)
|
|
1022
|
+
return localAppProjectionError('Runtime continuity carrier');
|
|
1023
|
+
return { ...base, type: 'reasoning-continuity', itemIndex: event.payload.reasoningContinuity.itemIndex,
|
|
1024
|
+
carrier: { ...carrier, payload: Array.from(carrier.payload) } };
|
|
1025
|
+
}
|
|
1026
|
+
case 'toolCall':
|
|
1027
|
+
if (!event.payload.toolCall.toolCall)
|
|
1028
|
+
return localAppProjectionError('Runtime tool call');
|
|
1029
|
+
return { ...base, type: 'tool-call', itemIndex: event.payload.toolCall.itemIndex, toolCall: toNimiToolCall(event.payload.toolCall.toolCall) };
|
|
957
1030
|
case 'delta':
|
|
958
|
-
return { ...base, type: 'delta', text: event.payload.delta.text };
|
|
1031
|
+
return { ...base, type: 'delta', text: event.payload.delta.text, itemIndex: event.payload.delta.itemIndex };
|
|
959
1032
|
case 'completed':
|
|
960
1033
|
return {
|
|
961
1034
|
...base,
|
|
@@ -968,6 +1041,7 @@ function projectRuntimeTextTurnEvent(event) {
|
|
|
968
1041
|
type: 'failed',
|
|
969
1042
|
reasonCode: runtimeReasonToken(event.payload.failed.reasonCode),
|
|
970
1043
|
actionHint: event.payload.failed.actionHint,
|
|
1044
|
+
...(event.payload.failed.interruption ? { interruption: localInterruptionFromRuntime(event.payload.failed.interruption) } : {}),
|
|
971
1045
|
};
|
|
972
1046
|
default:
|
|
973
1047
|
return localAppProjectionError('text-turn Runtime event');
|
|
@@ -975,11 +1049,14 @@ function projectRuntimeTextTurnEvent(event) {
|
|
|
975
1049
|
}
|
|
976
1050
|
function projectRuntimeScenarioExecuteResponse(response) {
|
|
977
1051
|
switch (response.output.oneofKind) {
|
|
1052
|
+
case 'textGenerate':
|
|
1053
|
+
return { output: { type: 'text-generate', items: toNimiTextOutputItems(response.output.textGenerate.items).map(modelTextOutputToLocalApp), finishReason: runtimeFinishReason(response.output.textGenerate.finishReason) }, traceId: response.traceId };
|
|
978
1054
|
case 'textEmbed':
|
|
979
1055
|
return {
|
|
980
1056
|
output: {
|
|
981
1057
|
type: 'text-embed',
|
|
982
1058
|
vectors: response.output.textEmbed.vectors.map((vector) => [...vector.values]),
|
|
1059
|
+
spaceId: response.output.textEmbed.spaceId,
|
|
983
1060
|
},
|
|
984
1061
|
traceId: response.traceId,
|
|
985
1062
|
};
|
|
@@ -998,6 +1075,7 @@ function projectRuntimeScenarioExecuteResponse(response) {
|
|
|
998
1075
|
function projectRuntimeLocalJob(job) {
|
|
999
1076
|
const interruption = localInterruptionFromRuntime(job.interruption);
|
|
1000
1077
|
return {
|
|
1078
|
+
...(job.videoFaceSwapSummary ? { videoFaceSwapSummary: { ...job.videoFaceSwapSummary, durationUs: runtimeSafeInteger(job.videoFaceSwapSummary.durationUs, 'video duration') } } : {}),
|
|
1001
1079
|
...(interruption ? { interruption } : {}),
|
|
1002
1080
|
jobId: job.jobId,
|
|
1003
1081
|
scenarioType: runtimeScenarioTypeName(job.scenarioType),
|
|
@@ -1047,6 +1125,8 @@ function projectRuntimeVoiceReference(reference) {
|
|
|
1047
1125
|
}
|
|
1048
1126
|
function runtimeScenarioTypeName(value) {
|
|
1049
1127
|
const types = {
|
|
1128
|
+
[ScenarioType.VIDEO_FACE_SWAP]: 'video-face-swap',
|
|
1129
|
+
[ScenarioType.IMAGE_FACE_SWAP]: 'image-face-swap',
|
|
1050
1130
|
[ScenarioType.VISION_LOCATE]: 'vision-locate',
|
|
1051
1131
|
[ScenarioType.IMAGE_GENERATE]: 'image-generate',
|
|
1052
1132
|
[ScenarioType.VIDEO_GENERATE]: 'video-generate',
|
|
@@ -1083,6 +1163,8 @@ function runtimeJobEventTypeName(value) {
|
|
|
1083
1163
|
return types[value] ?? localAppProjectionError('scenario Runtime event type');
|
|
1084
1164
|
}
|
|
1085
1165
|
function runtimeFinishReason(value) {
|
|
1166
|
+
if (value === FinishReason.TOOL_CALL)
|
|
1167
|
+
return 'tool-calls';
|
|
1086
1168
|
if (value === FinishReason.STOP)
|
|
1087
1169
|
return 'stop';
|
|
1088
1170
|
if (value === FinishReason.LENGTH)
|
|
@@ -1131,7 +1213,7 @@ function localVoiceCreationSource(source) {
|
|
|
1131
1213
|
return 'text-description';
|
|
1132
1214
|
return localAppProjectionError('voice asset creationSource');
|
|
1133
1215
|
}
|
|
1134
|
-
const LOCAL_SCENARIO_TYPES = ['image-generate', 'vision-locate', 'video-generate', 'speech-synthesize', 'speech-transcribe', 'voice-create', 'music-generate', 'world-generate'];
|
|
1216
|
+
const LOCAL_SCENARIO_TYPES = ['image-generate', 'image-face-swap', 'video-face-swap', 'vision-locate', 'video-generate', 'speech-synthesize', 'speech-transcribe', 'voice-create', 'music-generate', 'world-generate'];
|
|
1135
1217
|
const LOCAL_JOB_STATUSES = ['submitted', 'queued', 'running', 'completed', 'failed', 'canceled', 'timeout'];
|
|
1136
1218
|
function localJobSpecFromRuntimeRequest(request) {
|
|
1137
1219
|
assertExactKeys(request, ['head', 'scenarioType', 'executionMode', 'spec', 'requestId', 'idempotencyKey', 'labels', 'extensions'], 'Runtime Scenario Job adapter request');
|
|
@@ -1141,6 +1223,12 @@ function localJobSpecFromRuntimeRequest(request) {
|
|
|
1141
1223
|
if (!spec || spec.oneofKind === undefined)
|
|
1142
1224
|
adapterInputError('missing Scenario spec');
|
|
1143
1225
|
switch (spec.oneofKind) {
|
|
1226
|
+
case 'videoFaceSwap':
|
|
1227
|
+
requireScenarioType(request, ScenarioType.VIDEO_FACE_SWAP);
|
|
1228
|
+
return validateScenarioSpec({ type: 'video-face-swap', referenceImageArtifactId: spec.videoFaceSwap.referenceImageArtifactId, targetVideoArtifactId: spec.videoFaceSwap.targetVideoArtifactId, noFacePolicy: spec.videoFaceSwap.noFacePolicy === FaceSwapNoFacePolicy.FAIL ? 'fail' : spec.videoFaceSwap.noFacePolicy === FaceSwapNoFacePolicy.PRESERVE_FRAME ? 'preserve-frame' : adapterInputError('video no-face policy is required') }, false);
|
|
1229
|
+
case 'imageFaceSwap':
|
|
1230
|
+
requireScenarioType(request, ScenarioType.IMAGE_FACE_SWAP);
|
|
1231
|
+
return validateScenarioSpec({ type: 'image-face-swap', referenceImageArtifactId: spec.imageFaceSwap.referenceImageArtifactId, targetImageArtifactId: spec.imageFaceSwap.targetImageArtifactId }, false);
|
|
1144
1232
|
case 'visionLocate':
|
|
1145
1233
|
requireScenarioType(request, ScenarioType.VISION_LOCATE);
|
|
1146
1234
|
return validateScenarioSpec({ type: 'vision-locate', imageArtifactId: spec.visionLocate.imageArtifactId, query: spec.visionLocate.query, geometry: localLocateGeometry(spec.visionLocate.geometry) }, false);
|
|
@@ -1204,10 +1292,11 @@ function localJobSpecFromRuntimeRequest(request) {
|
|
|
1204
1292
|
case 'musicGenerate':
|
|
1205
1293
|
requireScenarioType(request, ScenarioType.MUSIC_GENERATE);
|
|
1206
1294
|
if (spec.musicGenerate.negativePrompt || spec.musicGenerate.style || spec.musicGenerate.title
|
|
1207
|
-
|| spec.musicGenerate.
|
|
1295
|
+
|| spec.musicGenerate.instrumental) {
|
|
1208
1296
|
return adapterInputError('unsupported MiniMax-Music3 fields are unavailable to Local Apps');
|
|
1209
1297
|
}
|
|
1210
|
-
return validateScenarioSpec({ type: 'music-generate', prompt: spec.musicGenerate.prompt, lyrics: spec.musicGenerate.lyrics
|
|
1298
|
+
return validateScenarioSpec({ type: 'music-generate', prompt: spec.musicGenerate.prompt, lyrics: spec.musicGenerate.lyrics,
|
|
1299
|
+
...(spec.musicGenerate.durationSeconds !== 0 ? { durationSeconds: spec.musicGenerate.durationSeconds } : {}) }, false);
|
|
1211
1300
|
case 'worldGenerate':
|
|
1212
1301
|
requireScenarioType(request, ScenarioType.WORLD_GENERATE);
|
|
1213
1302
|
if (spec.worldGenerate.conditioning.oneofKind !== undefined || spec.worldGenerate.tags.length > 0 || spec.worldGenerate.seed !== '0') {
|
|
@@ -1293,6 +1382,7 @@ function runtimeVoiceAudio(bytes, uri) {
|
|
|
1293
1382
|
}
|
|
1294
1383
|
function runtimeJobFromLocal(job) {
|
|
1295
1384
|
return {
|
|
1385
|
+
...(job.videoFaceSwapSummary ? { videoFaceSwapSummary: { ...job.videoFaceSwapSummary, durationUs: String(job.videoFaceSwapSummary.durationUs) } } : {}),
|
|
1296
1386
|
...(job.interruption ? { interruption: runtimeInterruptionFromLocal(job.interruption) } : {}),
|
|
1297
1387
|
jobId: job.jobId, head: undefined, scenarioType: runtimeScenarioType(job.scenarioType), executionMode: ExecutionMode.ASYNC_JOB,
|
|
1298
1388
|
routeDecision: RoutePolicy.UNSPECIFIED, modelResolved: '', status: runtimeJobStatus(job.status), providerJobId: '',
|
|
@@ -1321,11 +1411,13 @@ function runtimeJobEventFromLocal(event) {
|
|
|
1321
1411
|
return { eventType: runtimeJobEventType(event.eventType), sequence: event.sequence, traceId: event.traceId, timestamp: runtimeTimestamp(event.timestamp), job: runtimeJobFromLocal(event.job) };
|
|
1322
1412
|
}
|
|
1323
1413
|
function runtimeArtifactResponse(job, artifacts) {
|
|
1324
|
-
const output = runtimeOutput(job.scenarioType, artifacts, job.transcriptionText);
|
|
1414
|
+
const output = runtimeOutput(job.scenarioType, artifacts, job.transcriptionText, job.videoFaceSwapSummary);
|
|
1325
1415
|
return { jobId: job.jobId, artifacts, traceId: job.traceId, output };
|
|
1326
1416
|
}
|
|
1327
|
-
function runtimeOutput(type, artifacts, transcriptionText) {
|
|
1417
|
+
function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary) {
|
|
1328
1418
|
switch (type) {
|
|
1419
|
+
case 'video-face-swap': return videoFaceSwapSummary ? { output: { oneofKind: 'videoFaceSwap', videoFaceSwap: { artifacts, summary: { ...videoFaceSwapSummary, durationUs: String(videoFaceSwapSummary.durationUs) } } } } : undefined;
|
|
1420
|
+
case 'image-face-swap': return { output: { oneofKind: 'imageFaceSwap', imageFaceSwap: { artifacts } } };
|
|
1329
1421
|
case 'image-generate': return { output: { oneofKind: 'imageGenerate', imageGenerate: { artifacts } } };
|
|
1330
1422
|
case 'video-generate': return { output: { oneofKind: 'videoGenerate', videoGenerate: { artifacts } } };
|
|
1331
1423
|
case 'speech-synthesize': return { output: { oneofKind: 'speechSynthesize', speechSynthesize: { artifacts } } };
|
|
@@ -1339,7 +1431,7 @@ function runtimeOutput(type, artifacts, transcriptionText) {
|
|
|
1339
1431
|
}
|
|
1340
1432
|
}
|
|
1341
1433
|
function runtimeScenarioType(type) {
|
|
1342
|
-
return ({ 'image-generate': ScenarioType.IMAGE_GENERATE, 'vision-locate': ScenarioType.VISION_LOCATE, 'video-generate': ScenarioType.VIDEO_GENERATE, 'speech-synthesize': ScenarioType.SPEECH_SYNTHESIZE, 'speech-transcribe': ScenarioType.SPEECH_TRANSCRIBE, 'voice-create': ScenarioType.VOICE_CREATE, 'music-generate': ScenarioType.MUSIC_GENERATE, 'world-generate': ScenarioType.WORLD_GENERATE })[type];
|
|
1434
|
+
return ({ 'image-generate': ScenarioType.IMAGE_GENERATE, 'image-face-swap': ScenarioType.IMAGE_FACE_SWAP, 'video-face-swap': ScenarioType.VIDEO_FACE_SWAP, 'vision-locate': ScenarioType.VISION_LOCATE, 'video-generate': ScenarioType.VIDEO_GENERATE, 'speech-synthesize': ScenarioType.SPEECH_SYNTHESIZE, 'speech-transcribe': ScenarioType.SPEECH_TRANSCRIBE, 'voice-create': ScenarioType.VOICE_CREATE, 'music-generate': ScenarioType.MUSIC_GENERATE, 'world-generate': ScenarioType.WORLD_GENERATE })[type];
|
|
1343
1435
|
}
|
|
1344
1436
|
function runtimeJobStatus(status) {
|
|
1345
1437
|
return ({ submitted: ScenarioJobStatus.SUBMITTED, queued: ScenarioJobStatus.QUEUED, running: ScenarioJobStatus.RUNNING, completed: ScenarioJobStatus.COMPLETED, failed: ScenarioJobStatus.FAILED, canceled: ScenarioJobStatus.CANCELED, timeout: ScenarioJobStatus.TIMEOUT })[status];
|