@nimiplatform/sdk 0.13.0 → 0.21.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 +462 -0
- package/README.md +438 -17
- package/dist/core/ai/capability-configuration.d.ts +18 -0
- package/dist/core/ai/capability-configuration.d.ts.map +1 -1
- package/dist/core/ai/capability-configuration.js +39 -0
- package/dist/core/ai/capability-configuration.js.map +1 -1
- package/dist/core/ai/embeddings.d.ts +5 -0
- package/dist/core/ai/embeddings.d.ts.map +1 -1
- package/dist/core/ai/embeddings.js +30 -4
- package/dist/core/ai/embeddings.js.map +1 -1
- package/dist/core/ai/index.d.ts +4 -0
- package/dist/core/ai/index.d.ts.map +1 -1
- package/dist/core/ai/index.js +3 -0
- package/dist/core/ai/index.js.map +1 -1
- package/dist/core/ai/local-app-model.d.ts +15 -4
- package/dist/core/ai/local-app-model.d.ts.map +1 -1
- package/dist/core/ai/local-app-model.js +58 -18
- package/dist/core/ai/local-app-model.js.map +1 -1
- package/dist/core/ai/music-input-wire.d.ts +4 -0
- package/dist/core/ai/music-input-wire.d.ts.map +1 -0
- package/dist/core/ai/music-input-wire.js +9 -0
- package/dist/core/ai/music-input-wire.js.map +1 -0
- package/dist/core/ai/music-input.d.ts +44 -0
- package/dist/core/ai/music-input.d.ts.map +1 -0
- package/dist/core/ai/music-input.js +69 -0
- package/dist/core/ai/music-input.js.map +1 -0
- package/dist/core/ai/reasoning.d.ts +32 -0
- package/dist/core/ai/reasoning.d.ts.map +1 -0
- package/dist/core/ai/reasoning.js +74 -0
- package/dist/core/ai/reasoning.js.map +1 -0
- package/dist/core/ai/runtime-model.d.ts +2 -19
- package/dist/core/ai/runtime-model.d.ts.map +1 -1
- package/dist/core/ai/runtime-model.js +3 -47
- package/dist/core/ai/runtime-model.js.map +1 -1
- package/dist/core/ai/speech-input.d.ts +9 -0
- package/dist/core/ai/speech-input.d.ts.map +1 -0
- package/dist/core/ai/speech-input.js +16 -0
- package/dist/core/ai/speech-input.js.map +1 -0
- package/dist/core/ai/text-runner.js +11 -4
- package/dist/core/ai/text-runner.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/desktop-open.d.ts +4 -1
- package/dist/core/app/desktop-open.d.ts.map +1 -1
- package/dist/core/app/desktop-open.js +5 -1
- package/dist/core/app/desktop-open.js.map +1 -1
- package/dist/core/app/index.d.ts +34 -3
- package/dist/core/app/index.d.ts.map +1 -1
- package/dist/core/app/index.js +21 -0
- package/dist/core/app/index.js.map +1 -1
- package/dist/core/app/local-app-agent-introduction.d.ts +30 -0
- package/dist/core/app/local-app-agent-introduction.d.ts.map +1 -0
- package/dist/core/app/local-app-agent-introduction.js +64 -0
- package/dist/core/app/local-app-agent-introduction.js.map +1 -0
- package/dist/core/app/local-app-agent-work-input.d.ts +24 -0
- package/dist/core/app/local-app-agent-work-input.d.ts.map +1 -0
- package/dist/core/app/local-app-agent-work-input.js +50 -0
- package/dist/core/app/local-app-agent-work-input.js.map +1 -0
- package/dist/core/app/local-app-audio-separation.d.ts +15 -0
- package/dist/core/app/local-app-audio-separation.d.ts.map +1 -0
- package/dist/core/app/local-app-audio-separation.js +92 -0
- package/dist/core/app/local-app-audio-separation.js.map +1 -0
- package/dist/core/app/local-app-bytes.d.ts +10 -0
- package/dist/core/app/local-app-bytes.d.ts.map +1 -0
- package/dist/core/app/local-app-bytes.js +27 -0
- package/dist/core/app/local-app-bytes.js.map +1 -0
- package/dist/core/app/local-app-music-transcription.d.ts +43 -0
- package/dist/core/app/local-app-music-transcription.d.ts.map +1 -0
- package/dist/core/app/local-app-music-transcription.js +94 -0
- package/dist/core/app/local-app-music-transcription.js.map +1 -0
- package/dist/core/app/local-app-music.d.ts +50 -0
- package/dist/core/app/local-app-music.d.ts.map +1 -0
- package/dist/core/app/local-app-music.js +135 -0
- package/dist/core/app/local-app-music.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-activity-view.d.ts +59 -0
- package/dist/core/app/local-app-runtime-platform-activity-view.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-activity-view.js +283 -0
- package/dist/core/app/local-app-runtime-platform-activity-view.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-activity.d.ts +219 -0
- package/dist/core/app/local-app-runtime-platform-activity.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-activity.js +749 -0
- package/dist/core/app/local-app-runtime-platform-activity.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-agent-references.d.ts +4 -0
- package/dist/core/app/local-app-runtime-platform-agent-references.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-agent-references.js +21 -9
- package/dist/core/app/local-app-runtime-platform-agent-references.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-agent-work.d.ts +88 -0
- package/dist/core/app/local-app-runtime-platform-agent-work.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-agent-work.js +165 -0
- package/dist/core/app/local-app-runtime-platform-agent-work.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 +62 -1
- 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 +172 -34
- package/dist/core/app/local-app-runtime-platform-ai.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai.js +805 -112
- package/dist/core/app/local-app-runtime-platform-ai.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-assets.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-assets.js +37 -12
- package/dist/core/app/local-app-runtime-platform-assets.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-configure.d.ts +1 -1
- package/dist/core/app/local-app-runtime-platform-configure.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-configure.js +10 -10
- package/dist/core/app/local-app-runtime-platform-configure.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-conversation.d.ts +7 -4
- package/dist/core/app/local-app-runtime-platform-conversation.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-conversation.js +15 -10
- package/dist/core/app/local-app-runtime-platform-conversation.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-direct-agent-work.d.ts +5 -0
- package/dist/core/app/local-app-runtime-platform-direct-agent-work.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-direct-agent-work.js +38 -0
- package/dist/core/app/local-app-runtime-platform-direct-agent-work.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-direct-conversation.js +6 -6
- package/dist/core/app/local-app-runtime-platform-direct-conversation.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-integration.d.ts +128 -0
- package/dist/core/app/local-app-runtime-platform-integration.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-integration.js +263 -0
- package/dist/core/app/local-app-runtime-platform-integration.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-validation.d.ts +2 -0
- package/dist/core/app/local-app-runtime-platform-validation.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-validation.js +50 -3
- package/dist/core/app/local-app-runtime-platform-validation.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-vision.d.ts +1 -1
- package/dist/core/app/local-app-runtime-platform-vision.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-vision.js +5 -5
- package/dist/core/app/local-app-runtime-platform-vision.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform.d.ts +19 -15
- package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform.js +17 -6
- package/dist/core/app/local-app-runtime-platform.js.map +1 -1
- package/dist/core/app/local-app-speaker-embedding.d.ts +6 -0
- package/dist/core/app/local-app-speaker-embedding.d.ts.map +1 -0
- package/dist/core/app/local-app-speaker-embedding.js +14 -0
- package/dist/core/app/local-app-speaker-embedding.js.map +1 -0
- 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-decision.d.ts +114 -0
- package/dist/core/app/local-app-text-decision.d.ts.map +1 -0
- package/dist/core/app/local-app-text-decision.js +444 -0
- package/dist/core/app/local-app-text-decision.js.map +1 -0
- package/dist/core/app/local-app-text.d.ts +7 -1
- package/dist/core/app/local-app-text.d.ts.map +1 -1
- package/dist/core/app/local-app-text.js +16 -15
- package/dist/core/app/local-app-text.js.map +1 -1
- package/dist/core/app/local-app-transcription.d.ts +23 -0
- package/dist/core/app/local-app-transcription.d.ts.map +1 -0
- package/dist/core/app/local-app-transcription.js +48 -0
- package/dist/core/app/local-app-transcription.js.map +1 -0
- package/dist/core/app/local-app-voice-convert.d.ts +61 -0
- package/dist/core/app/local-app-voice-convert.d.ts.map +1 -0
- package/dist/core/app/local-app-voice-convert.js +133 -0
- package/dist/core/app/local-app-voice-convert.js.map +1 -0
- package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts +2 -2
- package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts.map +1 -1
- package/dist/core/app/runtime-account-realm-source-readiness.generated.js +5 -3
- package/dist/core/app/runtime-account-realm-source-readiness.generated.js.map +1 -1
- package/dist/core/text-stream-cleanup.d.ts +3 -0
- package/dist/core/text-stream-cleanup.d.ts.map +1 -0
- package/dist/core/text-stream-cleanup.js +19 -0
- package/dist/core/text-stream-cleanup.js.map +1 -0
- package/dist/core-generated/realm-client.d.ts.map +1 -1
- package/dist/core-generated/realm-client.js +10 -4
- package/dist/core-generated/realm-client.js.map +1 -1
- package/dist/core-generated/realm-typed-client.d.ts +159 -34
- package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
- package/dist/core-generated/realm-typed-client.js +81 -8
- 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 +312 -0
- package/dist/core-generated/runtime-client.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts +21 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/account.js +41 -5
- package/dist/core-generated/runtime-protobuf/runtime/v1/account.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts +158 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js +299 -2
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts +5 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js +4 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.d.ts +625 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.d.ts.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.js +1369 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.js.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts +2274 -134
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js +5178 -1218
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts +168 -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 +326 -5
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.d.ts +859 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.d.ts.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.js +1663 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.js.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/auth.d.ts +20 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/auth.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/auth.js +38 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/auth.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts +579 -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 +1056 -12
- 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 +161 -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 +160 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts +43 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js +88 -4
- package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/development.d.ts +53 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/development.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/development.js +118 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/development.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/integration.d.ts +1293 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/integration.d.ts.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/integration.js +2898 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/integration.js.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.d.ts +200 -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 +249 -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-protobuf/runtime/v1/local_runtime_recommendation.d.ts +8 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.js +9 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts +69 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js +120 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js.map +1 -1
- package/dist/core-generated/runtime-public-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-public-client.js +296 -8
- 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 +37 -1
- package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
- package/dist/core-generated/runtime-public-wire-codecs.d.ts +44 -5
- package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
- package/dist/core-generated/runtime-public-wire-codecs.js +44 -5
- 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 +39 -0
- package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
- package/dist/core-generated/runtime-typed-client.d.ts +66 -16
- package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-typed-client.js +398 -3
- package/dist/core-generated/runtime-typed-client.js.map +1 -1
- package/dist/core-generated/runtime-wire-codecs.d.ts +47 -5
- package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
- package/dist/core-generated/runtime-wire-codecs.js +47 -5
- package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
- package/dist/features/generation/index.d.ts +16 -2
- package/dist/features/generation/index.d.ts.map +1 -1
- package/dist/features/generation/index.js +26 -3
- package/dist/features/generation/index.js.map +1 -1
- package/dist/features/generation/media-params.d.ts +0 -3
- package/dist/features/generation/media-params.d.ts.map +1 -1
- package/dist/features/generation/media-params.js +8 -6
- package/dist/features/generation/media-params.js.map +1 -1
- package/dist/features/generation/runtime-generation-build.d.ts +0 -1
- package/dist/features/generation/runtime-generation-build.d.ts.map +1 -1
- package/dist/features/generation/runtime-generation-build.js +6 -1
- package/dist/features/generation/runtime-generation-build.js.map +1 -1
- package/dist/features/generation/runtime-image-generation.d.ts +5 -1
- package/dist/features/generation/runtime-image-generation.d.ts.map +1 -1
- package/dist/features/generation/runtime-image-generation.js +4 -0
- package/dist/features/generation/runtime-image-generation.js.map +1 -1
- package/dist/features/generation/runtime-job-builders.d.ts +0 -1
- package/dist/features/generation/runtime-job-builders.d.ts.map +1 -1
- package/dist/features/generation/runtime-job-builders.js +8 -10
- package/dist/features/generation/runtime-job-builders.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 +3 -2
- package/dist/realm/index.js.map +1 -1
- package/dist/runtime/chatgpt-plan.d.ts +7 -0
- package/dist/runtime/chatgpt-plan.d.ts.map +1 -0
- package/dist/runtime/chatgpt-plan.js +15 -0
- package/dist/runtime/chatgpt-plan.js.map +1 -0
- package/dist/runtime/config-projections.d.ts +2 -0
- package/dist/runtime/config-projections.d.ts.map +1 -1
- package/dist/runtime/config-projections.js +33 -1
- package/dist/runtime/config-projections.js.map +1 -1
- package/dist/runtime/connector-auth-acquisition-client.d.ts +3 -6
- package/dist/runtime/connector-auth-acquisition-client.d.ts.map +1 -1
- package/dist/runtime/connector-auth-acquisition-client.js +18 -11
- package/dist/runtime/connector-auth-acquisition-client.js.map +1 -1
- package/dist/runtime/connector-auth-acquisition-profiles.generated.d.ts +10 -11
- package/dist/runtime/connector-auth-acquisition-profiles.generated.d.ts.map +1 -1
- package/dist/runtime/connector-auth-acquisition-profiles.generated.js +13 -14
- package/dist/runtime/connector-auth-acquisition-profiles.generated.js.map +1 -1
- package/dist/runtime/connector-auth-acquisition.d.ts +26 -19
- package/dist/runtime/connector-auth-acquisition.d.ts.map +1 -1
- package/dist/runtime/connector-auth-acquisition.js +352 -269
- package/dist/runtime/connector-auth-acquisition.js.map +1 -1
- package/dist/runtime/connector-auth-profiles.generated.d.ts +1 -1
- package/dist/runtime/connector-auth-profiles.generated.d.ts.map +1 -1
- package/dist/runtime/connector-auth-profiles.generated.js +4 -4
- package/dist/runtime/connector-auth-profiles.generated.js.map +1 -1
- package/dist/runtime/connector-inventory.d.ts +11 -2
- package/dist/runtime/connector-inventory.d.ts.map +1 -1
- package/dist/runtime/connector-inventory.js +13 -4
- package/dist/runtime/connector-inventory.js.map +1 -1
- package/dist/runtime/desktop-audit.js +4 -1
- package/dist/runtime/desktop-audit.js.map +1 -1
- package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +130 -2
- package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
- package/dist/runtime/first-party-protected-runtime-profiles.generated.js +34 -2
- package/dist/runtime/first-party-protected-runtime-profiles.generated.js.map +1 -1
- package/dist/runtime/generated.d.ts +2 -2
- package/dist/runtime/generated.d.ts.map +1 -1
- package/dist/runtime/generated.js +1 -1
- package/dist/runtime/generated.js.map +1 -1
- package/dist/runtime/host.d.ts +3 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/host.js +4 -0
- package/dist/runtime/host.js.map +1 -1
- package/dist/runtime/index.d.ts +3 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +3 -1
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/machine-loadouts.d.ts +33 -1
- package/dist/runtime/machine-loadouts.d.ts.map +1 -1
- package/dist/runtime/machine-loadouts.js +39 -2
- package/dist/runtime/machine-loadouts.js.map +1 -1
- package/dist/runtime/node-grpc-errors.js +3 -3
- package/dist/runtime/node-grpc-errors.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/product-control-projection.d.ts.map +1 -1
- package/dist/runtime/product-control-projection.js +11 -2
- package/dist/runtime/product-control-projection.js.map +1 -1
- package/dist/runtime/product-control-types.d.ts +13 -2
- package/dist/runtime/product-control-types.d.ts.map +1 -1
- package/dist/runtime/product-control-types.js.map +1 -1
- package/dist/runtime/reason-messages.d.ts +3 -0
- package/dist/runtime/reason-messages.d.ts.map +1 -1
- package/dist/runtime/reason-messages.js +11 -2
- package/dist/runtime/reason-messages.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 +21 -17
- package/dist/runtime/runtime-local-environment-client-projections.js.map +1 -1
- package/dist/runtime/runtime-local-environment-client-types.d.ts +50 -19
- package/dist/runtime/runtime-local-environment-client-types.d.ts.map +1 -1
- package/dist/runtime/runtime-local-environment-client-values.d.ts +3 -1
- package/dist/runtime/runtime-local-environment-client-values.d.ts.map +1 -1
- package/dist/runtime/runtime-local-environment-client-values.js +43 -0
- package/dist/runtime/runtime-local-environment-client-values.js.map +1 -1
- package/dist/runtime/runtime-local-environment-client.d.ts.map +1 -1
- package/dist/runtime/runtime-local-environment-client.js +12 -3
- package/dist/runtime/runtime-local-environment-client.js.map +1 -1
- package/dist/runtime/runtime-local-recommendation-types.d.ts +3 -0
- package/dist/runtime/runtime-local-recommendation-types.d.ts.map +1 -1
- package/dist/runtime/runtime-local-recommendation.d.ts.map +1 -1
- package/dist/runtime/runtime-local-recommendation.js +1 -0
- package/dist/runtime/runtime-local-recommendation.js.map +1 -1
- package/dist/runtime/scenario-jobs.d.ts +23 -1
- package/dist/runtime/scenario-jobs.d.ts.map +1 -1
- package/dist/runtime/scenario-jobs.js +227 -264
- package/dist/runtime/scenario-jobs.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 +6 -0
- package/dist/runtime/shared-local-agent-ai-config.js.map +1 -1
- package/dist/runtime/wire-types/agent-participation-enums.d.ts +2 -1
- package/dist/runtime/wire-types/agent-participation-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/agent-participation-enums.js +2 -1
- package/dist/runtime/wire-types/agent-participation-enums.js.map +1 -1
- package/dist/runtime/wire-types/agent-participation-types.d.ts +4 -2
- package/dist/runtime/wire-types/agent-participation-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts +119 -3
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.js +136 -0
- package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-types.d.ts +8 -6
- package/dist/runtime/wire-types/ai-scenario-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/identity-app-enums.d.ts +47 -0
- package/dist/runtime/wire-types/identity-app-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/identity-app-enums.js +55 -0
- package/dist/runtime/wire-types/identity-app-enums.js.map +1 -1
- package/dist/runtime/wire-types/identity-app-types.d.ts +6 -4
- package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/local-memory-enums.d.ts +31 -1
- package/dist/runtime/wire-types/local-memory-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/local-memory-enums.js +34 -0
- package/dist/runtime/wire-types/local-memory-enums.js.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.d.ts +30 -1
- package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.js +29 -0
- package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +2 -2
- package/dist/types/errors.js.map +1 -1
- package/dist/types/reason-code.d.ts +2 -0
- package/dist/types/reason-code.d.ts.map +1 -1
- package/dist/types/reason-code.js +2 -0
- package/dist/types/reason-code.js.map +1 -1
- package/package.json +5 -5
|
@@ -1,7 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { validateNimiLocalAppVoiceConvertSpec, validateNimiLocalAppVoiceConversion, runtimeVoiceConvertSpec, localVoiceConvertSpec, localVoiceConversion, runtimeVoiceConversion } from './local-app-voice-convert.js';
|
|
2
|
+
import { validateNimiLocalAppMusicTranscribeSpec, validateNimiLocalAppMusicTranscription, runtimeMusicTranscribeSpec, localMusicTranscribeSpec, localMusicTranscription, runtimeMusicTranscription } from './local-app-music-transcription.js';
|
|
3
|
+
import { validateNimiLocalAppMusicGenerateSpec, validateNimiLocalAppMusicGeneration, runtimeMusicGenerateSpec, localMusicGenerateSpec, localMusicGeneration, runtimeMusicGeneration } from './local-app-music.js';
|
|
4
|
+
import { validateNimiLocalAppTextAnnotationResult } from './local-app-text-annotation.js';
|
|
5
|
+
import { validateNimiLocalAppSpeechTranscript } from './local-app-transcription.js';
|
|
6
|
+
import { validateNimiLocalAppSpeakerEmbedding } from './local-app-speaker-embedding.js';
|
|
7
|
+
import { validateNimiLocalAppAudioSeparation, localAudioSeparation, runtimeAudioSeparation } from './local-app-audio-separation.js';
|
|
8
|
+
import { prepareNimiLocalAppTextDecideSpec, validateNimiLocalAppTextDecideOutput, runtimeTextDecideSpec, localTextDecideOutputFromRuntime, } from './local-app-text-decision.js';
|
|
9
|
+
import { ReasonCode, createNimiError } from '../../types/index.js';
|
|
10
|
+
import { withTextStreamCleanupFailure } from '../text-stream-cleanup.js';
|
|
11
|
+
import { TextEmbedPurpose } from '../../core-generated/runtime-protobuf/runtime/v1/ai.js';
|
|
12
|
+
import { copyNimiLocalAppBytes, exactNimiLocalAppBytes, isNimiLocalAppByteView } from './local-app-bytes.js';
|
|
13
|
+
import { CanonicalChannelMode, ChatContentPartType, ExecutionMode, FaceSwapNoFacePolicy, FinishReason, ResponseFormatKind, ToolChoiceMode, ReasonCode as RuntimeReasonCode, RoutePolicy, ScenarioJobEventType, ScenarioJobStatus, ScenarioType, SpeechTimingMode, SpeechTranscriptStatus, SpeechDiarizationStatus, VideoContentRole, VideoContentType, VideoMode, VoiceAssetStatus, VoiceCreationSource, VoiceReferenceKind, VisionLocateGeometry, WorldImageProjection, } from '../../core-generated/runtime-typed-client.js';
|
|
2
14
|
import { toRuntimeMessages, toRuntimeTools, toRuntimeStruct, toNimiToolCall, toNimiTextOutputItems } from '../ai/runtime-model-text-projection.js';
|
|
15
|
+
import { toRuntimeReasoningConfig } from '../ai/reasoning.js';
|
|
3
16
|
import { validateLocalAppTextInput, projectLocalAppToolCall, projectLocalAppTextItems, projectLocalAppContinuity, modelTextOutputToLocalApp, localAppTextOutputToModel, } from './local-app-text.js';
|
|
4
|
-
import { asRecord, assertExactKeys, assertExactProjectionKeys, assertNoAuthorityMaterial, assertSafeProjection, localAppError, localAppProjectionError, projectionText, requireText, } from './local-app-runtime-platform-validation.js';
|
|
17
|
+
import { asRecord, assertExactKeys, assertExactProjectionKeys, assertNoAuthorityMaterial, assertSafeProjection, projectLocalAppSpeechAlignment, localAppError, localAppProjectionError, projectionText, requireText, } from './local-app-runtime-platform-validation.js';
|
|
5
18
|
import { projectVisionLocateResult, localVisionLocateFromRuntime, runtimeVisionLocateFromLocal, localLocateGeometry, projectLocalExecutionInterruption, localInterruptionFromRuntime, runtimeInterruptionFromLocal, } from './local-app-runtime-platform-vision.js';
|
|
6
19
|
const MAX_RESULT_BYTES = 256 * 1024;
|
|
7
20
|
const MAX_ARTIFACT_BYTES = 32 * 1024 * 1024;
|
|
@@ -22,6 +35,11 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
|
|
|
22
35
|
let sequence = 0n;
|
|
23
36
|
let terminal = false;
|
|
24
37
|
let hasPrimary = false;
|
|
38
|
+
let lastIndex = -1;
|
|
39
|
+
let lastKind = '';
|
|
40
|
+
let summaryOpen = false;
|
|
41
|
+
let failed = false;
|
|
42
|
+
let primaryFailure;
|
|
25
43
|
const toolIds = new Set();
|
|
26
44
|
try {
|
|
27
45
|
for await (const event of stream) {
|
|
@@ -29,6 +47,23 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
|
|
|
29
47
|
break;
|
|
30
48
|
if (terminal || BigInt(event.sequence) !== ++sequence)
|
|
31
49
|
localAppProjectionError('text-turn event sequence');
|
|
50
|
+
if ('itemIndex' in event) {
|
|
51
|
+
if (event.itemIndex === lastIndex) {
|
|
52
|
+
if (!(event.type === 'delta' && lastKind === 'delta') && !(event.type === 'reasoning-summary' && lastKind === 'reasoning-summary' && summaryOpen))
|
|
53
|
+
localAppProjectionError('text-turn item sequence');
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (event.itemIndex !== lastIndex + 1 || summaryOpen)
|
|
57
|
+
localAppProjectionError('text-turn item sequence');
|
|
58
|
+
lastIndex = event.itemIndex;
|
|
59
|
+
lastKind = event.type;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (event.type === 'reasoning-summary') {
|
|
63
|
+
if (input.reasoning?.presentation !== 'summary')
|
|
64
|
+
localAppProjectionError('unrequested reasoning summary');
|
|
65
|
+
summaryOpen = !event.itemCompleted;
|
|
66
|
+
}
|
|
32
67
|
if (event.type === 'delta')
|
|
33
68
|
hasPrimary = true;
|
|
34
69
|
if (event.type === 'tool-call') {
|
|
@@ -37,28 +72,64 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
|
|
|
37
72
|
localAppProjectionError('duplicate text tool call');
|
|
38
73
|
toolIds.add(event.toolCall.id);
|
|
39
74
|
}
|
|
40
|
-
if (event.type === 'completed' && !hasPrimary)
|
|
41
|
-
localAppProjectionError('missing primary text output');
|
|
75
|
+
if (event.type === 'completed' && (!hasPrimary || summaryOpen))
|
|
76
|
+
localAppProjectionError('missing primary text output or incomplete summary');
|
|
42
77
|
terminal = event.type === 'completed' || event.type === 'failed';
|
|
43
78
|
yield event;
|
|
44
79
|
}
|
|
45
80
|
if (!terminal && !canceled)
|
|
46
81
|
localAppProjectionError('text-turn missing terminal event');
|
|
47
82
|
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
failed = true;
|
|
85
|
+
primaryFailure = error;
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
48
88
|
finally {
|
|
49
|
-
|
|
89
|
+
try {
|
|
90
|
+
await cancel();
|
|
91
|
+
}
|
|
92
|
+
catch (cleanupError) {
|
|
93
|
+
if (failed)
|
|
94
|
+
throw withTextStreamCleanupFailure(primaryFailure, cleanupError);
|
|
95
|
+
throw cleanupError;
|
|
96
|
+
}
|
|
50
97
|
}
|
|
51
98
|
},
|
|
52
99
|
cancel,
|
|
53
100
|
});
|
|
54
101
|
},
|
|
55
102
|
}),
|
|
103
|
+
// @nimi-authority: rule.nimi.sdks.feature-clients.scenario-execute-call-control
|
|
56
104
|
scenario: Object.freeze({
|
|
57
|
-
execute: async (spec) =>
|
|
105
|
+
execute: async (spec, options) => {
|
|
106
|
+
const call = validateScenarioExecuteOptions(options);
|
|
107
|
+
if (call.signal?.aborted)
|
|
108
|
+
throw scenarioExecuteCanceledError();
|
|
109
|
+
const prepared = prepareScenarioExecuteSpec(spec);
|
|
110
|
+
return runScenarioExecuteCall(call, (shellOptions) => shell.scenario.execute(prepared.shellSpec, shellOptions), (value) => {
|
|
111
|
+
const projected = projectScenarioExecute(value, prepared.decide);
|
|
112
|
+
if (prepared.shellSpec.type === 'text-generate' && projected.output.type === 'text-generate'
|
|
113
|
+
&& prepared.shellSpec.reasoning?.presentation !== 'summary' && projected.output.items.some((item) => item.type === 'reasoning-summary'))
|
|
114
|
+
localAppProjectionError('unrequested reasoning summary');
|
|
115
|
+
if (prepared.shellSpec.type === 'text-embed') {
|
|
116
|
+
const output = projected.output;
|
|
117
|
+
if (output.type !== 'text-embed')
|
|
118
|
+
localAppProjectionError('text embed output type');
|
|
119
|
+
const dimensions = prepared.shellSpec.dimensions ?? output.vectors[0]?.length;
|
|
120
|
+
if (output.vectors.length !== prepared.shellSpec.inputs.length ||
|
|
121
|
+
output.vectors.some((row) => row.length !== dimensions)) {
|
|
122
|
+
localAppProjectionError('text embed output contract');
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return projected;
|
|
126
|
+
});
|
|
127
|
+
},
|
|
58
128
|
}),
|
|
59
129
|
scenarioJobs: Object.freeze({
|
|
60
|
-
submit: async (spec, options = {}) => projectScenarioJobSubmit(await shell.scenarioJobs.submit(validateScenarioSpec(spec, false), validateScenarioJobSubmitOptions(options))),
|
|
130
|
+
submit: async (spec, options = {}) => projectScenarioJobSubmit(await shell.scenarioJobs.submit(detachScenarioJobSpecBytes(validateScenarioSpec(spec, false)), validateScenarioJobSubmitOptions(options))),
|
|
61
131
|
get: async (jobId) => projectScenarioJobGet(await shell.scenarioJobs.get(boundedIdentifier(jobId, 'jobId'))),
|
|
132
|
+
lookupSubmission: async (clientSubmissionId) => projectScenarioJobGet(await shell.scenarioJobs.get('', validateClientSubmissionId(clientSubmissionId))),
|
|
62
133
|
subscribe: async (jobId) => projectSubscription(await shell.scenarioJobs.subscribe(boundedIdentifier(jobId, 'jobId')), projectScenarioJobEvent),
|
|
63
134
|
cancel: async (jobId, reason = '') => {
|
|
64
135
|
if (typeof reason !== 'string' || reason.trim() !== reason || utf8Length(reason) > 512 || hasControl(reason)) {
|
|
@@ -70,13 +141,8 @@ export function createNimiLocalAppAIConsumptionClient(shell) {
|
|
|
70
141
|
artifacts: Object.freeze({
|
|
71
142
|
read: async (artifactId) => projectArtifactRead(await shell.artifacts.read(boundedIdentifier(artifactId, 'artifactId'))),
|
|
72
143
|
upload: async (input) => {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!(input.bytes instanceof Uint8Array) || input.bytes.byteLength === 0
|
|
76
|
-
|| input.bytes.byteLength > MAX_ARTIFACT_BYTES || !isArtifactUploadMime(input.mimeType)) {
|
|
77
|
-
invalidAIInput('artifact upload is invalid');
|
|
78
|
-
}
|
|
79
|
-
return projectArtifactUpload(await shell.artifacts.upload({ bytes: [...input.bytes], mimeType: input.mimeType }), input.bytes.byteLength, input.mimeType);
|
|
144
|
+
const prepared = prepareArtifactUploadInput(input);
|
|
145
|
+
return projectArtifactUpload(await shell.artifacts.upload(prepared), prepared.bytes?.length, prepared.mimeType, prepared.audioPreparation);
|
|
80
146
|
},
|
|
81
147
|
}),
|
|
82
148
|
voiceAssets,
|
|
@@ -106,8 +172,17 @@ export function createNimiLocalAppAIConsumptionRuntimeClient(runtime) {
|
|
|
106
172
|
},
|
|
107
173
|
},
|
|
108
174
|
scenario: {
|
|
109
|
-
async execute(spec) {
|
|
110
|
-
|
|
175
|
+
async execute(spec, options) {
|
|
176
|
+
// The deadline travels in the request so Runtime owns it; the transport
|
|
177
|
+
// only bounds the call a little beyond it, so Runtime records an elapsed
|
|
178
|
+
// deadline as a timeout and an abort, which cancels at once, as a cancel.
|
|
179
|
+
const request = runtimeExecuteRequest(spec, options?.timeoutMs ?? 0);
|
|
180
|
+
const response = options
|
|
181
|
+
? await runtime.executeLocalAppScenario(request, {
|
|
182
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
183
|
+
...(options.timeoutMs !== undefined ? { timeoutMs: options.timeoutMs + RUNTIME_DEADLINE_GRACE_MS } : {}),
|
|
184
|
+
})
|
|
185
|
+
: await runtime.executeLocalAppScenario(request);
|
|
111
186
|
return projectRuntimeScenarioExecuteResponse(response);
|
|
112
187
|
},
|
|
113
188
|
},
|
|
@@ -115,14 +190,16 @@ export function createNimiLocalAppAIConsumptionRuntimeClient(runtime) {
|
|
|
115
190
|
async submit(spec, options = {}) {
|
|
116
191
|
const response = await runtime.submitLocalAppScenarioJob({
|
|
117
192
|
spec: runtimeLocalJobSpec(spec),
|
|
118
|
-
timeoutMs:
|
|
193
|
+
timeoutMs: 0,
|
|
194
|
+
clientSubmissionId: options.clientSubmissionId ?? '',
|
|
119
195
|
});
|
|
120
196
|
return { job: projectRuntimeLocalJob(requiredRuntimeValue(response.job, 'scenario Job')) };
|
|
121
197
|
},
|
|
122
|
-
async get(jobId) {
|
|
123
|
-
const response = await runtime.getLocalAppScenarioJob({ jobId });
|
|
198
|
+
async get(jobId, clientSubmissionId = '') {
|
|
199
|
+
const response = await runtime.getLocalAppScenarioJob({ jobId, clientSubmissionId });
|
|
124
200
|
return {
|
|
125
201
|
...(response.visionLocate ? { visionLocate: localVisionLocateFromRuntime(response.visionLocate) } : {}),
|
|
202
|
+
...(response.observationIssue ? { observationIssue: { reasonCode: runtimeReasonToken(response.observationIssue.reasonCode), observedAt: plainRuntimeTimestamp(response.observationIssue.observedAt) } } : {}),
|
|
126
203
|
job: projectRuntimeLocalJob(requiredRuntimeValue(response.job, 'scenario Job')),
|
|
127
204
|
asset: response.asset ? projectRuntimeLocalAppVoiceAsset(response.asset) : null,
|
|
128
205
|
voiceReference: response.voiceReference
|
|
@@ -152,30 +229,47 @@ export function createNimiLocalAppAIConsumptionRuntimeClient(runtime) {
|
|
|
152
229
|
async read(artifactId) {
|
|
153
230
|
const response = await runtime.readLocalAppArtifact({ artifactId });
|
|
154
231
|
return {
|
|
155
|
-
bytes:
|
|
232
|
+
bytes: response.bytes,
|
|
156
233
|
mimeType: response.mimeType,
|
|
157
234
|
sizeBytes: runtimeSafeInteger(response.sizeBytes, 'artifact size'),
|
|
158
235
|
};
|
|
159
236
|
},
|
|
160
237
|
async upload(input) {
|
|
161
238
|
const response = await runtime.uploadLocalAppArtifact({
|
|
162
|
-
bytes:
|
|
239
|
+
bytes: input.bytes ?? new Uint8Array(),
|
|
163
240
|
mimeType: input.mimeType,
|
|
241
|
+
appAssetRelativePath: input.source?.kind === 'app-asset' ? input.source.relativePath : '',
|
|
242
|
+
sourceArtifactId: input.source?.kind === 'artifact' ? input.source.artifactId : '',
|
|
243
|
+
audioPreparation: input.audioPreparation ? {
|
|
244
|
+
targetSampleRateHz: input.audioPreparation.targetSampleRateHz ?? 0,
|
|
245
|
+
channelMode: input.audioPreparation.channelMode === 'PRESERVE' ? CanonicalChannelMode.PRESERVE
|
|
246
|
+
: input.audioPreparation.channelMode === 'MONO_TO_STEREO' ? CanonicalChannelMode.MONO_TO_STEREO
|
|
247
|
+
: input.audioPreparation.channelMode === 'STEREO_TO_MONO' ? CanonicalChannelMode.STEREO_TO_MONO
|
|
248
|
+
: CanonicalChannelMode.UNSPECIFIED,
|
|
249
|
+
} : undefined,
|
|
164
250
|
});
|
|
165
251
|
return {
|
|
166
252
|
artifactId: response.artifactId,
|
|
167
253
|
sizeBytes: runtimeSafeInteger(response.sizeBytes, 'artifact size'),
|
|
168
254
|
mimeType: response.mimeType,
|
|
255
|
+
...(response.expiresAt ? { expiresAt: plainRuntimeTimestamp(response.expiresAt) } : {}),
|
|
256
|
+
...(response.audioInfo ? { audioInfo: {
|
|
257
|
+
sampleRateHz: response.audioInfo.sampleRateHz,
|
|
258
|
+
channels: response.audioInfo.channels,
|
|
259
|
+
frameCount: runtimeSafeInteger(response.audioInfo.frameCount, 'audio frames'),
|
|
260
|
+
durationMs: runtimeSafeInteger(response.audioInfo.durationMs, 'audio duration'),
|
|
261
|
+
} } : {}),
|
|
169
262
|
};
|
|
170
263
|
},
|
|
171
264
|
},
|
|
172
265
|
voiceAssets: {
|
|
173
266
|
list: (input) => voiceAssets.list(input),
|
|
267
|
+
delete: (voiceAssetId) => voiceAssets.delete(voiceAssetId),
|
|
174
268
|
},
|
|
175
269
|
});
|
|
176
270
|
}
|
|
177
271
|
export function createNimiLocalAppVoiceAssetsClient(shell) {
|
|
178
|
-
return createNimiLocalAppVoiceAssetsProjector((input) => shell.list(input));
|
|
272
|
+
return createNimiLocalAppVoiceAssetsProjector((input) => shell.list(input), (voiceAssetId) => shell.delete(voiceAssetId));
|
|
179
273
|
}
|
|
180
274
|
export function createNimiLocalAppVoiceAssetsRuntimeClient(runtime) {
|
|
181
275
|
return createNimiLocalAppVoiceAssetsProjector(async (input) => {
|
|
@@ -187,10 +281,16 @@ export function createNimiLocalAppVoiceAssetsRuntimeClient(runtime) {
|
|
|
187
281
|
assets: response.assets.map(projectRuntimeLocalAppVoiceAsset),
|
|
188
282
|
nextPageToken: response.nextPageToken,
|
|
189
283
|
};
|
|
190
|
-
});
|
|
284
|
+
}, (voiceAssetId) => runtime.deleteLocalAppVoiceAsset({ voiceAssetId }));
|
|
191
285
|
}
|
|
192
|
-
function createNimiLocalAppVoiceAssetsProjector(list) {
|
|
286
|
+
function createNimiLocalAppVoiceAssetsProjector(list, remove) {
|
|
193
287
|
return Object.freeze({
|
|
288
|
+
async delete(voiceAssetId) {
|
|
289
|
+
const result = asRecord(await remove(boundedIdentifier(voiceAssetId, 'voiceAssetId')));
|
|
290
|
+
if (!result || Object.keys(result).length !== 1 || result.deleted !== true)
|
|
291
|
+
localAppProjectionError('voice asset deletion was not confirmed');
|
|
292
|
+
return Object.freeze({ deleted: true });
|
|
293
|
+
},
|
|
194
294
|
async list(input = {}) {
|
|
195
295
|
const page = validateVoiceAssetsListInput(input);
|
|
196
296
|
return projectVoiceAssetsList(await list(page));
|
|
@@ -212,10 +312,11 @@ export function createNimiLocalAppRuntimeScenarioJobClient(ai) {
|
|
|
212
312
|
const client = {
|
|
213
313
|
terminalVoiceAssetProjection: 'protected-local',
|
|
214
314
|
async submitScenarioJob(request) {
|
|
315
|
+
if (request.head?.timeoutMs !== undefined && request.head.timeoutMs !== 0) {
|
|
316
|
+
invalidAIInput('Scenario Job business timeout is no longer supported');
|
|
317
|
+
}
|
|
215
318
|
const spec = localJobSpecFromRuntimeRequest(request);
|
|
216
|
-
const result = await ai.scenarioJobs.submit(spec, {
|
|
217
|
-
timeoutMs: boundedInteger(request.head?.timeoutMs ?? 0, 'Scenario Job timeoutMs', 0, 2_147_483_647),
|
|
218
|
-
});
|
|
319
|
+
const result = await ai.scenarioJobs.submit(spec, request.idempotencyKey ? { clientSubmissionId: validateClientSubmissionId(request.idempotencyKey) } : {});
|
|
219
320
|
return {
|
|
220
321
|
job: runtimeJobFromLocal(result.job),
|
|
221
322
|
};
|
|
@@ -225,6 +326,7 @@ export function createNimiLocalAppRuntimeScenarioJobClient(ai) {
|
|
|
225
326
|
const result = await ai.scenarioJobs.get(request.jobId);
|
|
226
327
|
return {
|
|
227
328
|
...(result.visionLocate ? { visionLocate: runtimeVisionLocateFromLocal(result.visionLocate) } : {}),
|
|
329
|
+
...(result.observationIssue ? { observationIssue: { reasonCode: runtimeReasonCode(result.observationIssue.reasonCode), observedAt: runtimeTimestamp(result.observationIssue.observedAt) } } : {}),
|
|
228
330
|
job: runtimeJobFromLocal(result.job),
|
|
229
331
|
asset: result.asset ? runtimeVoiceAssetFromLocal(result.asset) : undefined,
|
|
230
332
|
voiceReference: result.voiceReference ? {
|
|
@@ -241,18 +343,27 @@ export function createNimiLocalAppRuntimeScenarioJobClient(ai) {
|
|
|
241
343
|
const result = await ai.scenarioJobs.cancel(request.jobId, request.reason);
|
|
242
344
|
return { job: runtimeJobFromLocal(result.job) };
|
|
243
345
|
},
|
|
244
|
-
subscribeScenarioJobEvents(request) {
|
|
346
|
+
subscribeScenarioJobEvents(request, options) {
|
|
245
347
|
assertExactKeys(request, ['jobId'], 'local-app Scenario Job subscribe request');
|
|
246
348
|
return {
|
|
247
349
|
async *[Symbol.asyncIterator]() {
|
|
248
350
|
const subscription = await ai.scenarioJobs.subscribe(request.jobId);
|
|
351
|
+
let closing;
|
|
352
|
+
const close = () => closing ??= subscription.cancel();
|
|
353
|
+
const abort = () => { void close().catch(() => undefined); };
|
|
354
|
+
options?.signal?.addEventListener('abort', abort, { once: true });
|
|
355
|
+
if (options?.signal?.aborted)
|
|
356
|
+
abort();
|
|
249
357
|
try {
|
|
250
358
|
for await (const event of subscription) {
|
|
359
|
+
if (options?.signal?.aborted)
|
|
360
|
+
break;
|
|
251
361
|
yield runtimeJobEventFromLocal(event);
|
|
252
362
|
}
|
|
253
363
|
}
|
|
254
364
|
finally {
|
|
255
|
-
|
|
365
|
+
options?.signal?.removeEventListener('abort', abort);
|
|
366
|
+
await close();
|
|
256
367
|
}
|
|
257
368
|
},
|
|
258
369
|
};
|
|
@@ -266,6 +377,19 @@ export function createNimiLocalAppRuntimeScenarioJobClient(ai) {
|
|
|
266
377
|
};
|
|
267
378
|
return Object.freeze(client);
|
|
268
379
|
}
|
|
380
|
+
// The shell receives a detached exact byte range, so IPC carries neither a
|
|
381
|
+
// larger backing buffer nor later caller writes. Each Job spec has at most one
|
|
382
|
+
// inline audio field.
|
|
383
|
+
function detachScenarioJobSpecBytes(spec) {
|
|
384
|
+
const record = spec;
|
|
385
|
+
for (const key of ['audioSource', 'referenceAudio']) {
|
|
386
|
+
const source = asRecord(record[key]);
|
|
387
|
+
if (source?.type === 'bytes' && isNimiLocalAppByteView(source.bytes)) {
|
|
388
|
+
return { ...record, [key]: { type: 'bytes', bytes: copyNimiLocalAppBytes(source.bytes) } };
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return spec;
|
|
392
|
+
}
|
|
269
393
|
function validateScenarioSpec(spec, execute) {
|
|
270
394
|
const record = asRecord(spec);
|
|
271
395
|
if (!record || typeof record.type !== 'string')
|
|
@@ -276,6 +400,14 @@ function validateScenarioSpec(spec, execute) {
|
|
|
276
400
|
const { type: _type, ...input } = record;
|
|
277
401
|
return Object.freeze({ type: 'text-generate', ...validateLocalAppTextInput(input) });
|
|
278
402
|
}
|
|
403
|
+
if (record.type === 'text-decide') {
|
|
404
|
+
// App JSON state is product content: its keys are never read as authority
|
|
405
|
+
// fields. The closed envelope and exact bounds are checked instead.
|
|
406
|
+
if (!execute)
|
|
407
|
+
invalidAIInput('text-decide is a synchronous Scenario, not an async Job');
|
|
408
|
+
prepareNimiLocalAppTextDecideSpec(record);
|
|
409
|
+
return spec;
|
|
410
|
+
}
|
|
279
411
|
assertNoAuthorityMaterial(record);
|
|
280
412
|
switch (record.type) {
|
|
281
413
|
// @nimi-authority: rule.nimi.runtime.ai-provider.face-swap-video-job
|
|
@@ -308,13 +440,23 @@ function validateScenarioSpec(spec, execute) {
|
|
|
308
440
|
case 'text-embed':
|
|
309
441
|
if (!execute)
|
|
310
442
|
invalidAIInput('text-embed is not an async Job spec');
|
|
311
|
-
assertExactKeys(record, ['type', 'inputs'], 'text embed spec');
|
|
443
|
+
assertExactKeys(record, ['type', 'inputs', 'dimensions', 'purpose'], 'text embed spec');
|
|
444
|
+
if (record.purpose !== undefined && record.purpose !== 'retrieval-document' && record.purpose !== 'retrieval-query')
|
|
445
|
+
invalidAIInput('text embed purpose');
|
|
446
|
+
optionalBoundedInteger(record.dimensions, 'text embed dimensions', 1, 0xffff_ffff);
|
|
312
447
|
if (!Array.isArray(record.inputs) || record.inputs.length === 0 || record.inputs.length > 16) {
|
|
313
448
|
invalidAIInput('text embed inputs are invalid');
|
|
314
449
|
}
|
|
315
450
|
record.inputs.forEach((value, index) => boundedContent(value, `text embed input ${index}`, 32 * 1024));
|
|
316
|
-
|
|
451
|
+
return Object.freeze({
|
|
452
|
+
type: 'text-embed',
|
|
453
|
+
inputs: Object.freeze([...record.inputs]),
|
|
454
|
+
...(record.dimensions !== undefined ? { dimensions: record.dimensions } : {}),
|
|
455
|
+
...(record.purpose !== undefined ? { purpose: record.purpose } : {}),
|
|
456
|
+
});
|
|
317
457
|
case 'image-generate':
|
|
458
|
+
if (execute)
|
|
459
|
+
invalidAIInput('image-generate requires an async Job');
|
|
318
460
|
assertExactKeys(record, ['type', 'prompt', 'negativePrompt', 'n', 'size', 'aspectRatio', 'quality', 'style', 'seed', 'referenceImages', 'referenceImageArtifactId', 'mask', 'maskArtifactId', 'strength', 'responseFormat'], 'image spec');
|
|
319
461
|
boundedContent(record.prompt, 'image prompt', 32 * 1024);
|
|
320
462
|
optionalBoundedText(record.negativePrompt, 'image negativePrompt', 32 * 1024);
|
|
@@ -323,7 +465,7 @@ function validateScenarioSpec(spec, execute) {
|
|
|
323
465
|
boundedToken(record.aspectRatio, 'image aspectRatio', 128);
|
|
324
466
|
boundedToken(record.quality, 'image quality', 128);
|
|
325
467
|
boundedToken(record.style, 'image style', 128);
|
|
326
|
-
optionalBoundedInteger(record.seed, 'image seed',
|
|
468
|
+
optionalBoundedInteger(record.seed, 'image seed', -1, 2_147_483_647);
|
|
327
469
|
if (!Array.isArray(record.referenceImages) || record.referenceImages.length > 1)
|
|
328
470
|
invalidAIInput('image referenceImages are invalid');
|
|
329
471
|
record.referenceImages.forEach((value, index) => boundedHttpsUrl(value, `image reference ${index}`));
|
|
@@ -366,26 +508,79 @@ function validateScenarioSpec(spec, execute) {
|
|
|
366
508
|
invalidAIInput('speech-transcribe is not a synchronous spec');
|
|
367
509
|
validateSpeechTranscribeSpec(record);
|
|
368
510
|
break;
|
|
511
|
+
case 'text-annotate':
|
|
512
|
+
if (execute)
|
|
513
|
+
invalidAIInput('text-annotate is not a synchronous spec');
|
|
514
|
+
assertExactKeys(record, ['type', 'language', 'texts'], 'text annotation spec');
|
|
515
|
+
if (typeof record.language !== 'string' || !/^[a-z-]{2,16}$/.test(record.language)
|
|
516
|
+
|| !Array.isArray(record.texts) || record.texts.length < 1 || record.texts.length > 64
|
|
517
|
+
|| record.texts.some((text) => typeof text !== 'string' || /[\uD800-\uDFFF]/u.test(text))
|
|
518
|
+
|| record.texts.reduce((sum, text) => sum + new TextEncoder().encode(text).byteLength, 0) > 524288)
|
|
519
|
+
invalidAIInput('text annotation requires bounded Unicode documents');
|
|
520
|
+
break;
|
|
521
|
+
case 'audio-speaker-embed':
|
|
522
|
+
if (execute)
|
|
523
|
+
invalidAIInput('audio-speaker-embed is not a synchronous spec');
|
|
524
|
+
assertExactKeys(record, ['type', 'mimeType', 'audioSource', 'sourceAudio'], 'speaker representation spec');
|
|
525
|
+
boundedToken(record.mimeType, 'speaker mimeType', 128);
|
|
526
|
+
if ((record.audioSource === undefined) === (record.sourceAudio === undefined))
|
|
527
|
+
invalidAIInput('speaker encoding requires exactly one source');
|
|
528
|
+
if (record.audioSource !== undefined)
|
|
529
|
+
validateAudioSource(record.audioSource, MAX_ARTIFACT_BYTES, 'speaker audioSource');
|
|
530
|
+
if (record.sourceAudio !== undefined)
|
|
531
|
+
validateMusicAudioInput(record.sourceAudio, 'speaker sourceAudio', Number.MAX_SAFE_INTEGER);
|
|
532
|
+
break;
|
|
533
|
+
case 'audio-separate':
|
|
534
|
+
if (execute)
|
|
535
|
+
invalidAIInput('audio-separate is not a synchronous spec');
|
|
536
|
+
assertExactKeys(record, ['type', 'mimeType', 'audioSource', 'sourceAudio', 'includeInstrumentParts'], 'audio separation spec');
|
|
537
|
+
boundedToken(record.mimeType, 'audio separation mimeType', 128);
|
|
538
|
+
if ((record.audioSource === undefined) === (record.sourceAudio === undefined))
|
|
539
|
+
invalidAIInput('audio separation requires exactly one source');
|
|
540
|
+
if (record.audioSource !== undefined)
|
|
541
|
+
validateAudioSource(record.audioSource, MAX_ARTIFACT_BYTES, 'audio separation audioSource');
|
|
542
|
+
if (record.sourceAudio !== undefined)
|
|
543
|
+
validateMusicAudioInput(record.sourceAudio, 'audio separation sourceAudio');
|
|
544
|
+
if (record.includeInstrumentParts !== undefined && typeof record.includeInstrumentParts !== 'boolean')
|
|
545
|
+
invalidAIInput('audio separation includeInstrumentParts');
|
|
546
|
+
break;
|
|
369
547
|
case 'voice-create':
|
|
370
548
|
if (execute)
|
|
371
549
|
invalidAIInput('voice-create is not a synchronous spec');
|
|
372
550
|
validateVoiceCreateSpec(record);
|
|
373
551
|
break;
|
|
552
|
+
case 'music-transcribe':
|
|
553
|
+
if (execute)
|
|
554
|
+
invalidAIInput('music-transcribe is not a synchronous spec');
|
|
555
|
+
validateNimiLocalAppMusicTranscribeSpec(record);
|
|
556
|
+
break;
|
|
557
|
+
case 'audio-voice-convert':
|
|
558
|
+
if (execute)
|
|
559
|
+
invalidAIInput('audio-voice-convert is not a synchronous spec');
|
|
560
|
+
validateNimiLocalAppVoiceConvertSpec(record);
|
|
561
|
+
break;
|
|
374
562
|
case 'music-generate':
|
|
375
563
|
if (execute)
|
|
376
564
|
invalidAIInput('music-generate is not a synchronous spec');
|
|
377
|
-
|
|
378
|
-
boundedContent(record.prompt, 'music prompt', 32 * 1024);
|
|
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');
|
|
565
|
+
validateNimiLocalAppMusicGenerateSpec(record);
|
|
383
566
|
break;
|
|
384
567
|
case 'world-generate':
|
|
385
568
|
if (execute)
|
|
386
569
|
invalidAIInput('world-generate is not a synchronous spec');
|
|
387
|
-
assertExactKeys(record, ['type', 'prompt', 'displayName'], 'world spec');
|
|
388
|
-
|
|
570
|
+
assertExactKeys(record, ['type', 'prompt', 'displayName', 'image'], 'world spec');
|
|
571
|
+
if (record.prompt !== undefined)
|
|
572
|
+
optionalBoundedText(record.prompt, 'world prompt', 32 * 1024);
|
|
573
|
+
if (record.image !== undefined) {
|
|
574
|
+
const image = asRecord(record.image);
|
|
575
|
+
if (!image)
|
|
576
|
+
invalidAIInput('world image is invalid');
|
|
577
|
+
assertExactKeys(image, ['artifactId', 'projection'], 'world image');
|
|
578
|
+
boundedIdentifier(image.artifactId, 'world image artifactId');
|
|
579
|
+
if (image.projection !== 'ordinary' && image.projection !== 'equirectangular-360')
|
|
580
|
+
invalidAIInput('world projection is required');
|
|
581
|
+
}
|
|
582
|
+
else
|
|
583
|
+
boundedContent(record.prompt, 'world prompt', 32 * 1024);
|
|
389
584
|
optionalBoundedText(record.displayName, 'world displayName', 256);
|
|
390
585
|
break;
|
|
391
586
|
default:
|
|
@@ -394,11 +589,140 @@ function validateScenarioSpec(spec, execute) {
|
|
|
394
589
|
return spec;
|
|
395
590
|
}
|
|
396
591
|
function validateScenarioJobSubmitOptions(options) {
|
|
397
|
-
assertExactKeys(options, ['
|
|
592
|
+
assertExactKeys(options, ['clientSubmissionId'], 'Scenario Job submit options');
|
|
593
|
+
return Object.freeze({
|
|
594
|
+
...(options.clientSubmissionId !== undefined ? { clientSubmissionId: validateClientSubmissionId(options.clientSubmissionId) } : {}),
|
|
595
|
+
});
|
|
596
|
+
}
|
|
597
|
+
const MAX_SCENARIO_EXECUTE_TIMEOUT_MS = 120_000;
|
|
598
|
+
// How long past the caller deadline the transport waits for Runtime's own
|
|
599
|
+
// deadline reply before it gives up on an unresponsive service.
|
|
600
|
+
const RUNTIME_DEADLINE_GRACE_MS = 2_000;
|
|
601
|
+
function validateScenarioExecuteOptions(options) {
|
|
602
|
+
if (options === undefined)
|
|
603
|
+
return {};
|
|
604
|
+
assertExactKeys(options, ['signal', 'timeoutMs'], 'scenario execute options');
|
|
605
|
+
const signal = options.signal;
|
|
606
|
+
if (signal !== undefined && !isAbortSignal(signal))
|
|
607
|
+
invalidAIInput('scenario execute signal must be an AbortSignal');
|
|
608
|
+
const timeoutMs = options.timeoutMs === undefined
|
|
609
|
+
? undefined
|
|
610
|
+
: boundedInteger(options.timeoutMs, 'scenario execute timeoutMs', 1, MAX_SCENARIO_EXECUTE_TIMEOUT_MS);
|
|
398
611
|
return Object.freeze({
|
|
399
|
-
|
|
612
|
+
...(signal !== undefined ? { signal } : {}),
|
|
613
|
+
...(timeoutMs !== undefined ? { timeoutMs } : {}),
|
|
614
|
+
});
|
|
615
|
+
}
|
|
616
|
+
function isAbortSignal(value) {
|
|
617
|
+
if (!value || typeof value !== 'object')
|
|
618
|
+
return false;
|
|
619
|
+
const candidate = value;
|
|
620
|
+
return typeof candidate.aborted === 'boolean'
|
|
621
|
+
&& typeof candidate.addEventListener === 'function'
|
|
622
|
+
&& typeof candidate.removeEventListener === 'function';
|
|
623
|
+
}
|
|
624
|
+
function prepareScenarioExecuteSpec(spec) {
|
|
625
|
+
if (asRecord(spec)?.type === 'text-decide') {
|
|
626
|
+
const decide = prepareNimiLocalAppTextDecideSpec(spec);
|
|
627
|
+
return { shellSpec: decide, decide };
|
|
628
|
+
}
|
|
629
|
+
return { shellSpec: validateScenarioSpec(spec, true) };
|
|
630
|
+
}
|
|
631
|
+
// Settles the caller exactly once: an abort or an elapsed caller deadline
|
|
632
|
+
// rejects immediately without waiting for the carrier, and a late carrier
|
|
633
|
+
// result is never projected. An abort cancels the carrier call; the deadline
|
|
634
|
+
// travels with the call, so Runtime ends it there and records a timeout
|
|
635
|
+
// rather than the cancel an abort would be.
|
|
636
|
+
function runScenarioExecuteCall(call, invoke, project) {
|
|
637
|
+
if (!call.signal && call.timeoutMs === undefined) {
|
|
638
|
+
return invoke(undefined).then(project);
|
|
639
|
+
}
|
|
640
|
+
const controller = new AbortController();
|
|
641
|
+
const callerSignal = call.signal;
|
|
642
|
+
return new Promise((resolve, reject) => {
|
|
643
|
+
let settled = false;
|
|
644
|
+
let timer;
|
|
645
|
+
const settle = (complete) => {
|
|
646
|
+
if (settled)
|
|
647
|
+
return;
|
|
648
|
+
settled = true;
|
|
649
|
+
if (timer !== undefined)
|
|
650
|
+
clearTimeout(timer);
|
|
651
|
+
callerSignal?.removeEventListener('abort', onAbort);
|
|
652
|
+
complete();
|
|
653
|
+
};
|
|
654
|
+
const stop = (error) => {
|
|
655
|
+
settle(() => reject(error));
|
|
656
|
+
if (!controller.signal.aborted)
|
|
657
|
+
controller.abort(error);
|
|
658
|
+
};
|
|
659
|
+
const onAbort = () => stop(scenarioExecuteCanceledError());
|
|
660
|
+
callerSignal?.addEventListener('abort', onAbort, { once: true });
|
|
661
|
+
if (call.timeoutMs !== undefined) {
|
|
662
|
+
const timeoutMs = call.timeoutMs;
|
|
663
|
+
timer = setTimeout(() => settle(() => reject(scenarioExecuteTimeoutError(timeoutMs))), timeoutMs);
|
|
664
|
+
}
|
|
665
|
+
let pending;
|
|
666
|
+
try {
|
|
667
|
+
pending = invoke({
|
|
668
|
+
signal: controller.signal,
|
|
669
|
+
...(call.timeoutMs !== undefined ? { timeoutMs: call.timeoutMs } : {}),
|
|
670
|
+
});
|
|
671
|
+
}
|
|
672
|
+
catch (error) {
|
|
673
|
+
settle(() => reject(error));
|
|
674
|
+
return;
|
|
675
|
+
}
|
|
676
|
+
pending.then((value) => {
|
|
677
|
+
if (settled || callerSignal?.aborted)
|
|
678
|
+
return;
|
|
679
|
+
let projected;
|
|
680
|
+
try {
|
|
681
|
+
projected = project(value);
|
|
682
|
+
}
|
|
683
|
+
catch (error) {
|
|
684
|
+
settle(() => reject(error));
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
settle(() => resolve(projected));
|
|
688
|
+
}, (error) => {
|
|
689
|
+
// A carrier deadline surfaces as the same typed caller timeout.
|
|
690
|
+
settle(() => reject(call.timeoutMs !== undefined && isCarrierTimeout(error)
|
|
691
|
+
? scenarioExecuteTimeoutError(call.timeoutMs)
|
|
692
|
+
: error));
|
|
693
|
+
});
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
function isCarrierTimeout(error) {
|
|
697
|
+
const reasonCode = error && typeof error === 'object' ? error.reasonCode : undefined;
|
|
698
|
+
return reasonCode === 'timeout' || reasonCode === ReasonCode.OPERATION_TIMEOUT;
|
|
699
|
+
}
|
|
700
|
+
function scenarioExecuteCanceledError() {
|
|
701
|
+
return createNimiError({
|
|
702
|
+
message: 'Local-app scenario execution was canceled by its caller.',
|
|
703
|
+
code: ReasonCode.OPERATION_ABORTED,
|
|
704
|
+
reasonCode: ReasonCode.OPERATION_ABORTED,
|
|
705
|
+
actionHint: 'retry_if_still_needed',
|
|
706
|
+
retryable: false,
|
|
707
|
+
source: 'sdk',
|
|
400
708
|
});
|
|
401
709
|
}
|
|
710
|
+
function scenarioExecuteTimeoutError(timeoutMs) {
|
|
711
|
+
return createNimiError({
|
|
712
|
+
message: `Local-app scenario execution exceeded its ${timeoutMs} ms caller deadline.`,
|
|
713
|
+
code: ReasonCode.OPERATION_TIMEOUT,
|
|
714
|
+
reasonCode: ReasonCode.OPERATION_TIMEOUT,
|
|
715
|
+
actionHint: 'retry_with_a_longer_timeout',
|
|
716
|
+
retryable: true,
|
|
717
|
+
source: 'sdk',
|
|
718
|
+
details: { timeoutMs },
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
function validateClientSubmissionId(value) {
|
|
722
|
+
if (typeof value !== 'string' || !/^[A-Za-z0-9_-]{1,128}$/.test(value))
|
|
723
|
+
invalidAIInput('clientSubmissionId is invalid');
|
|
724
|
+
return value;
|
|
725
|
+
}
|
|
402
726
|
function validateVideoSpec(record) {
|
|
403
727
|
assertExactKeys(record, ['type', 'prompt', 'negativePrompt', 'mode', 'content', 'options'], 'video spec');
|
|
404
728
|
optionalBoundedText(record.prompt, 'video prompt', 32 * 1024);
|
|
@@ -442,7 +766,19 @@ function validateVideoSpec(record) {
|
|
|
442
766
|
}
|
|
443
767
|
}
|
|
444
768
|
function validateSpeechSynthesizeSpec(record) {
|
|
445
|
-
assertExactKeys(record, ['type', 'text', 'language', 'audioFormat', 'sampleRateHz', 'speed', 'pitch', 'volume', 'emotion', 'voiceRef', 'timingMode', 'voiceRenderHints'], 'speech synthesize spec');
|
|
769
|
+
assertExactKeys(record, ['type', 'text', 'language', 'audioFormat', 'sampleRateHz', 'speed', 'pitch', 'volume', 'emotion', 'voiceRef', 'timingMode', 'voiceRenderHints', 'identityAudio', 'performanceAudio'], 'speech synthesize spec');
|
|
770
|
+
for (const key of ['identityAudio', 'performanceAudio']) {
|
|
771
|
+
if (record[key] !== undefined) {
|
|
772
|
+
const reference = asRecord(record[key]);
|
|
773
|
+
assertExactKeys(reference, key === 'identityAudio' ? ['artifactId'] : ['artifactId', 'text'], key);
|
|
774
|
+
boundedIdentifier(reference.artifactId, key + ' artifactId');
|
|
775
|
+
if (key === 'performanceAudio') {
|
|
776
|
+
boundedContent(reference.text, 'performance transcript', 32768);
|
|
777
|
+
if (!String(reference.text).trim())
|
|
778
|
+
invalidAIInput('Performance transcript is required');
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
}
|
|
446
782
|
boundedContent(record.text, 'speech text', 32 * 1024);
|
|
447
783
|
boundedToken(record.language, 'speech language', 64);
|
|
448
784
|
boundedToken(record.audioFormat, 'speech audioFormat', 64);
|
|
@@ -515,7 +851,7 @@ function validateAudioSource(value, maxBytes, field) {
|
|
|
515
851
|
invalidAIInput(`${field} is invalid`);
|
|
516
852
|
if (source.type === 'bytes') {
|
|
517
853
|
assertExactKeys(source, ['type', 'bytes'], field);
|
|
518
|
-
|
|
854
|
+
validateInputBytes(source.bytes, field, maxBytes, false);
|
|
519
855
|
}
|
|
520
856
|
else if (source.type === 'uri') {
|
|
521
857
|
assertExactKeys(source, ['type', 'uri'], field);
|
|
@@ -524,6 +860,19 @@ function validateAudioSource(value, maxBytes, field) {
|
|
|
524
860
|
else
|
|
525
861
|
invalidAIInput(`${field} type is invalid`);
|
|
526
862
|
}
|
|
863
|
+
function validateMusicAudioInput(value, field, maxFrame = 57600000) {
|
|
864
|
+
const source = asRecord(value);
|
|
865
|
+
assertExactKeys(source, ['artifactId', 'range'], field);
|
|
866
|
+
boundedIdentifier(source?.artifactId, `${field} artifactId`);
|
|
867
|
+
if (source?.range !== undefined) {
|
|
868
|
+
const range = asRecord(source.range);
|
|
869
|
+
assertExactKeys(range, ['startFrame', 'endFrame'], field);
|
|
870
|
+
if (!range || !Number.isSafeInteger(range.startFrame) || range.startFrame < 0 || range.startFrame > maxFrame
|
|
871
|
+
|| !Number.isSafeInteger(range.endFrame) || range.endFrame < 1 || range.endFrame > maxFrame
|
|
872
|
+
|| range.startFrame >= range.endFrame)
|
|
873
|
+
invalidAIInput(`${field} range`);
|
|
874
|
+
}
|
|
875
|
+
}
|
|
527
876
|
function projectSubscription(subscription, projector) {
|
|
528
877
|
const record = asRecord(subscription);
|
|
529
878
|
assertExactProjectionKeys(record, ['events', 'cancel'], 'AI subscription');
|
|
@@ -552,6 +901,14 @@ function projectTextTurnEvent(value) {
|
|
|
552
901
|
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'toolCall'], 'text tool call');
|
|
553
902
|
return Object.freeze({ ...base, type: 'tool-call', itemIndex: projectionInteger(record.itemIndex, 'tool item index', 0, 4_294_967_295), toolCall: projectLocalAppToolCall(record.toolCall) });
|
|
554
903
|
}
|
|
904
|
+
if (record.type === 'reasoning-summary') {
|
|
905
|
+
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'text', 'itemCompleted'], 'text reasoning summary');
|
|
906
|
+
if (typeof record.itemCompleted !== 'boolean' || (record.text === '' && !record.itemCompleted))
|
|
907
|
+
localAppProjectionError('summary seal');
|
|
908
|
+
if (typeof record.text !== 'string')
|
|
909
|
+
localAppProjectionError('reasoning summary');
|
|
910
|
+
return Object.freeze({ ...base, type: 'reasoning-summary', itemIndex: projectionInteger(record.itemIndex, 'summary item index', 0, 4_294_967_295), text: optionalProjectionContent(record.text, 'reasoning summary', 64 * 1024), itemCompleted: record.itemCompleted });
|
|
911
|
+
}
|
|
555
912
|
if (record.type === 'reasoning-continuity') {
|
|
556
913
|
assertExactProjectionKeys(record, ['type', 'sequence', 'traceId', 'itemIndex', 'carrier'], 'text continuity');
|
|
557
914
|
return Object.freeze({ ...base, type: 'reasoning-continuity', itemIndex: projectionInteger(record.itemIndex, 'continuity item index', 0, 4_294_967_295), carrier: projectLocalAppContinuity(record.carrier) });
|
|
@@ -569,13 +926,18 @@ function projectTextTurnEvent(value) {
|
|
|
569
926
|
}
|
|
570
927
|
return localAppProjectionError('text-turn event type');
|
|
571
928
|
}
|
|
572
|
-
function projectScenarioExecute(value) {
|
|
929
|
+
function projectScenarioExecute(value, decide) {
|
|
573
930
|
const record = asRecord(value);
|
|
574
931
|
assertExactProjectionKeys(record, ['output', 'traceId'], 'scenario execute');
|
|
575
932
|
const output = asRecord(record.output);
|
|
576
933
|
if (!output)
|
|
577
934
|
localAppProjectionError('scenario execute output');
|
|
578
935
|
const traceId = boundedProjectionText(record.traceId, 'scenario execute traceId', 512);
|
|
936
|
+
if ((output.type === 'text-decide') !== Boolean(decide))
|
|
937
|
+
localAppProjectionError('scenario execute output type');
|
|
938
|
+
if (decide) {
|
|
939
|
+
return Object.freeze({ output: validateNimiLocalAppTextDecideOutput(output, decide), traceId });
|
|
940
|
+
}
|
|
579
941
|
if (output.type === 'text-generate') {
|
|
580
942
|
assertExactProjectionKeys(output, ['type', 'items', 'finishReason'], 'text generate output');
|
|
581
943
|
const items = projectLocalAppTextItems(output.items);
|
|
@@ -586,7 +948,7 @@ function projectScenarioExecute(value) {
|
|
|
586
948
|
}
|
|
587
949
|
assertSafeProjection(record);
|
|
588
950
|
if (output.type === 'text-embed') {
|
|
589
|
-
assertExactProjectionKeys(output, ['type', 'vectors', 'spaceId'], 'text embed output');
|
|
951
|
+
assertExactProjectionKeys(output, ['type', 'vectors', 'spaceId', ...(output.usage !== undefined ? ['usage'] : [])], 'text embed output');
|
|
590
952
|
const spaceId = boundedProjectionText(output.spaceId, 'embedding spaceId', 128);
|
|
591
953
|
if (!Array.isArray(output.vectors) || output.vectors.length === 0 || output.vectors.length > 16)
|
|
592
954
|
localAppProjectionError('text embed vectors');
|
|
@@ -596,11 +958,8 @@ function projectScenarioExecute(value) {
|
|
|
596
958
|
localAppProjectionError('text embed vector');
|
|
597
959
|
return Object.freeze([...vector]);
|
|
598
960
|
});
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
if (output.type === 'image-generate') {
|
|
602
|
-
assertExactProjectionKeys(output, ['type', 'artifacts'], 'image execute output');
|
|
603
|
-
return Object.freeze({ output: Object.freeze({ type: 'image-generate', artifacts: projectArtifacts(output.artifacts) }), traceId });
|
|
961
|
+
const usage = output.usage === undefined ? undefined : projectEmbeddingUsage(output.usage);
|
|
962
|
+
return Object.freeze({ output: Object.freeze({ type: 'text-embed', vectors: Object.freeze(vectors), spaceId, ...(usage ? { usage } : {}) }), traceId });
|
|
604
963
|
}
|
|
605
964
|
return localAppProjectionError('scenario execute output type');
|
|
606
965
|
}
|
|
@@ -611,7 +970,8 @@ function projectScenarioJobSubmit(value) {
|
|
|
611
970
|
}
|
|
612
971
|
function projectScenarioJobGet(value) {
|
|
613
972
|
const record = asRecord(value);
|
|
614
|
-
assertExactProjectionKeys(record, ['job', 'asset', 'voiceReference', ...(record && Object.hasOwn(record, 'visionLocate') ? ['visionLocate'] : [])], 'scenario Job result');
|
|
973
|
+
assertExactProjectionKeys(record, ['job', 'asset', 'voiceReference', ...(record && Object.hasOwn(record, 'visionLocate') ? ['visionLocate'] : []), ...(record && Object.hasOwn(record, 'observationIssue') ? ['observationIssue'] : [])], 'scenario Job result');
|
|
974
|
+
const observationIssue = record.observationIssue === undefined ? undefined : projectJobObservationIssue(record.observationIssue);
|
|
615
975
|
const job = projectScenarioJob(record.job);
|
|
616
976
|
const visionLocate = record.visionLocate === undefined ? undefined : projectVisionLocateResult(record.visionLocate);
|
|
617
977
|
if ((job.scenarioType === 'vision-locate' && job.status === 'completed') !== (visionLocate !== undefined) || (visionLocate && job.artifacts.length !== 0))
|
|
@@ -627,6 +987,7 @@ function projectScenarioJobGet(value) {
|
|
|
627
987
|
job,
|
|
628
988
|
asset,
|
|
629
989
|
voiceReference,
|
|
990
|
+
...(observationIssue ? { observationIssue } : {}),
|
|
630
991
|
...(visionLocate ? { visionLocate } : {}),
|
|
631
992
|
});
|
|
632
993
|
}
|
|
@@ -637,7 +998,7 @@ function projectScenarioJobEnvelope(value) {
|
|
|
637
998
|
}
|
|
638
999
|
function projectScenarioJob(value) {
|
|
639
1000
|
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');
|
|
1001
|
+
assertExactProjectionKeys(record, [...(record && Object.hasOwn(record, 'submissionOutcome') ? ['submissionOutcome'] : []), ...(record && Object.hasOwn(record, 'stopOutcome') ? ['stopOutcome'] : []), ...(record && Object.hasOwn(record, 'recoveryExpiresAt') ? ['recoveryExpiresAt'] : []), '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, 'speakerEmbedding') ? ['speakerEmbedding'] : []), ...(record && Object.hasOwn(record, 'musicGeneration') ? ['musicGeneration'] : []), ...(record && Object.hasOwn(record, 'musicTranscription') ? ['musicTranscription'] : []), ...(record && Object.hasOwn(record, 'voiceConversion') ? ['voiceConversion'] : []), ...(record && Object.hasOwn(record, 'transcription') ? ['transcription'] : []), ...(record && Object.hasOwn(record, 'interruption') ? ['interruption'] : []), ...(record && Object.hasOwn(record, 'videoFaceSwapSummary') ? ['videoFaceSwapSummary'] : [])], 'scenario Job');
|
|
641
1002
|
assertSafeProjection(record);
|
|
642
1003
|
if (!LOCAL_SCENARIO_TYPES.includes(record.scenarioType) || !LOCAL_JOB_STATUSES.includes(record.status))
|
|
643
1004
|
localAppProjectionError('scenario Job enum');
|
|
@@ -650,8 +1011,44 @@ function projectScenarioJob(value) {
|
|
|
650
1011
|
if (hasVideoSummary !== (record.scenarioType === 'video-face-swap' && record.status === 'completed'))
|
|
651
1012
|
localAppProjectionError('video face replacement summary state');
|
|
652
1013
|
const videoFaceSwapSummary = hasVideoSummary ? projectVideoFaceSwapSummary(record.videoFaceSwapSummary) : undefined;
|
|
1014
|
+
const transcription = record.transcription === undefined ? undefined : validateNimiLocalAppSpeechTranscript(record.transcription);
|
|
1015
|
+
if (transcription && (record.scenarioType !== 'speech-transcribe' || record.status !== 'completed' || transcription.text !== record.transcriptionText))
|
|
1016
|
+
localAppProjectionError('speech transcription state');
|
|
1017
|
+
const artifacts = projectArtifacts(record.artifacts);
|
|
1018
|
+
if ((record.audioSeparation !== undefined) !== (record.scenarioType === 'audio-separate' && record.status === 'completed'))
|
|
1019
|
+
localAppProjectionError('audio separation state');
|
|
1020
|
+
if ((record.textAnnotation !== undefined) !== (record.scenarioType === 'text-annotate' && record.status === 'completed'))
|
|
1021
|
+
localAppProjectionError('text annotation state');
|
|
1022
|
+
const textAnnotation = record.textAnnotation === undefined ? undefined : validateNimiLocalAppTextAnnotationResult(record.textAnnotation);
|
|
1023
|
+
if ((record.speakerEmbedding !== undefined) !== (record.scenarioType === 'audio-speaker-embed' && record.status === 'completed'))
|
|
1024
|
+
localAppProjectionError('speaker representation state');
|
|
1025
|
+
const speakerEmbedding = record.speakerEmbedding === undefined ? undefined : validateNimiLocalAppSpeakerEmbedding(record.speakerEmbedding);
|
|
1026
|
+
if (speakerEmbedding && artifacts.length)
|
|
1027
|
+
localAppProjectionError('speaker representation artifacts');
|
|
1028
|
+
const audioSeparation = record.audioSeparation === undefined ? undefined : validateNimiLocalAppAudioSeparation(record.audioSeparation, artifacts);
|
|
1029
|
+
if ((record.musicGeneration !== undefined) !== (record.scenarioType === 'music-generate' && record.status === 'completed'))
|
|
1030
|
+
localAppProjectionError('music generation state');
|
|
1031
|
+
if ((record.musicTranscription !== undefined) !== (record.scenarioType === 'music-transcribe' && record.status === 'completed'))
|
|
1032
|
+
localAppProjectionError('music transcription state');
|
|
1033
|
+
const musicTranscription = record.musicTranscription === undefined ? undefined : validateNimiLocalAppMusicTranscription(record.musicTranscription, artifacts);
|
|
1034
|
+
if ((record.voiceConversion !== undefined) !== (record.scenarioType === 'audio-voice-convert' && record.status === 'completed'))
|
|
1035
|
+
localAppProjectionError('voice conversion state');
|
|
1036
|
+
const voiceConversion = record.voiceConversion === undefined ? undefined : validateNimiLocalAppVoiceConversion(record.voiceConversion, artifacts);
|
|
1037
|
+
const musicGeneration = record.musicGeneration === undefined ? undefined : validateNimiLocalAppMusicGeneration(record.musicGeneration, artifacts);
|
|
1038
|
+
const recoveryExpiresAt = record.recoveryExpiresAt === undefined ? undefined : projectTimestamp(record.recoveryExpiresAt, 'music recovery expiry');
|
|
1039
|
+
if (record.recoveryExpiresAt !== undefined && (!recoveryExpiresAt || !['music-generate', 'music-transcribe', 'audio-voice-convert', 'voice-create'].includes(String(record.scenarioType)) || !['completed', 'failed', 'canceled', 'timeout'].includes(String(record.status))))
|
|
1040
|
+
localAppProjectionError('music recovery expiry state');
|
|
653
1041
|
return Object.freeze({
|
|
1042
|
+
...projectJobFacts(record),
|
|
1043
|
+
...(recoveryExpiresAt ? { recoveryExpiresAt } : {}),
|
|
1044
|
+
...(musicGeneration ? { musicGeneration } : {}),
|
|
1045
|
+
...(musicTranscription ? { musicTranscription } : {}),
|
|
1046
|
+
...(voiceConversion ? { voiceConversion } : {}),
|
|
1047
|
+
...(textAnnotation ? { textAnnotation } : {}),
|
|
1048
|
+
...(audioSeparation ? { audioSeparation } : {}),
|
|
1049
|
+
...(speakerEmbedding ? { speakerEmbedding } : {}),
|
|
654
1050
|
...(videoFaceSwapSummary ? { videoFaceSwapSummary } : {}),
|
|
1051
|
+
...(transcription ? { transcription } : {}),
|
|
655
1052
|
...(interruption ? { interruption } : {}),
|
|
656
1053
|
jobId: boundedProjectionText(record.jobId, 'scenario Job id', MAX_IDENTIFIER_BYTES),
|
|
657
1054
|
scenarioType: record.scenarioType,
|
|
@@ -661,13 +1058,58 @@ function projectScenarioJob(value) {
|
|
|
661
1058
|
progressTotalSteps: total,
|
|
662
1059
|
reasonCode: optionalProjectionText(record.reasonCode, 'scenario Job reasonCode', 128),
|
|
663
1060
|
reasonDetail: optionalProjectionText(record.reasonDetail, 'scenario Job reasonDetail', 1024),
|
|
664
|
-
artifacts
|
|
1061
|
+
artifacts,
|
|
665
1062
|
traceId: optionalProjectionText(record.traceId, 'scenario Job traceId', 512),
|
|
666
1063
|
createdAt: projectTimestamp(record.createdAt, 'scenario Job createdAt'),
|
|
667
1064
|
updatedAt: projectTimestamp(record.updatedAt, 'scenario Job updatedAt'),
|
|
668
|
-
transcriptionText:
|
|
1065
|
+
transcriptionText: optionalProjectionContent(record.transcriptionText, 'scenario Job transcriptionText', 1 << 20),
|
|
669
1066
|
});
|
|
670
1067
|
}
|
|
1068
|
+
const SUBMISSION_OUTCOMES = [undefined, 'not-dispatched', 'unknown', 'accepted', 'rejected'];
|
|
1069
|
+
const STOP_OUTCOMES = [undefined, 'not-dispatched', 'confirmed', 'unconfirmed'];
|
|
1070
|
+
function localJobFactsFromRuntime(job) {
|
|
1071
|
+
const submission = job.submissionOutcome ?? 0;
|
|
1072
|
+
const stop = job.stopOutcome ?? 0;
|
|
1073
|
+
if (!Number.isInteger(submission) || submission < 0 || submission >= SUBMISSION_OUTCOMES.length
|
|
1074
|
+
|| !Number.isInteger(stop) || stop < 0 || stop >= STOP_OUTCOMES.length)
|
|
1075
|
+
localAppProjectionError('Job outcome enum');
|
|
1076
|
+
return { ...(submission ? { submissionOutcome: SUBMISSION_OUTCOMES[submission] } : {}), ...(stop ? { stopOutcome: STOP_OUTCOMES[stop] } : {}) };
|
|
1077
|
+
}
|
|
1078
|
+
function projectJobFacts(record) {
|
|
1079
|
+
const submission = record.submissionOutcome;
|
|
1080
|
+
const stop = record.stopOutcome;
|
|
1081
|
+
if (!SUBMISSION_OUTCOMES.includes(submission) || !STOP_OUTCOMES.includes(stop))
|
|
1082
|
+
localAppProjectionError('Job outcome enum');
|
|
1083
|
+
if (record.status !== 'canceled' && stop !== undefined)
|
|
1084
|
+
localAppProjectionError('uncanceled Job stop facts');
|
|
1085
|
+
if (submission !== undefined) {
|
|
1086
|
+
const valid = record.status === 'submitted' || record.status === 'queued' ? submission === 'not-dispatched'
|
|
1087
|
+
: record.status === 'running' ? submission === 'unknown' || submission === 'accepted'
|
|
1088
|
+
: record.status === 'completed' ? submission === 'accepted'
|
|
1089
|
+
: record.status === 'timeout' ? submission !== 'rejected'
|
|
1090
|
+
: record.status === 'canceled' ? submission === 'not-dispatched' ? stop === 'not-dispatched'
|
|
1091
|
+
: submission === 'unknown' ? stop === 'unconfirmed' : stop === 'confirmed' || stop === 'unconfirmed'
|
|
1092
|
+
: record.status === 'failed';
|
|
1093
|
+
if (!valid)
|
|
1094
|
+
localAppProjectionError('Job outcome combination');
|
|
1095
|
+
if (record.reasonCode === 'ai-provider-task-canceled' && (record.status !== 'canceled' || submission !== 'accepted' || stop !== 'confirmed'))
|
|
1096
|
+
localAppProjectionError('provider cancellation facts');
|
|
1097
|
+
if (record.reasonCode === 'ai-provider-task-expired' && (record.status !== 'timeout' || submission !== 'accepted'))
|
|
1098
|
+
localAppProjectionError('provider expiration facts');
|
|
1099
|
+
}
|
|
1100
|
+
return { ...(submission !== undefined ? { submissionOutcome: submission } : {}), ...(stop !== undefined ? { stopOutcome: stop } : {}) };
|
|
1101
|
+
}
|
|
1102
|
+
function projectJobObservationIssue(value) {
|
|
1103
|
+
const record = asRecord(value);
|
|
1104
|
+
assertExactProjectionKeys(record, ['reasonCode', 'observedAt'], 'Job observation issue');
|
|
1105
|
+
const reasonCode = boundedProjectionText(record.reasonCode, 'observation reason', 128);
|
|
1106
|
+
if (runtimeReasonCode(reasonCode) === RuntimeReasonCode.REASON_CODE_UNSPECIFIED)
|
|
1107
|
+
localAppProjectionError('observation reason');
|
|
1108
|
+
const observedAt = projectTimestamp(record.observedAt, 'observation timestamp');
|
|
1109
|
+
if (!observedAt)
|
|
1110
|
+
localAppProjectionError('observation timestamp');
|
|
1111
|
+
return Object.freeze({ reasonCode, observedAt });
|
|
1112
|
+
}
|
|
671
1113
|
function projectVideoFaceSwapSummary(value) {
|
|
672
1114
|
const record = asRecord(value);
|
|
673
1115
|
assertExactProjectionKeys(record, ['totalFrames', 'transformedFrames', 'preservedFrames', 'durationUs', 'frameRate', 'audioPreserved'], 'video face replacement summary');
|
|
@@ -685,20 +1127,27 @@ function projectArtifacts(value) {
|
|
|
685
1127
|
return Object.freeze(value.map((entry) => {
|
|
686
1128
|
const record = asRecord(entry);
|
|
687
1129
|
const hasSeed = Boolean(record && Object.hasOwn(record, 'seed'));
|
|
1130
|
+
const hasAlignment = Boolean(record && Object.hasOwn(record, 'speechAlignment'));
|
|
688
1131
|
assertExactProjectionKeys(record, [
|
|
689
1132
|
'artifactId', 'mimeType', 'bytes', 'sizeBytes', 'sha256', 'durationMs',
|
|
690
|
-
'width', 'height', 'sampleRateHz', 'channels', ...(hasSeed ? ['seed'] : []),
|
|
1133
|
+
'width', 'height', 'sampleRateHz', 'channels', ...(record && Object.hasOwn(record, 'frameCount') ? ['frameCount'] : []), ...(hasSeed ? ['seed'] : []), ...(hasAlignment ? ['speechAlignment'] : []),
|
|
691
1134
|
], 'scenario artifact');
|
|
692
1135
|
const bytes = validateProjectionBytes(record.bytes, 'scenario artifact bytes');
|
|
693
1136
|
const sizeBytes = projectionInteger(record.sizeBytes, 'scenario artifact sizeBytes', 0, Number.MAX_SAFE_INTEGER);
|
|
694
|
-
if (bytes.
|
|
1137
|
+
if (bytes.byteLength > 0 && bytes.byteLength !== sizeBytes)
|
|
695
1138
|
localAppProjectionError('scenario artifact byte size');
|
|
696
1139
|
const mimeType = mimeProjection(record.mimeType);
|
|
697
1140
|
const seed = hasSeed
|
|
698
|
-
? projectionInteger(record.seed, 'scenario artifact seed',
|
|
1141
|
+
? projectionInteger(record.seed, 'scenario artifact seed', 0, 2_147_483_647)
|
|
699
1142
|
: undefined;
|
|
700
1143
|
if (hasSeed && !mimeType.startsWith('image/'))
|
|
701
1144
|
localAppProjectionError('scenario artifact seed mime');
|
|
1145
|
+
if (hasAlignment && !mimeType.startsWith('audio/'))
|
|
1146
|
+
localAppProjectionError('speech alignment requires audio');
|
|
1147
|
+
const speechAlignment = hasAlignment ? projectLocalAppSpeechAlignment(record.speechAlignment) : undefined;
|
|
1148
|
+
const frameCount = record.frameCount === undefined ? undefined : projectionInteger(record.frameCount, 'audio frame count', 1, Number.MAX_SAFE_INTEGER);
|
|
1149
|
+
if (frameCount !== undefined && (!mimeType.startsWith('audio/') || !(Number(record.sampleRateHz) > 0) || !(Number(record.channels) > 0)))
|
|
1150
|
+
localAppProjectionError('audio frame count requires an audio format');
|
|
702
1151
|
return Object.freeze({
|
|
703
1152
|
artifactId: boundedProjectionText(record.artifactId, 'scenario artifact id', MAX_IDENTIFIER_BYTES),
|
|
704
1153
|
mimeType,
|
|
@@ -710,34 +1159,129 @@ function projectArtifacts(value) {
|
|
|
710
1159
|
height: projectionInteger(record.height, 'scenario artifact height', 0, Number.MAX_SAFE_INTEGER),
|
|
711
1160
|
sampleRateHz: projectionInteger(record.sampleRateHz, 'scenario artifact sampleRateHz', 0, Number.MAX_SAFE_INTEGER),
|
|
712
1161
|
channels: projectionInteger(record.channels, 'scenario artifact channels', 0, Number.MAX_SAFE_INTEGER),
|
|
1162
|
+
...(frameCount !== undefined ? { frameCount } : {}),
|
|
713
1163
|
...(seed !== undefined ? { seed } : {}),
|
|
1164
|
+
...(speechAlignment ? { speechAlignment } : {}),
|
|
714
1165
|
});
|
|
715
1166
|
}));
|
|
716
1167
|
}
|
|
717
|
-
function projectArtifactUpload(value, expectedSize, expectedMimeType) {
|
|
1168
|
+
function projectArtifactUpload(value, expectedSize, expectedMimeType, preparation) {
|
|
718
1169
|
const record = asRecord(value);
|
|
719
|
-
assertExactProjectionKeys(record, ['artifactId', 'sizeBytes', 'mimeType'], 'artifact upload result');
|
|
1170
|
+
assertExactProjectionKeys(record, ['artifactId', 'sizeBytes', 'mimeType', ...(preparation ? ['audioInfo', 'expiresAt'] : expectedMimeType === 'text/vnd.abc' ? ['expiresAt'] : [])], 'artifact upload result');
|
|
720
1171
|
assertNoAuthorityMaterial(record);
|
|
721
1172
|
const artifactId = projectionText(record.artifactId, 'artifact upload artifactId');
|
|
722
1173
|
if (utf8Length(artifactId) > MAX_IDENTIFIER_BYTES
|
|
723
|
-
|| !Number.isSafeInteger(record.sizeBytes)
|
|
724
|
-
|| record.sizeBytes < 1 || record.sizeBytes > MAX_ARTIFACT_BYTES
|
|
725
|
-
|| record.mimeType !==
|
|
1174
|
+
|| typeof record.sizeBytes !== 'number' || !Number.isSafeInteger(record.sizeBytes)
|
|
1175
|
+
|| record.sizeBytes < 1 || record.sizeBytes > (preparation ? 512 * 1024 * 1024 : MAX_ARTIFACT_BYTES)
|
|
1176
|
+
|| record.mimeType !== (preparation ? 'audio/wav' : expectedMimeType)
|
|
1177
|
+
|| !isArtifactUploadMime(record.mimeType)) {
|
|
726
1178
|
localAppProjectionError('artifact upload result');
|
|
727
1179
|
}
|
|
728
|
-
|
|
1180
|
+
if (!preparation) {
|
|
1181
|
+
if (record.sizeBytes !== expectedSize || record.audioInfo !== undefined)
|
|
1182
|
+
localAppProjectionError('artifact upload result');
|
|
1183
|
+
if (expectedMimeType === 'text/vnd.abc') {
|
|
1184
|
+
const expiresAt = projectTimestamp(record.expiresAt, 'score expiry');
|
|
1185
|
+
if (!expiresAt || Number(record.sizeBytes) > 1048576)
|
|
1186
|
+
localAppProjectionError('score expiry or size');
|
|
1187
|
+
return Object.freeze({ artifactId, sizeBytes: record.sizeBytes, mimeType: record.mimeType, expiresAt });
|
|
1188
|
+
}
|
|
1189
|
+
return Object.freeze({ artifactId, sizeBytes: record.sizeBytes, mimeType: record.mimeType });
|
|
1190
|
+
}
|
|
1191
|
+
const audio = asRecord(record.audioInfo);
|
|
1192
|
+
const expiresAt = projectTimestamp(record.expiresAt, 'canonical audio expiry');
|
|
1193
|
+
if (!expiresAt)
|
|
1194
|
+
localAppProjectionError('canonical audio expiry');
|
|
1195
|
+
assertExactProjectionKeys(audio, ['sampleRateHz', 'channels', 'frameCount', 'durationMs'], 'canonical audio facts');
|
|
1196
|
+
const sampleRateHz = projectionInteger(audio.sampleRateHz, 'sampleRateHz', 8000, 96000);
|
|
1197
|
+
const channels = projectionInteger(audio.channels, 'channels', 1, 2);
|
|
1198
|
+
const frameCount = projectionInteger(audio.frameCount, 'frameCount', 1, sampleRateHz * 600);
|
|
1199
|
+
const durationMs = projectionInteger(audio.durationMs, 'durationMs', 0, 600000);
|
|
1200
|
+
if (durationMs !== Math.floor(frameCount * 1000 / sampleRateHz)
|
|
1201
|
+
|| Number(record.sizeBytes) < frameCount * channels * 4 + 44
|
|
1202
|
+
|| (preparation.targetSampleRateHz !== undefined && preparation.targetSampleRateHz !== sampleRateHz)
|
|
1203
|
+
|| (preparation.channelMode === 'MONO_TO_STEREO' && channels !== 2)
|
|
1204
|
+
|| (preparation.channelMode === 'STEREO_TO_MONO' && channels !== 1)) {
|
|
1205
|
+
localAppProjectionError('canonical audio facts');
|
|
1206
|
+
}
|
|
1207
|
+
return Object.freeze({ artifactId, sizeBytes: record.sizeBytes, mimeType: record.mimeType,
|
|
1208
|
+
expiresAt,
|
|
1209
|
+
audioInfo: Object.freeze({ sampleRateHz, channels, frameCount, durationMs }) });
|
|
1210
|
+
}
|
|
1211
|
+
// @nimi-authority: rule.nimi.runtime.ai-provider.canonical-audio-upload
|
|
1212
|
+
function prepareArtifactUploadInput(input) {
|
|
1213
|
+
assertExactKeys(input, ['bytes', 'source', 'mimeType', 'audioPreparation'], 'artifact upload input');
|
|
1214
|
+
assertNoAuthorityMaterial(input);
|
|
1215
|
+
if (!isArtifactUploadMime(input.mimeType) || (input.bytes !== undefined) === (input.source !== undefined)) {
|
|
1216
|
+
invalidAIInput('artifact upload requires exactly one source');
|
|
1217
|
+
}
|
|
1218
|
+
let source;
|
|
1219
|
+
if (input.source !== undefined) {
|
|
1220
|
+
if (!input.source || typeof input.source !== 'object')
|
|
1221
|
+
invalidAIInput('artifact source is invalid');
|
|
1222
|
+
if (input.source.kind === 'app-asset') {
|
|
1223
|
+
assertExactKeys(input.source, ['kind', 'relativePath'], 'artifact source');
|
|
1224
|
+
const relativePath = input.source.relativePath;
|
|
1225
|
+
if (typeof relativePath !== 'string' || !relativePath || utf8Length(relativePath) > 4096 || relativePath.includes('\0'))
|
|
1226
|
+
invalidAIInput('artifact source path is invalid');
|
|
1227
|
+
source = { kind: 'app-asset', relativePath };
|
|
1228
|
+
}
|
|
1229
|
+
else if (input.source.kind === 'artifact') {
|
|
1230
|
+
assertExactKeys(input.source, ['kind', 'artifactId'], 'artifact source');
|
|
1231
|
+
source = { kind: 'artifact', artifactId: boundedIdentifier(input.source.artifactId, 'artifactId') };
|
|
1232
|
+
}
|
|
1233
|
+
else
|
|
1234
|
+
invalidAIInput('artifact source kind is invalid');
|
|
1235
|
+
}
|
|
1236
|
+
else if (!isNimiLocalAppByteView(input.bytes) || input.bytes.byteLength === 0 || input.bytes.byteLength > MAX_ARTIFACT_BYTES) {
|
|
1237
|
+
invalidAIInput('artifact upload bytes are invalid');
|
|
1238
|
+
}
|
|
1239
|
+
if (input.mimeType === 'text/vnd.abc' && (!input.bytes || input.bytes.byteLength > 1048576 || source || input.audioPreparation))
|
|
1240
|
+
invalidAIInput('ABC requires inline bytes up to 1 MiB');
|
|
1241
|
+
let audioPreparation;
|
|
1242
|
+
if (input.audioPreparation !== undefined) {
|
|
1243
|
+
const candidate = input.audioPreparation;
|
|
1244
|
+
if (!candidate || typeof candidate !== 'object')
|
|
1245
|
+
invalidAIInput('audio preparation is invalid');
|
|
1246
|
+
assertExactKeys(candidate, ['profile', 'targetSampleRateHz', 'channelMode'], 'audio preparation');
|
|
1247
|
+
if (candidate.profile !== 'canonical-pcm-v1' || !['audio/wav', 'audio/mpeg', 'audio/flac'].includes(input.mimeType)
|
|
1248
|
+
|| (candidate.targetSampleRateHz !== undefined && (!Number.isInteger(candidate.targetSampleRateHz) || candidate.targetSampleRateHz < 8000 || candidate.targetSampleRateHz > 96000 || input.mimeType !== 'audio/wav'))
|
|
1249
|
+
|| (candidate.channelMode !== undefined && !['PRESERVE', 'MONO_TO_STEREO', 'STEREO_TO_MONO'].includes(candidate.channelMode))) {
|
|
1250
|
+
invalidAIInput('audio preparation is unsupported');
|
|
1251
|
+
}
|
|
1252
|
+
audioPreparation = { profile: 'canonical-pcm-v1',
|
|
1253
|
+
...(candidate.targetSampleRateHz !== undefined ? { targetSampleRateHz: candidate.targetSampleRateHz } : {}),
|
|
1254
|
+
...(candidate.channelMode !== undefined ? { channelMode: candidate.channelMode } : {}) };
|
|
1255
|
+
}
|
|
1256
|
+
if ((source || input.mimeType === 'audio/flac') && !audioPreparation)
|
|
1257
|
+
invalidAIInput('this source requires canonical audio preparation');
|
|
1258
|
+
if (source?.kind === 'artifact' && input.mimeType !== 'audio/wav')
|
|
1259
|
+
invalidAIInput('artifact source must already be canonical WAV');
|
|
1260
|
+
return { mimeType: input.mimeType, ...(source ? { source } : { bytes: copyNimiLocalAppBytes(input.bytes) }), ...(audioPreparation ? { audioPreparation } : {}) };
|
|
1261
|
+
}
|
|
1262
|
+
// Shared protected-carrier validation; this projects no ownership or readiness.
|
|
1263
|
+
export function validateNimiLocalAppArtifactUploadShellInput(value) {
|
|
1264
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
1265
|
+
invalidAIInput('artifact upload input is invalid');
|
|
1266
|
+
const record = value;
|
|
1267
|
+
if (record.bytes !== undefined && !isNimiLocalAppByteView(record.bytes))
|
|
1268
|
+
invalidAIInput('artifact upload bytes are invalid');
|
|
1269
|
+
return prepareArtifactUploadInput(record);
|
|
1270
|
+
}
|
|
1271
|
+
export function validateNimiLocalAppArtifactUploadResult(value, input) {
|
|
1272
|
+
return projectArtifactUpload(value, input.bytes?.byteLength, input.mimeType, input.audioPreparation);
|
|
729
1273
|
}
|
|
730
1274
|
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';
|
|
1275
|
+
return value === 'image/png' || value === 'image/jpeg' || value === 'image/webp' || value === 'image/gif' || value === 'audio/wav' || value === 'audio/mpeg' || value === 'audio/flac' || value === 'video/mp4' || value === 'text/vnd.abc';
|
|
732
1276
|
}
|
|
733
1277
|
function projectArtifactRead(value) {
|
|
734
1278
|
const record = asRecord(value);
|
|
735
1279
|
assertExactProjectionKeys(record, ['bytes', 'mimeType', 'sizeBytes'], 'artifact read');
|
|
736
1280
|
const bytes = validateProjectionBytes(record.bytes, 'artifact read bytes');
|
|
737
1281
|
const sizeBytes = projectionInteger(record.sizeBytes, 'artifact read sizeBytes', 0, MAX_ARTIFACT_BYTES);
|
|
738
|
-
if (bytes.
|
|
1282
|
+
if (bytes.byteLength !== sizeBytes)
|
|
739
1283
|
localAppProjectionError('artifact read byte size');
|
|
740
|
-
return Object.freeze({ bytes
|
|
1284
|
+
return Object.freeze({ bytes, mimeType: mimeProjection(record.mimeType), sizeBytes });
|
|
741
1285
|
}
|
|
742
1286
|
function projectScenarioJobEvent(value) {
|
|
743
1287
|
const record = asRecord(value);
|
|
@@ -823,6 +1367,7 @@ function runtimeTextTurnRequest(input) {
|
|
|
823
1367
|
return {
|
|
824
1368
|
messages,
|
|
825
1369
|
tools: toRuntimeTools(input.tools),
|
|
1370
|
+
...(input.reasoning === undefined ? {} : { reasoning: toRuntimeReasoningConfig(input.reasoning, (detail) => localAppError(detail, 'SDK_LOCAL_APP_INPUT_INVALID', 'provide_admitted_local_app_text_input')) }),
|
|
826
1371
|
toolChoice: choice === 'none' ? ToolChoiceMode.NONE : choice === 'auto' ? ToolChoiceMode.AUTO
|
|
827
1372
|
: choice === 'required' ? ToolChoiceMode.REQUIRED : choice ? ToolChoiceMode.TOOL : ToolChoiceMode.UNSPECIFIED,
|
|
828
1373
|
toolChoiceName: typeof choice === 'object' ? choice.name : '',
|
|
@@ -841,13 +1386,26 @@ function runtimeTextTurnRequest(input) {
|
|
|
841
1386
|
...(input.seed === undefined ? {} : { seed: String(input.seed) }),
|
|
842
1387
|
};
|
|
843
1388
|
}
|
|
844
|
-
function
|
|
1389
|
+
function projectEmbeddingUsage(value) {
|
|
1390
|
+
const usage = asRecord(value);
|
|
1391
|
+
assertExactProjectionKeys(usage, ['promptTokens', 'completionTokens', 'totalTokens'], 'embedding usage');
|
|
1392
|
+
const promptTokens = projectionInteger(usage.promptTokens, 'embedding prompt tokens', 0, Number.MAX_SAFE_INTEGER);
|
|
1393
|
+
const completionTokens = projectionInteger(usage.completionTokens, 'embedding completion tokens', 0, Number.MAX_SAFE_INTEGER);
|
|
1394
|
+
const totalTokens = projectionInteger(usage.totalTokens, 'embedding total tokens', 0, Number.MAX_SAFE_INTEGER);
|
|
1395
|
+
if (totalTokens !== promptTokens + completionTokens)
|
|
1396
|
+
localAppProjectionError('embedding total tokens');
|
|
1397
|
+
return Object.freeze({ promptTokens, completionTokens, totalTokens });
|
|
1398
|
+
}
|
|
1399
|
+
function runtimeExecuteRequest(spec, timeoutMs) {
|
|
845
1400
|
if (spec.type === 'text-generate')
|
|
846
|
-
return { spec: { oneofKind: 'textGenerate', textGenerate: runtimeTextTurnRequest(spec) } };
|
|
1401
|
+
return { spec: { oneofKind: 'textGenerate', textGenerate: runtimeTextTurnRequest(spec) }, timeoutMs };
|
|
847
1402
|
if (spec.type === 'text-embed') {
|
|
848
|
-
return { spec: { oneofKind: 'textEmbed', textEmbed: { inputs: [...spec.inputs] } } };
|
|
1403
|
+
return { spec: { oneofKind: 'textEmbed', textEmbed: { inputs: [...spec.inputs], purpose: spec.purpose === 'retrieval-document' ? TextEmbedPurpose.RETRIEVAL_DOCUMENT : spec.purpose === 'retrieval-query' ? TextEmbedPurpose.RETRIEVAL_QUERY : TextEmbedPurpose.UNSPECIFIED, ...(spec.dimensions !== undefined ? { dimensions: spec.dimensions } : {}) } }, timeoutMs };
|
|
849
1404
|
}
|
|
850
|
-
|
|
1405
|
+
if (spec.type === 'text-decide') {
|
|
1406
|
+
return { spec: { oneofKind: 'textDecide', textDecide: runtimeTextDecideSpec(spec) }, timeoutMs };
|
|
1407
|
+
}
|
|
1408
|
+
return invalidAIInput('unsupported synchronous Scenario spec');
|
|
851
1409
|
}
|
|
852
1410
|
function runtimeLocalJobSpec(spec) {
|
|
853
1411
|
switch (spec.type) {
|
|
@@ -905,8 +1463,24 @@ function runtimeLocalJobSpec(spec) {
|
|
|
905
1463
|
...(spec.voiceRef === null ? {} : { voiceRef: runtimeVoiceReference(spec.voiceRef) }),
|
|
906
1464
|
timingMode: runtimeSpeechTimingMode(spec.timingMode),
|
|
907
1465
|
...(spec.voiceRenderHints === null ? {} : { voiceRenderHints: { ...spec.voiceRenderHints } }),
|
|
1466
|
+
...(spec.identityAudio ? { identityAudio: { ...spec.identityAudio } } : {}),
|
|
1467
|
+
...(spec.performanceAudio ? { performanceAudio: { ...spec.performanceAudio } } : {}),
|
|
908
1468
|
},
|
|
909
1469
|
};
|
|
1470
|
+
case 'text-annotate':
|
|
1471
|
+
return { oneofKind: 'textAnnotate', textAnnotate: { language: spec.language, texts: [...spec.texts] } };
|
|
1472
|
+
case 'audio-speaker-embed':
|
|
1473
|
+
return { oneofKind: 'audioSpeakerEmbed', audioSpeakerEmbed: { mimeType: spec.mimeType,
|
|
1474
|
+
audioSource: spec.audioSource ? { source: spec.audioSource.type === 'bytes' ? { oneofKind: 'audioBytes', audioBytes: spec.audioSource.bytes } : { oneofKind: 'audioUri', audioUri: spec.audioSource.uri } } : undefined,
|
|
1475
|
+
sourceAudio: spec.sourceAudio ? { artifactId: spec.sourceAudio.artifactId, range: spec.sourceAudio.range ? { startFrame: String(spec.sourceAudio.range.startFrame), endFrame: String(spec.sourceAudio.range.endFrame) } : undefined } : undefined } };
|
|
1476
|
+
case 'audio-separate':
|
|
1477
|
+
return { oneofKind: 'audioSeparate', audioSeparate: { mimeType: spec.mimeType,
|
|
1478
|
+
audioSource: spec.audioSource ? { source: spec.audioSource.type === 'bytes'
|
|
1479
|
+
? { oneofKind: 'audioBytes', audioBytes: spec.audioSource.bytes }
|
|
1480
|
+
: { oneofKind: 'audioUri', audioUri: spec.audioSource.uri } } : undefined,
|
|
1481
|
+
sourceAudio: spec.sourceAudio ? { artifactId: spec.sourceAudio.artifactId,
|
|
1482
|
+
range: spec.sourceAudio.range ? { startFrame: String(spec.sourceAudio.range.startFrame), endFrame: String(spec.sourceAudio.range.endFrame) } : undefined } : undefined,
|
|
1483
|
+
includeInstrumentParts: spec.includeInstrumentParts ?? false } };
|
|
910
1484
|
case 'speech-transcribe':
|
|
911
1485
|
return {
|
|
912
1486
|
oneofKind: 'speechTranscribe',
|
|
@@ -920,7 +1494,7 @@ function runtimeLocalJobSpec(spec) {
|
|
|
920
1494
|
responseFormat: spec.responseFormat,
|
|
921
1495
|
audioSource: {
|
|
922
1496
|
source: spec.audioSource.type === 'bytes'
|
|
923
|
-
? { oneofKind: 'audioBytes', audioBytes:
|
|
1497
|
+
? { oneofKind: 'audioBytes', audioBytes: spec.audioSource.bytes }
|
|
924
1498
|
: { oneofKind: 'audioUri', audioUri: spec.audioSource.uri },
|
|
925
1499
|
},
|
|
926
1500
|
},
|
|
@@ -934,7 +1508,7 @@ function runtimeLocalJobSpec(spec) {
|
|
|
934
1508
|
oneofKind: 'referenceAudio',
|
|
935
1509
|
referenceAudio: {
|
|
936
1510
|
referenceAudioBytes: spec.referenceAudio.type === 'bytes'
|
|
937
|
-
?
|
|
1511
|
+
? spec.referenceAudio.bytes
|
|
938
1512
|
: new Uint8Array(),
|
|
939
1513
|
referenceAudioUri: spec.referenceAudio.type === 'uri' ? spec.referenceAudio.uri : '',
|
|
940
1514
|
referenceAudioMime: spec.referenceAudioMime,
|
|
@@ -960,13 +1534,17 @@ function runtimeLocalJobSpec(spec) {
|
|
|
960
1534
|
},
|
|
961
1535
|
},
|
|
962
1536
|
};
|
|
1537
|
+
case 'music-transcribe':
|
|
1538
|
+
return { oneofKind: 'musicTranscribe', musicTranscribe: runtimeMusicTranscribeSpec(spec) };
|
|
1539
|
+
case 'audio-voice-convert':
|
|
1540
|
+
return { oneofKind: 'audioVoiceConvert', audioVoiceConvert: runtimeVoiceConvertSpec(spec) };
|
|
963
1541
|
case 'music-generate':
|
|
964
1542
|
return {
|
|
965
1543
|
oneofKind: 'musicGenerate',
|
|
966
|
-
musicGenerate:
|
|
1544
|
+
musicGenerate: runtimeMusicGenerateSpec(spec),
|
|
967
1545
|
};
|
|
968
1546
|
case 'world-generate':
|
|
969
|
-
return { oneofKind: 'worldGenerate', worldGenerate: { prompt: spec.prompt, displayName: spec.displayName } };
|
|
1547
|
+
return { oneofKind: 'worldGenerate', worldGenerate: { prompt: spec.prompt ?? '', displayName: spec.displayName, ...(spec.image ? { image: { artifactId: spec.image.artifactId, projection: spec.image.projection === 'ordinary' ? WorldImageProjection.ORDINARY : WorldImageProjection.EQUIRECTANGULAR_360 } } : {}) } };
|
|
970
1548
|
}
|
|
971
1549
|
}
|
|
972
1550
|
function runtimeImageSpec(spec) {
|
|
@@ -1031,6 +1609,8 @@ function runtimeVoiceReference(value) {
|
|
|
1031
1609
|
function projectRuntimeTextTurnEvent(event) {
|
|
1032
1610
|
const base = { sequence: event.sequence, traceId: event.traceId };
|
|
1033
1611
|
switch (event.payload.oneofKind) {
|
|
1612
|
+
case 'reasoningSummary':
|
|
1613
|
+
return { ...base, type: 'reasoning-summary', ...event.payload.reasoningSummary };
|
|
1034
1614
|
case 'reasoningContinuity': {
|
|
1035
1615
|
const carrier = event.payload.reasoningContinuity.carrier;
|
|
1036
1616
|
if (!carrier)
|
|
@@ -1072,17 +1652,16 @@ function projectRuntimeScenarioExecuteResponse(response) {
|
|
|
1072
1652
|
type: 'text-embed',
|
|
1073
1653
|
vectors: response.output.textEmbed.vectors.map((vector) => [...vector.values]),
|
|
1074
1654
|
spaceId: response.output.textEmbed.spaceId,
|
|
1655
|
+
...(response.output.textEmbed.usage ? { usage: {
|
|
1656
|
+
promptTokens: Number(response.output.textEmbed.usage.inputTokens),
|
|
1657
|
+
completionTokens: Number(response.output.textEmbed.usage.outputTokens),
|
|
1658
|
+
totalTokens: Number(response.output.textEmbed.usage.inputTokens) + Number(response.output.textEmbed.usage.outputTokens),
|
|
1659
|
+
} } : {}),
|
|
1075
1660
|
},
|
|
1076
1661
|
traceId: response.traceId,
|
|
1077
1662
|
};
|
|
1078
|
-
case '
|
|
1079
|
-
return {
|
|
1080
|
-
output: {
|
|
1081
|
-
type: 'image-generate',
|
|
1082
|
-
artifacts: response.output.imageGenerate.artifacts.map(projectRuntimeLocalArtifact),
|
|
1083
|
-
},
|
|
1084
|
-
traceId: response.traceId,
|
|
1085
|
-
};
|
|
1663
|
+
case 'textDecide':
|
|
1664
|
+
return { output: localTextDecideOutputFromRuntime(response.output.textDecide), traceId: response.traceId };
|
|
1086
1665
|
default:
|
|
1087
1666
|
return localAppProjectionError('scenario Runtime output');
|
|
1088
1667
|
}
|
|
@@ -1090,6 +1669,7 @@ function projectRuntimeScenarioExecuteResponse(response) {
|
|
|
1090
1669
|
function projectRuntimeLocalJob(job) {
|
|
1091
1670
|
const interruption = localInterruptionFromRuntime(job.interruption);
|
|
1092
1671
|
return {
|
|
1672
|
+
...localJobFactsFromRuntime(job),
|
|
1093
1673
|
...(job.videoFaceSwapSummary ? { videoFaceSwapSummary: { ...job.videoFaceSwapSummary, durationUs: runtimeSafeInteger(job.videoFaceSwapSummary.durationUs, 'video duration') } } : {}),
|
|
1094
1674
|
...(interruption ? { interruption } : {}),
|
|
1095
1675
|
jobId: job.jobId,
|
|
@@ -1104,14 +1684,22 @@ function projectRuntimeLocalJob(job) {
|
|
|
1104
1684
|
traceId: job.traceId,
|
|
1105
1685
|
createdAt: plainRuntimeTimestamp(job.createdAt),
|
|
1106
1686
|
updatedAt: plainRuntimeTimestamp(job.updatedAt),
|
|
1687
|
+
...(job.recoveryExpiresAt ? { recoveryExpiresAt: plainRuntimeTimestamp(job.recoveryExpiresAt) } : {}),
|
|
1107
1688
|
transcriptionText: job.transcriptionText,
|
|
1689
|
+
...(job.textAnnotation ? { textAnnotation: job.textAnnotation } : {}),
|
|
1690
|
+
...(job.speakerEmbedding ? { speakerEmbedding: validateNimiLocalAppSpeakerEmbedding({ vector: job.speakerEmbedding.vector?.values, spaceId: job.speakerEmbedding.spaceId }) } : {}),
|
|
1691
|
+
...(job.audioSeparation ? { audioSeparation: localAudioSeparation(job.audioSeparation) } : {}),
|
|
1692
|
+
...(job.musicGeneration ? { musicGeneration: localMusicGeneration(job.musicGeneration) } : {}),
|
|
1693
|
+
...(job.musicTranscription ? { musicTranscription: localMusicTranscription(job.musicTranscription) } : {}),
|
|
1694
|
+
...(job.voiceConversion ? { voiceConversion: localVoiceConversion(job.voiceConversion) } : {}),
|
|
1695
|
+
...(job.transcription ? { transcription: localTranscriptionFromRuntime(job.transcription) } : {}),
|
|
1108
1696
|
};
|
|
1109
1697
|
}
|
|
1110
1698
|
function projectRuntimeLocalArtifact(artifact) {
|
|
1111
1699
|
return {
|
|
1112
1700
|
artifactId: artifact.artifactId,
|
|
1113
1701
|
mimeType: artifact.mimeType,
|
|
1114
|
-
bytes:
|
|
1702
|
+
bytes: artifact.bytes,
|
|
1115
1703
|
sizeBytes: runtimeSafeInteger(artifact.sizeBytes, 'scenario artifact size'),
|
|
1116
1704
|
sha256: artifact.sha256,
|
|
1117
1705
|
durationMs: runtimeSafeInteger(artifact.durationMs, 'scenario artifact duration'),
|
|
@@ -1119,7 +1707,12 @@ function projectRuntimeLocalArtifact(artifact) {
|
|
|
1119
1707
|
height: artifact.height,
|
|
1120
1708
|
sampleRateHz: artifact.sampleRateHz,
|
|
1121
1709
|
channels: artifact.channels,
|
|
1710
|
+
...(BigInt(artifact.frameCount ?? '0') > 0n ? { frameCount: runtimeSafeInteger(artifact.frameCount, 'audio frames') } : {}),
|
|
1122
1711
|
...(artifact.seed !== undefined ? { seed: artifact.seed } : {}),
|
|
1712
|
+
...(artifact.speechAlignment ? { speechAlignment: {
|
|
1713
|
+
unit: artifact.speechAlignment.unit === 1 ? 'word' : artifact.speechAlignment.unit === 2 ? 'char' : 'invalid',
|
|
1714
|
+
tokens: artifact.speechAlignment.tokens.map(token => ({ token: token.token, startMs: runtimeSafeInteger(token.startMs, 'alignment start'), endMs: runtimeSafeInteger(token.endMs, 'alignment end') })),
|
|
1715
|
+
} } : {}),
|
|
1123
1716
|
};
|
|
1124
1717
|
}
|
|
1125
1718
|
function projectRuntimeLocalJobEvent(event) {
|
|
@@ -1147,8 +1740,13 @@ function runtimeScenarioTypeName(value) {
|
|
|
1147
1740
|
[ScenarioType.VIDEO_GENERATE]: 'video-generate',
|
|
1148
1741
|
[ScenarioType.SPEECH_SYNTHESIZE]: 'speech-synthesize',
|
|
1149
1742
|
[ScenarioType.SPEECH_TRANSCRIBE]: 'speech-transcribe',
|
|
1743
|
+
[ScenarioType.TEXT_ANNOTATE]: 'text-annotate',
|
|
1744
|
+
[ScenarioType.AUDIO_SPEAKER_EMBED]: 'audio-speaker-embed',
|
|
1745
|
+
[ScenarioType.AUDIO_SEPARATE]: 'audio-separate',
|
|
1150
1746
|
[ScenarioType.VOICE_CREATE]: 'voice-create',
|
|
1151
1747
|
[ScenarioType.MUSIC_GENERATE]: 'music-generate',
|
|
1748
|
+
[ScenarioType.MUSIC_TRANSCRIBE]: 'music-transcribe',
|
|
1749
|
+
[ScenarioType.AUDIO_VOICE_CONVERT]: 'audio-voice-convert',
|
|
1152
1750
|
[ScenarioType.WORLD_GENERATE]: 'world-generate',
|
|
1153
1751
|
};
|
|
1154
1752
|
return types[value] ?? localAppProjectionError('scenario Runtime type');
|
|
@@ -1228,8 +1826,13 @@ function localVoiceCreationSource(source) {
|
|
|
1228
1826
|
return 'text-description';
|
|
1229
1827
|
return localAppProjectionError('voice asset creationSource');
|
|
1230
1828
|
}
|
|
1231
|
-
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'];
|
|
1829
|
+
const LOCAL_SCENARIO_TYPES = ['image-generate', 'image-face-swap', 'video-face-swap', 'vision-locate', 'video-generate', 'speech-synthesize', 'speech-transcribe', 'text-annotate', 'audio-speaker-embed', 'audio-separate', 'voice-create', 'music-generate', 'music-transcribe', 'audio-voice-convert', 'world-generate'];
|
|
1232
1830
|
const LOCAL_JOB_STATUSES = ['submitted', 'queued', 'running', 'completed', 'failed', 'canceled', 'timeout'];
|
|
1831
|
+
export function validateNimiLocalAppSpeakerEmbedSpec(value) {
|
|
1832
|
+
if (asRecord(value)?.type !== 'audio-speaker-embed')
|
|
1833
|
+
adapterInputError('speaker representation spec is required');
|
|
1834
|
+
return validateScenarioSpec(value, false);
|
|
1835
|
+
}
|
|
1233
1836
|
function localJobSpecFromRuntimeRequest(request) {
|
|
1234
1837
|
assertExactKeys(request, ['head', 'scenarioType', 'executionMode', 'spec', 'requestId', 'idempotencyKey', 'labels', 'extensions'], 'Runtime Scenario Job adapter request');
|
|
1235
1838
|
if (request.executionMode !== ExecutionMode.ASYNC_JOB || request.extensions.length > 0)
|
|
@@ -1238,6 +1841,30 @@ function localJobSpecFromRuntimeRequest(request) {
|
|
|
1238
1841
|
if (!spec || spec.oneofKind === undefined)
|
|
1239
1842
|
adapterInputError('missing Scenario spec');
|
|
1240
1843
|
switch (spec.oneofKind) {
|
|
1844
|
+
case 'audioSpeakerEmbed': {
|
|
1845
|
+
requireScenarioType(request, ScenarioType.AUDIO_SPEAKER_EMBED);
|
|
1846
|
+
assertExactKeys(spec.audioSpeakerEmbed, ['mimeType', 'audioSource', 'sourceAudio'], 'Runtime speaker representation spec');
|
|
1847
|
+
const inline = spec.audioSpeakerEmbed.audioSource?.source;
|
|
1848
|
+
const owned = spec.audioSpeakerEmbed.sourceAudio;
|
|
1849
|
+
if ((spec.audioSpeakerEmbed.audioSource !== undefined) === (owned !== undefined))
|
|
1850
|
+
adapterInputError('Local App speaker representation requires exactly one source');
|
|
1851
|
+
if (spec.audioSpeakerEmbed.audioSource !== undefined && (!inline || (inline.oneofKind !== 'audioBytes' && inline.oneofKind !== 'audioUri')))
|
|
1852
|
+
adapterInputError('Local App speaker representation requires bytes or URI audio');
|
|
1853
|
+
if (inline) {
|
|
1854
|
+
assertExactKeys(spec.audioSpeakerEmbed.audioSource, ['source'], 'Runtime speaker audio source');
|
|
1855
|
+
assertExactKeys(inline, ['oneofKind', inline.oneofKind], 'Runtime speaker audio content');
|
|
1856
|
+
}
|
|
1857
|
+
if (owned) {
|
|
1858
|
+
assertExactKeys(owned, ['artifactId', 'range'], 'Runtime speaker owned audio');
|
|
1859
|
+
if (owned.range)
|
|
1860
|
+
assertExactKeys(owned.range, ['startFrame', 'endFrame'], 'Runtime speaker frame range');
|
|
1861
|
+
}
|
|
1862
|
+
return validateNimiLocalAppSpeakerEmbedSpec({ type: 'audio-speaker-embed', mimeType: spec.audioSpeakerEmbed.mimeType,
|
|
1863
|
+
...(inline?.oneofKind === 'audioBytes' ? { audioSource: { type: 'bytes', bytes: inline.audioBytes } }
|
|
1864
|
+
: inline?.oneofKind === 'audioUri' ? { audioSource: { type: 'uri', uri: inline.audioUri } } : {}),
|
|
1865
|
+
...(owned ? { sourceAudio: { artifactId: owned.artifactId, ...(owned.range ? { range: { startFrame: safeOptionalInt64(owned.range.startFrame, 'speaker source start frame'), endFrame: safeOptionalInt64(owned.range.endFrame, 'speaker source end frame') } } : {}) } } : {}),
|
|
1866
|
+
});
|
|
1867
|
+
}
|
|
1241
1868
|
case 'videoFaceSwap':
|
|
1242
1869
|
requireScenarioType(request, ScenarioType.VIDEO_FACE_SWAP);
|
|
1243
1870
|
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);
|
|
@@ -1276,6 +1903,24 @@ function localJobSpecFromRuntimeRequest(request) {
|
|
|
1276
1903
|
case 'speechTranscribe':
|
|
1277
1904
|
requireScenarioType(request, ScenarioType.SPEECH_TRANSCRIBE);
|
|
1278
1905
|
return validateScenarioSpec(runtimeSpeechTranscribeSpec(spec.speechTranscribe), false);
|
|
1906
|
+
case 'textAnnotate':
|
|
1907
|
+
requireScenarioType(request, ScenarioType.TEXT_ANNOTATE);
|
|
1908
|
+
return validateScenarioSpec({ type: 'text-annotate', language: spec.textAnnotate.language, texts: [...spec.textAnnotate.texts] }, false);
|
|
1909
|
+
case 'audioSeparate': {
|
|
1910
|
+
requireScenarioType(request, ScenarioType.AUDIO_SEPARATE);
|
|
1911
|
+
const inline = spec.audioSeparate.audioSource?.source;
|
|
1912
|
+
const owned = spec.audioSeparate.sourceAudio;
|
|
1913
|
+
if ((inline !== undefined) === (owned !== undefined))
|
|
1914
|
+
adapterInputError('Local App separation requires exactly one source');
|
|
1915
|
+
if (inline && (inline.oneofKind === undefined || inline.oneofKind === 'audioChunks'))
|
|
1916
|
+
adapterInputError('Local App separation requires bytes or URI audio');
|
|
1917
|
+
return validateScenarioSpec({ type: 'audio-separate', mimeType: spec.audioSeparate.mimeType,
|
|
1918
|
+
...(inline ? { audioSource: inline.oneofKind === 'audioBytes'
|
|
1919
|
+
? { type: 'bytes', bytes: exactNimiLocalAppBytes(inline.audioBytes) } : { type: 'uri', uri: inline.audioUri } } : {}),
|
|
1920
|
+
...(owned ? { sourceAudio: { artifactId: owned.artifactId,
|
|
1921
|
+
...(owned.range ? { range: { startFrame: Number(owned.range.startFrame), endFrame: Number(owned.range.endFrame) } } : {}) } } : {}),
|
|
1922
|
+
...(spec.audioSeparate.includeInstrumentParts ? { includeInstrumentParts: true } : {}) }, false);
|
|
1923
|
+
}
|
|
1279
1924
|
case 'voiceCreate': {
|
|
1280
1925
|
requireScenarioType(request, ScenarioType.VOICE_CREATE);
|
|
1281
1926
|
if (spec.voiceCreate.targetModelId)
|
|
@@ -1304,20 +1949,32 @@ function localJobSpecFromRuntimeRequest(request) {
|
|
|
1304
1949
|
}
|
|
1305
1950
|
return adapterInputError('voice create source is invalid');
|
|
1306
1951
|
}
|
|
1952
|
+
case 'musicTranscribe':
|
|
1953
|
+
requireScenarioType(request, ScenarioType.MUSIC_TRANSCRIBE);
|
|
1954
|
+
return localMusicTranscribeSpec(spec.musicTranscribe);
|
|
1955
|
+
case 'audioVoiceConvert':
|
|
1956
|
+
requireScenarioType(request, ScenarioType.AUDIO_VOICE_CONVERT);
|
|
1957
|
+
return localVoiceConvertSpec(spec.audioVoiceConvert);
|
|
1307
1958
|
case 'musicGenerate':
|
|
1308
1959
|
requireScenarioType(request, ScenarioType.MUSIC_GENERATE);
|
|
1309
|
-
|
|
1310
|
-
|| spec.musicGenerate.instrumental) {
|
|
1311
|
-
return adapterInputError('unsupported MiniMax-Music3 fields are unavailable to Local Apps');
|
|
1312
|
-
}
|
|
1313
|
-
return validateScenarioSpec({ type: 'music-generate', prompt: spec.musicGenerate.prompt, lyrics: spec.musicGenerate.lyrics,
|
|
1314
|
-
...(spec.musicGenerate.durationSeconds !== 0 ? { durationSeconds: spec.musicGenerate.durationSeconds } : {}) }, false);
|
|
1960
|
+
return localMusicGenerateSpec(spec.musicGenerate);
|
|
1315
1961
|
case 'worldGenerate':
|
|
1316
1962
|
requireScenarioType(request, ScenarioType.WORLD_GENERATE);
|
|
1317
|
-
if (spec.worldGenerate.
|
|
1318
|
-
return adapterInputError('Local App worlds accept
|
|
1963
|
+
if (spec.worldGenerate.tags.length > 0 || spec.worldGenerate.seed !== '0')
|
|
1964
|
+
return adapterInputError('Local App worlds do not accept tags or seed');
|
|
1965
|
+
{
|
|
1966
|
+
const conditioning = spec.worldGenerate.conditioning;
|
|
1967
|
+
let image;
|
|
1968
|
+
if (conditioning.oneofKind !== undefined) {
|
|
1969
|
+
if (conditioning.oneofKind !== 'imagePrompt' || conditioning.imagePrompt.content?.source.oneofKind !== 'artifactId')
|
|
1970
|
+
return adapterInputError('Local App worlds require an owned image');
|
|
1971
|
+
const projection = conditioning.imagePrompt.projection;
|
|
1972
|
+
if (projection !== WorldImageProjection.ORDINARY && projection !== WorldImageProjection.EQUIRECTANGULAR_360)
|
|
1973
|
+
return adapterInputError('World projection is required');
|
|
1974
|
+
image = { artifactId: conditioning.imagePrompt.content.source.artifactId, projection: projection === WorldImageProjection.ORDINARY ? 'ordinary' : 'equirectangular-360' };
|
|
1975
|
+
}
|
|
1976
|
+
return validateScenarioSpec({ type: 'world-generate', prompt: spec.worldGenerate.textPrompt, displayName: spec.worldGenerate.displayName, ...(image ? { image } : {}) }, false);
|
|
1319
1977
|
}
|
|
1320
|
-
return validateScenarioSpec({ type: 'world-generate', prompt: spec.worldGenerate.textPrompt, displayName: spec.worldGenerate.displayName }, false);
|
|
1321
1978
|
default:
|
|
1322
1979
|
return adapterInputError(`Scenario type ${spec.oneofKind} is unavailable to Local Apps`);
|
|
1323
1980
|
}
|
|
@@ -1373,6 +2030,8 @@ function runtimeSpeechSynthesizeSpec(spec) {
|
|
|
1373
2030
|
...(spec.volume !== undefined ? { volume: spec.volume } : {}),
|
|
1374
2031
|
emotion: spec.emotion, voiceRef, timingMode: speechTimingName(spec.timingMode),
|
|
1375
2032
|
voiceRenderHints: spec.voiceRenderHints ? { ...spec.voiceRenderHints } : null,
|
|
2033
|
+
...(spec.identityAudio ? { identityAudio: { ...spec.identityAudio } } : {}),
|
|
2034
|
+
...(spec.performanceAudio ? { performanceAudio: { ...spec.performanceAudio } } : {}),
|
|
1376
2035
|
};
|
|
1377
2036
|
}
|
|
1378
2037
|
function runtimeSpeechTranscribeSpec(spec) {
|
|
@@ -1386,14 +2045,14 @@ function runtimeSpeechTranscribeSpec(spec) {
|
|
|
1386
2045
|
...(spec.speakerCount !== undefined ? { speakerCount: spec.speakerCount } : {}),
|
|
1387
2046
|
prompt: spec.prompt, responseFormat: spec.responseFormat,
|
|
1388
2047
|
audioSource: source.oneofKind === 'audioBytes'
|
|
1389
|
-
? { type: 'bytes', bytes:
|
|
2048
|
+
? { type: 'bytes', bytes: exactNimiLocalAppBytes(source.audioBytes) }
|
|
1390
2049
|
: { type: 'uri', uri: source.audioUri },
|
|
1391
2050
|
};
|
|
1392
2051
|
}
|
|
1393
2052
|
function runtimeVoiceAudio(bytes, uri) {
|
|
1394
2053
|
if (bytes.length > 0 === Boolean(uri))
|
|
1395
2054
|
adapterInputError('voice reference audio must select exactly one source');
|
|
1396
|
-
return bytes.length > 0 ? { type: 'bytes', bytes:
|
|
2055
|
+
return bytes.length > 0 ? { type: 'bytes', bytes: exactNimiLocalAppBytes(bytes) } : { type: 'uri', uri };
|
|
1397
2056
|
}
|
|
1398
2057
|
function runtimeJobFromLocal(job) {
|
|
1399
2058
|
return {
|
|
@@ -1401,12 +2060,22 @@ function runtimeJobFromLocal(job) {
|
|
|
1401
2060
|
...(job.interruption ? { interruption: runtimeInterruptionFromLocal(job.interruption) } : {}),
|
|
1402
2061
|
jobId: job.jobId, head: undefined, scenarioType: runtimeScenarioType(job.scenarioType), executionMode: ExecutionMode.ASYNC_JOB,
|
|
1403
2062
|
routeDecision: RoutePolicy.UNSPECIFIED, modelResolved: '', status: runtimeJobStatus(job.status), providerJobId: '',
|
|
2063
|
+
submissionOutcome: SUBMISSION_OUTCOMES.indexOf(job.submissionOutcome),
|
|
2064
|
+
stopOutcome: STOP_OUTCOMES.indexOf(job.stopOutcome),
|
|
1404
2065
|
reasonCode: runtimeReasonCode(job.reasonCode), reasonDetail: job.reasonDetail, retryCount: 0,
|
|
1405
2066
|
createdAt: runtimeTimestamp(job.createdAt), updatedAt: runtimeTimestamp(job.updatedAt), nextPollAt: undefined,
|
|
2067
|
+
recoveryExpiresAt: runtimeTimestamp(job.recoveryExpiresAt ?? null),
|
|
1406
2068
|
artifacts: job.artifacts.map((artifact) => runtimeArtifactFromLocal(artifact)), usage: undefined, traceId: job.traceId,
|
|
1407
2069
|
ignoredExtensions: [], reasonMetadata: undefined, progressPercent: job.progressPercent,
|
|
1408
2070
|
progressCurrentStep: job.progressCurrentStep, progressTotalSteps: job.progressTotalSteps,
|
|
1409
2071
|
transcriptionText: job.transcriptionText,
|
|
2072
|
+
transcription: runtimeTranscriptionFromLocal(job.transcription),
|
|
2073
|
+
audioSeparation: runtimeAudioSeparation(job.audioSeparation),
|
|
2074
|
+
speakerEmbedding: job.speakerEmbedding ? { vector: { values: [...job.speakerEmbedding.vector] }, spaceId: job.speakerEmbedding.spaceId } : undefined,
|
|
2075
|
+
musicGeneration: runtimeMusicGeneration(job.musicGeneration),
|
|
2076
|
+
musicTranscription: runtimeMusicTranscription(job.musicTranscription),
|
|
2077
|
+
voiceConversion: runtimeVoiceConversion(job.voiceConversion),
|
|
2078
|
+
textAnnotation: runtimeAnnotationFromLocal(job.textAnnotation),
|
|
1410
2079
|
};
|
|
1411
2080
|
}
|
|
1412
2081
|
function runtimeVoiceAssetFromLocal(asset) {
|
|
@@ -1419,17 +2088,20 @@ function runtimeVoiceAssetFromLocal(asset) {
|
|
|
1419
2088
|
creationSource: runtimeVoiceCreationSource(asset.creationSource),
|
|
1420
2089
|
};
|
|
1421
2090
|
}
|
|
1422
|
-
function runtimeArtifactFromLocal(artifact, bytes =
|
|
1423
|
-
return { artifactId: artifact.artifactId, mimeType, bytes, uri: '', sha256: artifact.sha256, sizeBytes: String(sizeBytes), durationMs: String(artifact.durationMs), fps: 0, width: artifact.width, height: artifact.height, sampleRateHz: artifact.sampleRateHz, channels: artifact.channels,
|
|
2091
|
+
function runtimeArtifactFromLocal(artifact, bytes = artifact.bytes, mimeType = artifact.mimeType, sizeBytes = artifact.sizeBytes) {
|
|
2092
|
+
return { artifactId: artifact.artifactId, mimeType, bytes, uri: '', sha256: artifact.sha256, sizeBytes: String(sizeBytes), durationMs: String(artifact.durationMs), fps: 0, width: artifact.width, height: artifact.height, sampleRateHz: artifact.sampleRateHz, channels: artifact.channels, frameCount: String(artifact.frameCount ?? 0), speechAlignment: artifact.speechAlignment ? {
|
|
2093
|
+
unit: artifact.speechAlignment.unit === 'word' ? 1 : 2,
|
|
2094
|
+
tokens: artifact.speechAlignment.tokens.map(token => ({ token: token.token, startMs: String(token.startMs), endMs: String(token.endMs) })),
|
|
2095
|
+
} : undefined, metadata: undefined, seed: artifact.seed };
|
|
1424
2096
|
}
|
|
1425
2097
|
function runtimeJobEventFromLocal(event) {
|
|
1426
2098
|
return { eventType: runtimeJobEventType(event.eventType), sequence: event.sequence, traceId: event.traceId, timestamp: runtimeTimestamp(event.timestamp), job: runtimeJobFromLocal(event.job) };
|
|
1427
2099
|
}
|
|
1428
2100
|
function runtimeArtifactResponse(job, artifacts) {
|
|
1429
|
-
const output = runtimeOutput(job.scenarioType, artifacts, job.transcriptionText, job.videoFaceSwapSummary);
|
|
2101
|
+
const output = runtimeOutput(job.scenarioType, artifacts, job.transcriptionText, job.videoFaceSwapSummary, job.transcription, job.audioSeparation, job.textAnnotation, job.musicGeneration, job.musicTranscription, job.voiceConversion, job.speakerEmbedding);
|
|
1430
2102
|
return { jobId: job.jobId, artifacts, traceId: job.traceId, output };
|
|
1431
2103
|
}
|
|
1432
|
-
function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary) {
|
|
2104
|
+
function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary, transcription, audioSeparation, textAnnotation, musicGeneration, musicTranscription, voiceConversion, speakerEmbedding) {
|
|
1433
2105
|
switch (type) {
|
|
1434
2106
|
case 'video-face-swap': return videoFaceSwapSummary ? { output: { oneofKind: 'videoFaceSwap', videoFaceSwap: { artifacts, summary: { ...videoFaceSwapSummary, durationUs: String(videoFaceSwapSummary.durationUs) } } } } : undefined;
|
|
1435
2107
|
case 'image-face-swap': return { output: { oneofKind: 'imageFaceSwap', imageFaceSwap: { artifacts } } };
|
|
@@ -1437,16 +2109,21 @@ function runtimeOutput(type, artifacts, transcriptionText, videoFaceSwapSummary)
|
|
|
1437
2109
|
case 'video-generate': return { output: { oneofKind: 'videoGenerate', videoGenerate: { artifacts } } };
|
|
1438
2110
|
case 'speech-synthesize': return { output: { oneofKind: 'speechSynthesize', speechSynthesize: { artifacts } } };
|
|
1439
2111
|
case 'speech-transcribe': {
|
|
1440
|
-
if (!transcriptionText.trim() || utf8Length(transcriptionText) >
|
|
2112
|
+
if ((!transcriptionText.trim() && transcription?.status !== 'no-speech') || utf8Length(transcriptionText) > (1 << 20))
|
|
1441
2113
|
localAppProjectionError('speech transcription text');
|
|
1442
|
-
return { output: { oneofKind: 'speechTranscribe', speechTranscribe: { text: transcriptionText, artifacts } } };
|
|
2114
|
+
return { output: { oneofKind: 'speechTranscribe', speechTranscribe: { text: transcriptionText, artifacts, transcription: runtimeTranscriptionFromLocal(transcription) } } };
|
|
1443
2115
|
}
|
|
1444
|
-
case '
|
|
2116
|
+
case 'text-annotate': return { output: { oneofKind: 'textAnnotation', textAnnotation: runtimeAnnotationFromLocal(textAnnotation) } };
|
|
2117
|
+
case 'audio-speaker-embed': return speakerEmbedding ? { output: { oneofKind: 'audioSpeakerEmbed', audioSpeakerEmbed: { vector: { values: [...speakerEmbedding.vector] }, spaceId: speakerEmbedding.spaceId } } } : undefined;
|
|
2118
|
+
case 'audio-separate': return { output: { oneofKind: 'audioSeparate', audioSeparate: { artifacts, separation: runtimeAudioSeparation(audioSeparation) } } };
|
|
2119
|
+
case 'music-transcribe': return { output: { oneofKind: 'musicTranscribe', musicTranscribe: { artifacts, transcription: runtimeMusicTranscription(musicTranscription) } } };
|
|
2120
|
+
case 'audio-voice-convert': return { output: { oneofKind: 'audioVoiceConvert', audioVoiceConvert: { artifacts, conversion: runtimeVoiceConversion(voiceConversion) } } };
|
|
2121
|
+
case 'music-generate': return { output: { oneofKind: 'musicGenerate', musicGenerate: { artifacts, generation: runtimeMusicGeneration(musicGeneration) } } };
|
|
1445
2122
|
default: return undefined;
|
|
1446
2123
|
}
|
|
1447
2124
|
}
|
|
1448
2125
|
function runtimeScenarioType(type) {
|
|
1449
|
-
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];
|
|
2126
|
+
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-speaker-embed': ScenarioType.AUDIO_SPEAKER_EMBED, 'audio-separate': ScenarioType.AUDIO_SEPARATE, 'voice-create': ScenarioType.VOICE_CREATE, 'music-generate': ScenarioType.MUSIC_GENERATE, 'music-transcribe': ScenarioType.MUSIC_TRANSCRIBE, 'audio-voice-convert': ScenarioType.AUDIO_VOICE_CONVERT, 'world-generate': ScenarioType.WORLD_GENERATE })[type];
|
|
1450
2127
|
}
|
|
1451
2128
|
function runtimeJobStatus(status) {
|
|
1452
2129
|
return ({ submitted: ScenarioJobStatus.SUBMITTED, queued: ScenarioJobStatus.QUEUED, running: ScenarioJobStatus.RUNNING, completed: ScenarioJobStatus.COMPLETED, failed: ScenarioJobStatus.FAILED, canceled: ScenarioJobStatus.CANCELED, timeout: ScenarioJobStatus.TIMEOUT })[status];
|
|
@@ -1585,17 +2262,15 @@ function optionalBoundedInteger(value, field, minimum, maximum) {
|
|
|
1585
2262
|
function optionalBoundedNumber(value, field, minimum, maximum) {
|
|
1586
2263
|
return value === undefined ? undefined : boundedNumber(value, field, minimum, maximum);
|
|
1587
2264
|
}
|
|
1588
|
-
function
|
|
1589
|
-
if (!
|
|
1590
|
-
|| value.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255))
|
|
2265
|
+
function validateInputBytes(value, field, maximum, allowEmpty) {
|
|
2266
|
+
if (!isNimiLocalAppByteView(value) || (!allowEmpty && value.byteLength === 0) || value.byteLength > maximum)
|
|
1591
2267
|
invalidAIInput(`${field} is invalid`);
|
|
1592
2268
|
return value;
|
|
1593
2269
|
}
|
|
1594
2270
|
function validateProjectionBytes(value, field) {
|
|
1595
|
-
if (!
|
|
1596
|
-
|| value.some((byte) => !Number.isInteger(byte) || byte < 0 || byte > 255))
|
|
2271
|
+
if (!isNimiLocalAppByteView(value) || value.byteLength > MAX_ARTIFACT_BYTES)
|
|
1597
2272
|
localAppProjectionError(field);
|
|
1598
|
-
return
|
|
2273
|
+
return exactNimiLocalAppBytes(value);
|
|
1599
2274
|
}
|
|
1600
2275
|
function projectionInteger(value, field, minimum, maximum) {
|
|
1601
2276
|
if (typeof value !== 'number' || !Number.isSafeInteger(value) || value < minimum || value > maximum)
|
|
@@ -1614,9 +2289,14 @@ function optionalProjectionText(value, field, maximum) {
|
|
|
1614
2289
|
return value;
|
|
1615
2290
|
}
|
|
1616
2291
|
function boundedProjectionContent(value, field, maximum) {
|
|
1617
|
-
|
|
2292
|
+
const text = optionalProjectionContent(value, field, maximum);
|
|
2293
|
+
if (!text)
|
|
2294
|
+
localAppProjectionError(field);
|
|
2295
|
+
return text;
|
|
2296
|
+
}
|
|
2297
|
+
function optionalProjectionContent(value, field, maximum) {
|
|
2298
|
+
if (typeof value !== 'string' || utf8Length(value) > maximum || value.includes('\0'))
|
|
1618
2299
|
localAppProjectionError(field);
|
|
1619
|
-
}
|
|
1620
2300
|
return value;
|
|
1621
2301
|
}
|
|
1622
2302
|
function mimeProjection(value) {
|
|
@@ -1640,4 +2320,17 @@ function invalidAIInput(reason) {
|
|
|
1640
2320
|
function adapterInputError(reason) {
|
|
1641
2321
|
return localAppError(`Runtime Scenario Job cannot use the Local App carrier: ${reason}.`, 'SDK_LOCAL_APP_INPUT_INVALID', 'use_admitted_local_app_scenario_fields');
|
|
1642
2322
|
}
|
|
2323
|
+
function localTranscriptionFromRuntime(value) {
|
|
2324
|
+
const status = value.status === SpeechTranscriptStatus.TRANSCRIBED ? 'transcribed' : value.status === SpeechTranscriptStatus.NO_SPEECH ? 'no-speech' : '';
|
|
2325
|
+
return validateNimiLocalAppSpeechTranscript({ status, text: value.text, language: value.language, words: value.words.map((word) => ({ ...word })),
|
|
2326
|
+
...(value.diarization ? { diarization: { status: value.diarization.status === SpeechDiarizationStatus.DIARIZED ? 'diarized' : value.diarization.status === SpeechDiarizationStatus.NO_SPEAKERS ? 'no-speakers' : '', durationSeconds: value.diarization.durationSeconds, intervals: value.diarization.intervals.map((interval) => ({ ...interval })) } } : {}) });
|
|
2327
|
+
}
|
|
2328
|
+
function runtimeTranscriptionFromLocal(value) {
|
|
2329
|
+
return value ? { status: value.status === 'transcribed' ? SpeechTranscriptStatus.TRANSCRIBED : SpeechTranscriptStatus.NO_SPEECH, text: value.text, language: value.language, words: value.words.map((word) => ({ ...word })),
|
|
2330
|
+
...(value.diarization ? { diarization: { status: value.diarization.status === 'diarized' ? SpeechDiarizationStatus.DIARIZED : SpeechDiarizationStatus.NO_SPEAKERS, durationSeconds: value.diarization.durationSeconds, intervals: value.diarization.intervals.map((interval) => ({ ...interval })) } } : {}) } : undefined;
|
|
2331
|
+
}
|
|
2332
|
+
function runtimeAnnotationFromLocal(value) {
|
|
2333
|
+
return value ? { documents: value.documents.map((doc) => ({ text: doc.text, language: doc.language,
|
|
2334
|
+
tokens: doc.tokens.map((token) => ({ ...token })), sentences: doc.sentences.map((sentence) => ({ ...sentence })) })) } : undefined;
|
|
2335
|
+
}
|
|
1643
2336
|
//# sourceMappingURL=local-app-runtime-platform-ai.js.map
|