@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.
Files changed (411) hide show
  1. package/CHANGELOG.md +462 -0
  2. package/README.md +438 -17
  3. package/dist/core/ai/capability-configuration.d.ts +18 -0
  4. package/dist/core/ai/capability-configuration.d.ts.map +1 -1
  5. package/dist/core/ai/capability-configuration.js +39 -0
  6. package/dist/core/ai/capability-configuration.js.map +1 -1
  7. package/dist/core/ai/embeddings.d.ts +5 -0
  8. package/dist/core/ai/embeddings.d.ts.map +1 -1
  9. package/dist/core/ai/embeddings.js +30 -4
  10. package/dist/core/ai/embeddings.js.map +1 -1
  11. package/dist/core/ai/index.d.ts +4 -0
  12. package/dist/core/ai/index.d.ts.map +1 -1
  13. package/dist/core/ai/index.js +3 -0
  14. package/dist/core/ai/index.js.map +1 -1
  15. package/dist/core/ai/local-app-model.d.ts +15 -4
  16. package/dist/core/ai/local-app-model.d.ts.map +1 -1
  17. package/dist/core/ai/local-app-model.js +58 -18
  18. package/dist/core/ai/local-app-model.js.map +1 -1
  19. package/dist/core/ai/music-input-wire.d.ts +4 -0
  20. package/dist/core/ai/music-input-wire.d.ts.map +1 -0
  21. package/dist/core/ai/music-input-wire.js +9 -0
  22. package/dist/core/ai/music-input-wire.js.map +1 -0
  23. package/dist/core/ai/music-input.d.ts +44 -0
  24. package/dist/core/ai/music-input.d.ts.map +1 -0
  25. package/dist/core/ai/music-input.js +69 -0
  26. package/dist/core/ai/music-input.js.map +1 -0
  27. package/dist/core/ai/reasoning.d.ts +32 -0
  28. package/dist/core/ai/reasoning.d.ts.map +1 -0
  29. package/dist/core/ai/reasoning.js +74 -0
  30. package/dist/core/ai/reasoning.js.map +1 -0
  31. package/dist/core/ai/runtime-model.d.ts +2 -19
  32. package/dist/core/ai/runtime-model.d.ts.map +1 -1
  33. package/dist/core/ai/runtime-model.js +3 -47
  34. package/dist/core/ai/runtime-model.js.map +1 -1
  35. package/dist/core/ai/speech-input.d.ts +9 -0
  36. package/dist/core/ai/speech-input.d.ts.map +1 -0
  37. package/dist/core/ai/speech-input.js +16 -0
  38. package/dist/core/ai/speech-input.js.map +1 -0
  39. package/dist/core/ai/text-runner.js +11 -4
  40. package/dist/core/ai/text-runner.js.map +1 -1
  41. package/dist/core/ai/voice-reference-input.d.ts +9 -0
  42. package/dist/core/ai/voice-reference-input.d.ts.map +1 -0
  43. package/dist/core/ai/voice-reference-input.js +17 -0
  44. package/dist/core/ai/voice-reference-input.js.map +1 -0
  45. package/dist/core/app/desktop-open.d.ts +4 -1
  46. package/dist/core/app/desktop-open.d.ts.map +1 -1
  47. package/dist/core/app/desktop-open.js +5 -1
  48. package/dist/core/app/desktop-open.js.map +1 -1
  49. package/dist/core/app/index.d.ts +34 -3
  50. package/dist/core/app/index.d.ts.map +1 -1
  51. package/dist/core/app/index.js +21 -0
  52. package/dist/core/app/index.js.map +1 -1
  53. package/dist/core/app/local-app-agent-introduction.d.ts +30 -0
  54. package/dist/core/app/local-app-agent-introduction.d.ts.map +1 -0
  55. package/dist/core/app/local-app-agent-introduction.js +64 -0
  56. package/dist/core/app/local-app-agent-introduction.js.map +1 -0
  57. package/dist/core/app/local-app-agent-work-input.d.ts +24 -0
  58. package/dist/core/app/local-app-agent-work-input.d.ts.map +1 -0
  59. package/dist/core/app/local-app-agent-work-input.js +50 -0
  60. package/dist/core/app/local-app-agent-work-input.js.map +1 -0
  61. package/dist/core/app/local-app-audio-separation.d.ts +15 -0
  62. package/dist/core/app/local-app-audio-separation.d.ts.map +1 -0
  63. package/dist/core/app/local-app-audio-separation.js +92 -0
  64. package/dist/core/app/local-app-audio-separation.js.map +1 -0
  65. package/dist/core/app/local-app-bytes.d.ts +10 -0
  66. package/dist/core/app/local-app-bytes.d.ts.map +1 -0
  67. package/dist/core/app/local-app-bytes.js +27 -0
  68. package/dist/core/app/local-app-bytes.js.map +1 -0
  69. package/dist/core/app/local-app-music-transcription.d.ts +43 -0
  70. package/dist/core/app/local-app-music-transcription.d.ts.map +1 -0
  71. package/dist/core/app/local-app-music-transcription.js +94 -0
  72. package/dist/core/app/local-app-music-transcription.js.map +1 -0
  73. package/dist/core/app/local-app-music.d.ts +50 -0
  74. package/dist/core/app/local-app-music.d.ts.map +1 -0
  75. package/dist/core/app/local-app-music.js +135 -0
  76. package/dist/core/app/local-app-music.js.map +1 -0
  77. package/dist/core/app/local-app-runtime-platform-activity-view.d.ts +59 -0
  78. package/dist/core/app/local-app-runtime-platform-activity-view.d.ts.map +1 -0
  79. package/dist/core/app/local-app-runtime-platform-activity-view.js +283 -0
  80. package/dist/core/app/local-app-runtime-platform-activity-view.js.map +1 -0
  81. package/dist/core/app/local-app-runtime-platform-activity.d.ts +219 -0
  82. package/dist/core/app/local-app-runtime-platform-activity.d.ts.map +1 -0
  83. package/dist/core/app/local-app-runtime-platform-activity.js +749 -0
  84. package/dist/core/app/local-app-runtime-platform-activity.js.map +1 -0
  85. package/dist/core/app/local-app-runtime-platform-agent-references.d.ts +4 -0
  86. package/dist/core/app/local-app-runtime-platform-agent-references.d.ts.map +1 -1
  87. package/dist/core/app/local-app-runtime-platform-agent-references.js +21 -9
  88. package/dist/core/app/local-app-runtime-platform-agent-references.js.map +1 -1
  89. package/dist/core/app/local-app-runtime-platform-agent-work.d.ts +88 -0
  90. package/dist/core/app/local-app-runtime-platform-agent-work.d.ts.map +1 -0
  91. package/dist/core/app/local-app-runtime-platform-agent-work.js +165 -0
  92. package/dist/core/app/local-app-runtime-platform-agent-work.js.map +1 -0
  93. package/dist/core/app/local-app-runtime-platform-ai-config.d.ts.map +1 -1
  94. package/dist/core/app/local-app-runtime-platform-ai-config.js +62 -1
  95. package/dist/core/app/local-app-runtime-platform-ai-config.js.map +1 -1
  96. package/dist/core/app/local-app-runtime-platform-ai.d.ts +172 -34
  97. package/dist/core/app/local-app-runtime-platform-ai.d.ts.map +1 -1
  98. package/dist/core/app/local-app-runtime-platform-ai.js +805 -112
  99. package/dist/core/app/local-app-runtime-platform-ai.js.map +1 -1
  100. package/dist/core/app/local-app-runtime-platform-assets.d.ts.map +1 -1
  101. package/dist/core/app/local-app-runtime-platform-assets.js +37 -12
  102. package/dist/core/app/local-app-runtime-platform-assets.js.map +1 -1
  103. package/dist/core/app/local-app-runtime-platform-configure.d.ts +1 -1
  104. package/dist/core/app/local-app-runtime-platform-configure.d.ts.map +1 -1
  105. package/dist/core/app/local-app-runtime-platform-configure.js +10 -10
  106. package/dist/core/app/local-app-runtime-platform-configure.js.map +1 -1
  107. package/dist/core/app/local-app-runtime-platform-conversation.d.ts +7 -4
  108. package/dist/core/app/local-app-runtime-platform-conversation.d.ts.map +1 -1
  109. package/dist/core/app/local-app-runtime-platform-conversation.js +15 -10
  110. package/dist/core/app/local-app-runtime-platform-conversation.js.map +1 -1
  111. package/dist/core/app/local-app-runtime-platform-direct-agent-work.d.ts +5 -0
  112. package/dist/core/app/local-app-runtime-platform-direct-agent-work.d.ts.map +1 -0
  113. package/dist/core/app/local-app-runtime-platform-direct-agent-work.js +38 -0
  114. package/dist/core/app/local-app-runtime-platform-direct-agent-work.js.map +1 -0
  115. package/dist/core/app/local-app-runtime-platform-direct-conversation.js +6 -6
  116. package/dist/core/app/local-app-runtime-platform-direct-conversation.js.map +1 -1
  117. package/dist/core/app/local-app-runtime-platform-integration.d.ts +128 -0
  118. package/dist/core/app/local-app-runtime-platform-integration.d.ts.map +1 -0
  119. package/dist/core/app/local-app-runtime-platform-integration.js +263 -0
  120. package/dist/core/app/local-app-runtime-platform-integration.js.map +1 -0
  121. package/dist/core/app/local-app-runtime-platform-validation.d.ts +2 -0
  122. package/dist/core/app/local-app-runtime-platform-validation.d.ts.map +1 -1
  123. package/dist/core/app/local-app-runtime-platform-validation.js +50 -3
  124. package/dist/core/app/local-app-runtime-platform-validation.js.map +1 -1
  125. package/dist/core/app/local-app-runtime-platform-vision.d.ts +1 -1
  126. package/dist/core/app/local-app-runtime-platform-vision.d.ts.map +1 -1
  127. package/dist/core/app/local-app-runtime-platform-vision.js +5 -5
  128. package/dist/core/app/local-app-runtime-platform-vision.js.map +1 -1
  129. package/dist/core/app/local-app-runtime-platform.d.ts +19 -15
  130. package/dist/core/app/local-app-runtime-platform.d.ts.map +1 -1
  131. package/dist/core/app/local-app-runtime-platform.js +17 -6
  132. package/dist/core/app/local-app-runtime-platform.js.map +1 -1
  133. package/dist/core/app/local-app-speaker-embedding.d.ts +6 -0
  134. package/dist/core/app/local-app-speaker-embedding.d.ts.map +1 -0
  135. package/dist/core/app/local-app-speaker-embedding.js +14 -0
  136. package/dist/core/app/local-app-speaker-embedding.js.map +1 -0
  137. package/dist/core/app/local-app-text-annotation.d.ts +24 -0
  138. package/dist/core/app/local-app-text-annotation.d.ts.map +1 -0
  139. package/dist/core/app/local-app-text-annotation.js +71 -0
  140. package/dist/core/app/local-app-text-annotation.js.map +1 -0
  141. package/dist/core/app/local-app-text-decision.d.ts +114 -0
  142. package/dist/core/app/local-app-text-decision.d.ts.map +1 -0
  143. package/dist/core/app/local-app-text-decision.js +444 -0
  144. package/dist/core/app/local-app-text-decision.js.map +1 -0
  145. package/dist/core/app/local-app-text.d.ts +7 -1
  146. package/dist/core/app/local-app-text.d.ts.map +1 -1
  147. package/dist/core/app/local-app-text.js +16 -15
  148. package/dist/core/app/local-app-text.js.map +1 -1
  149. package/dist/core/app/local-app-transcription.d.ts +23 -0
  150. package/dist/core/app/local-app-transcription.d.ts.map +1 -0
  151. package/dist/core/app/local-app-transcription.js +48 -0
  152. package/dist/core/app/local-app-transcription.js.map +1 -0
  153. package/dist/core/app/local-app-voice-convert.d.ts +61 -0
  154. package/dist/core/app/local-app-voice-convert.d.ts.map +1 -0
  155. package/dist/core/app/local-app-voice-convert.js +133 -0
  156. package/dist/core/app/local-app-voice-convert.js.map +1 -0
  157. package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts +2 -2
  158. package/dist/core/app/runtime-account-realm-source-readiness.generated.d.ts.map +1 -1
  159. package/dist/core/app/runtime-account-realm-source-readiness.generated.js +5 -3
  160. package/dist/core/app/runtime-account-realm-source-readiness.generated.js.map +1 -1
  161. package/dist/core/text-stream-cleanup.d.ts +3 -0
  162. package/dist/core/text-stream-cleanup.d.ts.map +1 -0
  163. package/dist/core/text-stream-cleanup.js +19 -0
  164. package/dist/core/text-stream-cleanup.js.map +1 -0
  165. package/dist/core-generated/realm-client.d.ts.map +1 -1
  166. package/dist/core-generated/realm-client.js +10 -4
  167. package/dist/core-generated/realm-client.js.map +1 -1
  168. package/dist/core-generated/realm-typed-client.d.ts +159 -34
  169. package/dist/core-generated/realm-typed-client.d.ts.map +1 -1
  170. package/dist/core-generated/realm-typed-client.js +81 -8
  171. package/dist/core-generated/realm-typed-client.js.map +1 -1
  172. package/dist/core-generated/runtime-client.d.ts.map +1 -1
  173. package/dist/core-generated/runtime-client.js +312 -0
  174. package/dist/core-generated/runtime-client.js.map +1 -1
  175. package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts +21 -0
  176. package/dist/core-generated/runtime-protobuf/runtime/v1/account.d.ts.map +1 -1
  177. package/dist/core-generated/runtime-protobuf/runtime/v1/account.js +41 -5
  178. package/dist/core-generated/runtime-protobuf/runtime/v1/account.js.map +1 -1
  179. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts +158 -1
  180. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.d.ts.map +1 -1
  181. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js +299 -2
  182. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_service.js.map +1 -1
  183. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts +5 -1
  184. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.d.ts.map +1 -1
  185. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js +4 -0
  186. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_source_materialization.js.map +1 -1
  187. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.d.ts +625 -0
  188. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.d.ts.map +1 -0
  189. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.js +1369 -0
  190. package/dist/core-generated/runtime-protobuf/runtime/v1/agent_work.js.map +1 -0
  191. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts +2274 -134
  192. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.d.ts.map +1 -1
  193. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js +5178 -1218
  194. package/dist/core-generated/runtime-protobuf/runtime/v1/ai.js.map +1 -1
  195. package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts +168 -0
  196. package/dist/core-generated/runtime-protobuf/runtime/v1/app.d.ts.map +1 -1
  197. package/dist/core-generated/runtime-protobuf/runtime/v1/app.js +326 -5
  198. package/dist/core-generated/runtime-protobuf/runtime/v1/app.js.map +1 -1
  199. package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.d.ts +859 -0
  200. package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.d.ts.map +1 -0
  201. package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.js +1663 -0
  202. package/dist/core-generated/runtime-protobuf/runtime/v1/app_activity.js.map +1 -0
  203. package/dist/core-generated/runtime-protobuf/runtime/v1/auth.d.ts +20 -0
  204. package/dist/core-generated/runtime-protobuf/runtime/v1/auth.d.ts.map +1 -1
  205. package/dist/core-generated/runtime-protobuf/runtime/v1/auth.js +38 -0
  206. package/dist/core-generated/runtime-protobuf/runtime/v1/auth.js.map +1 -1
  207. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts +579 -0
  208. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.d.ts.map +1 -1
  209. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js +1056 -12
  210. package/dist/core-generated/runtime-protobuf/runtime/v1/capability_configuration.js.map +1 -1
  211. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts +161 -1
  212. package/dist/core-generated/runtime-protobuf/runtime/v1/common.d.ts.map +1 -1
  213. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js +160 -0
  214. package/dist/core-generated/runtime-protobuf/runtime/v1/common.js.map +1 -1
  215. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts +43 -0
  216. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.d.ts.map +1 -1
  217. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js +88 -4
  218. package/dist/core-generated/runtime-protobuf/runtime/v1/connector.js.map +1 -1
  219. package/dist/core-generated/runtime-protobuf/runtime/v1/development.d.ts +53 -0
  220. package/dist/core-generated/runtime-protobuf/runtime/v1/development.d.ts.map +1 -1
  221. package/dist/core-generated/runtime-protobuf/runtime/v1/development.js +118 -0
  222. package/dist/core-generated/runtime-protobuf/runtime/v1/development.js.map +1 -1
  223. package/dist/core-generated/runtime-protobuf/runtime/v1/integration.d.ts +1293 -0
  224. package/dist/core-generated/runtime-protobuf/runtime/v1/integration.d.ts.map +1 -0
  225. package/dist/core-generated/runtime-protobuf/runtime/v1/integration.js +2898 -0
  226. package/dist/core-generated/runtime-protobuf/runtime/v1/integration.js.map +1 -0
  227. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.d.ts +200 -0
  228. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.d.ts.map +1 -1
  229. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.js +249 -4
  230. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime.js.map +1 -1
  231. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.d.ts +13 -0
  232. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.d.ts.map +1 -1
  233. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.js +17 -1
  234. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_device_environment.js.map +1 -1
  235. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.d.ts +8 -0
  236. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.d.ts.map +1 -1
  237. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.js +9 -1
  238. package/dist/core-generated/runtime-protobuf/runtime/v1/local_runtime_recommendation.js.map +1 -1
  239. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts +69 -0
  240. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.d.ts.map +1 -1
  241. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js +120 -0
  242. package/dist/core-generated/runtime-protobuf/runtime/v1/runtime_service_control.js.map +1 -1
  243. package/dist/core-generated/runtime-public-client.d.ts.map +1 -1
  244. package/dist/core-generated/runtime-public-client.js +296 -8
  245. package/dist/core-generated/runtime-public-client.js.map +1 -1
  246. package/dist/core-generated/runtime-public-rpc-auth-posture.d.ts.map +1 -1
  247. package/dist/core-generated/runtime-public-rpc-auth-posture.js +37 -1
  248. package/dist/core-generated/runtime-public-rpc-auth-posture.js.map +1 -1
  249. package/dist/core-generated/runtime-public-wire-codecs.d.ts +44 -5
  250. package/dist/core-generated/runtime-public-wire-codecs.d.ts.map +1 -1
  251. package/dist/core-generated/runtime-public-wire-codecs.js +44 -5
  252. package/dist/core-generated/runtime-public-wire-codecs.js.map +1 -1
  253. package/dist/core-generated/runtime-rpc-auth-posture.d.ts.map +1 -1
  254. package/dist/core-generated/runtime-rpc-auth-posture.js +39 -0
  255. package/dist/core-generated/runtime-rpc-auth-posture.js.map +1 -1
  256. package/dist/core-generated/runtime-typed-client.d.ts +66 -16
  257. package/dist/core-generated/runtime-typed-client.d.ts.map +1 -1
  258. package/dist/core-generated/runtime-typed-client.js +398 -3
  259. package/dist/core-generated/runtime-typed-client.js.map +1 -1
  260. package/dist/core-generated/runtime-wire-codecs.d.ts +47 -5
  261. package/dist/core-generated/runtime-wire-codecs.d.ts.map +1 -1
  262. package/dist/core-generated/runtime-wire-codecs.js +47 -5
  263. package/dist/core-generated/runtime-wire-codecs.js.map +1 -1
  264. package/dist/features/generation/index.d.ts +16 -2
  265. package/dist/features/generation/index.d.ts.map +1 -1
  266. package/dist/features/generation/index.js +26 -3
  267. package/dist/features/generation/index.js.map +1 -1
  268. package/dist/features/generation/media-params.d.ts +0 -3
  269. package/dist/features/generation/media-params.d.ts.map +1 -1
  270. package/dist/features/generation/media-params.js +8 -6
  271. package/dist/features/generation/media-params.js.map +1 -1
  272. package/dist/features/generation/runtime-generation-build.d.ts +0 -1
  273. package/dist/features/generation/runtime-generation-build.d.ts.map +1 -1
  274. package/dist/features/generation/runtime-generation-build.js +6 -1
  275. package/dist/features/generation/runtime-generation-build.js.map +1 -1
  276. package/dist/features/generation/runtime-image-generation.d.ts +5 -1
  277. package/dist/features/generation/runtime-image-generation.d.ts.map +1 -1
  278. package/dist/features/generation/runtime-image-generation.js +4 -0
  279. package/dist/features/generation/runtime-image-generation.js.map +1 -1
  280. package/dist/features/generation/runtime-job-builders.d.ts +0 -1
  281. package/dist/features/generation/runtime-job-builders.d.ts.map +1 -1
  282. package/dist/features/generation/runtime-job-builders.js +8 -10
  283. package/dist/features/generation/runtime-job-builders.js.map +1 -1
  284. package/dist/realm/index.d.ts +1 -1
  285. package/dist/realm/index.d.ts.map +1 -1
  286. package/dist/realm/index.js +3 -2
  287. package/dist/realm/index.js.map +1 -1
  288. package/dist/runtime/chatgpt-plan.d.ts +7 -0
  289. package/dist/runtime/chatgpt-plan.d.ts.map +1 -0
  290. package/dist/runtime/chatgpt-plan.js +15 -0
  291. package/dist/runtime/chatgpt-plan.js.map +1 -0
  292. package/dist/runtime/config-projections.d.ts +2 -0
  293. package/dist/runtime/config-projections.d.ts.map +1 -1
  294. package/dist/runtime/config-projections.js +33 -1
  295. package/dist/runtime/config-projections.js.map +1 -1
  296. package/dist/runtime/connector-auth-acquisition-client.d.ts +3 -6
  297. package/dist/runtime/connector-auth-acquisition-client.d.ts.map +1 -1
  298. package/dist/runtime/connector-auth-acquisition-client.js +18 -11
  299. package/dist/runtime/connector-auth-acquisition-client.js.map +1 -1
  300. package/dist/runtime/connector-auth-acquisition-profiles.generated.d.ts +10 -11
  301. package/dist/runtime/connector-auth-acquisition-profiles.generated.d.ts.map +1 -1
  302. package/dist/runtime/connector-auth-acquisition-profiles.generated.js +13 -14
  303. package/dist/runtime/connector-auth-acquisition-profiles.generated.js.map +1 -1
  304. package/dist/runtime/connector-auth-acquisition.d.ts +26 -19
  305. package/dist/runtime/connector-auth-acquisition.d.ts.map +1 -1
  306. package/dist/runtime/connector-auth-acquisition.js +352 -269
  307. package/dist/runtime/connector-auth-acquisition.js.map +1 -1
  308. package/dist/runtime/connector-auth-profiles.generated.d.ts +1 -1
  309. package/dist/runtime/connector-auth-profiles.generated.d.ts.map +1 -1
  310. package/dist/runtime/connector-auth-profiles.generated.js +4 -4
  311. package/dist/runtime/connector-auth-profiles.generated.js.map +1 -1
  312. package/dist/runtime/connector-inventory.d.ts +11 -2
  313. package/dist/runtime/connector-inventory.d.ts.map +1 -1
  314. package/dist/runtime/connector-inventory.js +13 -4
  315. package/dist/runtime/connector-inventory.js.map +1 -1
  316. package/dist/runtime/desktop-audit.js +4 -1
  317. package/dist/runtime/desktop-audit.js.map +1 -1
  318. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts +130 -2
  319. package/dist/runtime/first-party-protected-runtime-profiles.generated.d.ts.map +1 -1
  320. package/dist/runtime/first-party-protected-runtime-profiles.generated.js +34 -2
  321. package/dist/runtime/first-party-protected-runtime-profiles.generated.js.map +1 -1
  322. package/dist/runtime/generated.d.ts +2 -2
  323. package/dist/runtime/generated.d.ts.map +1 -1
  324. package/dist/runtime/generated.js +1 -1
  325. package/dist/runtime/generated.js.map +1 -1
  326. package/dist/runtime/host.d.ts +3 -0
  327. package/dist/runtime/host.d.ts.map +1 -1
  328. package/dist/runtime/host.js +4 -0
  329. package/dist/runtime/host.js.map +1 -1
  330. package/dist/runtime/index.d.ts +3 -0
  331. package/dist/runtime/index.d.ts.map +1 -1
  332. package/dist/runtime/index.js +3 -1
  333. package/dist/runtime/index.js.map +1 -1
  334. package/dist/runtime/machine-loadouts.d.ts +33 -1
  335. package/dist/runtime/machine-loadouts.d.ts.map +1 -1
  336. package/dist/runtime/machine-loadouts.js +39 -2
  337. package/dist/runtime/machine-loadouts.js.map +1 -1
  338. package/dist/runtime/node-grpc-errors.js +3 -3
  339. package/dist/runtime/node-grpc-errors.js.map +1 -1
  340. package/dist/runtime/node-grpc.d.ts.map +1 -1
  341. package/dist/runtime/node-grpc.js +35 -4
  342. package/dist/runtime/node-grpc.js.map +1 -1
  343. package/dist/runtime/product-control-projection.d.ts.map +1 -1
  344. package/dist/runtime/product-control-projection.js +11 -2
  345. package/dist/runtime/product-control-projection.js.map +1 -1
  346. package/dist/runtime/product-control-types.d.ts +13 -2
  347. package/dist/runtime/product-control-types.d.ts.map +1 -1
  348. package/dist/runtime/product-control-types.js.map +1 -1
  349. package/dist/runtime/reason-messages.d.ts +3 -0
  350. package/dist/runtime/reason-messages.d.ts.map +1 -1
  351. package/dist/runtime/reason-messages.js +11 -2
  352. package/dist/runtime/reason-messages.js.map +1 -1
  353. package/dist/runtime/runtime-local-environment-client-projections.d.ts.map +1 -1
  354. package/dist/runtime/runtime-local-environment-client-projections.js +21 -17
  355. package/dist/runtime/runtime-local-environment-client-projections.js.map +1 -1
  356. package/dist/runtime/runtime-local-environment-client-types.d.ts +50 -19
  357. package/dist/runtime/runtime-local-environment-client-types.d.ts.map +1 -1
  358. package/dist/runtime/runtime-local-environment-client-values.d.ts +3 -1
  359. package/dist/runtime/runtime-local-environment-client-values.d.ts.map +1 -1
  360. package/dist/runtime/runtime-local-environment-client-values.js +43 -0
  361. package/dist/runtime/runtime-local-environment-client-values.js.map +1 -1
  362. package/dist/runtime/runtime-local-environment-client.d.ts.map +1 -1
  363. package/dist/runtime/runtime-local-environment-client.js +12 -3
  364. package/dist/runtime/runtime-local-environment-client.js.map +1 -1
  365. package/dist/runtime/runtime-local-recommendation-types.d.ts +3 -0
  366. package/dist/runtime/runtime-local-recommendation-types.d.ts.map +1 -1
  367. package/dist/runtime/runtime-local-recommendation.d.ts.map +1 -1
  368. package/dist/runtime/runtime-local-recommendation.js +1 -0
  369. package/dist/runtime/runtime-local-recommendation.js.map +1 -1
  370. package/dist/runtime/scenario-jobs.d.ts +23 -1
  371. package/dist/runtime/scenario-jobs.d.ts.map +1 -1
  372. package/dist/runtime/scenario-jobs.js +227 -264
  373. package/dist/runtime/scenario-jobs.js.map +1 -1
  374. package/dist/runtime/shared-local-agent-ai-config.d.ts.map +1 -1
  375. package/dist/runtime/shared-local-agent-ai-config.js +6 -0
  376. package/dist/runtime/shared-local-agent-ai-config.js.map +1 -1
  377. package/dist/runtime/wire-types/agent-participation-enums.d.ts +2 -1
  378. package/dist/runtime/wire-types/agent-participation-enums.d.ts.map +1 -1
  379. package/dist/runtime/wire-types/agent-participation-enums.js +2 -1
  380. package/dist/runtime/wire-types/agent-participation-enums.js.map +1 -1
  381. package/dist/runtime/wire-types/agent-participation-types.d.ts +4 -2
  382. package/dist/runtime/wire-types/agent-participation-types.d.ts.map +1 -1
  383. package/dist/runtime/wire-types/ai-scenario-enums.d.ts +119 -3
  384. package/dist/runtime/wire-types/ai-scenario-enums.d.ts.map +1 -1
  385. package/dist/runtime/wire-types/ai-scenario-enums.js +136 -0
  386. package/dist/runtime/wire-types/ai-scenario-enums.js.map +1 -1
  387. package/dist/runtime/wire-types/ai-scenario-types.d.ts +8 -6
  388. package/dist/runtime/wire-types/ai-scenario-types.d.ts.map +1 -1
  389. package/dist/runtime/wire-types/identity-app-enums.d.ts +47 -0
  390. package/dist/runtime/wire-types/identity-app-enums.d.ts.map +1 -1
  391. package/dist/runtime/wire-types/identity-app-enums.js +55 -0
  392. package/dist/runtime/wire-types/identity-app-enums.js.map +1 -1
  393. package/dist/runtime/wire-types/identity-app-types.d.ts +6 -4
  394. package/dist/runtime/wire-types/identity-app-types.d.ts.map +1 -1
  395. package/dist/runtime/wire-types/local-memory-enums.d.ts +31 -1
  396. package/dist/runtime/wire-types/local-memory-enums.d.ts.map +1 -1
  397. package/dist/runtime/wire-types/local-memory-enums.js +34 -0
  398. package/dist/runtime/wire-types/local-memory-enums.js.map +1 -1
  399. package/dist/runtime/wire-types/reason-code-enums.d.ts +30 -1
  400. package/dist/runtime/wire-types/reason-code-enums.d.ts.map +1 -1
  401. package/dist/runtime/wire-types/reason-code-enums.js +29 -0
  402. package/dist/runtime/wire-types/reason-code-enums.js.map +1 -1
  403. package/dist/types/errors.d.ts +1 -1
  404. package/dist/types/errors.d.ts.map +1 -1
  405. package/dist/types/errors.js +2 -2
  406. package/dist/types/errors.js.map +1 -1
  407. package/dist/types/reason-code.d.ts +2 -0
  408. package/dist/types/reason-code.d.ts.map +1 -1
  409. package/dist/types/reason-code.js +2 -0
  410. package/dist/types/reason-code.js.map +1 -1
  411. package/package.json +5 -5
