@nimiplatform/sdk 0.12.0 → 0.15.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/CHANGELOG.md +72 -0
- package/README.md +391 -0
- package/dist/core/ai/capability-configuration.d.ts +3 -0
- package/dist/core/ai/capability-configuration.d.ts.map +1 -1
- package/dist/core/ai/capability-configuration.js +3 -0
- package/dist/core/ai/capability-configuration.js.map +1 -1
- package/dist/core/ai/local-app-model.d.ts.map +1 -1
- package/dist/core/ai/local-app-model.js +29 -1
- package/dist/core/ai/local-app-model.js.map +1 -1
- package/dist/core/ai/voice-reference-input.d.ts +9 -0
- package/dist/core/ai/voice-reference-input.d.ts.map +1 -0
- package/dist/core/ai/voice-reference-input.js +17 -0
- package/dist/core/ai/voice-reference-input.js.map +1 -0
- package/dist/core/app/index.d.ts +8 -2
- package/dist/core/app/index.d.ts.map +1 -1
- package/dist/core/app/index.js +4 -1
- package/dist/core/app/index.js.map +1 -1
- package/dist/core/app/local-app-audio-separation.d.ts +6 -0
- package/dist/core/app/local-app-audio-separation.d.ts.map +1 -0
- package/dist/core/app/local-app-audio-separation.js +31 -0
- package/dist/core/app/local-app-audio-separation.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-ai-config.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai-config.js +7 -0
- package/dist/core/app/local-app-runtime-platform-ai-config.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai.d.ts +21 -1
- package/dist/core/app/local-app-runtime-platform-ai.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai.js +111 -20
- package/dist/core/app/local-app-runtime-platform-ai.js.map +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 +8 -0
- package/dist/core/app/local-app-runtime-platform-validation.js.map +1 -1
- package/dist/core/app/local-app-text-annotation.d.ts +24 -0
- package/dist/core/app/local-app-text-annotation.d.ts.map +1 -0
- package/dist/core/app/local-app-text-annotation.js +71 -0
- package/dist/core/app/local-app-text-annotation.js.map +1 -0
- package/dist/core/app/local-app-text.d.ts +15 -0
- package/dist/core/app/local-app-text.d.ts.map +1 -1
- package/dist/core/app/local-app-text.js +47 -1
- package/dist/core/app/local-app-text.js.map +1 -1
- package/dist/core/app/local-app-transcription.d.ts +12 -0
- package/dist/core/app/local-app-transcription.d.ts.map +1 -0
- package/dist/core/app/local-app-transcription.js +28 -0
- package/dist/core/app/local-app-transcription.js.map +1 -0
- package/dist/core-generated/realm-typed-client.d.ts +73 -5
- package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
- package/dist/core-generated/realm-typed-client.js +64 -2
- package/dist/core-generated/realm-typed-client.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts +382 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js +769 -6
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts +128 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.js +254 -2
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts +123 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js +189 -8
- package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +15 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.js +15 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.d.ts +34 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.js +36 -4
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.d.ts +13 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.js +17 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.js.map +1 -1
- package/dist/core-generated/runtime-typed-client.d.ts +4 -4
- package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-typed-client.js +1 -1
- package/dist/core-generated/runtime-typed-client.js.map +1 -1
- package/dist/features/generation/index.d.ts +2 -0
- package/dist/features/generation/index.d.ts.map +1 -1
- package/dist/features/generation/index.js +12 -2
- package/dist/features/generation/index.js.map +1 -1
- package/dist/runtime/config-projections.d.ts.map +1 -1
- package/dist/runtime/config-projections.js +30 -1
- package/dist/runtime/config-projections.js.map +1 -1
- package/dist/runtime/connector-inventory.js +3 -3
- package/dist/runtime/connector-inventory.js.map +1 -1
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +2 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/machine-loadouts.d.ts +15 -1
- package/dist/runtime/machine-loadouts.d.ts.map +1 -1
- package/dist/runtime/machine-loadouts.js +13 -2
- package/dist/runtime/machine-loadouts.js.map +1 -1
- package/dist/runtime/node-grpc.d.ts.map +1 -1
- package/dist/runtime/node-grpc.js +35 -4
- package/dist/runtime/node-grpc.js.map +1 -1
- package/dist/runtime/runtime-local-environment-client-projections.d.ts.map +1 -1
- package/dist/runtime/runtime-local-environment-client-projections.js +4 -0
- package/dist/runtime/runtime-local-environment-client-projections.js.map +1 -1
- package/dist/runtime/runtime-local-environment-client-types.d.ts +10 -1
- package/dist/runtime/runtime-local-environment-client-types.d.ts.map +1 -1
- package/dist/runtime/runtime-local-environment-client.d.ts.map +1 -1
- package/dist/runtime/runtime-local-environment-client.js +5 -1
- package/dist/runtime/runtime-local-environment-client.js.map +1 -1
- package/dist/runtime/shared-local-agent-ai-config.d.ts.map +1 -1
- package/dist/runtime/shared-local-agent-ai-config.js +3 -0
- package/dist/runtime/shared-local-agent-ai-config.js.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts +8 -1
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.js +8 -0
- package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-types.d.ts +4 -4
- package/dist/runtime/wire-types/ai-scenario-types.d.ts.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 +2 -0
- package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.js +2 -0
- package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
- package/package.json +4 -2
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { validateNimiLocalAppTextAnnotationResult } from './local-app-text-annotation.js';
|
|
2
|
+
import { validateNimiLocalAppSpeechTranscript } from './local-app-transcription.js';
|
|
3
|
+
import { validateNimiLocalAppAudioSeparation } from './local-app-audio-separation.js';
|
|
4
|
+
import { ChatContentPartType, ExecutionMode, FaceSwapNoFacePolicy, FinishReason, ResponseFormatKind, ToolChoiceMode, ReasonCode as RuntimeReasonCode, RoutePolicy, ScenarioJobEventType, ScenarioJobStatus, ScenarioType, SpeechTimingMode, SpeechTranscriptStatus, VideoContentRole, VideoContentType, VideoMode, VoiceAssetStatus, VoiceCreationSource, VoiceReferenceKind, VisionLocateGeometry, } from '../../core-generated/runtime-typed-client.js';
|
|
2
5
|
import { toRuntimeMessages, toRuntimeTools, toRuntimeStruct, toNimiToolCall, toNimiTextOutputItems } from '../ai/runtime-model-text-projection.js';
|
|
3
6
|
import { validateLocalAppTextInput, projectLocalAppToolCall, projectLocalAppTextItems, projectLocalAppContinuity, modelTextOutputToLocalApp, localAppTextOutputToModel, } from './local-app-text.js';
|
|
4
7
|
import { asRecord, assertExactKeys, assertExactProjectionKeys, assertNoAuthorityMaterial, assertSafeProjection, localAppError, localAppProjectionError, projectionText, requireText, } from './local-app-runtime-platform-validation.js';
|
|
@@ -366,6 +369,23 @@ function validateScenarioSpec(spec, execute) {
|
|
|
366
369
|
invalidAIInput('speech-transcribe is not a synchronous spec');
|
|
367
370
|
validateSpeechTranscribeSpec(record);
|
|
368
371
|
break;
|
|
372
|
+
case 'text-annotate':
|
|
373
|
+
if (execute)
|
|
374
|
+
invalidAIInput('text-annotate is not a synchronous spec');
|
|
375
|
+
assertExactKeys(record, ['type', 'language', 'texts'], 'text annotation spec');
|
|
376
|
+
if (typeof record.language !== 'string' || !/^[a-z-]{2,16}$/.test(record.language)
|
|
377
|
+
|| !Array.isArray(record.texts) || record.texts.length < 1 || record.texts.length > 64
|
|
378
|
+
|| record.texts.some((text) => typeof text !== 'string' || /[\uD800-\uDFFF]/u.test(text))
|
|
379
|
+
|| record.texts.reduce((sum, text) => sum + new TextEncoder().encode(text).byteLength, 0) > 524288)
|
|
380
|
+
invalidAIInput('text annotation requires bounded Unicode documents');
|
|
381
|
+
break;
|
|
382
|
+
case 'audio-separate':
|
|
383
|
+
if (execute)
|
|
384
|
+
invalidAIInput('audio-separate is not a synchronous spec');
|
|
385
|
+
assertExactKeys(record, ['type', 'mimeType', 'audioSource'], 'audio separation spec');
|
|
386
|
+
boundedToken(record.mimeType, 'audio separation mimeType', 128);
|
|
387
|
+
validateAudioSource(record.audioSource, MAX_ARTIFACT_BYTES, 'audio separation audioSource');
|
|
388
|
+
break;
|
|
369
389
|
case 'voice-create':
|
|
370
390
|
if (execute)
|
|
371
391
|
invalidAIInput('voice-create is not a synchronous spec');
|
|
@@ -637,7 +657,7 @@ function projectScenarioJobEnvelope(value) {
|
|
|
637
657
|
}
|
|
638
658
|
function projectScenarioJob(value) {
|
|
639
659
|
const record = asRecord(value);
|
|
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');
|
|
660
|
+
assertExactProjectionKeys(record, ['jobId', 'scenarioType', 'status', 'progressPercent', 'progressCurrentStep', 'progressTotalSteps', 'reasonCode', 'reasonDetail', 'artifacts', 'traceId', 'createdAt', 'updatedAt', 'transcriptionText', ...(record && Object.hasOwn(record, 'textAnnotation') ? ['textAnnotation'] : []), ...(record && Object.hasOwn(record, 'audioSeparation') ? ['audioSeparation'] : []), ...(record && Object.hasOwn(record, 'transcription') ? ['transcription'] : []), ...(record && Object.hasOwn(record, 'interruption') ? ['interruption'] : []), ...(record && Object.hasOwn(record, 'videoFaceSwapSummary') ? ['videoFaceSwapSummary'] : [])], 'scenario Job');
|
|
641
661
|
assertSafeProjection(record);
|
|
642
662
|
if (!LOCAL_SCENARIO_TYPES.includes(record.scenarioType) || !LOCAL_JOB_STATUSES.includes(record.status))
|
|
643
663
|
localAppProjectionError('scenario Job enum');
|
|
@@ -650,8 +670,21 @@ function projectScenarioJob(value) {
|
|
|
650
670
|
if (hasVideoSummary !== (record.scenarioType === 'video-face-swap' && record.status === 'completed'))
|
|
651
671
|
localAppProjectionError('video face replacement summary state');
|
|
652
672
|
const videoFaceSwapSummary = hasVideoSummary ? projectVideoFaceSwapSummary(record.videoFaceSwapSummary) : undefined;
|
|
673
|
+
const transcription = record.transcription === undefined ? undefined : validateNimiLocalAppSpeechTranscript(record.transcription);
|
|
674
|
+
if (transcription && (record.scenarioType !== 'speech-transcribe' || record.status !== 'completed' || transcription.text !== record.transcriptionText))
|
|
675
|
+
localAppProjectionError('speech transcription state');
|
|
676
|
+
const artifacts = projectArtifacts(record.artifacts);
|
|
677
|
+
if ((record.audioSeparation !== undefined) !== (record.scenarioType === 'audio-separate' && record.status === 'completed'))
|
|
678
|
+
localAppProjectionError('audio separation state');
|
|
679
|
+
if ((record.textAnnotation !== undefined) !== (record.scenarioType === 'text-annotate' && record.status === 'completed'))
|
|
680
|
+
localAppProjectionError('text annotation state');
|
|
681
|
+
const textAnnotation = record.textAnnotation === undefined ? undefined : validateNimiLocalAppTextAnnotationResult(record.textAnnotation);
|
|
682
|
+
const audioSeparation = record.audioSeparation === undefined ? undefined : validateNimiLocalAppAudioSeparation(record.audioSeparation, artifacts);
|
|
653
683
|
return Object.freeze({
|
|
684
|
+
...(textAnnotation ? { textAnnotation } : {}),
|
|
685
|
+
...(audioSeparation ? { audioSeparation } : {}),
|
|
654
686
|
...(videoFaceSwapSummary ? { videoFaceSwapSummary } : {}),
|
|
687
|
+
...(transcription ? { transcription } : {}),
|
|
655
688
|
...(interruption ? { interruption } : {}),
|
|
656
689
|
jobId: boundedProjectionText(record.jobId, 'scenario Job id', MAX_IDENTIFIER_BYTES),
|
|
657
690
|
scenarioType: record.scenarioType,
|
|
@@ -661,11 +694,11 @@ function projectScenarioJob(value) {
|
|
|
661
694
|
progressTotalSteps: total,
|
|
662
695
|
reasonCode: optionalProjectionText(record.reasonCode, 'scenario Job reasonCode', 128),
|
|
663
696
|
reasonDetail: optionalProjectionText(record.reasonDetail, 'scenario Job reasonDetail', 1024),
|
|
664
|
-
artifacts
|
|
697
|
+
artifacts,
|
|
665
698
|
traceId: optionalProjectionText(record.traceId, 'scenario Job traceId', 512),
|
|
666
699
|
createdAt: projectTimestamp(record.createdAt, 'scenario Job createdAt'),
|
|
667
700
|
updatedAt: projectTimestamp(record.updatedAt, 'scenario Job updatedAt'),
|
|
668
|
-
transcriptionText:
|
|
701
|
+
transcriptionText: optionalProjectionContent(record.transcriptionText, 'scenario Job transcriptionText', 1 << 20),
|
|
669
702
|
});
|
|
670
703
|
}
|
|
671
704
|
function projectVideoFaceSwapSummary(value) {
|
|
@@ -795,18 +828,33 @@ function projectRuntimeLocalAppVoiceAsset(asset) {
|
|
|
795
828
|
expiresAt: plainRuntimeTimestamp(asset.expiresAt),
|
|
796
829
|
};
|
|
797
830
|
}
|
|
831
|
+
function runtimeLocalTextPart(part) {
|
|
832
|
+
if (part.type === 'text')
|
|
833
|
+
return { type: ChatContentPartType.TEXT, content: { oneofKind: 'text', text: part.text } };
|
|
834
|
+
if (part.type === 'image-url')
|
|
835
|
+
return { type: ChatContentPartType.IMAGE_URL, content: { oneofKind: 'imageUrl', imageUrl: { url: part.url, detail: '' } } };
|
|
836
|
+
return {
|
|
837
|
+
type: ChatContentPartType.ARTIFACT_REF,
|
|
838
|
+
content: { oneofKind: 'artifactRef', artifactRef: { artifactId: part.artifactId, localArtifactId: '', mimeType: part.mediaType, displayName: part.displayName ?? '' } },
|
|
839
|
+
};
|
|
840
|
+
}
|
|
798
841
|
function runtimeTextTurnRequest(input) {
|
|
799
|
-
const messages =
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
842
|
+
const messages = input.messages.map((message) => {
|
|
843
|
+
if (message.parts?.length)
|
|
844
|
+
return { role: message.role, text: '', turnItems: [], parts: message.parts.map(runtimeLocalTextPart) };
|
|
845
|
+
const [projected] = toRuntimeMessages([{
|
|
846
|
+
role: message.role,
|
|
847
|
+
content: message.turnItems?.length || message.role === 'assistant' ? [] : [{ type: 'text', text: message.text }],
|
|
848
|
+
turnItems: message.turnItems?.length ? message.turnItems.map((item) => item.type === 'output'
|
|
849
|
+
? { ...item, output: localAppTextOutputToModel(item.output) } : item) : message.role === 'assistant'
|
|
850
|
+
? [{ type: 'output', output: { type: 'text', text: message.text } }] : undefined,
|
|
851
|
+
}]);
|
|
852
|
+
return { role: message.role, text: projected.content, turnItems: projected.turnItems, parts: [] };
|
|
853
|
+
});
|
|
806
854
|
const choice = input.toolChoice;
|
|
807
855
|
const format = input.responseFormat;
|
|
808
856
|
return {
|
|
809
|
-
messages
|
|
857
|
+
messages,
|
|
810
858
|
tools: toRuntimeTools(input.tools),
|
|
811
859
|
toolChoice: choice === 'none' ? ToolChoiceMode.NONE : choice === 'auto' ? ToolChoiceMode.AUTO
|
|
812
860
|
: choice === 'required' ? ToolChoiceMode.REQUIRED : choice ? ToolChoiceMode.TOOL : ToolChoiceMode.UNSPECIFIED,
|
|
@@ -892,6 +940,12 @@ function runtimeLocalJobSpec(spec) {
|
|
|
892
940
|
...(spec.voiceRenderHints === null ? {} : { voiceRenderHints: { ...spec.voiceRenderHints } }),
|
|
893
941
|
},
|
|
894
942
|
};
|
|
943
|
+
case 'text-annotate':
|
|
944
|
+
return { oneofKind: 'textAnnotate', textAnnotate: { language: spec.language, texts: [...spec.texts] } };
|
|
945
|
+
case 'audio-separate':
|
|
946
|
+
return { oneofKind: 'audioSeparate', audioSeparate: { mimeType: spec.mimeType, audioSource: { source: spec.audioSource.type === 'bytes'
|
|
947
|
+
? { oneofKind: 'audioBytes', audioBytes: Uint8Array.from(spec.audioSource.bytes) }
|
|
948
|
+
: { oneofKind: 'audioUri', audioUri: spec.audioSource.uri } } } };
|
|
895
949
|
case 'speech-transcribe':
|
|
896
950
|
return {
|
|
897
951
|
oneofKind: 'speechTranscribe',
|
|
@@ -1090,6 +1144,9 @@ function projectRuntimeLocalJob(job) {
|
|
|
1090
1144
|
createdAt: plainRuntimeTimestamp(job.createdAt),
|
|
1091
1145
|
updatedAt: plainRuntimeTimestamp(job.updatedAt),
|
|
1092
1146
|
transcriptionText: job.transcriptionText,
|
|
1147
|
+
...(job.textAnnotation ? { textAnnotation: job.textAnnotation } : {}),
|
|
1148
|
+
...(job.audioSeparation ? { audioSeparation: job.audioSeparation } : {}),
|
|
1149
|
+
...(job.transcription ? { transcription: localTranscriptionFromRuntime(job.transcription) } : {}),
|
|
1093
1150
|
};
|
|
1094
1151
|
}
|
|
1095
1152
|
function projectRuntimeLocalArtifact(artifact) {
|
|
@@ -1132,6 +1189,8 @@ function runtimeScenarioTypeName(value) {
|
|
|
1132
1189
|
[ScenarioType.VIDEO_GENERATE]: 'video-generate',
|
|
1133
1190
|
[ScenarioType.SPEECH_SYNTHESIZE]: 'speech-synthesize',
|
|
1134
1191
|
[ScenarioType.SPEECH_TRANSCRIBE]: 'speech-transcribe',
|
|
1192
|
+
[ScenarioType.TEXT_ANNOTATE]: 'text-annotate',
|
|
1193
|
+
[ScenarioType.AUDIO_SEPARATE]: 'audio-separate',
|
|
1135
1194
|
[ScenarioType.VOICE_CREATE]: 'voice-create',
|
|
1136
1195
|
[ScenarioType.MUSIC_GENERATE]: 'music-generate',
|
|
1137
1196
|
[ScenarioType.WORLD_GENERATE]: 'world-generate',
|
|
@@ -1213,7 +1272,7 @@ function localVoiceCreationSource(source) {
|
|
|
1213
1272
|
return 'text-description';
|
|
1214
1273
|
return localAppProjectionError('voice asset creationSource');
|
|
1215
1274
|
}
|
|
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'];
|
|
1275
|
+
const LOCAL_SCENARIO_TYPES = ['image-generate', 'image-face-swap', 'video-face-swap', 'vision-locate', 'video-generate', 'speech-synthesize', 'speech-transcribe', 'text-annotate', 'audio-separate', 'voice-create', 'music-generate', 'world-generate'];
|
|
1217
1276
|
const LOCAL_JOB_STATUSES = ['submitted', 'queued', 'running', 'completed', 'failed', 'canceled', 'timeout'];
|
|
1218
1277
|
function localJobSpecFromRuntimeRequest(request) {
|
|
1219
1278
|
assertExactKeys(request, ['head', 'scenarioType', 'executionMode', 'spec', 'requestId', 'idempotencyKey', 'labels', 'extensions'], 'Runtime Scenario Job adapter request');
|
|
@@ -1261,6 +1320,17 @@ function localJobSpecFromRuntimeRequest(request) {
|
|
|
1261
1320
|
case 'speechTranscribe':
|
|
1262
1321
|
requireScenarioType(request, ScenarioType.SPEECH_TRANSCRIBE);
|
|
1263
1322
|
return validateScenarioSpec(runtimeSpeechTranscribeSpec(spec.speechTranscribe), false);
|
|
1323
|
+
case 'textAnnotate':
|
|
1324
|
+
requireScenarioType(request, ScenarioType.TEXT_ANNOTATE);
|
|
1325
|
+
return validateScenarioSpec({ type: 'text-annotate', language: spec.textAnnotate.language, texts: [...spec.textAnnotate.texts] }, false);
|
|
1326
|
+
case 'audioSeparate': {
|
|
1327
|
+
requireScenarioType(request, ScenarioType.AUDIO_SEPARATE);
|
|
1328
|
+
const source = spec.audioSeparate.audioSource?.source;
|
|
1329
|
+
if (!source || source.oneofKind === undefined || source.oneofKind === 'audioChunks')
|
|
1330
|
+
adapterInputError('Local App separation requires bytes or URI audio');
|
|
1331
|
+
return validateScenarioSpec({ type: 'audio-separate', mimeType: spec.audioSeparate.mimeType, audioSource: source.oneofKind === 'audioBytes'
|
|
1332
|
+
? { type: 'bytes', bytes: Array.from(source.audioBytes) } : { type: 'uri', uri: source.audioUri } }, false);
|
|
1333
|
+
}
|
|
1264
1334
|
case 'voiceCreate': {
|
|
1265
1335
|
requireScenarioType(request, ScenarioType.VOICE_CREATE);
|
|
1266
1336
|
if (spec.voiceCreate.targetModelId)
|
|
@@ -1392,6 +1462,9 @@ function runtimeJobFromLocal(job) {
|
|
|
1392
1462
|
ignoredExtensions: [], reasonMetadata: undefined, progressPercent: job.progressPercent,
|
|
1393
1463
|
progressCurrentStep: job.progressCurrentStep, progressTotalSteps: job.progressTotalSteps,
|
|
1394
1464
|
transcriptionText: job.transcriptionText,
|
|
1465
|
+
transcription: runtimeTranscriptionFromLocal(job.transcription),
|
|
1466
|
+
audioSeparation: job.audioSeparation,
|
|
1467
|
+
textAnnotation: runtimeAnnotationFromLocal(job.textAnnotation),
|
|
1395
1468
|
};
|
|
1396
1469
|
}
|
|
1397
1470
|
function runtimeVoiceAssetFromLocal(asset) {
|
|
@@ -1411,10 +1484,10 @@ function runtimeJobEventFromLocal(event) {
|
|
|
1411
1484
|
return { eventType: runtimeJobEventType(event.eventType), sequence: event.sequence, traceId: event.traceId, timestamp: runtimeTimestamp(event.timestamp), job: runtimeJobFromLocal(event.job) };
|
|
1412
1485
|
}
|
|
1413
1486
|
function runtimeArtifactResponse(job, artifacts) {
|
|
1414
|
-
const output = runtimeOutput(job.scenarioType, artifacts, job.transcriptionText, job.videoFaceSwapSummary);
|
|
1487
|
+
const output = runtimeOutput(job.scenarioType, artifacts, job.transcriptionText, job.videoFaceSwapSummary, job.transcription, job.audioSeparation, job.textAnnotation);
|
|
1415
1488
|
return { jobId: job.jobId, artifacts, traceId: job.traceId, output };
|
|
1416
1489
|
}
|
|
1417
|
-
function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary) {
|
|
1490
|
+
function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary, transcription, audioSeparation, textAnnotation) {
|
|
1418
1491
|
switch (type) {
|
|
1419
1492
|
case 'video-face-swap': return videoFaceSwapSummary ? { output: { oneofKind: 'videoFaceSwap', videoFaceSwap: { artifacts, summary: { ...videoFaceSwapSummary, durationUs: String(videoFaceSwapSummary.durationUs) } } } } : undefined;
|
|
1420
1493
|
case 'image-face-swap': return { output: { oneofKind: 'imageFaceSwap', imageFaceSwap: { artifacts } } };
|
|
@@ -1422,16 +1495,18 @@ function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary)
|
|
|
1422
1495
|
case 'video-generate': return { output: { oneofKind: 'videoGenerate', videoGenerate: { artifacts } } };
|
|
1423
1496
|
case 'speech-synthesize': return { output: { oneofKind: 'speechSynthesize', speechSynthesize: { artifacts } } };
|
|
1424
1497
|
case 'speech-transcribe': {
|
|
1425
|
-
if (!transcriptionText.trim() || utf8Length(transcriptionText) >
|
|
1498
|
+
if ((!transcriptionText.trim() && transcription?.status !== 'no-speech') || utf8Length(transcriptionText) > (1 << 20))
|
|
1426
1499
|
localAppProjectionError('speech transcription text');
|
|
1427
|
-
return { output: { oneofKind: 'speechTranscribe', speechTranscribe: { text: transcriptionText, artifacts } } };
|
|
1500
|
+
return { output: { oneofKind: 'speechTranscribe', speechTranscribe: { text: transcriptionText, artifacts, transcription: runtimeTranscriptionFromLocal(transcription) } } };
|
|
1428
1501
|
}
|
|
1502
|
+
case 'text-annotate': return { output: { oneofKind: 'textAnnotation', textAnnotation: runtimeAnnotationFromLocal(textAnnotation) } };
|
|
1503
|
+
case 'audio-separate': return { output: { oneofKind: 'audioSeparate', audioSeparate: { artifacts, separation: audioSeparation } } };
|
|
1429
1504
|
case 'music-generate': return { output: { oneofKind: 'musicGenerate', musicGenerate: { artifacts } } };
|
|
1430
1505
|
default: return undefined;
|
|
1431
1506
|
}
|
|
1432
1507
|
}
|
|
1433
1508
|
function runtimeScenarioType(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];
|
|
1509
|
+
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, 'text-annotate': ScenarioType.TEXT_ANNOTATE, 'audio-separate': ScenarioType.AUDIO_SEPARATE, 'voice-create': ScenarioType.VOICE_CREATE, 'music-generate': ScenarioType.MUSIC_GENERATE, 'world-generate': ScenarioType.WORLD_GENERATE })[type];
|
|
1435
1510
|
}
|
|
1436
1511
|
function runtimeJobStatus(status) {
|
|
1437
1512
|
return ({ submitted: ScenarioJobStatus.SUBMITTED, queued: ScenarioJobStatus.QUEUED, running: ScenarioJobStatus.RUNNING, completed: ScenarioJobStatus.COMPLETED, failed: ScenarioJobStatus.FAILED, canceled: ScenarioJobStatus.CANCELED, timeout: ScenarioJobStatus.TIMEOUT })[status];
|
|
@@ -1599,9 +1674,14 @@ function optionalProjectionText(value, field, maximum) {
|
|
|
1599
1674
|
return value;
|
|
1600
1675
|
}
|
|
1601
1676
|
function boundedProjectionContent(value, field, maximum) {
|
|
1602
|
-
|
|
1677
|
+
const text = optionalProjectionContent(value, field, maximum);
|
|
1678
|
+
if (!text)
|
|
1679
|
+
localAppProjectionError(field);
|
|
1680
|
+
return text;
|
|
1681
|
+
}
|
|
1682
|
+
function optionalProjectionContent(value, field, maximum) {
|
|
1683
|
+
if (typeof value !== 'string' || utf8Length(value) > maximum || value.includes('\0'))
|
|
1603
1684
|
localAppProjectionError(field);
|
|
1604
|
-
}
|
|
1605
1685
|
return value;
|
|
1606
1686
|
}
|
|
1607
1687
|
function mimeProjection(value) {
|
|
@@ -1625,4 +1705,15 @@ function invalidAIInput(reason) {
|
|
|
1625
1705
|
function adapterInputError(reason) {
|
|
1626
1706
|
return localAppError(`Runtime Scenario Job cannot use the Local App carrier: ${reason}.`, 'SDK_LOCAL_APP_INPUT_INVALID', 'use_admitted_local_app_scenario_fields');
|
|
1627
1707
|
}
|
|
1708
|
+
function localTranscriptionFromRuntime(value) {
|
|
1709
|
+
const status = value.status === SpeechTranscriptStatus.TRANSCRIBED ? 'transcribed' : value.status === SpeechTranscriptStatus.NO_SPEECH ? 'no-speech' : '';
|
|
1710
|
+
return validateNimiLocalAppSpeechTranscript({ status, text: value.text, language: value.language, words: value.words.map((word) => ({ ...word })) });
|
|
1711
|
+
}
|
|
1712
|
+
function runtimeTranscriptionFromLocal(value) {
|
|
1713
|
+
return value ? { status: value.status === 'transcribed' ? SpeechTranscriptStatus.TRANSCRIBED : SpeechTranscriptStatus.NO_SPEECH, text: value.text, language: value.language, words: value.words.map((word) => ({ ...word })) } : undefined;
|
|
1714
|
+
}
|
|
1715
|
+
function runtimeAnnotationFromLocal(value) {
|
|
1716
|
+
return value ? { documents: value.documents.map((doc) => ({ text: doc.text, language: doc.language,
|
|
1717
|
+
tokens: doc.tokens.map((token) => ({ ...token })), sentences: doc.sentences.map((sentence) => ({ ...sentence })) })) } : undefined;
|
|
1718
|
+
}
|
|
1628
1719
|
//# sourceMappingURL=local-app-runtime-platform-ai.js.map
|