@nocha/cli 4.6.1 → 4.13.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 (250) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/NOCHA.schema.json +1670 -3
  3. package/dist/build-info.json +4 -4
  4. package/dist/dev-offline-compiler.js +682 -7
  5. package/dist/dev-offline-runner.js +48 -6
  6. package/dist/development-live-host.js +13 -1
  7. package/dist/nocha.js +804 -60
  8. package/dist/reference-integrity.json +135 -101
  9. package/dist/references/api/README.md +24 -23
  10. package/dist/references/api/signatures.md +23 -2
  11. package/dist/references/base/server/tooling/sdk-sources.ts +2 -2
  12. package/dist/references/base/src/platform/failure.ts +1 -1
  13. package/dist/references/base/src/types/nocha/assets-media.d.ts +8 -0
  14. package/dist/references/base/src/types/nocha/assets-operations.d.ts +3 -0
  15. package/dist/references/base/src/types/nocha/capability-deadlines.d.ts +6 -0
  16. package/dist/references/base/src/types/nocha/capability-needs.d.ts +7 -0
  17. package/dist/references/base/src/types/nocha/capability-operations.d.ts +3 -1
  18. package/dist/references/base/src/types/nocha/drive-operations.d.ts +56 -0
  19. package/dist/references/base/src/types/nocha/drive-types.d.ts +77 -0
  20. package/dist/references/base/src/types/nocha/drive.d.ts +54 -0
  21. package/dist/references/base/src/types/nocha/error-codes.d.ts +9 -0
  22. package/dist/references/base/src/types/nocha/execution.d.ts +1 -1
  23. package/dist/references/base/src/types/nocha/index.d.ts +4 -0
  24. package/dist/references/base/src/types/nocha/media-read.d.ts +29 -0
  25. package/dist/references/base/src/types/nocha/operation-waiting.d.ts +8 -0
  26. package/dist/references/base/src/types/nocha/operation-wire-types.d.ts +30 -2
  27. package/dist/references/base/src/types/nocha/protocol.d.ts +7 -3
  28. package/dist/references/base/src/types/nocha/types/ai-wire.d.ts +40 -1
  29. package/dist/references/base/src/types/nocha/types/ai.d.ts +1 -1
  30. package/dist/references/base/src/types/nocha/types/assets-wire.d.ts +9 -1
  31. package/dist/references/base/src/types/nocha/types/assets.d.ts +22 -5
  32. package/dist/references/base/src/types/nocha/types/video-sdk-wire.d.ts +174 -13
  33. package/dist/references/base/src/types/nocha/types/video-wire.d.ts +120 -7
  34. package/dist/references/base/src/types/nocha/types/video.d.ts +5 -2
  35. package/dist/references/base/src/types/nocha/video-analysis.d.ts +10 -0
  36. package/dist/references/base/src/types/nocha/video-media.d.ts +1 -3
  37. package/dist/references/duel/server/tooling/sdk-sources.ts +2 -2
  38. package/dist/references/duel/src/types/nocha/assets-media.d.ts +8 -0
  39. package/dist/references/duel/src/types/nocha/assets-operations.d.ts +3 -0
  40. package/dist/references/duel/src/types/nocha/capability-deadlines.d.ts +6 -0
  41. package/dist/references/duel/src/types/nocha/capability-needs.d.ts +7 -0
  42. package/dist/references/duel/src/types/nocha/capability-operations.d.ts +3 -1
  43. package/dist/references/duel/src/types/nocha/drive-operations.d.ts +56 -0
  44. package/dist/references/duel/src/types/nocha/drive-types.d.ts +77 -0
  45. package/dist/references/duel/src/types/nocha/drive.d.ts +54 -0
  46. package/dist/references/duel/src/types/nocha/error-codes.d.ts +9 -0
  47. package/dist/references/duel/src/types/nocha/execution.d.ts +1 -1
  48. package/dist/references/duel/src/types/nocha/index.d.ts +4 -0
  49. package/dist/references/duel/src/types/nocha/media-read.d.ts +29 -0
  50. package/dist/references/duel/src/types/nocha/operation-waiting.d.ts +8 -0
  51. package/dist/references/duel/src/types/nocha/operation-wire-types.d.ts +30 -2
  52. package/dist/references/duel/src/types/nocha/protocol.d.ts +7 -3
  53. package/dist/references/duel/src/types/nocha/types/ai-wire.d.ts +40 -1
  54. package/dist/references/duel/src/types/nocha/types/ai.d.ts +1 -1
  55. package/dist/references/duel/src/types/nocha/types/assets-wire.d.ts +9 -1
  56. package/dist/references/duel/src/types/nocha/types/assets.d.ts +22 -5
  57. package/dist/references/duel/src/types/nocha/types/video-sdk-wire.d.ts +174 -13
  58. package/dist/references/duel/src/types/nocha/types/video-wire.d.ts +120 -7
  59. package/dist/references/duel/src/types/nocha/types/video.d.ts +5 -2
  60. package/dist/references/duel/src/types/nocha/video-analysis.d.ts +10 -0
  61. package/dist/references/duel/src/types/nocha/video-media.d.ts +1 -3
  62. package/dist/references/recipes/README.md +1 -0
  63. package/dist/references/recipes/backend-transaction/src/platform/failure.ts +1 -1
  64. package/dist/references/recipes/drive/NOCHA.json +24 -0
  65. package/dist/references/recipes/drive/README.md +15 -0
  66. package/dist/references/recipes/drive/SKILL.md +24 -0
  67. package/dist/references/recipes/drive/recipe.ts +34 -0
  68. package/dist/references/recipes/music/README.md +1 -1
  69. package/dist/references/recipes/types/nocha/assets-media.d.ts +8 -0
  70. package/dist/references/recipes/types/nocha/assets-operations.d.ts +3 -0
  71. package/dist/references/recipes/types/nocha/capability-deadlines.d.ts +6 -0
  72. package/dist/references/recipes/types/nocha/capability-needs.d.ts +7 -0
  73. package/dist/references/recipes/types/nocha/capability-operations.d.ts +3 -1
  74. package/dist/references/recipes/types/nocha/drive-operations.d.ts +56 -0
  75. package/dist/references/recipes/types/nocha/drive-types.d.ts +77 -0
  76. package/dist/references/recipes/types/nocha/drive.d.ts +54 -0
  77. package/dist/references/recipes/types/nocha/error-codes.d.ts +9 -0
  78. package/dist/references/recipes/types/nocha/execution.d.ts +1 -1
  79. package/dist/references/recipes/types/nocha/index.d.ts +4 -0
  80. package/dist/references/recipes/types/nocha/media-read.d.ts +29 -0
  81. package/dist/references/recipes/types/nocha/operation-waiting.d.ts +8 -0
  82. package/dist/references/recipes/types/nocha/operation-wire-types.d.ts +30 -2
  83. package/dist/references/recipes/types/nocha/protocol.d.ts +7 -3
  84. package/dist/references/recipes/types/nocha/types/ai-wire.d.ts +40 -1
  85. package/dist/references/recipes/types/nocha/types/ai.d.ts +1 -1
  86. package/dist/references/recipes/types/nocha/types/assets-wire.d.ts +9 -1
  87. package/dist/references/recipes/types/nocha/types/assets.d.ts +22 -5
  88. package/dist/references/recipes/types/nocha/types/video-sdk-wire.d.ts +174 -13
  89. package/dist/references/recipes/types/nocha/types/video-wire.d.ts +120 -7
  90. package/dist/references/recipes/types/nocha/types/video.d.ts +5 -2
  91. package/dist/references/recipes/types/nocha/video-analysis.d.ts +10 -0
  92. package/dist/references/recipes/types/nocha/video-media.d.ts +1 -3
  93. package/dist/references/stage/server/tooling/sdk-sources.ts +2 -2
  94. package/dist/references/stage/src/types/nocha/assets-media.d.ts +8 -0
  95. package/dist/references/stage/src/types/nocha/assets-operations.d.ts +3 -0
  96. package/dist/references/stage/src/types/nocha/capability-deadlines.d.ts +6 -0
  97. package/dist/references/stage/src/types/nocha/capability-needs.d.ts +7 -0
  98. package/dist/references/stage/src/types/nocha/capability-operations.d.ts +3 -1
  99. package/dist/references/stage/src/types/nocha/drive-operations.d.ts +56 -0
  100. package/dist/references/stage/src/types/nocha/drive-types.d.ts +77 -0
  101. package/dist/references/stage/src/types/nocha/drive.d.ts +54 -0
  102. package/dist/references/stage/src/types/nocha/error-codes.d.ts +9 -0
  103. package/dist/references/stage/src/types/nocha/execution.d.ts +1 -1
  104. package/dist/references/stage/src/types/nocha/index.d.ts +4 -0
  105. package/dist/references/stage/src/types/nocha/media-read.d.ts +29 -0
  106. package/dist/references/stage/src/types/nocha/operation-waiting.d.ts +8 -0
  107. package/dist/references/stage/src/types/nocha/operation-wire-types.d.ts +30 -2
  108. package/dist/references/stage/src/types/nocha/protocol.d.ts +7 -3
  109. package/dist/references/stage/src/types/nocha/types/ai-wire.d.ts +40 -1
  110. package/dist/references/stage/src/types/nocha/types/ai.d.ts +1 -1
  111. package/dist/references/stage/src/types/nocha/types/assets-wire.d.ts +9 -1
  112. package/dist/references/stage/src/types/nocha/types/assets.d.ts +22 -5
  113. package/dist/references/stage/src/types/nocha/types/video-sdk-wire.d.ts +174 -13
  114. package/dist/references/stage/src/types/nocha/types/video-wire.d.ts +120 -7
  115. package/dist/references/stage/src/types/nocha/types/video.d.ts +5 -2
  116. package/dist/references/stage/src/types/nocha/video-analysis.d.ts +10 -0
  117. package/dist/references/stage/src/types/nocha/video-media.d.ts +1 -3
  118. package/dist/references/workshop/server/tooling/sdk-sources.ts +2 -2
  119. package/dist/references/workshop/src/types/nocha/assets-media.d.ts +8 -0
  120. package/dist/references/workshop/src/types/nocha/assets-operations.d.ts +3 -0
  121. package/dist/references/workshop/src/types/nocha/capability-deadlines.d.ts +6 -0
  122. package/dist/references/workshop/src/types/nocha/capability-needs.d.ts +7 -0
  123. package/dist/references/workshop/src/types/nocha/capability-operations.d.ts +3 -1
  124. package/dist/references/workshop/src/types/nocha/drive-operations.d.ts +56 -0
  125. package/dist/references/workshop/src/types/nocha/drive-types.d.ts +77 -0
  126. package/dist/references/workshop/src/types/nocha/drive.d.ts +54 -0
  127. package/dist/references/workshop/src/types/nocha/error-codes.d.ts +9 -0
  128. package/dist/references/workshop/src/types/nocha/execution.d.ts +1 -1
  129. package/dist/references/workshop/src/types/nocha/index.d.ts +4 -0
  130. package/dist/references/workshop/src/types/nocha/media-read.d.ts +29 -0
  131. package/dist/references/workshop/src/types/nocha/operation-waiting.d.ts +8 -0
  132. package/dist/references/workshop/src/types/nocha/operation-wire-types.d.ts +30 -2
  133. package/dist/references/workshop/src/types/nocha/protocol.d.ts +7 -3
  134. package/dist/references/workshop/src/types/nocha/types/ai-wire.d.ts +40 -1
  135. package/dist/references/workshop/src/types/nocha/types/ai.d.ts +1 -1
  136. package/dist/references/workshop/src/types/nocha/types/assets-wire.d.ts +9 -1
  137. package/dist/references/workshop/src/types/nocha/types/assets.d.ts +22 -5
  138. package/dist/references/workshop/src/types/nocha/types/video-sdk-wire.d.ts +174 -13
  139. package/dist/references/workshop/src/types/nocha/types/video-wire.d.ts +120 -7
  140. package/dist/references/workshop/src/types/nocha/types/video.d.ts +5 -2
  141. package/dist/references/workshop/src/types/nocha/video-analysis.d.ts +10 -0
  142. package/dist/references/workshop/src/types/nocha/video-media.d.ts +1 -3
  143. package/dist/sdk-versions.json +1 -1
  144. package/dist/sdks/@nocha/sdk/dist/assets-operations.d.ts +3 -0
  145. package/dist/sdks/@nocha/sdk/dist/bridge.js +3 -3
  146. package/dist/sdks/@nocha/sdk/dist/capabilities.js +2 -2
  147. package/dist/sdks/@nocha/sdk/dist/capability-deadlines.d.ts +6 -0
  148. package/dist/sdks/@nocha/sdk/dist/capability-needs.d.ts +7 -0
  149. package/dist/sdks/@nocha/sdk/dist/capability-operations.d.ts +3 -1
  150. package/dist/sdks/@nocha/sdk/dist/{chunk-A3QFRV4K.js → chunk-7SH7NNX6.js} +2 -2
  151. package/dist/sdks/@nocha/sdk/dist/{chunk-3ULBSRGX.js → chunk-B34FPFNB.js} +1 -1
  152. package/dist/sdks/@nocha/sdk/dist/{chunk-MNRQELK7.js → chunk-EAC27UOG.js} +152 -7
  153. package/dist/sdks/{@watchirl/experience-sdk/dist/nocha/network-operations.d.ts → @nocha/sdk/dist/drive-operations.d.ts} +21 -18
  154. package/dist/sdks/@nocha/sdk/dist/drive-types.d.ts +76 -0
  155. package/dist/sdks/@nocha/sdk/dist/drive.d.ts +53 -0
  156. package/dist/sdks/@nocha/sdk/dist/error-codes.d.ts +9 -0
  157. package/dist/sdks/@nocha/sdk/dist/execution.d.ts +1 -1
  158. package/dist/sdks/@nocha/sdk/dist/host.js +1 -1
  159. package/dist/sdks/@nocha/sdk/dist/index.d.ts +4 -0
  160. package/dist/sdks/@nocha/sdk/dist/index.js +521 -125
  161. package/dist/sdks/@nocha/sdk/dist/operation-wire-types.d.ts +30 -2
  162. package/dist/sdks/@nocha/sdk/dist/protocol.d.ts +7 -3
  163. package/dist/sdks/@nocha/sdk/dist/protocol.js +19 -1
  164. package/dist/sdks/@nocha/sdk/dist/types/ai-wire.d.ts +40 -1
  165. package/dist/sdks/@nocha/sdk/dist/types/ai.d.ts +1 -1
  166. package/dist/sdks/@nocha/sdk/dist/types/assets-wire.d.ts +9 -1
  167. package/dist/sdks/@nocha/sdk/dist/types/assets.d.ts +22 -5
  168. package/dist/sdks/@nocha/sdk/dist/types/video-sdk-wire.d.ts +174 -13
  169. package/dist/sdks/@nocha/sdk/dist/types/video-wire.d.ts +120 -7
  170. package/dist/sdks/@nocha/sdk/dist/types/video.d.ts +5 -2
  171. package/dist/sdks/@nocha/sdk/dist/video-analysis.d.ts +9 -0
  172. package/dist/sdks/@nocha/sdk/dist/vite.js +3 -1
  173. package/dist/sdks/@nocha/sdk/package.json +1 -1
  174. package/dist/sdks/@watchirl/experience-sdk/dist/index.d.ts +2 -2
  175. package/dist/sdks/@watchirl/experience-sdk/dist/index.js +339 -4523
  176. package/dist/sdks/@watchirl/experience-sdk/dist/legacy-video.d.ts +2 -2
  177. package/dist/sdks/@watchirl/experience-sdk/dist/types.d.ts +1 -1
  178. package/dist/watchirl-sdk.js +333 -4515
  179. package/package.json +1 -1
  180. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/access.d.ts +0 -23
  181. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/ai-operations.d.ts +0 -252
  182. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/assets-operations.d.ts +0 -102
  183. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/assistant-contract.d.ts +0 -29
  184. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/assistant-controls.d.ts +0 -11
  185. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/assistant.d.ts +0 -57
  186. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/automations-operations.d.ts +0 -377
  187. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/automations-types.d.ts +0 -156
  188. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/automations.d.ts +0 -27
  189. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/backend-database.d.ts +0 -17
  190. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/backend-operations.d.ts +0 -71
  191. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/backend-requests.d.ts +0 -57
  192. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/backend-runtime.d.ts +0 -106
  193. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/backend-transactions.d.ts +0 -53
  194. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/bridge.d.ts +0 -6
  195. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/capability-deadlines.d.ts +0 -63
  196. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/capability-needs.d.ts +0 -154
  197. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/capability-operations.d.ts +0 -73
  198. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/clipping-types.d.ts +0 -134
  199. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/connectors-operations.d.ts +0 -103
  200. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/connectors-types.d.ts +0 -10
  201. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/connectors.d.ts +0 -14
  202. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/context.d.ts +0 -18
  203. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/device-operations.d.ts +0 -452
  204. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/device-types.d.ts +0 -53
  205. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/email-operations.d.ts +0 -30
  206. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/email.d.ts +0 -9
  207. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/error-codes.d.ts +0 -299
  208. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/errors.d.ts +0 -36
  209. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/execution.d.ts +0 -15
  210. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/experience-context-types.d.ts +0 -12
  211. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/experience-context.d.ts +0 -8
  212. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/inbox-operations.d.ts +0 -58
  213. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/inbox.d.ts +0 -23
  214. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/index.d.ts +0 -101
  215. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/multiplayer-facade.d.ts +0 -44
  216. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/multiplayer-operations.d.ts +0 -80
  217. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/multiplayer.d.ts +0 -16
  218. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/navigation.d.ts +0 -16
  219. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/network.d.ts +0 -13
  220. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/notifications-operations.d.ts +0 -29
  221. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/notifications.d.ts +0 -9
  222. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/operation-metadata.d.ts +0 -67
  223. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/operation-wire-types.d.ts +0 -319
  224. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/outirl-operations.d.ts +0 -352
  225. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/outirl.d.ts +0 -31
  226. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/presence-operations.d.ts +0 -24
  227. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/protocol.d.ts +0 -378
  228. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/state.d.ts +0 -13
  229. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/storage-operation-types.d.ts +0 -49
  230. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/storage-operations.d.ts +0 -229
  231. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/storage.d.ts +0 -32
  232. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/transport.d.ts +0 -36
  233. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/ai-wire.d.ts +0 -337
  234. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/ai.d.ts +0 -20
  235. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/assets-wire.d.ts +0 -27
  236. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/assets.d.ts +0 -40
  237. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/json.d.ts +0 -8
  238. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/network.d.ts +0 -16
  239. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/outirl.d.ts +0 -326
  240. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/storage.d.ts +0 -74
  241. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/video-sdk-wire.d.ts +0 -460
  242. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/video-wire.d.ts +0 -440
  243. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/video.d.ts +0 -164
  244. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/types/voice-wire.d.ts +0 -17
  245. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/video-operations.d.ts +0 -646
  246. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/video-properties.d.ts +0 -6
  247. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/viewport-types.d.ts +0 -14
  248. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/viewport.d.ts +0 -7
  249. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/voice.d.ts +0 -13
  250. package/dist/sdks/@watchirl/experience-sdk/dist/nocha/workspace.d.ts +0 -7