@@ -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
- // The Electron/Node host cannot represent larger timeout delays safely. This is
5
- // a runtime representation limit, not a product policy for OAuth lifetimes.
6
- const MAX_RUNTIME_TIMER_DELAY_MS = 2_147_483_647;
7
- const MAX_RUNTIME_TIMER_DELAY_SECONDS = Math.floor(MAX_RUNTIME_TIMER_DELAY_MS / 1000);
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 Error(`${errorLabel} returned invalid JSON`);
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 Error(`${errorLabel} returned a non-object JSON payload`);
127
+ throw new NimiConnectorAuthAcquisitionError('AUTHORIZATION_INVALID', `${errorLabel} returned a non-object JSON payload`);
112
128
  }
113
129
  return parsed;
114
130
  }
115
- function toIsoTimestamp(value, field) {
116
- const date = new Date(value);
117
- if (Number.isNaN(date.getTime())) {
118
- throw new Error(`${field} exceeds the runtime date capacity`);
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 date.toISOString();
149
+ return output;
121
150
  }
122
- function maskUserCode(userCode) {
123
- const normalized = String(userCode || '').trim();
124
- if (!normalized) {
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
- if (normalized.length <= 4) {
128
- return normalized;
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 `${normalized.slice(0, 2)}***${normalized.slice(-2)}`;
131
- }
132
- function logAcquisition(host, level, message, details) {
133
- host.log?.(level, message, details);
168
+ return bytes.subarray(0, length);
134
169
  }
135
- async function postJson(host, profile, purpose, url, payload, signal) {
136
- return awaitWithCancellation(host.proxyHttp({
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 buildManagedCredentialJson(input) {
149
- const accessToken = toTrimmedString(input.accessToken);
150
- if (!accessToken) {
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
- async function persistManagedConnectorCredentialThroughRuntime(input) {
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 acquireManagedConnectorCredentialWithProfile(options, profile, lifecycle.signal);
427
+ return await acquireWithProfile(options, profile, lifecycle.signal);
234
428
  }
235
429
  finally {
236
430
  lifecycle.dispose();
237
431
  }
238
432
  }
239
- async function acquireManagedConnectorCredentialWithProfile(options, profile, signal) {
433
+ async function acquireWithProfile(options, profile, signal) {
240
434
  const host = options.host;
241
435
  throwIfAborted(signal);
242
- logAcquisition(host, 'info', 'managed-oauth:device-code-request:start', {
243
- profileId: profile.profileId,
244
- });
245
- const deviceCodeResponse = await postJson(host, profile, 'device_authorization', profile.deviceAuthorizationUrl, {
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
- logAcquisition(host, 'info', 'managed-oauth:device-code-request:success', {
287
- profileId: profile.profileId,
288
- pollIntervalSeconds,
289
- expiresInSeconds,
290
- userCode: maskUserCode(userCode),
291
- hasVerificationUriComplete: Boolean(toTrimmedString(deviceData.verification_uri_complete)),
292
- });
293
- throwIfAborted(signal);
294
- options.onPending?.({
295
- userCode,
296
- verificationUrl,
297
- expiresInSeconds,
298
- pollIntervalSeconds,
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
- verificationUrl,
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
- if (acquisitionNow(host) >= deadlineMs)
327
- break;
328
- pollAttempt += 1;
329
- const pollResponse = await postJson(host, profile, 'device_token', profile.deviceTokenUrl, {
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
- if (pollResponse.status === 403 || pollResponse.status === 404) {
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
- if (!codeResponse) {
359
- logAcquisition(host, 'warn', 'managed-oauth:poll:timeout', {
360
- profileId: profile.profileId,
361
- attempts: pollAttempt,
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 exchange = await awaitWithCancellation(host.oauthTokenExchange({
382
- provider: profile.tokenExchangeProvider,
383
- clientId: profile.clientId,
384
- code: authorizationCode,
385
- codeVerifier,
386
- redirectUri: profile.redirectUri,
387
- }, signal), signal);
388
- const accessToken = toTrimmedString(exchange.accessToken);
389
- if (!accessToken) {
390
- throw new Error('Managed OAuth token exchange did not return an access token');
391
- }
392
- const nowMs = acquisitionNow(host);
393
- const credential = buildManagedCredentialJson({
394
- profile,
395
- accessToken,
396
- refreshToken: exchange.refreshToken,
397
- tokenType: exchange.tokenType,
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:token-exchange:success', {
488
+ logAcquisition(host, 'info', 'managed-oauth:authorization:validated', {
403
489
  profileId: profile.profileId,
404
- hasRefreshToken: Boolean(toTrimmedString(exchange.refreshToken)),
405
- expiresIn: Number.isFinite(exchange.expiresIn) ? exchange.expiresIn : null,
490
+ initialRegistration: registration.initialRegistration,
406
491
  });
407
- throwIfAborted(signal);
408
- const connectorId = await persistManagedConnectorCredentialThroughRuntime({
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
- return {
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