@nimiplatform/sdk 0.15.0 → 0.22.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 +500 -1
- package/README.md +181 -346
- package/dist/core/ai/capability-configuration.d.ts +15 -0
- package/dist/core/ai/capability-configuration.d.ts.map +1 -1
- package/dist/core/ai/capability-configuration.js +36 -0
- package/dist/core/ai/capability-configuration.js.map +1 -1
- package/dist/core/ai/embeddings.d.ts +6 -0
- package/dist/core/ai/embeddings.d.ts.map +1 -1
- package/dist/core/ai/embeddings.js +33 -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 +57 -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/app/desktop-open.d.ts +11 -5
- package/dist/core/app/desktop-open.d.ts.map +1 -1
- package/dist/core/app/desktop-open.js +24 -16
- package/dist/core/app/desktop-open.js.map +1 -1
- package/dist/core/app/index.d.ts +32 -5
- package/dist/core/app/index.d.ts.map +1 -1
- package/dist/core/app/index.js +19 -1
- package/dist/core/app/index.js.map +1 -1
- package/dist/core/app/local-app-agent-introduction.d.ts +33 -0
- package/dist/core/app/local-app-agent-introduction.d.ts.map +1 -0
- package/dist/core/app/local-app-agent-introduction.js +94 -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 +9 -0
- package/dist/core/app/local-app-audio-separation.d.ts.map +1 -1
- package/dist/core/app/local-app-audio-separation.js +64 -3
- package/dist/core/app/local-app-audio-separation.js.map +1 -1
- 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 +285 -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 +753 -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 +55 -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 +154 -36
- package/dist/core/app/local-app-runtime-platform-ai.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-ai.js +738 -121
- 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 +38 -4
- package/dist/core/app/local-app-runtime-platform-configure.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-configure.js +130 -28
- package/dist/core/app/local-app-runtime-platform-configure.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-conversation.d.ts +74 -10
- package/dist/core/app/local-app-runtime-platform-conversation.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-conversation.js +176 -29
- 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.d.ts +4 -1
- package/dist/core/app/local-app-runtime-platform-direct-conversation.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-direct-conversation.js +64 -11
- package/dist/core/app/local-app-runtime-platform-direct-conversation.js.map +1 -1
- package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.d.ts +2 -0
- package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.js +10 -2
- package/dist/core/app/local-app-runtime-platform-direct-realm-realtime.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-life.d.ts +33 -0
- package/dist/core/app/local-app-runtime-platform-life.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-life.js +59 -0
- package/dist/core/app/local-app-runtime-platform-life.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-proactive.d.ts +28 -0
- package/dist/core/app/local-app-runtime-platform-proactive.d.ts.map +1 -0
- package/dist/core/app/local-app-runtime-platform-proactive.js +42 -0
- package/dist/core/app/local-app-runtime-platform-proactive.js.map +1 -0
- package/dist/core/app/local-app-runtime-platform-realm-realtime.d.ts +6 -2
- package/dist/core/app/local-app-runtime-platform-realm-realtime.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform-realm-realtime.js +15 -4
- package/dist/core/app/local-app-runtime-platform-realm-realtime.js.map +1 -1
- 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 +42 -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 +22 -17
- package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
- package/dist/core/app/local-app-runtime-platform.js +22 -8
- 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-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 +11 -0
- package/dist/core/app/local-app-transcription.d.ts.map +1 -1
- package/dist/core/app/local-app-transcription.js +22 -2
- package/dist/core/app/local-app-transcription.js.map +1 -1
- 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 +17 -12
- 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 +43 -103
- package/dist/core-generated/realm-client.js.map +1 -1
- package/dist/core-generated/realm-typed-client.d.ts +339 -457
- package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
- package/dist/core-generated/realm-typed-client.js +72 -208
- 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 +388 -12
- package/dist/core-generated/runtime-client.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.d.ts +16 -18
- package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/google/protobuf/field_mask.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/google/protobuf/struct.d.ts +33 -22
- package/dist/core-generated/runtime-protobuf/google/protobuf/struct.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/google/protobuf/struct.js +8 -3
- package/dist/core-generated/runtime-protobuf/google/protobuf/struct.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/google/protobuf/timestamp.d.ts +3 -3
- package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts +31 -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 +49 -5
- package/dist/core-generated/runtime-protobuf/runtime/v1/account.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.d.ts +147 -4
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.js +327 -14
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_configure.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.d.ts +167 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.d.ts.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.js +312 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_life.js.map +1 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts +606 -148
- 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 +1631 -722
- 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 +9 -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 +8 -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 +1872 -106
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js +4718 -1513
- package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts +40 -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 +72 -3
- 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/audit.d.ts +712 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/audit.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/audit.js +1461 -0
- package/dist/core-generated/runtime-protobuf/runtime/v1/audit.js.map +1 -1
- 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 +548 -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 +1309 -242
- package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.d.ts +67 -4
- package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.js +101 -10
- package/dist/core-generated/runtime-protobuf/runtime/v1/cognition_memory.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +150 -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 +149 -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 +81 -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 +166 -5
- 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 +166 -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 +217 -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_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/realm_realtime.d.ts +181 -8
- package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.d.ts.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.js +402 -18
- package/dist/core-generated/runtime-protobuf/runtime/v1/realm_realtime.js.map +1 -1
- package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts +110 -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 +213 -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 +364 -20
- 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 +46 -3
- package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
- package/dist/core-generated/runtime-public-wire-codecs.d.ts +56 -10
- package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
- package/dist/core-generated/runtime-public-wire-codecs.js +56 -10
- 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 +49 -2
- package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
- package/dist/core-generated/runtime-typed-client.d.ts +86 -26
- package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
- package/dist/core-generated/runtime-typed-client.js +487 -11
- package/dist/core-generated/runtime-typed-client.js.map +1 -1
- package/dist/core-generated/runtime-wire-codecs.d.ts +60 -10
- package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
- package/dist/core-generated/runtime-wire-codecs.js +61 -11
- package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
- package/dist/features/generation/index.d.ts +14 -2
- package/dist/features/generation/index.d.ts.map +1 -1
- package/dist/features/generation/index.js +14 -1
- 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/account-settings.d.ts +5 -3
- package/dist/realm/account-settings.d.ts.map +1 -1
- package/dist/realm/account-settings.js +3 -3
- package/dist/realm/account-settings.js.map +1 -1
- package/dist/realm/generated.d.ts +1 -1
- package/dist/realm/generated.d.ts.map +1 -1
- package/dist/realm/generated.js.map +1 -1
- package/dist/realm/index.d.ts +4 -4
- package/dist/realm/index.d.ts.map +1 -1
- package/dist/realm/index.js +8 -17
- package/dist/realm/index.js.map +1 -1
- package/dist/realm/media-delivery.d.ts +4 -0
- package/dist/realm/media-delivery.d.ts.map +1 -0
- package/dist/realm/media-delivery.js +65 -0
- package/dist/realm/media-delivery.js.map +1 -0
- package/dist/realm/resource-upload.d.ts +12 -3
- package/dist/realm/resource-upload.d.ts.map +1 -1
- package/dist/realm/resource-upload.js +93 -241
- package/dist/realm/resource-upload.js.map +1 -1
- package/dist/realm/social-types.d.ts +1 -15
- package/dist/realm/social-types.d.ts.map +1 -1
- package/dist/realm/social.d.ts +3 -17
- package/dist/realm/social.d.ts.map +1 -1
- package/dist/realm/social.js +0 -175
- package/dist/realm/social.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 +12 -0
- package/dist/runtime/config-projections.d.ts.map +1 -1
- package/dist/runtime/config-projections.js +11 -3
- 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 +19 -3
- package/dist/runtime/connector-inventory.d.ts.map +1 -1
- package/dist/runtime/connector-inventory.js +77 -25
- 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/desktop-first-party-runtime.d.ts +8 -1
- package/dist/runtime/desktop-first-party-runtime.d.ts.map +1 -1
- package/dist/runtime/desktop-first-party-runtime.js +80 -2
- package/dist/runtime/desktop-first-party-runtime.js.map +1 -1
- package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +174 -10
- package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
- package/dist/runtime/first-party-protected-runtime-profiles.generated.js +45 -4
- 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 +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +12 -10
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/machine-loadouts.d.ts +18 -0
- package/dist/runtime/machine-loadouts.d.ts.map +1 -1
- package/dist/runtime/machine-loadouts.js +26 -0
- 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 +24 -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 +6 -0
- package/dist/runtime/reason-messages.d.ts.map +1 -1
- package/dist/runtime/reason-messages.js +17 -2
- package/dist/runtime/reason-messages.js.map +1 -1
- package/dist/runtime/runtime-agent-inspect-projection.d.ts +2 -3
- package/dist/runtime/runtime-agent-inspect-projection.d.ts.map +1 -1
- package/dist/runtime/runtime-agent-inspect-projection.js +2 -27
- package/dist/runtime/runtime-agent-inspect-projection.js.map +1 -1
- package/dist/runtime/runtime-agent-inspect-types.d.ts +4 -32
- package/dist/runtime/runtime-agent-inspect-types.d.ts.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 +19 -19
- package/dist/runtime/runtime-local-environment-client-projections.js.map +1 -1
- package/dist/runtime/runtime-local-environment-client-types.d.ts +48 -21
- 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 +27 -4
- 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/runtime-method-modules.d.ts +1 -1
- package/dist/runtime/runtime-method-modules.d.ts.map +1 -1
- package/dist/runtime/runtime-method-modules.js +4 -2
- package/dist/runtime/runtime-method-modules.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 +3 -0
- package/dist/runtime/shared-local-agent-ai-config.js.map +1 -1
- package/dist/runtime/wire-types/agent-participation-enums.d.ts +3 -1
- package/dist/runtime/wire-types/agent-participation-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/agent-participation-enums.js +3 -1
- package/dist/runtime/wire-types/agent-participation-enums.js.map +1 -1
- package/dist/runtime/wire-types/agent-participation-types.d.ts +8 -4
- package/dist/runtime/wire-types/agent-participation-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts +130 -3
- package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-enums.js +149 -0
- package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
- package/dist/runtime/wire-types/ai-scenario-types.d.ts +10 -8
- 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 +8 -6
- package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
- package/dist/runtime/wire-types/local-memory-enums.d.ts +40 -1
- package/dist/runtime/wire-types/local-memory-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/local-memory-enums.js +44 -0
- package/dist/runtime/wire-types/local-memory-enums.js.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.d.ts +29 -1
- package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
- package/dist/runtime/wire-types/reason-code-enums.js +28 -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/dist/types/sha256.d.ts +6 -1
- package/dist/types/sha256.d.ts.map +1 -1
- package/dist/types/sha256.js +60 -25
- package/dist/types/sha256.js.map +1 -1
- package/package.json +5 -5
- package/dist/realm/feed.d.ts +0 -4
- package/dist/realm/feed.d.ts.map +0 -1
- package/dist/realm/feed.js +0 -10
- package/dist/realm/feed.js.map +0 -1
|
@@ -1,30 +1,26 @@
|
|
|
1
1
|
import { CONNECTOR_AUTH_ACQUISITION_PROFILES, } from './connector-auth-acquisition-profiles.generated.js';
|
|
2
2
|
export { CONNECTOR_AUTH_ACQUISITION_PROFILES };
|
|
3
|
-
import { ConnectorAuthKind, ConnectorStatus, } from '../core-generated/runtime-typed-client.js';
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import { ConnectorAuthKind, ConnectorKind, ConnectorStatus, } from '../core-generated/runtime-typed-client.js';
|
|
4
|
+
// Bounds the pages read while looking up the Connector to reauthorize.
|
|
5
|
+
const REGISTRATION_LOOKUP_MAX_PAGES = 20;
|
|
6
|
+
// Stable acquisition outcome without provider text, tokens or codes.
|
|
7
|
+
export class NimiConnectorAuthAcquisitionError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
constructor(code, message) {
|
|
10
|
+
super(message);
|
|
11
|
+
this.name = 'NimiConnectorAuthAcquisitionError';
|
|
12
|
+
this.code = code;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
const SIWC_CREDENTIAL_SCHEMA = 'nimi.openai_chatgpt_plan.siwc/v1';
|
|
16
|
+
const SIWC_DIRECT_SCOPE = 'chatgpt.tokens.use.direct';
|
|
17
|
+
const SIWC_OFFLINE_SCOPE = 'offline_access';
|
|
18
|
+
const HOST_ID_PREFIXES = ['urn:uuid:', 'urn:ietf:params:oauth:jwk-thumbprint:', 'did:key:'];
|
|
19
|
+
const MAX_TOKEN_RESPONSE_BYTES = 64 * 1024;
|
|
20
|
+
const MAX_CALLBACK_VALUE_BYTES = 4096;
|
|
8
21
|
function toTrimmedString(value) {
|
|
9
22
|
return typeof value === 'string' ? value.trim() : '';
|
|
10
23
|
}
|
|
11
|
-
function toTimerRepresentableProviderPositiveInt(value, fallback, field) {
|
|
12
|
-
if (value === undefined) {
|
|
13
|
-
return fallback;
|
|
14
|
-
}
|
|
15
|
-
const numeric = typeof value === 'number'
|
|
16
|
-
? value
|
|
17
|
-
: typeof value === 'string' && /^\d+$/u.test(value.trim())
|
|
18
|
-
? Number(value.trim())
|
|
19
|
-
: Number.NaN;
|
|
20
|
-
if (!Number.isSafeInteger(numeric) || numeric <= 0) {
|
|
21
|
-
throw new Error(`${field} must be a positive integer`);
|
|
22
|
-
}
|
|
23
|
-
if (numeric > MAX_RUNTIME_TIMER_DELAY_SECONDS) {
|
|
24
|
-
throw new Error(`${field} exceeds the runtime timer capacity`);
|
|
25
|
-
}
|
|
26
|
-
return numeric;
|
|
27
|
-
}
|
|
28
24
|
function abortReason(signal) {
|
|
29
25
|
return signal.reason ?? new DOMException('Managed OAuth acquisition was canceled', 'AbortError');
|
|
30
26
|
}
|
|
@@ -32,6 +28,32 @@ function throwIfAborted(signal) {
|
|
|
32
28
|
if (signal?.aborted)
|
|
33
29
|
throw abortReason(signal);
|
|
34
30
|
}
|
|
31
|
+
// Bounds how long cancellation waits for a host that is still creating the
|
|
32
|
+
// callback listener; a listener the host returns later is still closed.
|
|
33
|
+
const CALLBACK_STARTUP_CLEANUP_WAIT_MS = 5_000;
|
|
34
|
+
// The acquisition owns the loopback listener from the moment the host starts
|
|
35
|
+
// creating it. When cancellation, timeout or a startup failure wins that race,
|
|
36
|
+
// a listener the host still returns is closed, and the acquisition settles only
|
|
37
|
+
// after that close (bounded for a host that never returns).
|
|
38
|
+
async function startOwnedAuthorizationCallback(host, request, signal) {
|
|
39
|
+
const starting = host.startAuthorizationCallback(request, signal);
|
|
40
|
+
try {
|
|
41
|
+
return await awaitWithCancellation(starting, signal);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
const cleanup = starting.then((late) => late.close(), () => undefined).catch(() => undefined);
|
|
45
|
+
let timer;
|
|
46
|
+
await Promise.race([
|
|
47
|
+
cleanup,
|
|
48
|
+
new Promise((resolve) => {
|
|
49
|
+
timer = setTimeout(resolve, CALLBACK_STARTUP_CLEANUP_WAIT_MS);
|
|
50
|
+
}),
|
|
51
|
+
]);
|
|
52
|
+
if (timer !== undefined)
|
|
53
|
+
clearTimeout(timer);
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
35
57
|
async function awaitWithCancellation(promise, signal) {
|
|
36
58
|
if (!signal)
|
|
37
59
|
return promise;
|
|
@@ -83,15 +105,6 @@ function createAcquisitionSignal(signals, timeoutMs) {
|
|
|
83
105
|
},
|
|
84
106
|
};
|
|
85
107
|
}
|
|
86
|
-
async function runWithBoundedAcquisitionSignal(signals, timeoutMs, operation) {
|
|
87
|
-
const lifecycle = createAcquisitionSignal(signals, timeoutMs);
|
|
88
|
-
try {
|
|
89
|
-
return await operation(lifecycle.signal);
|
|
90
|
-
}
|
|
91
|
-
finally {
|
|
92
|
-
lifecycle.dispose();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
108
|
function acquisitionNow(host) {
|
|
96
109
|
const value = host.now();
|
|
97
110
|
if (!Number.isSafeInteger(value)) {
|
|
@@ -100,79 +113,66 @@ function acquisitionNow(host) {
|
|
|
100
113
|
return value;
|
|
101
114
|
}
|
|
102
115
|
function parseJsonObject(body, errorLabel) {
|
|
116
|
+
if (String(body || '').length > MAX_TOKEN_RESPONSE_BYTES) {
|
|
117
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', `${errorLabel} exceeded its fixed size`);
|
|
118
|
+
}
|
|
103
119
|
let parsed;
|
|
104
120
|
try {
|
|
105
121
|
parsed = JSON.parse(String(body || ''));
|
|
106
122
|
}
|
|
107
123
|
catch {
|
|
108
|
-
throw new
|
|
124
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', `${errorLabel} returned invalid JSON`);
|
|
109
125
|
}
|
|
110
126
|
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
111
|
-
throw new
|
|
127
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', `${errorLabel} returned a non-object JSON payload`);
|
|
112
128
|
}
|
|
113
129
|
return parsed;
|
|
114
130
|
}
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
131
|
+
function logAcquisition(host, level, message, details) {
|
|
132
|
+
host.log?.(level, message, details);
|
|
133
|
+
}
|
|
134
|
+
const BASE64URL_ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; // pragma: allowlist secret -- RFC 4648 base64url alphabet
|
|
135
|
+
function base64UrlEncode(bytes) {
|
|
136
|
+
let output = '';
|
|
137
|
+
for (let index = 0; index < bytes.length; index += 3) {
|
|
138
|
+
const a = bytes[index] ?? 0;
|
|
139
|
+
const b = bytes[index + 1] ?? 0;
|
|
140
|
+
const c = bytes[index + 2] ?? 0;
|
|
141
|
+
const triple = (a << 16) | (b << 8) | c;
|
|
142
|
+
output += BASE64URL_ALPHABET[(triple >> 18) & 63];
|
|
143
|
+
output += BASE64URL_ALPHABET[(triple >> 12) & 63];
|
|
144
|
+
if (index + 1 < bytes.length)
|
|
145
|
+
output += BASE64URL_ALPHABET[(triple >> 6) & 63];
|
|
146
|
+
if (index + 2 < bytes.length)
|
|
147
|
+
output += BASE64URL_ALPHABET[triple & 63];
|
|
119
148
|
}
|
|
120
|
-
return
|
|
149
|
+
return output;
|
|
121
150
|
}
|
|
122
|
-
function
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
return '';
|
|
151
|
+
function base64UrlDecode(value) {
|
|
152
|
+
if (!/^[A-Za-z0-9_-]*$/u.test(value) || value.length % 4 === 1) {
|
|
153
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ID token is not base64url encoded');
|
|
126
154
|
}
|
|
127
|
-
|
|
128
|
-
|
|
155
|
+
const bytes = new Uint8Array(new ArrayBuffer(Math.floor((value.length * 6) / 8)));
|
|
156
|
+
let length = 0;
|
|
157
|
+
let buffer = 0;
|
|
158
|
+
let bits = 0;
|
|
159
|
+
for (const char of value) {
|
|
160
|
+
buffer = ((buffer << 6) | BASE64URL_ALPHABET.indexOf(char)) & 0xffffff;
|
|
161
|
+
bits += 6;
|
|
162
|
+
if (bits >= 8) {
|
|
163
|
+
bits -= 8;
|
|
164
|
+
bytes[length] = (buffer >> bits) & 0xff;
|
|
165
|
+
length += 1;
|
|
166
|
+
}
|
|
129
167
|
}
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
function logAcquisition(host, level, message, details) {
|
|
133
|
-
host.log?.(level, message, details);
|
|
168
|
+
return bytes.subarray(0, length);
|
|
134
169
|
}
|
|
135
|
-
|
|
136
|
-
return
|
|
137
|
-
profileId: profile.profileId,
|
|
138
|
-
purpose,
|
|
139
|
-
url,
|
|
140
|
-
method: 'POST',
|
|
141
|
-
headers: {
|
|
142
|
-
'Content-Type': 'application/json',
|
|
143
|
-
Accept: 'application/json',
|
|
144
|
-
},
|
|
145
|
-
body: JSON.stringify(payload),
|
|
146
|
-
}, signal), signal);
|
|
170
|
+
function randomToken(crypto, byteLength) {
|
|
171
|
+
return base64UrlEncode(crypto.getRandomValues(new Uint8Array(byteLength)));
|
|
147
172
|
}
|
|
148
|
-
function
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
throw new Error('Managed OAuth credential payload requires an access token');
|
|
152
|
-
}
|
|
153
|
-
const refreshToken = toTrimmedString(input.refreshToken);
|
|
154
|
-
const tokenType = toTrimmedString(input.tokenType);
|
|
155
|
-
const scope = toTrimmedString(input.scope);
|
|
156
|
-
const expiresIn = input.expiresIn;
|
|
157
|
-
if (expiresIn !== undefined && (!Number.isSafeInteger(expiresIn) || expiresIn <= 0)) {
|
|
158
|
-
throw new Error('Managed OAuth token exchange expires_in must be a positive integer');
|
|
159
|
-
}
|
|
160
|
-
const expiresAt = typeof expiresIn === 'number'
|
|
161
|
-
? toIsoTimestamp(input.now + expiresIn * 1000, 'Managed OAuth token exchange expires_in')
|
|
162
|
-
: undefined;
|
|
163
|
-
return {
|
|
164
|
-
expiresAt,
|
|
165
|
-
credentialJson: JSON.stringify({
|
|
166
|
-
access_token: accessToken,
|
|
167
|
-
refresh_token: refreshToken || undefined,
|
|
168
|
-
token_type: tokenType || undefined,
|
|
169
|
-
scope: scope || undefined,
|
|
170
|
-
expires_in: expiresIn,
|
|
171
|
-
expires_at: expiresAt,
|
|
172
|
-
issuer: input.profile.issuer,
|
|
173
|
-
obtained_at: toIsoTimestamp(input.now, 'Managed OAuth acquisition clock'),
|
|
174
|
-
}),
|
|
175
|
-
};
|
|
173
|
+
async function pkceChallenge(crypto, verifier) {
|
|
174
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(verifier));
|
|
175
|
+
return base64UrlEncode(new Uint8Array(digest));
|
|
176
176
|
}
|
|
177
177
|
function profileForId(profileId) {
|
|
178
178
|
const normalized = String(profileId || '').trim().toLowerCase();
|
|
@@ -182,18 +182,217 @@ function profileForId(profileId) {
|
|
|
182
182
|
}
|
|
183
183
|
return profile;
|
|
184
184
|
}
|
|
185
|
-
|
|
185
|
+
function validHostIdentifier(value) {
|
|
186
|
+
if (!value || value !== value.trim() || value.length > 512 || /\s/u.test(value))
|
|
187
|
+
return false;
|
|
188
|
+
return HOST_ID_PREFIXES.some((prefix) => value.startsWith(prefix) && value.length > prefix.length);
|
|
189
|
+
}
|
|
190
|
+
function exactCallbackRedirect(profile, redirectUri) {
|
|
191
|
+
let parsed;
|
|
192
|
+
try {
|
|
193
|
+
parsed = new URL(redirectUri);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
throw new Error('Authorization callback listener returned an invalid redirect URI');
|
|
197
|
+
}
|
|
198
|
+
const port = Number(parsed.port);
|
|
199
|
+
if (parsed.protocol !== 'http:' || parsed.hostname !== profile.callbackHost || !Number.isSafeInteger(port) || port <= 0 ||
|
|
200
|
+
parsed.pathname !== profile.callbackPath || parsed.search || parsed.hash || parsed.username || parsed.password) {
|
|
201
|
+
throw new Error('Authorization callback listener is not the admitted loopback callback');
|
|
202
|
+
}
|
|
203
|
+
return `http://${profile.callbackHost}:${port}${profile.callbackPath}`;
|
|
204
|
+
}
|
|
205
|
+
// Explicit reauthorization reuses the registration that Runtime custody bound
|
|
206
|
+
// to this Connector; the renderer never supplies a client or account.
|
|
207
|
+
async function registrationContext(options, profile, signal) {
|
|
208
|
+
const connectorId = toTrimmedString(options.connectorId);
|
|
209
|
+
if (!connectorId) {
|
|
210
|
+
return { clientId: profile.initialClientId, initialRegistration: true, loginHint: '' };
|
|
211
|
+
}
|
|
212
|
+
let connector;
|
|
213
|
+
let pageToken = '';
|
|
214
|
+
for (let page = 0; page < REGISTRATION_LOOKUP_MAX_PAGES && !connector; page += 1) {
|
|
215
|
+
const response = await awaitWithCancellation(options.runtime.listConnectors({
|
|
216
|
+
pageSize: 0,
|
|
217
|
+
pageToken,
|
|
218
|
+
kindFilter: ConnectorKind.REMOTE_MANAGED,
|
|
219
|
+
statusFilter: ConnectorStatus.UNSPECIFIED,
|
|
220
|
+
providerFilter: profile.providerAuthProfile,
|
|
221
|
+
}, withAcquisitionSignal(options.callOptions, signal)), signal);
|
|
222
|
+
connector = (response.connectors ?? []).find((candidate) => candidate.connectorId === connectorId);
|
|
223
|
+
pageToken = toTrimmedString(response.nextPageToken);
|
|
224
|
+
if (!pageToken)
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
const clientId = toTrimmedString(connector?.oauthRegistration?.issuedClientId);
|
|
228
|
+
if (!connector || connector.provider !== profile.providerAuthProfile ||
|
|
229
|
+
connector.providerAuthProfile !== profile.providerAuthProfile || !clientId || clientId === profile.initialClientId) {
|
|
230
|
+
throw new NimiConnectorAuthAcquisitionError('REGISTRATION_UNAVAILABLE', 'This Connector has no ChatGPT plan registration to reauthorize; add the account again');
|
|
231
|
+
}
|
|
232
|
+
const accountLabel = toTrimmedString(connector.oauthRegistration?.accountLabel);
|
|
233
|
+
return { clientId, initialRegistration: false, loginHint: accountLabel.includes('@') ? accountLabel : '' };
|
|
234
|
+
}
|
|
235
|
+
function authorizationUrl(input) {
|
|
236
|
+
const params = new URLSearchParams();
|
|
237
|
+
params.set('client_id', input.registration.clientId);
|
|
238
|
+
if (input.registration.initialRegistration) {
|
|
239
|
+
params.set('agent_name_hint', input.profile.agentNameHint);
|
|
240
|
+
}
|
|
241
|
+
params.set('ext_agent_host_id', input.hostId);
|
|
242
|
+
if (input.registration.loginHint) {
|
|
243
|
+
params.set('login_hint', input.registration.loginHint);
|
|
244
|
+
}
|
|
245
|
+
params.set('response_type', 'code');
|
|
246
|
+
params.set('redirect_uri', input.redirectUri);
|
|
247
|
+
params.set('scope', input.profile.scopes.join(' '));
|
|
248
|
+
params.set('resource', input.profile.resource);
|
|
249
|
+
params.set('state', input.state);
|
|
250
|
+
params.set('nonce', input.nonce);
|
|
251
|
+
params.set('code_challenge_method', 'S256');
|
|
252
|
+
params.set('code_challenge', input.challenge);
|
|
253
|
+
return `${input.profile.authorizationUrl}?${params.toString()}`;
|
|
254
|
+
}
|
|
255
|
+
function boundedCallbackValue(params, key) {
|
|
256
|
+
const value = params[key];
|
|
257
|
+
if (typeof value !== 'string' || !value || value.length > MAX_CALLBACK_VALUE_BYTES || value !== value.trim()) {
|
|
258
|
+
return '';
|
|
259
|
+
}
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
function callbackRegistration(params, profile, registration, expectedState) {
|
|
263
|
+
if (boundedCallbackValue(params, 'state') !== expectedState) {
|
|
264
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'Authorization callback state did not match this sign-in');
|
|
265
|
+
}
|
|
266
|
+
const error = boundedCallbackValue(params, 'error');
|
|
267
|
+
if (error === 'access_denied') {
|
|
268
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_DENIED', 'ChatGPT sign-in was canceled or denied');
|
|
269
|
+
}
|
|
270
|
+
if (error) {
|
|
271
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ChatGPT sign-in returned an authorization error');
|
|
272
|
+
}
|
|
273
|
+
const code = boundedCallbackValue(params, 'code');
|
|
274
|
+
if (!code) {
|
|
275
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'Authorization callback did not include a code');
|
|
276
|
+
}
|
|
277
|
+
const returnedClientId = boundedCallbackValue(params, 'client_id');
|
|
278
|
+
if (registration.initialRegistration) {
|
|
279
|
+
if (!returnedClientId || returnedClientId === profile.initialClientId) {
|
|
280
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ChatGPT registration did not return an issued client');
|
|
281
|
+
}
|
|
282
|
+
return { code, clientId: returnedClientId };
|
|
283
|
+
}
|
|
284
|
+
if (returnedClientId && returnedClientId !== registration.clientId) {
|
|
285
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'Authorization returned a different ChatGPT registration');
|
|
286
|
+
}
|
|
287
|
+
return { code, clientId: registration.clientId };
|
|
288
|
+
}
|
|
289
|
+
async function exchangeAuthorizationCode(input) {
|
|
290
|
+
const form = new URLSearchParams();
|
|
291
|
+
form.set('grant_type', 'authorization_code');
|
|
292
|
+
form.set('client_id', input.clientId);
|
|
293
|
+
form.set('code', input.code);
|
|
294
|
+
form.set('code_verifier', input.verifier);
|
|
295
|
+
form.set('redirect_uri', input.redirectUri);
|
|
296
|
+
form.set('resource', input.profile.resource);
|
|
297
|
+
const response = await awaitWithCancellation(input.host.proxyHttp({
|
|
298
|
+
profileId: input.profile.profileId,
|
|
299
|
+
purpose: 'authorization_code_exchange',
|
|
300
|
+
url: input.profile.tokenUrl,
|
|
301
|
+
method: 'POST',
|
|
302
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded', Accept: 'application/json' },
|
|
303
|
+
body: form.toString(),
|
|
304
|
+
}, input.signal), input.signal);
|
|
305
|
+
if (!response.ok) {
|
|
306
|
+
let oauthError = '';
|
|
307
|
+
try {
|
|
308
|
+
oauthError = toTrimmedString(JSON.parse(response.body).error);
|
|
309
|
+
}
|
|
310
|
+
catch {
|
|
311
|
+
oauthError = '';
|
|
312
|
+
}
|
|
313
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', oauthError === 'invalid_grant'
|
|
314
|
+
? 'The ChatGPT authorization code expired or was already used; sign in again'
|
|
315
|
+
: `ChatGPT token exchange failed with HTTP ${response.status}`);
|
|
316
|
+
}
|
|
317
|
+
const payload = parseJsonObject(response.body, 'ChatGPT token exchange');
|
|
318
|
+
const accessToken = toTrimmedString(payload.access_token);
|
|
319
|
+
const refreshToken = toTrimmedString(payload.refresh_token);
|
|
320
|
+
const idToken = toTrimmedString(payload.id_token);
|
|
321
|
+
const tokenType = toTrimmedString(payload.token_type);
|
|
322
|
+
const scopes = toTrimmedString(payload.scope).split(/\s+/u).filter(Boolean);
|
|
323
|
+
if (!accessToken || !refreshToken || !idToken || tokenType.toLowerCase() !== 'bearer') {
|
|
324
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ChatGPT token exchange returned an incomplete token set');
|
|
325
|
+
}
|
|
326
|
+
return { accessToken, refreshToken, idToken, tokenType: 'Bearer', scopes };
|
|
327
|
+
}
|
|
328
|
+
// Verifies the RS256 ID token against OpenAI's published JWKS and binds it to
|
|
329
|
+
// this attempt's issued client and nonce.
|
|
330
|
+
async function verifyIdToken(input) {
|
|
331
|
+
const parts = input.idToken.split('.');
|
|
332
|
+
if (parts.length !== 3) {
|
|
333
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ID token is not a signed JWT');
|
|
334
|
+
}
|
|
335
|
+
const decoder = new TextDecoder();
|
|
336
|
+
const header = parseJsonObject(decoder.decode(base64UrlDecode(parts[0] ?? '')), 'ID token header');
|
|
337
|
+
const claims = parseJsonObject(decoder.decode(base64UrlDecode(parts[1] ?? '')), 'ID token claims');
|
|
338
|
+
const kid = toTrimmedString(header.kid);
|
|
339
|
+
if (header.alg !== 'RS256' || !kid) {
|
|
340
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ID token signing algorithm is not admitted');
|
|
341
|
+
}
|
|
342
|
+
const jwksResponse = await awaitWithCancellation(input.host.proxyHttp({
|
|
343
|
+
profileId: input.profile.profileId,
|
|
344
|
+
purpose: 'jwks',
|
|
345
|
+
url: input.profile.jwksUrl,
|
|
346
|
+
method: 'GET',
|
|
347
|
+
headers: { Accept: 'application/json' },
|
|
348
|
+
}, input.signal), input.signal);
|
|
349
|
+
if (!jwksResponse.ok) {
|
|
350
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', `OpenAI signing keys were unavailable (HTTP ${jwksResponse.status})`);
|
|
351
|
+
}
|
|
352
|
+
const jwks = parseJsonObject(jwksResponse.body, 'OpenAI signing keys');
|
|
353
|
+
const keys = Array.isArray(jwks.keys) ? jwks.keys : [];
|
|
354
|
+
const jwk = keys.find((candidate) => {
|
|
355
|
+
const key = candidate;
|
|
356
|
+
return key && key.kid === kid && key.kty === 'RSA' && (key.use === undefined || key.use === 'sig') &&
|
|
357
|
+
(key.alg === undefined || key.alg === 'RS256') && typeof key.n === 'string' && typeof key.e === 'string';
|
|
358
|
+
});
|
|
359
|
+
if (!jwk) {
|
|
360
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ID token signing key is not published');
|
|
361
|
+
}
|
|
362
|
+
const key = await input.host.crypto.subtle.importKey('jwk', { kty: 'RSA', n: jwk.n, e: jwk.e, alg: 'RS256', ext: true }, { name: 'RSASSA-PKCS1-v1_5', hash: 'SHA-256' }, false, ['verify']);
|
|
363
|
+
const signatureValid = await input.host.crypto.subtle.verify('RSASSA-PKCS1-v1_5', key, base64UrlDecode(parts[2] ?? ''), new TextEncoder().encode(`${parts[0]}.${parts[1]}`));
|
|
364
|
+
if (!signatureValid) {
|
|
365
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ID token signature is invalid');
|
|
366
|
+
}
|
|
367
|
+
const audience = Array.isArray(claims.aud) ? claims.aud : [claims.aud];
|
|
368
|
+
const expires = typeof claims.exp === 'number' ? claims.exp : Number.NaN;
|
|
369
|
+
const subject = toTrimmedString(claims.sub);
|
|
370
|
+
if (claims.iss !== input.profile.issuer || !audience.includes(input.clientId) || claims.nonce !== input.nonce ||
|
|
371
|
+
!Number.isFinite(expires) || expires * 1000 <= acquisitionNow(input.host) || !subject) {
|
|
372
|
+
throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', 'ID token does not match this ChatGPT sign-in');
|
|
373
|
+
}
|
|
374
|
+
const email = toTrimmedString(claims.email);
|
|
375
|
+
return { subject, email: email.includes('@') && !/\s/u.test(email) && email.length <= 512 ? email : '' };
|
|
376
|
+
}
|
|
377
|
+
function withAcquisitionSignal(options, signal) {
|
|
378
|
+
return { ...withoutAcquisitionCancellation(options), signal };
|
|
379
|
+
}
|
|
380
|
+
function withoutAcquisitionCancellation(options) {
|
|
381
|
+
return {
|
|
382
|
+
metadata: options?.metadata,
|
|
383
|
+
timeoutMs: options?.timeoutMs,
|
|
384
|
+
responseMetadataObserver: options?.responseMetadataObserver,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
async function persistAuthorizationThroughRuntime(input) {
|
|
388
|
+
// The final Runtime custody write is the commit point: cancellation before
|
|
389
|
+
// dispatch aborts; after dispatch the host waits for the exact result.
|
|
186
390
|
throwIfAborted(input.signal);
|
|
187
391
|
const finalWriteCallOptions = withoutAcquisitionCancellation(input.options.callOptions);
|
|
188
|
-
const provider = toTrimmedString(input.options.provider) || input.profile.providerAuthProfile;
|
|
189
|
-
const endpoint = toTrimmedString(input.options.endpoint);
|
|
190
|
-
const label = toTrimmedString(input.options.label) || `${input.profile.providerAuthProfile} managed OAuth`;
|
|
191
392
|
const connectorId = toTrimmedString(input.options.connectorId);
|
|
192
393
|
if (connectorId) {
|
|
193
394
|
const response = await input.options.runtime.updateConnector({
|
|
194
395
|
connectorId,
|
|
195
|
-
endpoint: endpoint || undefined,
|
|
196
|
-
label: input.options.label === undefined ? undefined : label,
|
|
197
396
|
status: ConnectorStatus.UNSPECIFIED,
|
|
198
397
|
authKind: ConnectorAuthKind.OAUTH_MANAGED,
|
|
199
398
|
providerAuthProfile: input.profile.providerAuthProfile,
|
|
@@ -201,9 +400,10 @@ async function persistManagedConnectorCredentialThroughRuntime(input) {
|
|
|
201
400
|
}, finalWriteCallOptions);
|
|
202
401
|
return response.connector?.connectorId || connectorId;
|
|
203
402
|
}
|
|
403
|
+
const label = toTrimmedString(input.options.label) || input.accountLabel || 'ChatGPT plan';
|
|
204
404
|
const response = await input.options.runtime.createConnector({
|
|
205
|
-
provider,
|
|
206
|
-
endpoint,
|
|
405
|
+
provider: input.profile.providerAuthProfile,
|
|
406
|
+
endpoint: '',
|
|
207
407
|
label,
|
|
208
408
|
apiKey: '',
|
|
209
409
|
authKind: ConnectorAuthKind.OAUTH_MANAGED,
|
|
@@ -216,206 +416,89 @@ async function persistManagedConnectorCredentialThroughRuntime(input) {
|
|
|
216
416
|
}
|
|
217
417
|
return createdConnectorId;
|
|
218
418
|
}
|
|
219
|
-
function withoutAcquisitionCancellation(options) {
|
|
220
|
-
return {
|
|
221
|
-
metadata: options?.metadata,
|
|
222
|
-
timeoutMs: options?.timeoutMs,
|
|
223
|
-
responseMetadataObserver: options?.responseMetadataObserver,
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
419
|
// @nimi-authority: definition.nimi.sdks.feature-clients.connector-auth-plane
|
|
227
420
|
// @nimi-authority: rule.nimi.sdks.feature-clients.r060
|
|
228
421
|
// @nimi-authority: rule.nimi.sdks.feature-clients.r061
|
|
422
|
+
// @nimi-authority: rule.nimi.sdks.feature-clients.siwc-refresh
|
|
229
423
|
export async function acquireNimiManagedConnectorCredentialInHost(options) {
|
|
230
424
|
const profile = profileForId(options.profileId);
|
|
231
|
-
const lifecycle = createAcquisitionSignal([options.signal, options.callOptions?.signal]);
|
|
425
|
+
const lifecycle = createAcquisitionSignal([options.signal, options.callOptions?.signal], profile.acquisitionTimeoutSeconds * 1000);
|
|
232
426
|
try {
|
|
233
|
-
return await
|
|
427
|
+
return await acquireWithProfile(options, profile, lifecycle.signal);
|
|
234
428
|
}
|
|
235
429
|
finally {
|
|
236
430
|
lifecycle.dispose();
|
|
237
431
|
}
|
|
238
432
|
}
|
|
239
|
-
async function
|
|
433
|
+
async function acquireWithProfile(options, profile, signal) {
|
|
240
434
|
const host = options.host;
|
|
241
435
|
throwIfAborted(signal);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
client_id: profile.clientId,
|
|
247
|
-
}, signal);
|
|
248
|
-
if (!deviceCodeResponse.ok) {
|
|
249
|
-
logAcquisition(host, 'error', 'managed-oauth:device-code-request:failed', {
|
|
250
|
-
profileId: profile.profileId,
|
|
251
|
-
status: deviceCodeResponse.status,
|
|
252
|
-
});
|
|
253
|
-
throw new Error(`Managed OAuth device code request failed with HTTP ${deviceCodeResponse.status}`);
|
|
254
|
-
}
|
|
255
|
-
const deviceData = parseJsonObject(deviceCodeResponse.body, 'Managed OAuth device code request');
|
|
256
|
-
const userCode = toTrimmedString(deviceData.user_code);
|
|
257
|
-
const deviceAuthId = toTrimmedString(deviceData.device_auth_id);
|
|
258
|
-
const providerPollIntervalSeconds = toTimerRepresentableProviderPositiveInt(deviceData.interval, profile.defaultPollIntervalSeconds, 'Managed OAuth device code interval');
|
|
259
|
-
if (providerPollIntervalSeconds > profile.maxPollIntervalSeconds) {
|
|
260
|
-
throw new Error(`Managed OAuth device code interval must not exceed ${profile.maxPollIntervalSeconds}`);
|
|
261
|
-
}
|
|
262
|
-
const pollIntervalSeconds = Math.max(profile.minPollIntervalSeconds, providerPollIntervalSeconds);
|
|
263
|
-
const expiresInSeconds = toTimerRepresentableProviderPositiveInt(deviceData.expires_in, profile.defaultExpiresInSeconds, 'Managed OAuth device code expires_in');
|
|
264
|
-
if (expiresInSeconds > profile.maxExpiresInSeconds) {
|
|
265
|
-
throw new Error(`Managed OAuth device code expires_in must not exceed ${profile.maxExpiresInSeconds}`);
|
|
266
|
-
}
|
|
267
|
-
const verificationUrl = toTrimmedString(deviceData.verification_uri_complete) || profile.fallbackVerificationUrl;
|
|
268
|
-
return runWithBoundedAcquisitionSignal([signal], expiresInSeconds * 1000, async (boundedSignal) => completeManagedConnectorCredentialFromDeviceCode({
|
|
269
|
-
options,
|
|
270
|
-
profile,
|
|
271
|
-
host,
|
|
272
|
-
deviceData,
|
|
273
|
-
userCode,
|
|
274
|
-
deviceAuthId,
|
|
275
|
-
pollIntervalSeconds,
|
|
276
|
-
expiresInSeconds,
|
|
277
|
-
verificationUrl,
|
|
278
|
-
signal: boundedSignal,
|
|
279
|
-
}));
|
|
280
|
-
}
|
|
281
|
-
async function completeManagedConnectorCredentialFromDeviceCode(input) {
|
|
282
|
-
const { options, profile, host, deviceData, userCode, deviceAuthId, pollIntervalSeconds, expiresInSeconds, verificationUrl, signal, } = input;
|
|
283
|
-
if (!userCode || !deviceAuthId) {
|
|
284
|
-
throw new Error('Managed OAuth device code response is missing user_code or device_auth_id');
|
|
436
|
+
const registration = await registrationContext(options, profile, signal);
|
|
437
|
+
const hostId = toTrimmedString(await awaitWithCancellation(host.hostIdentifier(signal), signal));
|
|
438
|
+
if (!validHostIdentifier(hostId)) {
|
|
439
|
+
throw new Error('Local host identifier is not an admitted opaque ext_agent_host_id');
|
|
285
440
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
});
|
|
300
|
-
throwIfAborted(signal);
|
|
301
|
-
logAcquisition(host, 'info', 'managed-oauth:browser-open:start', {
|
|
302
|
-
profileId: profile.profileId,
|
|
303
|
-
verificationUrl,
|
|
304
|
-
});
|
|
305
|
-
const launchResult = await awaitWithCancellation(host.openExternalUrl(verificationUrl, signal), signal);
|
|
306
|
-
if (!launchResult.opened) {
|
|
307
|
-
logAcquisition(host, 'error', 'managed-oauth:browser-open:failed', {
|
|
441
|
+
const state = randomToken(host.crypto, 32);
|
|
442
|
+
const nonce = randomToken(host.crypto, 32);
|
|
443
|
+
const verifier = randomToken(host.crypto, 64);
|
|
444
|
+
const challenge = await pkceChallenge(host.crypto, verifier);
|
|
445
|
+
const callback = await startOwnedAuthorizationCallback(host, {
|
|
446
|
+
profileId: profile.profileId, host: profile.callbackHost, path: profile.callbackPath,
|
|
447
|
+
}, signal);
|
|
448
|
+
let params;
|
|
449
|
+
let redirectUri;
|
|
450
|
+
try {
|
|
451
|
+
redirectUri = exactCallbackRedirect(profile, callback.redirectUri);
|
|
452
|
+
const url = authorizationUrl({ profile, registration, hostId, redirectUri, state, nonce, challenge });
|
|
453
|
+
logAcquisition(host, 'info', 'managed-oauth:browser-authorization:start', {
|
|
308
454
|
profileId: profile.profileId,
|
|
309
|
-
|
|
455
|
+
initialRegistration: registration.initialRegistration,
|
|
310
456
|
});
|
|
311
|
-
throw new Error('Unable to open the browser for managed OAuth sign-in');
|
|
312
|
-
}
|
|
313
|
-
const deadlineMs = acquisitionNow(host) + expiresInSeconds * 1000;
|
|
314
|
-
const maxPollAttempts = Math.ceil(expiresInSeconds / profile.minPollIntervalSeconds);
|
|
315
|
-
let codeResponse = null;
|
|
316
|
-
let pollAttempt = 0;
|
|
317
|
-
let lastPollStatus = null;
|
|
318
|
-
while (acquisitionNow(host) < deadlineMs && pollAttempt < maxPollAttempts) {
|
|
319
|
-
throwIfAborted(signal);
|
|
320
|
-
const remainingMs = Math.max(0, deadlineMs - acquisitionNow(host));
|
|
321
|
-
const sleepMs = Math.min(pollIntervalSeconds * 1000, remainingMs);
|
|
322
|
-
if (sleepMs <= 0)
|
|
323
|
-
break;
|
|
324
|
-
await awaitWithCancellation(host.sleep(sleepMs, signal), signal);
|
|
325
457
|
throwIfAborted(signal);
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
device_auth_id: deviceAuthId,
|
|
331
|
-
user_code: userCode,
|
|
332
|
-
}, signal);
|
|
333
|
-
lastPollStatus = pollResponse.status;
|
|
334
|
-
if (pollResponse.status === 200) {
|
|
335
|
-
logAcquisition(host, 'info', 'managed-oauth:poll:authorized', {
|
|
336
|
-
profileId: profile.profileId,
|
|
337
|
-
attempt: pollAttempt,
|
|
338
|
-
status: pollResponse.status,
|
|
339
|
-
});
|
|
340
|
-
codeResponse = parseJsonObject(pollResponse.body, 'Managed OAuth device auth poll');
|
|
341
|
-
break;
|
|
458
|
+
options.onPending?.({ authorizationUrl: url, expiresInSeconds: profile.acquisitionTimeoutSeconds });
|
|
459
|
+
const launch = await awaitWithCancellation(host.openExternalUrl(url, signal), signal);
|
|
460
|
+
if (!launch.opened) {
|
|
461
|
+
throw new NimiConnectorAuthAcquisitionError('BROWSER_UNAVAILABLE', 'Unable to open the browser for ChatGPT sign-in');
|
|
342
462
|
}
|
|
343
|
-
|
|
344
|
-
logAcquisition(host, 'debug', 'managed-oauth:poll:pending', {
|
|
345
|
-
profileId: profile.profileId,
|
|
346
|
-
attempt: pollAttempt,
|
|
347
|
-
status: pollResponse.status,
|
|
348
|
-
});
|
|
349
|
-
continue;
|
|
350
|
-
}
|
|
351
|
-
logAcquisition(host, 'error', 'managed-oauth:poll:failed', {
|
|
352
|
-
profileId: profile.profileId,
|
|
353
|
-
attempt: pollAttempt,
|
|
354
|
-
status: pollResponse.status,
|
|
355
|
-
});
|
|
356
|
-
throw new Error(`Managed OAuth device auth polling failed with HTTP ${pollResponse.status}`);
|
|
463
|
+
params = await awaitWithCancellation(callback.waitForCallback(signal), signal);
|
|
357
464
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
lastStatus: lastPollStatus,
|
|
363
|
-
});
|
|
364
|
-
const timeoutDetails = [
|
|
365
|
-
`attempts=${pollAttempt}`,
|
|
366
|
-
`lastStatus=${lastPollStatus ?? 'none'}`,
|
|
367
|
-
];
|
|
368
|
-
throw new Error(`Managed OAuth sign-in timed out before authorization completed (${timeoutDetails.join(', ')})`);
|
|
369
|
-
}
|
|
370
|
-
const authorizationCode = toTrimmedString(codeResponse.authorization_code);
|
|
371
|
-
const codeVerifier = toTrimmedString(codeResponse.code_verifier);
|
|
372
|
-
if (!authorizationCode || !codeVerifier) {
|
|
373
|
-
throw new Error('Managed OAuth device auth response is missing authorization_code or code_verifier');
|
|
374
|
-
}
|
|
375
|
-
logAcquisition(host, 'info', 'managed-oauth:token-exchange:start', {
|
|
376
|
-
profileId: profile.profileId,
|
|
377
|
-
attemptCount: pollAttempt,
|
|
378
|
-
redirectUri: profile.redirectUri,
|
|
379
|
-
});
|
|
465
|
+
finally {
|
|
466
|
+
await callback.close();
|
|
467
|
+
}
|
|
468
|
+
const { code, clientId } = callbackRegistration(params, profile, registration, state);
|
|
380
469
|
throwIfAborted(signal);
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
scope: exchange.scope,
|
|
399
|
-
expiresIn: exchange.expiresIn,
|
|
400
|
-
now: nowMs,
|
|
470
|
+
const tokens = await exchangeAuthorizationCode({ host, profile, clientId, code, verifier, redirectUri, signal });
|
|
471
|
+
const identity = await verifyIdToken({ host, profile, idToken: tokens.idToken, clientId, nonce, signal });
|
|
472
|
+
if (!tokens.scopes.includes(SIWC_DIRECT_SCOPE) || !tokens.scopes.includes(SIWC_OFFLINE_SCOPE)) {
|
|
473
|
+
throw new NimiConnectorAuthAcquisitionError('PLAN_USAGE_NOT_GRANTED', 'ChatGPT plan usage was not granted for this sign-in; enable it and sign in again');
|
|
474
|
+
}
|
|
475
|
+
const credentialJson = JSON.stringify({
|
|
476
|
+
schema: SIWC_CREDENTIAL_SCHEMA,
|
|
477
|
+
issuer: profile.issuer,
|
|
478
|
+
subject: identity.subject,
|
|
479
|
+
...(identity.email ? { email: identity.email } : {}),
|
|
480
|
+
client_id: clientId,
|
|
481
|
+
ext_agent_host_id: hostId,
|
|
482
|
+
access_token: tokens.accessToken,
|
|
483
|
+
refresh_token: tokens.refreshToken,
|
|
484
|
+
token_type: tokens.tokenType,
|
|
485
|
+
scopes: tokens.scopes,
|
|
486
|
+
saved_at: new Date(acquisitionNow(host)).toISOString().replace(/\.\d{3}Z$/u, 'Z'),
|
|
401
487
|
});
|
|
402
|
-
logAcquisition(host, 'info', 'managed-oauth:
|
|
488
|
+
logAcquisition(host, 'info', 'managed-oauth:authorization:validated', {
|
|
403
489
|
profileId: profile.profileId,
|
|
404
|
-
|
|
405
|
-
expiresIn: Number.isFinite(exchange.expiresIn) ? exchange.expiresIn : null,
|
|
490
|
+
initialRegistration: registration.initialRegistration,
|
|
406
491
|
});
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
options,
|
|
410
|
-
profile,
|
|
411
|
-
credentialJson: credential.credentialJson,
|
|
412
|
-
signal,
|
|
492
|
+
const connectorId = await persistAuthorizationThroughRuntime({
|
|
493
|
+
options, profile, credentialJson, accountLabel: identity.email, signal,
|
|
413
494
|
});
|
|
414
|
-
|
|
495
|
+
const result = {
|
|
415
496
|
profileId: profile.profileId,
|
|
416
497
|
providerAuthProfile: profile.providerAuthProfile,
|
|
417
498
|
connectorId,
|
|
418
|
-
expiresAt: credential.expiresAt,
|
|
419
499
|
};
|
|
500
|
+
if (identity.email)
|
|
501
|
+
result.accountLabel = identity.email;
|
|
502
|
+
return result;
|
|
420
503
|
}
|
|
421
504
|
//# sourceMappingURL=connector-auth-acquisition.js.map
|