@@ -9,7 +9,7 @@ import {
9
9
  isIdempotencyKey,
10
10
  markExperienceContextAvailable,
11
11
  subscribeBridgeEvents
12
- } from "./chunk-A3QFRV4K.js";
12
+ } from "./chunk-7SH7NNX6.js";
13
13
  import {
14
14
  ASSISTANT_CONFIRMATION_ACTIONS,
15
15
  ASSISTANT_CONTEXT_MAX_BYTES,
@@ -21,17 +21,22 @@ import {
21
21
  } from "./chunk-4AHRR2WX.js";
22
22
  import {
23
23
  deadlineMs
24
- } from "./chunk-3ULBSRGX.js";
24
+ } from "./chunk-B34FPFNB.js";
25
25
  import {
26
+ ASSET_MEDIA_MAX_BYTES,
27
+ DRIVE_FOLDER_MAX_DEPTH,
28
+ DRIVE_TRANSFER_MAX_BYTES,
26
29
  NOCHA_BRIDGE_PROTOCOL,
27
30
  NOCHA_NAVIGATION_PROTOCOL,
28
31
  NochaError,
29
32
  aiGenerateNeeds,
30
33
  aiOperationDefinitions,
34
+ assetMediaTypes,
31
35
  assetsOperationDefinitions,
32
36
  capabilityDeadlines,
33
37
  classifyError,
34
38
  deviceOperationDefinitions,
39
+ driveOperationDefinitions,
35
40
  emailOperationDefinitions,
36
41
  experienceBackendErrorCodes,
37
42
  generationWaiting,
@@ -59,15 +64,18 @@ import {
59
64
  operationWaiting,
60
65
  outirlOperationDefinitions,
61
66
  readEffectiveVideoProperties,
67
+ readVideoAnalysisResult,
68
+ readVideoEditPlan,
62
69
  readVideoProperties,
63
70
  readVideoPropertyDefinition,
71
+ readVideoReferenceReplaces,
64
72
  storageOperations,
65
73
  videoLocales,
66
74
  videoOperationDefinitions,
67
75
  videoStepIdPattern,
68
76
  videoWaitSchedule,
69
77
  wireError
70
- } from "./chunk-MNRQELK7.js";
78
+ } from "./chunk-EAC27UOG.js";
71
79
 
72
80
  // src/automations.ts
73
81
  function createAutomations(context) {
@@ -177,7 +185,7 @@ function text(value, field3) {
177
185
  function optionalString(value, field3) {
178
186
  if (value !== void 0 && typeof value !== "string") throw invalid(`${field3} must be a string`);
179
187
  }
180
- var modelPattern = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,99}$/;
188
+ var modelPattern = /^[A-Za-z0-9][A-Za-z0-9._:@/-]{0,99}$/;
181
189
  var voicePattern = /^[A-Za-z0-9_:.-]{1,160}$/;
182
190
  var languagePattern = /^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
183
191
  function matching(value, pattern, field3) {
@@ -197,6 +205,30 @@ function singleSource(value) {
197
205
  if (ids.length !== 1) throw invalid("inputAssetIds must contain exactly one authorized source asset");
198
206
  return ids;
199
207
  }
208
+ var voiceSettingBounds = {
209
+ stability: ["stability", 0, 1],
210
+ similarityBoost: ["similarity_boost", 0, 1],
211
+ style: ["style", 0, 1],
212
+ speed: ["speed", 0.7, 1.2]
213
+ };
214
+ function voiceSettings(value) {
215
+ if (value === void 0) return {};
216
+ if (!isRecord(value)) throw invalid("voiceSettings must be an object");
217
+ const unknown = Object.entries(value).find(([key, setting]) => setting !== void 0 && key !== "useSpeakerBoost" && !Object.hasOwn(voiceSettingBounds, key));
218
+ if (unknown) throw invalid(`voiceSettings.${unknown[0]} is not a voice setting`);
219
+ const settings = {};
220
+ for (const [key, [field3, min, max]] of Object.entries(voiceSettingBounds)) {
221
+ const setting = value[key];
222
+ if (setting === void 0) continue;
223
+ if (typeof setting !== "number" || !Number.isFinite(setting) || setting < min || setting > max) throw invalid(`voiceSettings.${key} must be a number from ${min} to ${max}`);
224
+ settings[field3] = setting;
225
+ }
226
+ if (value.useSpeakerBoost !== void 0) {
227
+ if (typeof value.useSpeakerBoost !== "boolean") throw invalid("voiceSettings.useSpeakerBoost must be a boolean");
228
+ settings.use_speaker_boost = value.useSpeakerBoost;
229
+ }
230
+ return Object.keys(settings).length ? { voice_settings: settings } : {};
231
+ }
200
232
  function responseFormat(schema, schemaName, fallback) {
201
233
  if (!isRecord(schema)) throw invalid("schema must be a JSON schema object");
202
234
  optionalString(schemaName, "schemaName");
@@ -256,7 +288,8 @@ function aiGenerateWire(input3) {
256
288
  need,
257
289
  ...value.language ? { language: matching(value.language, languagePattern, "language") } : {},
258
290
  ...value.voice ? { voice_id: matching(value.voice, voicePattern, "voice") } : {},
259
- ...value.model !== void 0 ? { model: matching(value.model, modelPattern, "model") } : {}
291
+ ...value.model !== void 0 ? { model: matching(value.model, modelPattern, "model") } : {},
292
+ ...voiceSettings(value.voiceSettings)
260
293
  };
261
294
  case "audio.transcribe":
262
295
  if (value.audioDataUrl === void 0 && value.durationSeconds === void 0 && value.inputAssetIds === void 0) throw invalid("audioDataUrl must be an audio data URL");
@@ -275,12 +308,17 @@ function aiGenerateWire(input3) {
275
308
  };
276
309
  case "audio.generate":
277
310
  optionalNumber(value.durationSeconds, "durationSeconds");
311
+ if (value.instrumental !== void 0 && typeof value.instrumental !== "boolean") throw invalid("instrumental must be a boolean");
312
+ if (value.instrumental && value.lyrics != null) throw invalid("An instrumental track takes no lyrics");
278
313
  return {
279
314
  ...policy(value),
280
315
  need,
281
316
  prompt: text(value.prompt, "prompt"),
282
317
  duration_seconds: value.durationSeconds ?? 60,
283
318
  output_format: value.outputFormat ?? "mp3",
319
+ ...value.instrumental !== void 0 ? { instrumental: value.instrumental } : {},
320
+ ...value.model !== void 0 ? { model: matching(value.model, modelPattern, "model") } : {},
321
+ ...value.inputAssetIds !== void 0 ? { input_asset_ids: singleSource(value.inputAssetIds) } : {},
284
322
  ...value.lyrics != null ? { lyrics: value.lyrics } : {},
285
323
  ...value.seed != null ? { seed: value.seed } : {},
286
324
  ...value.bpm != null ? { bpm: value.bpm } : {},
@@ -339,6 +377,21 @@ function aiGenerateWire(input3) {
339
377
  ...value.prompt !== void 0 ? { prompt: value.prompt } : {},
340
378
  ...value.mode !== void 0 ? { mode: value.mode } : {}
341
379
  };
380
+ case "audio.voice_change":
381
+ if (value.audioDataUrl === void 0 === (value.inputAssetIds === void 0)) throw invalid("Provide one recording: audioDataUrl or inputAssetIds");
382
+ if (value.audioDataUrl !== void 0 && (typeof value.audioDataUrl !== "string" || !value.audioDataUrl.startsWith("data:"))) throw invalid("audioDataUrl must be an audio data URL");
383
+ if (value.durationSeconds !== void 0) throw invalid("durationSeconds is not accepted by audio.voice_change");
384
+ if (value.voice === void 0) throw invalid("voice is required by audio.voice_change");
385
+ if (value.removeBackgroundNoise !== void 0 && typeof value.removeBackgroundNoise !== "boolean") throw invalid("removeBackgroundNoise must be a boolean");
386
+ return {
387
+ ...budget(value),
388
+ need,
389
+ ...value.audioDataUrl !== void 0 ? { audio_data_url: value.audioDataUrl } : { input_asset_ids: singleSource(value.inputAssetIds) },
390
+ voice_id: matching(value.voice, voicePattern, "voice"),
391
+ ...value.model !== void 0 ? { model: matching(value.model, modelPattern, "model") } : {},
392
+ ...voiceSettings(value.voiceSettings),
393
+ ...value.removeBackgroundNoise !== void 0 ? { remove_background_noise: value.removeBackgroundNoise } : {}
394
+ };
342
395
  }
343
396
  }
344
397
  var decisionTypes = /* @__PURE__ */ new Set(["choice", "score", "noul"]);
@@ -400,7 +453,7 @@ function generationResult(need, value) {
400
453
  throw reject("Nocha returned an invalid generation result");
401
454
  }
402
455
  const media = !Array.isArray(value.asset_ids) || !value.asset_ids.length || !isArrayOf(value.asset_ids, isString) || !isArrayOf(value.assets, (asset) => isRecord(asset) && isString(asset.id)) || value.asset_ids.some((id) => !value.assets.some((asset) => asset.id === id));
403
- const invalid2 = need === "text.structured" ? !isString(value.text) || value.structured === void 0 : need.startsWith("text.") ? !isString(value.text) : need === "web.research" ? value.structured === void 0 || !isArrayOf(value.sources, isSource) || !Number.isInteger(value.search_call_count) || Number(value.search_call_count) < 1 : need === "audio.synthesize" ? !isNonEmptyString(value.audio_base64) || !isString(value.mime_type) || !value.mime_type.startsWith("audio/") : need === "audio.transcribe" ? !isString(value.text) || value.duration_seconds !== void 0 && !isFiniteNumber(value.duration_seconds) : isMediaNeed(need) ? media : true;
456
+ const invalid2 = need === "text.structured" ? !isString(value.text) || value.structured === void 0 : need.startsWith("text.") ? !isString(value.text) : need === "web.research" ? value.structured === void 0 || !isArrayOf(value.sources, isSource) || !Number.isInteger(value.search_call_count) || Number(value.search_call_count) < 1 : need === "audio.synthesize" ? !isNonEmptyString(value.audio_base64) || !isString(value.mime_type) || !value.mime_type.startsWith("audio/") : need === "audio.transcribe" ? !isString(value.text) || value.duration_seconds !== void 0 && !isFiniteNumber(value.duration_seconds) : isMediaNeed(need) ? media || value.duration_seconds !== void 0 && !isFiniteNumber(value.duration_seconds) : true;
404
457
  if (invalid2) throw reject(`Nocha returned an invalid ${need} result`);
405
458
  return value;
406
459
  }
@@ -537,7 +590,7 @@ async function models(context, input3, options) {
537
590
  async function voices(context, input3, options) {
538
591
  const wire = aiVoicesWire(input3);
539
592
  const value = await context.invoke(aiOperationDefinitions["voices"].capability, aiOperationDefinitions["voices"].operation, wire, options);
540
- if (!isRecord(value) || !isNonEmptyString(value.model) || !isNonEmptyString(value.default_voice) || value.next_cursor !== null && !isNonEmptyString(value.next_cursor) || !isArrayOf(value.voices, (voice) => isRecord(voice) && isNonEmptyString(voice.id) && isString(voice.name) && isStringList(voice.languages) && (voice.collection === "standard" || voice.collection === "library") && [voice.description, voice.gender, voice.age, voice.accent, voice.alias].every(isOptionalString))) {
593
+ if (!isRecord(value) || !isNonEmptyString(value.model) || !isNonEmptyString(value.default_voice) || value.next_cursor !== null && !isNonEmptyString(value.next_cursor) || !isArrayOf(value.voices, (voice) => isRecord(voice) && isNonEmptyString(voice.id) && isString(voice.name) && isStringList(voice.languages) && (voice.collection === "standard" || voice.collection === "library") && [voice.description, voice.gender, voice.age, voice.accent, voice.alias].every(isOptionalString) && (voice.price_multiplier === void 0 || isFiniteNumber(voice.price_multiplier) && voice.price_multiplier > 0))) {
541
594
  throw reject("Nocha returned invalid speech voices");
542
595
  }
543
596
  return value;
@@ -554,6 +607,102 @@ function createAi(context) {
554
607
  });
555
608
  }
556
609
 
610
+ // src/media-read.ts
611
+ function mediaReadTimeout(options, fallback) {
612
+ if (!isRecord(options)) throw invalid("Request options must be an object");
613
+ if (options.onProgress !== void 0 && typeof options.onProgress !== "function") throw invalid("onProgress must be a function");
614
+ if (options.signal !== void 0 && !(options.signal instanceof AbortSignal)) throw invalid("signal must be an AbortSignal");
615
+ const timeout = options.timeoutMs ?? fallback;
616
+ if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) throw invalid("timeoutMs must be a positive finite timer duration");
617
+ return timeout;
618
+ }
619
+ function readHostMedia(read2) {
620
+ const { noun, options } = read2;
621
+ const subject = noun.charAt(0).toUpperCase() + noun.slice(1);
622
+ const unsupported = () => new NochaError("media_unsupported_host", `This Nocha host cannot read ${noun} media`);
623
+ const host = window.parent;
624
+ const requestId = crypto.randomUUID();
625
+ return new Promise((resolve, reject2) => {
626
+ let acknowledged = false;
627
+ const cleanup = () => {
628
+ clearTimeout(unanswered);
629
+ clearTimeout(timer);
630
+ window.removeEventListener("message", receive);
631
+ options.signal?.removeEventListener("abort", abort);
632
+ };
633
+ const stop = (error) => {
634
+ cleanup();
635
+ try {
636
+ host.postMessage({ protocol: "nocha.media.v1", type: "abort", requestId }, "*");
637
+ } catch {
638
+ }
639
+ reject2(error);
640
+ };
641
+ const abort = () => stop(new NochaError("aborted", `${subject} read aborted`));
642
+ const receive = (event) => {
643
+ const message = event.data;
644
+ if (!isFromHost(event) || !isRecord(message) || message.protocol !== "nocha.media.v1" || message.requestId !== requestId) return;
645
+ clearTimeout(unanswered);
646
+ if (message.type === "progress") {
647
+ acknowledged = true;
648
+ if (options.onProgress && isCount(message.loaded) && (message.total === null || isCount(message.total))) {
649
+ notifyListener(options.onProgress, { loaded: message.loaded, total: message.total });
650
+ }
651
+ return;
652
+ }
653
+ if (message.type !== "result" && message.type !== "error") return;
654
+ cleanup();
655
+ const value = message.type === "result" ? read2.accept(message.result) : void 0;
656
+ if (message.type === "error" && read2.unknownReadRefused && !acknowledged && isRecord(message.error) && message.error.code === "invalid_request") reject2(unsupported());
657
+ else if (message.type === "error") reject2(wireError(message.error, { code: "media_unavailable", message: `${subject} media is unavailable` }));
658
+ else if (value !== void 0) resolve(value);
659
+ else reject2(new NochaError("invalid_result", `Nocha returned an invalid ${noun} file`));
660
+ };
661
+ const unanswered = read2.timeoutMs > read2.firstReplyMs ? setTimeout(() => stop(unsupported()), read2.firstReplyMs) : void 0;
662
+ const timer = setTimeout(() => stop(new NochaError("invocation_timed_out", `Local ${noun} read timed out`)), read2.timeoutMs);
663
+ window.addEventListener("message", receive);
664
+ options.signal?.addEventListener("abort", abort, { once: true });
665
+ try {
666
+ read2.send(host, requestId);
667
+ } catch (error) {
668
+ cleanup();
669
+ reject2(new NochaError("invalid_request", `The request cannot be sent to the Nocha host: ${error instanceof Error ? error.message : String(error)}`));
670
+ }
671
+ });
672
+ }
673
+
674
+ // src/assets-media.ts
675
+ var mediaTypes = new Set(assetMediaTypes);
676
+ function isAssetMedia(value, id) {
677
+ return isRecord(value) && value.id === id && mediaTypes.has(value.mime_type) && value.blob instanceof Blob && value.blob.type === value.mime_type && value.blob.size > 0 && value.blob.size <= ASSET_MEDIA_MAX_BYTES && value.size_bytes === value.blob.size;
678
+ }
679
+ async function readAssetMedia(context, input3, options = {}) {
680
+ if (!isRecord(input3) || !isUuid(input3.assetId)) throw new NochaError("invalid_request", "assetId must be an asset id");
681
+ const assetId = input3.assetId;
682
+ const timeout = mediaReadTimeout(options, operationWaiting.assets.media);
683
+ assertHostCapability("assets");
684
+ const usageId = context.usageId;
685
+ if (usageId === void 0) throw new NochaError("usage_required", "assets.media requires nocha.use(<declared usage id>)");
686
+ if (options.signal?.aborted) throw new NochaError("aborted", "Asset read aborted");
687
+ return readHostMedia({
688
+ noun: "asset",
689
+ timeoutMs: timeout,
690
+ firstReplyMs: operationWaiting.assets["media.firstReply"],
691
+ options,
692
+ unknownReadRefused: true,
693
+ accept: (result2) => isAssetMedia(result2, assetId) ? result2.blob : void 0,
694
+ send: (host, requestId) => host.postMessage({
695
+ protocol: "nocha.media.v1",
696
+ type: "read",
697
+ requestId,
698
+ capability: assetsOperationDefinitions["read"].capability,
699
+ operation: assetsOperationDefinitions["read"].operation,
700
+ usageId,
701
+ input: { asset_id: assetId }
702
+ }, "*")
703
+ });
704
+ }
705
+
557
706
  // src/attachments.ts
558
707
  var maxBytes = 64 * 1024 * 1024;
559
708
  var attachmentTypes = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp", "video/mp4", "audio/wav", "audio/mp4"]);
@@ -623,7 +772,9 @@ async function attachmentUrl(context, input3, options) {
623
772
  var readableTypes = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp", "audio/mpeg", "audio/wav", "audio/flac", "audio/ogg"]);
624
773
  var uploadableTypes = /* @__PURE__ */ new Set(["image/jpeg", "image/png", "image/webp"]);
625
774
  var videoTypes = /* @__PURE__ */ new Set(["video/mp4", "video/quicktime"]);
626
- var maxVideoBytes = 64 * 1024 * 1024;
775
+ var audioTypes = /* @__PURE__ */ new Set(["audio/mpeg", "audio/wav"]);
776
+ var audioAliases = { "audio/mp3": "audio/mpeg", "audio/x-wav": "audio/wav", "audio/wave": "audio/wav", "audio/vnd.wave": "audio/wav" };
777
+ var maxMediaBytes = 64 * 1024 * 1024;
627
778
  async function read(context, input3, options) {
628
779
  if (!isRecord(input3) || !isUuid(input3.assetId)) throw new NochaError("invalid_request", "assetId must be an asset id");
629
780
  const value = await context.invoke(assetsOperationDefinitions["read"].capability, assetsOperationDefinitions["read"].operation, { asset_id: input3.assetId }, options);
@@ -637,18 +788,23 @@ function bytesToBase64(bytes) {
637
788
  for (let offset = 0; offset < bytes.length; offset += 32768) binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
638
789
  return btoa(binary);
639
790
  }
640
- function videoType(file, filename) {
641
- if (file.type) return videoTypes.has(file.type) ? file.type : void 0;
791
+ function binaryType(file, filename) {
792
+ if (file.type) {
793
+ const type = file.type.toLowerCase();
794
+ return videoTypes.has(type) || audioTypes.has(type) ? type : audioAliases[type];
795
+ }
642
796
  const name = filename ?? ("name" in file ? String(file.name) : "");
643
- return /\.(mp4|m4v)$/i.test(name) ? "video/mp4" : /\.mov$/i.test(name) ? "video/quicktime" : void 0;
797
+ return /\.(mp4|m4v)$/i.test(name) ? "video/mp4" : /\.mov$/i.test(name) ? "video/quicktime" : /\.mp3$/i.test(name) ? "audio/mpeg" : /\.wav$/i.test(name) ? "audio/wav" : void 0;
644
798
  }
645
- async function uploadVideo(context, file, mimeType, filename, options = {}) {
646
- if (file.size > maxVideoBytes) throw invalid("The video must be at most 64 MiB");
799
+ async function uploadBinary(context, file, mimeType, filename, options = {}) {
800
+ const kind = mimeType.startsWith("audio/") ? "Audio" : "Video";
801
+ if (file.size > maxMediaBytes) throw invalid(`The ${kind.toLowerCase()} file must be at most 64 MiB`);
647
802
  assertHostCapability("assets");
648
803
  if (context.usageId === void 0) throw new NochaError("usage_required", "assets.upload requires nocha.use(<declared usage id>)");
649
804
  if (options.idempotencyKey !== void 0 && !isIdempotencyKey(options.idempotencyKey)) throw invalid("idempotencyKey must contain 8 to 200 characters");
650
- if (options.signal?.aborted) throw new NochaError("aborted", "Video upload aborted");
651
- const name = filename ?? ("name" in file ? String(file.name) : mimeType === "video/quicktime" ? "source-video.mov" : "source-video.mp4");
805
+ if (options.signal?.aborted) throw new NochaError("aborted", `${kind} upload aborted`);
806
+ const fallback = { "video/mp4": "source-video.mp4", "video/quicktime": "source-video.mov", "audio/mpeg": "soundtrack.mp3", "audio/wav": "soundtrack.wav" }[mimeType];
807
+ const name = filename ?? ("name" in file ? String(file.name) : fallback);
652
808
  const input3 = { filename: name.replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 120), mime_type: mimeType, size_bytes: file.size };
653
809
  const timeout = options.timeoutMs ?? operationWaiting.assets.uploadAttachment;
654
810
  if (!Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) throw invalid("timeoutMs must be a positive finite timer duration");
@@ -663,7 +819,7 @@ async function uploadVideo(context, file, mimeType, filename, options = {}) {
663
819
  const abort = () => {
664
820
  host.postMessage({ protocol: "nocha.upload.v1", type: "abort", requestId }, "*");
665
821
  cleanup();
666
- reject2(new NochaError("aborted", "Video upload aborted"));
822
+ reject2(new NochaError("aborted", `${kind} upload aborted`));
667
823
  };
668
824
  const expire = () => {
669
825
  cleanup();
@@ -679,7 +835,7 @@ async function uploadVideo(context, file, mimeType, filename, options = {}) {
679
835
  cleanup();
680
836
  const result2 = message.result;
681
837
  if (message.type === "result" && isRecord(result2) && isNonEmptyString(result2.id) && isString(result2.mime_type) && typeof result2.size_bytes === "string" && /^\d+$/.test(result2.size_bytes)) resolve(result2);
682
- else reject2(wireError(message.error, { code: "upload_failed", message: "Video upload failed" }));
838
+ else reject2(wireError(message.error, { code: "upload_failed", message: `${kind} upload failed` }));
683
839
  };
684
840
  const timer = setTimeout(expire, timeout);
685
841
  window.addEventListener("message", receive);
@@ -693,11 +849,11 @@ async function uploadVideo(context, file, mimeType, filename, options = {}) {
693
849
  });
694
850
  }
695
851
  async function upload(context, input3, options) {
696
- if (!isRecord(input3) || !(input3.file instanceof Blob) || !input3.file.size) throw new NochaError("invalid_request", "A non-empty image or video file is required");
852
+ if (!isRecord(input3) || !(input3.file instanceof Blob) || !input3.file.size) throw new NochaError("invalid_request", "A non-empty image, video or audio file is required");
697
853
  if (input3.filename !== void 0 && typeof input3.filename !== "string") throw new NochaError("invalid_request", "filename must be a string");
698
- const file = input3.file, video = videoType(file, input3.filename);
699
- if (video) return uploadVideo(context, file, video, input3.filename, options);
700
- if (!uploadableTypes.has(file.type)) throw new NochaError("invalid_request", "Choose a JPEG, PNG or WebP image, or an MP4 or QuickTime video of at most 64 MiB");
854
+ const file = input3.file, binary = binaryType(file, input3.filename);
855
+ if (binary) return uploadBinary(context, file, binary, input3.filename, options);
856
+ if (!uploadableTypes.has(file.type)) throw new NochaError("invalid_request", "Choose a JPEG, PNG or WebP image, an MP4 or QuickTime video, or an MP3 or WAV audio file of at most 64 MiB");
701
857
  const value = await context.invoke(assetsOperationDefinitions["upload"].capability, assetsOperationDefinitions["upload"].operation, {
702
858
  data_base64: bytesToBase64(new Uint8Array(await file.arrayBuffer())),
703
859
  mime_type: file.type,
@@ -711,6 +867,7 @@ async function upload(context, input3, options) {
711
867
  function createAssets(context) {
712
868
  return Object.freeze({
713
869
  read: (input3, options) => read(context, input3, options),
870
+ media: (input3, options) => readAssetMedia(context, input3, options),
714
871
  upload: (input3, options) => upload(context, input3, options),
715
872
  uploadAttachment: (input3, options) => uploadAttachment(context, input3, options),
716
873
  attachmentUrl: (input3, options) => attachmentUrl(context, input3, options)
@@ -1656,6 +1813,224 @@ function createDevice(context, subscriptions) {
1656
1813
  });
1657
1814
  }
1658
1815
 
1816
+ // src/drive.ts
1817
+ var forbiddenCharacter = (character) => character === "/" || character === "\\" || character.charCodeAt(0) < 32 || character.charCodeAt(0) === 127;
1818
+ var usagePattern2 = /^[a-zA-Z0-9][a-zA-Z0-9._:-]{0,127}$/;
1819
+ var mimePattern = /^[a-z0-9][a-z0-9.+-]*\/[a-z0-9][a-z0-9.+-]*$/;
1820
+ var acceptPattern = /^[a-z0-9][a-z0-9.+-]*\/(?:\*|[a-z0-9][a-z0-9.+-]*)$/;
1821
+ function driveName(value, field3) {
1822
+ const name = typeof value === "string" ? value.trim() : "";
1823
+ if (!name || name.length > 255 || [...name].some(forbiddenCharacter) || name === "." || name === "..") throw invalid(`${field3} must be a Drive name: 1 to 255 characters, without / or \\`);
1824
+ return name;
1825
+ }
1826
+ function dialogHints(folder, title) {
1827
+ if (folder !== void 0 && (!Array.isArray(folder) || folder.length > DRIVE_FOLDER_MAX_DEPTH)) throw invalid(`folder must list at most ${DRIVE_FOLDER_MAX_DEPTH} folder names`);
1828
+ if (title !== void 0 && (typeof title !== "string" || !title.trim() || title.trim().length > 120)) throw invalid("title must have 1 to 120 characters");
1829
+ const names = Array.isArray(folder) ? folder.map((item) => driveName(item, "Each folder")) : void 0;
1830
+ return { ...names?.length ? { folder: names } : {}, ...typeof title === "string" ? { title: title.trim() } : {} };
1831
+ }
1832
+ function timeoutOf(value, fallback) {
1833
+ const timeout = value ?? fallback;
1834
+ if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) throw invalid("timeoutMs must be a positive finite timer duration");
1835
+ return timeout;
1836
+ }
1837
+ function checkOptions(options) {
1838
+ if (!isRecord(options)) throw invalid("Request options must be an object");
1839
+ if (options.onProgress !== void 0 && typeof options.onProgress !== "function") throw invalid("onProgress must be a function");
1840
+ if (options.signal !== void 0 && !(options.signal instanceof AbortSignal)) throw invalid("signal must be an AbortSignal");
1841
+ }
1842
+ var isSaveResult = (value) => isRecord(value) && (value.saved === false || value.saved === true && isRecord(value.file) && isNonEmptyString(value.file.id) && isNonEmptyString(value.file.name) && isArrayOf(value.file.path, isString) && isString(value.file.mimeType) && isCount(value.file.sizeBytes));
1843
+ function requireUsage(context, operation2) {
1844
+ assertHostCapability("drive");
1845
+ if (context.usageId === void 0) throw new NochaError("usage_required", `drive.${operation2} requires nocha.use(<declared usage id>)`);
1846
+ return context.usageId;
1847
+ }
1848
+ function saveFile(context, input3, options) {
1849
+ const { file } = input3;
1850
+ if (!file.size) throw invalid("A non-empty file is required");
1851
+ if (file.size > DRIVE_TRANSFER_MAX_BYTES) throw new NochaError("source_too_large", "A Drive file sent by an experience is at most 64 MiB");
1852
+ const fallbackName = "name" in file && typeof file.name === "string" && file.name.trim() ? file.name : "file";
1853
+ const name = driveName(input3.name ?? fallbackName, "name");
1854
+ const declared = (typeof input3.mimeType === "string" ? input3.mimeType : file.type).trim().toLowerCase().split(";", 1)[0] ?? "";
1855
+ if (input3.mimeType !== void 0 && !mimePattern.test(declared)) throw invalid("mimeType must be a MIME type such as audio/mpeg");
1856
+ const hints = dialogHints(options.folder, options.title);
1857
+ const usageId = requireUsage(context, "save");
1858
+ if (options.idempotencyKey !== void 0 && !isIdempotencyKey(options.idempotencyKey)) throw invalid("idempotencyKey must contain 8 to 200 characters");
1859
+ const timeout = timeoutOf(options.timeoutMs, operationWaiting.drive.save);
1860
+ if (options.signal?.aborted) throw new NochaError("aborted", "Drive save aborted");
1861
+ const wire = { name, mime_type: mimePattern.test(declared) ? declared : "application/octet-stream", size_bytes: file.size, ...hints };
1862
+ const host = window.parent;
1863
+ const requestId = crypto.randomUUID();
1864
+ return new Promise((resolve, reject2) => {
1865
+ const cleanup = () => {
1866
+ clearTimeout(timer);
1867
+ window.removeEventListener("message", receive);
1868
+ options.signal?.removeEventListener("abort", abort);
1869
+ };
1870
+ const abort = () => {
1871
+ host.postMessage({ protocol: "nocha.upload.v1", type: "abort", requestId }, "*");
1872
+ cleanup();
1873
+ reject2(new NochaError("aborted", "Drive save aborted"));
1874
+ };
1875
+ const expire = () => {
1876
+ cleanup();
1877
+ reject2(new NochaError("invocation_timed_out", "Local Drive wait timed out; the file may still be saved"));
1878
+ };
1879
+ const receive = (event) => {
1880
+ const message = event.data;
1881
+ if (!isFromHost(event) || !isRecord(message) || message.protocol !== "nocha.upload.v1" || message.requestId !== requestId) return;
1882
+ if (message.type === "progress") {
1883
+ if (options.onProgress && isCount(message.loaded)) notifyListener(options.onProgress, { loaded: message.loaded, total: file.size });
1884
+ return;
1885
+ }
1886
+ cleanup();
1887
+ if (message.type === "result" && isSaveResult(message.result)) resolve(message.result);
1888
+ else if (message.type === "result") reject2(new NochaError("invalid_result", "Nocha returned an invalid Drive save result"));
1889
+ else reject2(wireError(message.error, { code: "upload_failed", message: "Drive save failed" }));
1890
+ };
1891
+ const timer = setTimeout(expire, timeout);
1892
+ window.addEventListener("message", receive);
1893
+ options.signal?.addEventListener("abort", abort, { once: true });
1894
+ try {
1895
+ host.postMessage({
1896
+ protocol: "nocha.upload.v1",
1897
+ type: "upload",
1898
+ requestId,
1899
+ capability: driveOperationDefinitions.save.capability,
1900
+ operation: driveOperationDefinitions.save.operation,
1901
+ usageId,
1902
+ idempotencyKey: options.idempotencyKey ?? `${requestId}:drive`,
1903
+ input: wire,
1904
+ file
1905
+ }, "*");
1906
+ } catch (error) {
1907
+ cleanup();
1908
+ reject2(error);
1909
+ }
1910
+ });
1911
+ }
1912
+ async function saveVideo(context, input3, options) {
1913
+ const video = input3.video;
1914
+ if (!isRecord(video) || typeof video.usage !== "string" || !usagePattern2.test(video.usage) || !isNonEmptyString(video.id) || video.id.length > 200) {
1915
+ throw invalid("video must name the declared video usage and the generation id: { usage, id }");
1916
+ }
1917
+ const name = input3.name === void 0 ? void 0 : driveName(input3.name, "name");
1918
+ const hints = dialogHints(options.folder, options.title);
1919
+ requireUsage(context, "save");
1920
+ const value = await context.invoke(driveOperationDefinitions.save.capability, driveOperationDefinitions.save.operation, {
1921
+ video: { usage: video.usage, id: video.id },
1922
+ ...name ? { name } : {},
1923
+ ...hints
1924
+ }, {
1925
+ ...options.idempotencyKey !== void 0 ? { idempotencyKey: options.idempotencyKey } : {},
1926
+ timeoutMs: timeoutOf(options.timeoutMs, operationWaiting.drive.save),
1927
+ ...options.signal !== void 0 ? { signal: options.signal } : {}
1928
+ });
1929
+ if (!isSaveResult(value)) throw new NochaError("invalid_result", "Nocha returned an invalid Drive save result");
1930
+ return value;
1931
+ }
1932
+ async function save(context, input3, options = {}) {
1933
+ checkOptions(options);
1934
+ if (!isRecord(input3)) throw invalid("Expected { file } or { video }");
1935
+ if ("file" in input3 && input3.file !== void 0) {
1936
+ if (!(input3.file instanceof Blob)) throw invalid("file must be a Blob or a File");
1937
+ return saveFile(context, input3, options);
1938
+ }
1939
+ if ("video" in input3 && input3.video !== void 0) return saveVideo(context, input3, options);
1940
+ throw invalid("Expected { file } or { video }");
1941
+ }
1942
+ function isPickTransfer(value, maxBytes2) {
1943
+ if (!isRecord(value)) return false;
1944
+ if (value.picked === false) return true;
1945
+ return value.picked === true && isRecord(value.drive) && isNonEmptyString(value.drive.id) && isArrayOf(value.drive.path, isString) && isCount(value.drive.sizeBytes) && isNonEmptyString(value.name) && isString(value.mime_type) && value.blob instanceof Blob && value.blob.size === value.drive.sizeBytes && value.blob.size <= maxBytes2;
1946
+ }
1947
+ async function pick(context, input3 = {}, options = {}) {
1948
+ checkOptions(options);
1949
+ if (!isRecord(input3)) throw invalid("Expected { accept?, maxBytes?, title?, folder? }");
1950
+ const accept = input3.accept;
1951
+ if (accept !== void 0 && (!Array.isArray(accept) || !accept.length || accept.length > 16 || accept.some((pattern) => typeof pattern !== "string" || !acceptPattern.test(pattern.trim().toLowerCase())))) {
1952
+ throw invalid("accept must list 1 to 16 MIME patterns such as audio/* or audio/mpeg");
1953
+ }
1954
+ const maxBytes2 = input3.maxBytes ?? DRIVE_TRANSFER_MAX_BYTES;
1955
+ if (!isCount(maxBytes2) || maxBytes2 < 1 || maxBytes2 > DRIVE_TRANSFER_MAX_BYTES) throw invalid("maxBytes must be an integer from 1 to 64 MiB");
1956
+ const hints = dialogHints(input3.folder, input3.title);
1957
+ const usageId = requireUsage(context, "pick");
1958
+ const timeout = timeoutOf(options.timeoutMs, operationWaiting.drive.pick);
1959
+ if (options.signal?.aborted) throw new NochaError("aborted", "Drive pick aborted");
1960
+ const wire = { ...accept ? { accept: accept.map((pattern) => pattern.trim().toLowerCase()) } : {}, ...input3.maxBytes !== void 0 ? { max_bytes: maxBytes2 } : {}, ...hints };
1961
+ const firstReply = operationWaiting.drive["pick.firstReply"];
1962
+ const host = window.parent;
1963
+ const requestId = crypto.randomUUID();
1964
+ return new Promise((resolve, reject2) => {
1965
+ const cleanup = () => {
1966
+ clearTimeout(unanswered);
1967
+ clearTimeout(timer);
1968
+ window.removeEventListener("message", receive);
1969
+ options.signal?.removeEventListener("abort", abort);
1970
+ };
1971
+ const stop = (error) => {
1972
+ cleanup();
1973
+ try {
1974
+ host.postMessage({ protocol: "nocha.media.v1", type: "abort", requestId }, "*");
1975
+ } catch {
1976
+ }
1977
+ reject2(error);
1978
+ };
1979
+ const abort = () => stop(new NochaError("aborted", "Drive pick aborted"));
1980
+ const receive = (event) => {
1981
+ const message = event.data;
1982
+ if (!isFromHost(event) || !isRecord(message) || message.protocol !== "nocha.media.v1" || message.requestId !== requestId) return;
1983
+ clearTimeout(unanswered);
1984
+ if (message.type === "progress") {
1985
+ if (options.onProgress && isCount(message.loaded) && (message.total === null || isCount(message.total))) {
1986
+ notifyListener(options.onProgress, { loaded: message.loaded, total: message.total });
1987
+ }
1988
+ return;
1989
+ }
1990
+ if (message.type !== "result" && message.type !== "error") return;
1991
+ cleanup();
1992
+ if (message.type === "error") {
1993
+ reject2(wireError(message.error, { code: "media_unavailable", message: "The Drive file is unavailable" }));
1994
+ return;
1995
+ }
1996
+ const result2 = message.result;
1997
+ if (!isPickTransfer(result2, maxBytes2)) {
1998
+ reject2(new NochaError("invalid_result", "Nocha returned an invalid Drive file"));
1999
+ return;
2000
+ }
2001
+ if (result2.picked === false) {
2002
+ resolve({ picked: false });
2003
+ return;
2004
+ }
2005
+ resolve({ picked: true, file: new File([result2.blob], result2.name, { type: result2.mime_type || result2.blob.type }), drive: { id: result2.drive.id, path: [...result2.drive.path], sizeBytes: result2.drive.sizeBytes } });
2006
+ };
2007
+ const unanswered = timeout > firstReply ? setTimeout(() => stop(new NochaError("client_update_required", "Update Nocha to choose a file from the Drive")), firstReply) : void 0;
2008
+ const timer = setTimeout(() => stop(new NochaError("invocation_timed_out", "Local Drive wait timed out")), timeout);
2009
+ window.addEventListener("message", receive);
2010
+ options.signal?.addEventListener("abort", abort, { once: true });
2011
+ try {
2012
+ host.postMessage({
2013
+ protocol: "nocha.media.v1",
2014
+ type: "read",
2015
+ requestId,
2016
+ capability: driveOperationDefinitions.pick.capability,
2017
+ operation: driveOperationDefinitions.pick.operation,
2018
+ usageId,
2019
+ input: wire
2020
+ }, "*");
2021
+ } catch (error) {
2022
+ cleanup();
2023
+ reject2(new NochaError("invalid_request", `The request cannot be sent to the Nocha host: ${error instanceof Error ? error.message : String(error)}`));
2024
+ }
2025
+ });
2026
+ }
2027
+ function createDrive(context) {
2028
+ return Object.freeze({
2029
+ save: (input3, options) => save(context, input3, options),
2030
+ pick: (input3, options) => pick(context, input3, options)
2031
+ });
2032
+ }
2033
+
1659
2034
  // src/experience-context.ts
1660
2035
  var current = null;
1661
2036
  var pending = null;
@@ -3087,9 +3462,10 @@ var locales = new Set(videoLocales);
3087
3462
  var speechModes = /* @__PURE__ */ new Set(["none", "auto", "required"]);
3088
3463
  var resolutions = /* @__PURE__ */ new Set(["720p", "1080p"]);
3089
3464
  var efforts = /* @__PURE__ */ new Set(["auto", "low", "medium", "high"]);
3090
- var videoWorkflowFamilies = /* @__PURE__ */ new Set(["classic", "narrative", "image_loop"]);
3465
+ var videoWorkflowFamilies = /* @__PURE__ */ new Set(["classic", "narrative", "image_loop", "analysis"]);
3091
3466
  var videoStages = ["preparing", "planning", "generating_speech", "generating_media", "assembling"];
3092
3467
  var workflowId = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,199}$/;
3468
+ var analysisSubjectId = /^[plo][1-9]\d{0,2}$/;
3093
3469
  function videoId(value) {
3094
3470
  if (typeof value !== "string" || !isUuid(value.trim())) throw invalid("A valid video generation id is required");
3095
3471
  return value.trim();
@@ -3107,11 +3483,20 @@ function text3(value, label) {
3107
3483
  if (typeof value !== "string" || !value.trim()) throw invalid(`${label} must be a non-empty string`);
3108
3484
  return value.trim();
3109
3485
  }
3486
+ function replaces(value, label) {
3487
+ if (value === void 0) return void 0;
3488
+ if (!isRecord(value)) throw invalid(`${label} must be an object`);
3489
+ const subject = text3(value.subjectId, `${label}.subjectId`), description = text3(value.description, `${label}.description`);
3490
+ if (subject !== void 0 && !analysisSubjectId.test(subject)) throw invalid(`${label}.subjectId must be a subject of the analysis such as p1, l1 or o1`);
3491
+ if (!subject && !description) throw invalid(`${label} needs a subjectId, a description or both`);
3492
+ return { ...subject ? { subject_id: subject } : {}, ...description ? { description } : {} };
3493
+ }
3110
3494
  function reference(value, index) {
3111
3495
  const label = `references[${index}]`;
3112
3496
  if (!isRecord(value)) throw invalid(`${label} must be an object`);
3113
3497
  const role = text3(value.role, `${label}.role`), name = text3(value.name, `${label}.name`), description = text3(value.description, `${label}.description`);
3114
- const details = { ...role ? { role } : {}, ...name ? { name } : {}, ...description ? { description } : {} };
3498
+ const replaced = replaces(value.replaces, `${label}.replaces`);
3499
+ const details = { ...role ? { role } : {}, ...name ? { name } : {}, ...description ? { description } : {}, ...replaced ? { replaces: replaced } : {} };
3115
3500
  if (value.assetId === void 0 === (value.studioReferenceId === void 0)) throw invalid(`${label} needs one assetId or one studioReferenceId`);
3116
3501
  const id = value.assetId ?? value.studioReferenceId;
3117
3502
  if (typeof id !== "string" || !isUuid(id.trim())) throw invalid(`${label} id must be a uuid`);
@@ -3182,6 +3567,9 @@ function videoRequestWire(input3) {
3182
3567
  if (typeof input3.prompt !== "string" || !input3.prompt.trim()) throw invalid("prompt must be a non-empty string");
3183
3568
  if (input3.referencePreparation !== void 0 && input3.referencePreparation !== "auto") throw invalid("referencePreparation must be auto when provided");
3184
3569
  if (input3.references !== void 0 && !Array.isArray(input3.references)) throw invalid("references must be a list");
3570
+ if (input3.sourceAnalysisId !== void 0 && (typeof input3.sourceAnalysisId !== "string" || !isUuid(input3.sourceAnalysisId.trim()))) {
3571
+ throw invalid("sourceAnalysisId must be the id of an analyse-video generation");
3572
+ }
3185
3573
  const parameters = canonicalParameters(input3);
3186
3574
  properties(input3.properties);
3187
3575
  return {
@@ -3196,6 +3584,7 @@ function videoRequestWire(input3) {
3196
3584
  ...input3.properties === void 0 ? {} : { properties: input3.properties },
3197
3585
  ...input3.references === void 0 ? {} : { references: input3.references.map(reference) },
3198
3586
  ...input3.referencePreparation ? { reference_preparation: "auto" } : {},
3587
+ ...input3.sourceAnalysisId === void 0 ? {} : { source_analysis_id: input3.sourceAnalysisId.trim().toLowerCase() },
3199
3588
  ...input3.effort === void 0 ? {} : { effort: member(input3.effort, efforts, "effort") }
3200
3589
  };
3201
3590
  }
@@ -3254,67 +3643,26 @@ function isMediaResult(value, id) {
3254
3643
  }
3255
3644
  async function readVideoMedia(context, input3, options = {}) {
3256
3645
  const id = videoId(isRecord(input3) ? input3.id : void 0);
3257
- if (!isRecord(options)) throw invalid("Request options must be an object");
3258
- if (options.onProgress !== void 0 && typeof options.onProgress !== "function") throw invalid("onProgress must be a function");
3259
- if (options.signal !== void 0 && !(options.signal instanceof AbortSignal)) throw invalid("signal must be an AbortSignal");
3260
- const timeout = options.timeoutMs ?? operationWaiting.video.media;
3261
- if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0 || timeout > 2147483647) throw invalid("timeoutMs must be a positive finite timer duration");
3646
+ const timeout = mediaReadTimeout(options, operationWaiting.video.media);
3262
3647
  assertHostCapability("video");
3263
- if (context.usageId === void 0) throw new NochaError("usage_required", "video.media requires nocha.use(<declared usage id>)");
3648
+ const usageId = context.usageId;
3649
+ if (usageId === void 0) throw new NochaError("usage_required", "video.media requires nocha.use(<declared usage id>)");
3264
3650
  if (options.signal?.aborted) throw new NochaError("aborted", "Video read aborted");
3265
- const firstReply = operationWaiting.video["media.firstReply"];
3266
- const host = window.parent;
3267
- const requestId = crypto.randomUUID();
3268
- return new Promise((resolve, reject2) => {
3269
- const cleanup = () => {
3270
- clearTimeout(unanswered);
3271
- clearTimeout(timer);
3272
- window.removeEventListener("message", receive);
3273
- options.signal?.removeEventListener("abort", abort);
3274
- };
3275
- const stop = (error) => {
3276
- cleanup();
3277
- try {
3278
- host.postMessage({ protocol: "nocha.media.v1", type: "abort", requestId }, "*");
3279
- } catch {
3280
- }
3281
- reject2(error);
3282
- };
3283
- const abort = () => stop(new NochaError("aborted", "Video read aborted"));
3284
- const receive = (event) => {
3285
- const message = event.data;
3286
- if (!isFromHost(event) || !isRecord(message) || message.protocol !== "nocha.media.v1" || message.requestId !== requestId) return;
3287
- clearTimeout(unanswered);
3288
- if (message.type === "progress") {
3289
- if (options.onProgress && isCount(message.loaded) && (message.total === null || isCount(message.total))) {
3290
- notifyListener(options.onProgress, { loaded: message.loaded, total: message.total });
3291
- }
3292
- return;
3293
- }
3294
- if (message.type !== "result" && message.type !== "error") return;
3295
- cleanup();
3296
- if (message.type === "error") reject2(wireError(message.error, { code: "media_unavailable", message: "Video media is unavailable" }));
3297
- else if (isMediaResult(message.result, id)) resolve(message.result.blob);
3298
- else reject2(new NochaError("invalid_result", "Nocha returned an invalid video file"));
3299
- };
3300
- const unanswered = timeout > firstReply ? setTimeout(() => stop(new NochaError("media_unsupported_host", "This Nocha host cannot read video media")), firstReply) : void 0;
3301
- const timer = setTimeout(() => stop(new NochaError("invocation_timed_out", "Local video read timed out")), timeout);
3302
- window.addEventListener("message", receive);
3303
- options.signal?.addEventListener("abort", abort, { once: true });
3304
- try {
3305
- host.postMessage({
3306
- protocol: "nocha.media.v1",
3307
- type: "read",
3308
- requestId,
3309
- capability: videoOperationDefinitions["get"].capability,
3310
- operation: videoOperationDefinitions["get"].operation,
3311
- usageId: context.usageId,
3312
- input: { id }
3313
- }, "*");
3314
- } catch (error) {
3315
- cleanup();
3316
- reject2(new NochaError("invalid_request", `The request cannot be sent to the Nocha host: ${error instanceof Error ? error.message : String(error)}`));
3317
- }
3651
+ return readHostMedia({
3652
+ noun: "video",
3653
+ timeoutMs: timeout,
3654
+ firstReplyMs: operationWaiting.video["media.firstReply"],
3655
+ options,
3656
+ accept: (result2) => isMediaResult(result2, id) ? result2.blob : void 0,
3657
+ send: (host, requestId) => host.postMessage({
3658
+ protocol: "nocha.media.v1",
3659
+ type: "read",
3660
+ requestId,
3661
+ capability: videoOperationDefinitions["get"].capability,
3662
+ operation: videoOperationDefinitions["get"].operation,
3663
+ usageId,
3664
+ input: { id }
3665
+ }, "*")
3318
3666
  });
3319
3667
  }
3320
3668
 
@@ -3388,13 +3736,13 @@ var text4 = (value) => string(value) ? value : null;
3388
3736
  var count = (value) => typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
3389
3737
  var measure = (value) => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : null;
3390
3738
  var credits2 = (value) => string(value) && /^\d+$/.test(value);
3391
- var pick = (value, values) => string(value) && values.includes(value) ? value : null;
3392
- var keep = (value, values) => Array.isArray(value) ? value.filter((item) => pick(item, values) !== null) : [];
3739
+ var pick2 = (value, values) => string(value) && values.includes(value) ? value : null;
3740
+ var keep = (value, values) => Array.isArray(value) ? value.filter((item) => pick2(item, values) !== null) : [];
3393
3741
  var counts = (value) => Array.isArray(value) ? value.filter(count) : [];
3394
3742
  var records = (value) => Array.isArray(value) ? value.filter(isRecord) : [];
3395
3743
  var optionalText = (value, key) => string(value[key]) ? { [key]: value[key] } : {};
3396
- var families = ["classic", "narrative", "image_loop"];
3397
- var kinds = ["film", "image_loop"];
3744
+ var families = ["classic", "narrative", "image_loop", "analysis"];
3745
+ var kinds = ["film", "image_loop", "analysis"];
3398
3746
  var speech = ["none", "auto", "required"];
3399
3747
  var ratios = ["9:16", "16:9", "1:1"];
3400
3748
  var locales2 = videoLocales;
@@ -3402,6 +3750,35 @@ var resolutions2 = ["720p", "1080p"];
3402
3750
  var efforts2 = ["auto", "low", "medium", "high"];
3403
3751
  var stages = ["preparing", "planning", "generating_speech", "generating_media", "assembling"];
3404
3752
  var costEffects = ["none", "may_change_quantity", "may_change_unit_price", "may_change_route"];
3753
+ var resumeReasons = [
3754
+ "interrupted",
3755
+ "inputs_changed",
3756
+ "provider_unavailable",
3757
+ "storage_full",
3758
+ "paid_work_retained",
3759
+ "retryable_failure",
3760
+ "final_failure",
3761
+ "budget_exhausted",
3762
+ "workflow_taken_over",
3763
+ "media_expired"
3764
+ ];
3765
+ var resumeActions = ["keep", "redo", "run"];
3766
+ function resume(value) {
3767
+ if (value === void 0) return void 0;
3768
+ if (!isRecord(value)) return null;
3769
+ const estimated = value.estimated_microcredits;
3770
+ if (typeof value.available !== "boolean" || !credits2(value.remaining_microcredits) || !(estimated === null || credits2(estimated))) return null;
3771
+ return {
3772
+ available: value.available,
3773
+ reason: pick2(value.reason, resumeReasons),
3774
+ steps: records(value.steps).flatMap((step2) => {
3775
+ const action = pick2(step2.action, resumeActions);
3776
+ return string(step2.id) && action && typeof step2.paid === "boolean" ? [{ id: step2.id, action, paid: step2.paid }] : [];
3777
+ }),
3778
+ estimated_microcredits: estimated,
3779
+ remaining_microcredits: value.remaining_microcredits
3780
+ };
3781
+ }
3405
3782
  var scalar = (value) => typeof value === "string" || typeof value === "boolean" || typeof value === "number" && Number.isFinite(value);
3406
3783
  function parameterValue2(value) {
3407
3784
  if (scalar(value)) return value;
@@ -3424,8 +3801,8 @@ function parameterValues2(value) {
3424
3801
  return { ...workflow2 === void 0 ? {} : { workflow: workflow2 }, ...modules === void 0 ? {} : { modules } };
3425
3802
  }
3426
3803
  function parameterDefinition(value) {
3427
- const scope = pick(value.scope, ["workflow", "module"]);
3428
- const costEffect = pick(value.cost_effect, costEffects);
3804
+ const scope = pick2(value.scope, ["workflow", "module"]);
3805
+ const costEffect = pick2(value.cost_effect, costEffects);
3429
3806
  const moduleId = value.module_id, instanceId = value.module_instance_id;
3430
3807
  const identity2 = scope === "workflow" ? moduleId === null && instanceId === null : scope === "module" && string(moduleId) && string(instanceId);
3431
3808
  const defaultValue = value.default === null ? null : parameterValue2(value.default);
@@ -3461,6 +3838,7 @@ function failure2(value) {
3461
3838
  }
3462
3839
  function result(value) {
3463
3840
  if (value === null) return null;
3841
+ if (isRecord(value) && value.kind !== void 0) return readVideoAnalysisResult(value);
3464
3842
  if (!isRecord(value) || measure(value.actual_duration_seconds) === null || !string(value.download_url) || !string(value.download_url_expires_at) || value.mime_type !== "video/mp4" || !string(value.sha256) || !count(value.size_bytes)) return void 0;
3465
3843
  return {
3466
3844
  actual_duration_seconds: value.actual_duration_seconds,
@@ -3473,18 +3851,18 @@ function result(value) {
3473
3851
  ...string(value.asset_id) && /^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(value.asset_id) ? { asset_id: value.asset_id } : {},
3474
3852
  ...count(value.width) && value.width > 0 ? { width: value.width } : {},
3475
3853
  ...count(value.height) && value.height > 0 ? { height: value.height } : {},
3476
- ...pick(value.aspect_ratio, ratios) ? { aspect_ratio: pick(value.aspect_ratio, ratios) } : {}
3854
+ ...pick2(value.aspect_ratio, ratios) ? { aspect_ratio: pick2(value.aspect_ratio, ratios) } : {}
3477
3855
  };
3478
3856
  }
3479
3857
  function workflowRef(value) {
3480
3858
  if (!isRecord(value) || !string(value.id) || !value.id) return null;
3481
- return { id: value.id, family: pick(value.family, families), revision: count(value.revision) ? value.revision : null, digest: text4(value.digest), ...optionalText(value, "name") };
3859
+ return { id: value.id, family: pick2(value.family, families), revision: count(value.revision) ? value.revision : null, digest: text4(value.digest), ...optionalText(value, "name") };
3482
3860
  }
3483
3861
  function automation(value) {
3484
3862
  if (!isRecord(value) || !string(value.id) || !string(value.started_at) || !string(value.updated_at)) return void 0;
3485
3863
  return {
3486
3864
  id: value.id,
3487
- status: pick(value.status, ["running", "stopping", "completed", "blocked", "cancelled"]),
3865
+ status: pick2(value.status, ["running", "stopping", "completed", "blocked", "cancelled"]),
3488
3866
  started_at: value.started_at,
3489
3867
  updated_at: value.updated_at,
3490
3868
  finished_at: text4(value.finished_at),
@@ -3492,8 +3870,8 @@ function automation(value) {
3492
3870
  steps: records(value.steps).filter((step2) => string(step2.id)).map((step2) => ({
3493
3871
  id: step2.id,
3494
3872
  operation: text4(step2.operation),
3495
- status: pick(step2.status, ["pending", "queued", "running", "retrying", "completed", "partial", "blocked", "cancelled", "skipped"]),
3496
- freshness: pick(step2.freshness, ["fresh", "outdated", "update_available", "missing"]),
3873
+ status: pick2(step2.status, ["pending", "queued", "running", "retrying", "completed", "partial", "blocked", "cancelled", "skipped"]),
3874
+ freshness: pick2(step2.freshness, ["fresh", "outdated", "update_available", "missing"]),
3497
3875
  produced_by: isRecord(step2.produced_by) && string(step2.produced_by.module_id) && count(step2.produced_by.revision) ? { module_id: step2.produced_by.module_id, revision: step2.produced_by.revision } : null,
3498
3876
  jobs_count: count(step2.jobs_count) ? step2.jobs_count : 0,
3499
3877
  error: failure2(step2.error)
@@ -3506,7 +3884,7 @@ function automation(value) {
3506
3884
  step_id: text4(job.step_id),
3507
3885
  operation: job.operation,
3508
3886
  module,
3509
- status: pick(job.status, ["queued", "running", "retrying", "succeeded", "failed", "cancelled", "blocked"]),
3887
+ status: pick2(job.status, ["queued", "running", "retrying", "succeeded", "failed", "cancelled", "blocked"]),
3510
3888
  attempt: count(job.attempt) ? job.attempt : null,
3511
3889
  progress: { percent: measure(progress.percent), completed_units: measure(progress.completed_units), total_units: measure(progress.total_units) },
3512
3890
  created_at: job.created_at,
@@ -3530,7 +3908,7 @@ function readVideoGeneration(value) {
3530
3908
  audience_view: "shared",
3531
3909
  id: value.id,
3532
3910
  collection_id: value.collection_id,
3533
- kind: pick(value.kind, kinds),
3911
+ kind: pick2(value.kind, kinds),
3534
3912
  status: "succeeded",
3535
3913
  created_at: value.created_at,
3536
3914
  updated_at: value.updated_at,
@@ -3557,37 +3935,40 @@ function readVideoGeneration(value) {
3557
3935
  const origin = isRecord(value.origin) && value.origin.type === "nocha_experience" && ["experience_id", "experience_code", "experience_title", "revision_id"].every((key) => string(value.origin[key])) ? value.origin : null;
3558
3936
  const access2 = isRecord(value.automation_access) ? value.automation_access : null;
3559
3937
  const automationValue = automation(value.automation);
3938
+ const resumeValue = resume(value.resume);
3939
+ const editPlan = readVideoEditPlan(value.edit_plan);
3560
3940
  const generationValue = {
3561
3941
  audience_view: "author",
3562
3942
  id: value.id,
3563
- status: pick(value.status, ["queued", "running", "cancelling", "succeeded", "failed", "cancelled"]),
3564
- kind: pick(value.kind, kinds),
3943
+ status: pick2(value.status, ["queued", "running", "cancelling", "succeeded", "failed", "cancelled"]),
3944
+ kind: pick2(value.kind, kinds),
3565
3945
  workflow: workflow2,
3566
3946
  request: {
3567
3947
  workflow: { id: requested.id, ...requested.revision === null ? {} : { revision: requested.revision } },
3568
3948
  goal: request.goal,
3569
3949
  duration_seconds: request.duration_seconds,
3570
- aspect_ratio: pick(request.aspect_ratio, ratios),
3571
- locale: pick(request.locale, locales2),
3572
- speech: pick(request.speech, speech),
3573
- ...request.output_resolution === void 0 ? {} : { output_resolution: pick(request.output_resolution, resolutions2) },
3950
+ aspect_ratio: pick2(request.aspect_ratio, ratios),
3951
+ locale: pick2(request.locale, locales2),
3952
+ speech: pick2(request.speech, speech),
3953
+ ...request.output_resolution === void 0 ? {} : { output_resolution: pick2(request.output_resolution, resolutions2) },
3574
3954
  ...request.parameters === void 0 ? {} : { parameters: requestedParameters ?? {} },
3575
3955
  ...requestedProperties === void 0 ? {} : { properties: requestedProperties },
3576
3956
  ...request.reference_preparation === "auto" ? { reference_preparation: "auto" } : {},
3577
- ...request.effort === void 0 ? {} : { effort: pick(request.effort, efforts2) },
3957
+ ...string(request.source_analysis_id) && request.source_analysis_id ? { source_analysis_id: request.source_analysis_id } : {},
3958
+ ...request.effort === void 0 ? {} : { effort: pick2(request.effort, efforts2) },
3578
3959
  collection_id: text4(request.collection_id),
3579
3960
  confirmed_maximum_microcredits: credits2(request.confirmed_maximum_microcredits) ? request.confirmed_maximum_microcredits : null
3580
3961
  },
3581
3962
  parameters: parameters && count(parameters.duration_seconds) ? {
3582
3963
  duration_seconds: parameters.duration_seconds,
3583
- aspect_ratio: pick(parameters.aspect_ratio, ratios),
3584
- locale: pick(parameters.locale, locales2),
3585
- speech: pick(parameters.speech, speech),
3586
- output_resolution: pick(parameters.output_resolution, resolutions2),
3964
+ aspect_ratio: pick2(parameters.aspect_ratio, ratios),
3965
+ locale: pick2(parameters.locale, locales2),
3966
+ speech: pick2(parameters.speech, speech),
3967
+ output_resolution: pick2(parameters.output_resolution, resolutions2),
3587
3968
  reference_count: count(parameters.reference_count) ? parameters.reference_count : 0,
3588
3969
  ...parameters.reference_preparation === "auto" ? { reference_preparation: "auto" } : {},
3589
3970
  ...generation ? { generation: {
3590
- intensity: pick(generation.intensity, ["low", "medium", "high"]),
3971
+ intensity: pick2(generation.intensity, ["low", "medium", "high"]),
3591
3972
  ...count(generation.preference_revision) ? { preference_revision: generation.preference_revision } : {},
3592
3973
  ...string(generation.policy_signature) ? { policy_signature: generation.policy_signature } : {}
3593
3974
  } } : {},
@@ -3595,13 +3976,17 @@ function readVideoGeneration(value) {
3595
3976
  ...effectiveModules === void 0 ? {} : { modules: effectiveModules }
3596
3977
  } : null,
3597
3978
  ...effectiveProperties === void 0 ? {} : { properties: effectiveProperties },
3598
- references: records(value.references).filter((item) => string(item.asset_id)).map((item) => ({
3599
- asset_id: item.asset_id,
3600
- ...optionalText(item, "role"),
3601
- ...optionalText(item, "name"),
3602
- ...optionalText(item, "description"),
3603
- availability: pick(item.availability, ["available", "expired", "pending"])
3604
- })),
3979
+ references: records(value.references).filter((item) => string(item.asset_id)).map((item) => {
3980
+ const replaces2 = readVideoReferenceReplaces(item.replaces);
3981
+ return {
3982
+ asset_id: item.asset_id,
3983
+ ...optionalText(item, "role"),
3984
+ ...optionalText(item, "name"),
3985
+ ...optionalText(item, "description"),
3986
+ ...replaces2 ? { replaces: replaces2 } : {},
3987
+ availability: pick2(item.availability, ["available", "expired", "pending"])
3988
+ };
3989
+ }),
3605
3990
  origin: origin ? {
3606
3991
  type: "nocha_experience",
3607
3992
  experience_id: origin.experience_id,
@@ -3611,7 +3996,7 @@ function readVideoGeneration(value) {
3611
3996
  } : null,
3612
3997
  progress: {
3613
3998
  percent: Math.min(100, progress.percent),
3614
- stage: pick(progress.stage, stages),
3999
+ stage: pick2(progress.stage, stages),
3615
4000
  ...progress.step === null || string(progress.step) ? { step: progress.step } : {}
3616
4001
  },
3617
4002
  ...automationValue ? { automation: automationValue } : {},
@@ -3625,7 +4010,9 @@ function readVideoGeneration(value) {
3625
4010
  },
3626
4011
  actual_duration_seconds: measure(value.actual_duration_seconds),
3627
4012
  error: failure2(value.error),
4013
+ ...resumeValue === void 0 ? {} : { resume: resumeValue },
3628
4014
  result: output,
4015
+ ...editPlan === void 0 ? {} : { edit_plan: editPlan },
3629
4016
  created_at: value.created_at,
3630
4017
  updated_at: value.updated_at
3631
4018
  };
@@ -3643,7 +4030,7 @@ function step(value) {
3643
4030
  id: value.id,
3644
4031
  operation: text4(value.operation),
3645
4032
  lane: text4(value.lane),
3646
- execution: pick(value.execution, ["segment", "historical"]),
4033
+ execution: pick2(value.execution, ["segment", "historical"]),
3647
4034
  ...module ? { module } : {},
3648
4035
  ...typeof value.restartable === "boolean" ? { restartable: value.restartable } : {},
3649
4036
  ...Array.isArray(value.properties) ? { properties: value.properties.flatMap((item) => {
@@ -3653,47 +4040,53 @@ function step(value) {
3653
4040
  modules: records(value.modules).filter((item) => string(item.id) && string(item.instance_id) && string(item.title) && count(item.revision)).map((item) => ({ id: item.id, instance_id: item.instance_id, title: item.title, revision: item.revision }))
3654
4041
  };
3655
4042
  }
4043
+ function referenceRole(value) {
4044
+ const media = pick2(value.media, ["image", "video", "audio"]);
4045
+ if (!string(value.role) || !value.role || !media || !count(value.min) || !count(value.max) || value.max < 1) return null;
4046
+ return { role: value.role, media, min: value.min, max: value.max, gap_seconds: measure(value.gap_seconds), crossfade_seconds: measure(value.crossfade_seconds) };
4047
+ }
3656
4048
  function readVideoWorkflow(value) {
3657
4049
  if (!isRecord(value) || !string(value.id) || !value.id || !string(value.name) || !isRecord(value.duration_seconds) || !isRecord(value.references)) return null;
3658
4050
  const durations = value.duration_seconds, references = value.references, availability = isRecord(value.availability) ? value.availability : {};
3659
4051
  if (!count(durations.min) || !count(durations.max) || !count(references.min) || !count(references.max)) return null;
3660
4052
  return {
3661
4053
  id: value.id,
3662
- origin: pick(value.origin, ["builtin", "saved"]),
4054
+ origin: pick2(value.origin, ["builtin", "saved"]),
3663
4055
  revision: count(value.revision) ? value.revision : null,
3664
4056
  latest_revision: count(value.latest_revision) ? value.latest_revision : null,
3665
4057
  digest: text4(value.digest),
3666
4058
  base_id: text4(value.base_id),
3667
4059
  name: value.name,
3668
4060
  description: string(value.description) ? value.description : "",
3669
- kind: pick(value.kind, kinds),
3670
- family: pick(value.family, families),
3671
- variant: pick(value.variant, ["native", "voix", "bande-son", "video-noire", "micro", "live"]),
4061
+ kind: pick2(value.kind, kinds),
4062
+ family: pick2(value.family, families),
4063
+ variant: pick2(value.variant, ["native", "voix", "bande-son", "video-noire", "micro", "live"]),
3672
4064
  duration_seconds: { min: durations.min, max: durations.max, allowed: Array.isArray(durations.allowed) ? counts(durations.allowed) : null },
3673
4065
  default_for_durations_seconds: counts(value.default_for_durations_seconds),
3674
4066
  aspect_ratios: keep(value.aspect_ratios, ratios),
3675
4067
  output_resolutions: keep(value.output_resolutions, resolutions2),
3676
4068
  locales: keep(value.locales, locales2),
3677
4069
  speech_modes: records(value.speech_modes).flatMap((item) => {
3678
- const mode = pick(item.mode, speech);
4070
+ const mode = pick2(item.mode, speech);
3679
4071
  return mode ? [{ mode, durations_seconds: Array.isArray(item.durations_seconds) ? counts(item.durations_seconds) : null }] : [];
3680
4072
  }),
3681
4073
  references: {
3682
4074
  min: references.min,
3683
4075
  max: references.max,
3684
4076
  mime_types: Array.isArray(references.mime_types) ? references.mime_types.filter(string) : [],
3685
- requires_non_character: references.requires_non_character === true
4077
+ requires_non_character: references.requires_non_character === true,
4078
+ roles: records(references.roles).map(referenceRole).filter((item) => item !== null)
3686
4079
  },
3687
4080
  reference_preparation: value.reference_preparation === true,
3688
4081
  restart_from: Array.isArray(value.restart_from) ? value.restart_from.filter(string) : [],
3689
4082
  provider_needs: Array.isArray(value.provider_needs) ? value.provider_needs.filter(string) : [],
3690
- interaction: pick(value.interaction, ["none", "recordings", "live"]),
4083
+ interaction: pick2(value.interaction, ["none", "recordings", "live"]),
3691
4084
  steps: records(value.steps).map(step).filter((item) => item !== null),
3692
4085
  parameters: records(value.parameters).map(parameterDefinition).filter((item) => item !== null),
3693
4086
  availability: availability.status === "available" ? { status: "available" } : {
3694
4087
  status: "unavailable",
3695
4088
  message: string(availability.message) ? availability.message : "",
3696
- reason: pick(availability.reason, ["interactive", "providers", "modules", "render_target", "base", "unavailable"])
4089
+ reason: pick2(availability.reason, ["interactive", "providers", "modules", "render_target", "base", "unavailable"])
3697
4090
  }
3698
4091
  };
3699
4092
  }
@@ -3749,10 +4142,12 @@ async function list(context, input3 = {}, options) {
3749
4142
  if (!isRecord(input3) || input3.limit !== void 0 && !Number.isInteger(input3.limit) || input3.cursor !== void 0 && typeof input3.cursor !== "string") {
3750
4143
  throw invalid("list takes an integer limit and a string cursor");
3751
4144
  }
4145
+ const workflow2 = input3.workflow === void 0 ? void 0 : videoWorkflowRef({ id: input3.workflow }, "list workflow").id;
3752
4146
  const value = await context.invoke(videoOperationDefinitions["list"].capability, videoOperationDefinitions["list"].operation, {
3753
4147
  api,
3754
4148
  ...input3.cursor ? { cursor: input3.cursor } : {},
3755
- ...input3.limit === void 0 ? {} : { limit: input3.limit }
4149
+ ...input3.limit === void 0 ? {} : { limit: input3.limit },
4150
+ ...workflow2 ? { workflow: workflow2 } : {}
3756
4151
  }, options);
3757
4152
  if (!isRecord(value) || !Array.isArray(value.items) || !isRecord(value.pagination) || typeof value.pagination.has_more !== "boolean" || !(value.pagination.next_cursor === null || typeof value.pagination.next_cursor === "string")) throw invalidResult2("video generation list");
3758
4153
  return { items: value.items.map(readable), pagination: { has_more: value.pagination.has_more, next_cursor: value.pagination.next_cursor } };
@@ -4083,6 +4478,7 @@ function createFacades(context, shared) {
4083
4478
  multiplayer,
4084
4479
  outirl: createOutirl(context),
4085
4480
  device: createDevice(context, shared.motion),
4481
+ drive: createDrive(context),
4086
4482
  voice: createVoice(context)
4087
4483
  };
4088
4484
  }