@5ss/ai-tools 2.11.1

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 (342) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/LICENSE +21 -0
  3. package/README.md +221 -0
  4. package/dist/ai-sdk/index.d.ts +15 -0
  5. package/dist/ai-sdk/index.d.ts.map +1 -0
  6. package/dist/ai-sdk/index.js +24 -0
  7. package/dist/ai-sdk/index.js.map +1 -0
  8. package/dist/artifact-D064mHfK.js +44 -0
  9. package/dist/artifact-D064mHfK.js.map +1 -0
  10. package/dist/artifacts-O8g-40Pw.js +404 -0
  11. package/dist/artifacts-O8g-40Pw.js.map +1 -0
  12. package/dist/aws-json-CecFqzqX.js +23 -0
  13. package/dist/aws-json-CecFqzqX.js.map +1 -0
  14. package/dist/aws-service-msttbPrz.js +58 -0
  15. package/dist/aws-service-msttbPrz.js.map +1 -0
  16. package/dist/batch-BMM5dXqL.d.ts +22 -0
  17. package/dist/batch-BMM5dXqL.d.ts.map +1 -0
  18. package/dist/batch-Co1ujeAW.js +67 -0
  19. package/dist/batch-Co1ujeAW.js.map +1 -0
  20. package/dist/bedrock-agentcore-browser-a_qOs-NR.js +182 -0
  21. package/dist/bedrock-agentcore-browser-a_qOs-NR.js.map +1 -0
  22. package/dist/bedrock-agentcore-code-interpreter-MWK-8RhA.js +357 -0
  23. package/dist/bedrock-agentcore-code-interpreter-MWK-8RhA.js.map +1 -0
  24. package/dist/bytes-BxpimpQx.js +45 -0
  25. package/dist/bytes-BxpimpQx.js.map +1 -0
  26. package/dist/client-CCKGsTeI.js +743 -0
  27. package/dist/client-CCKGsTeI.js.map +1 -0
  28. package/dist/cloudflare/index.d.ts +37 -0
  29. package/dist/cloudflare/index.d.ts.map +1 -0
  30. package/dist/cloudflare/index.js +41 -0
  31. package/dist/cloudflare/index.js.map +1 -0
  32. package/dist/cloudflare-browser-B6Yolpin.js +428 -0
  33. package/dist/cloudflare-browser-B6Yolpin.js.map +1 -0
  34. package/dist/cloudflare-email-Dy0KHeDf.js +197 -0
  35. package/dist/cloudflare-email-Dy0KHeDf.js.map +1 -0
  36. package/dist/cloudflare-sandbox-Dp_uNaqW.js +982 -0
  37. package/dist/cloudflare-sandbox-Dp_uNaqW.js.map +1 -0
  38. package/dist/content-type-CORxaxcv.js +49 -0
  39. package/dist/content-type-CORxaxcv.js.map +1 -0
  40. package/dist/core/index.d.ts +4 -0
  41. package/dist/core/index.js +204 -0
  42. package/dist/core/index.js.map +1 -0
  43. package/dist/define-CvpJ_pNP.js +115 -0
  44. package/dist/define-CvpJ_pNP.js.map +1 -0
  45. package/dist/errors-DoSpNHvs.js +20 -0
  46. package/dist/errors-DoSpNHvs.js.map +1 -0
  47. package/dist/errors-aKhko9T1.d.ts +18 -0
  48. package/dist/errors-aKhko9T1.d.ts.map +1 -0
  49. package/dist/eventbridge-scheduler-Bh6GqZY2.js +349 -0
  50. package/dist/eventbridge-scheduler-Bh6GqZY2.js.map +1 -0
  51. package/dist/framework-context-DVIIY8ZO.js +24 -0
  52. package/dist/framework-context-DVIIY8ZO.js.map +1 -0
  53. package/dist/gotenberg-NuJjxyln.js +291 -0
  54. package/dist/gotenberg-NuJjxyln.js.map +1 -0
  55. package/dist/http/index.d.ts +47 -0
  56. package/dist/http/index.d.ts.map +1 -0
  57. package/dist/http/index.js +3 -0
  58. package/dist/http-service-DDNCO1s4.js +254 -0
  59. package/dist/http-service-DDNCO1s4.js.map +1 -0
  60. package/dist/http-service-T7E5UjP8.d.ts +80 -0
  61. package/dist/http-service-T7E5UjP8.d.ts.map +1 -0
  62. package/dist/imessage-BSAFOI8Z.js +154 -0
  63. package/dist/imessage-BSAFOI8Z.js.map +1 -0
  64. package/dist/index-BU4gmYO8.d.ts +254 -0
  65. package/dist/index-BU4gmYO8.d.ts.map +1 -0
  66. package/dist/index-CCivzmxO.d.ts +188 -0
  67. package/dist/index-CCivzmxO.d.ts.map +1 -0
  68. package/dist/index-CLmTrcu5.d.ts +22 -0
  69. package/dist/index-CLmTrcu5.d.ts.map +1 -0
  70. package/dist/index-CZX5OeOF.d.ts +235 -0
  71. package/dist/index-CZX5OeOF.d.ts.map +1 -0
  72. package/dist/index-CdFmEfZO.d.ts +359 -0
  73. package/dist/index-CdFmEfZO.d.ts.map +1 -0
  74. package/dist/index-Cuh6eMWc.d.ts +285 -0
  75. package/dist/index-Cuh6eMWc.d.ts.map +1 -0
  76. package/dist/index-DuOGj7vc.d.ts +107 -0
  77. package/dist/index-DuOGj7vc.d.ts.map +1 -0
  78. package/dist/index-ccZ1XOHw.d.ts +69 -0
  79. package/dist/index-ccZ1XOHw.d.ts.map +1 -0
  80. package/dist/index-n8JTpNf1.d.ts +247 -0
  81. package/dist/index-n8JTpNf1.d.ts.map +1 -0
  82. package/dist/index-pwW1OsOx.d.ts +134 -0
  83. package/dist/index-pwW1OsOx.d.ts.map +1 -0
  84. package/dist/index-zK1ZwS4m.d.ts +347 -0
  85. package/dist/index-zK1ZwS4m.d.ts.map +1 -0
  86. package/dist/limits-hjrO8zUG.js +80 -0
  87. package/dist/limits-hjrO8zUG.js.map +1 -0
  88. package/dist/mastra/index.d.ts +14 -0
  89. package/dist/mastra/index.d.ts.map +1 -0
  90. package/dist/mastra/index.js +26 -0
  91. package/dist/mastra/index.js.map +1 -0
  92. package/dist/mastra-vector-Dhc6XZ8l.js +234 -0
  93. package/dist/mastra-vector-Dhc6XZ8l.js.map +1 -0
  94. package/dist/mcp/index.d.ts +80 -0
  95. package/dist/mcp/index.d.ts.map +1 -0
  96. package/dist/mcp/index.js +97 -0
  97. package/dist/mcp/index.js.map +1 -0
  98. package/dist/modules/artifacts/index.d.ts +337 -0
  99. package/dist/modules/artifacts/index.d.ts.map +1 -0
  100. package/dist/modules/artifacts/index.js +348 -0
  101. package/dist/modules/artifacts/index.js.map +1 -0
  102. package/dist/modules/browser/index.d.ts +516 -0
  103. package/dist/modules/browser/index.d.ts.map +1 -0
  104. package/dist/modules/browser/index.js +475 -0
  105. package/dist/modules/browser/index.js.map +1 -0
  106. package/dist/modules/calendar/index.d.ts +93 -0
  107. package/dist/modules/calendar/index.d.ts.map +1 -0
  108. package/dist/modules/calendar/index.js +131 -0
  109. package/dist/modules/calendar/index.js.map +1 -0
  110. package/dist/modules/code-sandbox/index.d.ts +317 -0
  111. package/dist/modules/code-sandbox/index.d.ts.map +1 -0
  112. package/dist/modules/code-sandbox/index.js +537 -0
  113. package/dist/modules/code-sandbox/index.js.map +1 -0
  114. package/dist/modules/content-type/index.d.ts +22 -0
  115. package/dist/modules/content-type/index.d.ts.map +1 -0
  116. package/dist/modules/content-type/index.js +66 -0
  117. package/dist/modules/content-type/index.js.map +1 -0
  118. package/dist/modules/crypto/index.d.ts +115 -0
  119. package/dist/modules/crypto/index.d.ts.map +1 -0
  120. package/dist/modules/crypto/index.js +139 -0
  121. package/dist/modules/crypto/index.js.map +1 -0
  122. package/dist/modules/document/index.d.ts +575 -0
  123. package/dist/modules/document/index.d.ts.map +1 -0
  124. package/dist/modules/document/index.js +444 -0
  125. package/dist/modules/document/index.js.map +1 -0
  126. package/dist/modules/document-extract/index.d.ts +438 -0
  127. package/dist/modules/document-extract/index.d.ts.map +1 -0
  128. package/dist/modules/document-extract/index.js +127 -0
  129. package/dist/modules/document-extract/index.js.map +1 -0
  130. package/dist/modules/document-render/index.d.ts +336 -0
  131. package/dist/modules/document-render/index.d.ts.map +1 -0
  132. package/dist/modules/document-render/index.js +155 -0
  133. package/dist/modules/document-render/index.js.map +1 -0
  134. package/dist/modules/email/index.d.ts +311 -0
  135. package/dist/modules/email/index.d.ts.map +1 -0
  136. package/dist/modules/email/index.js +167 -0
  137. package/dist/modules/email/index.js.map +1 -0
  138. package/dist/modules/email-message/index.d.ts +95 -0
  139. package/dist/modules/email-message/index.d.ts.map +1 -0
  140. package/dist/modules/email-message/index.js +264 -0
  141. package/dist/modules/email-message/index.js.map +1 -0
  142. package/dist/modules/file-convert/index.d.ts +273 -0
  143. package/dist/modules/file-convert/index.d.ts.map +1 -0
  144. package/dist/modules/file-convert/index.js +103 -0
  145. package/dist/modules/file-convert/index.js.map +1 -0
  146. package/dist/modules/files/index.d.ts +452 -0
  147. package/dist/modules/files/index.d.ts.map +1 -0
  148. package/dist/modules/files/index.js +733 -0
  149. package/dist/modules/files/index.js.map +1 -0
  150. package/dist/modules/image/index.d.ts +342 -0
  151. package/dist/modules/image/index.d.ts.map +1 -0
  152. package/dist/modules/image/index.js +281 -0
  153. package/dist/modules/image/index.js.map +1 -0
  154. package/dist/modules/messaging/index.d.ts +608 -0
  155. package/dist/modules/messaging/index.d.ts.map +1 -0
  156. package/dist/modules/messaging/index.js +1067 -0
  157. package/dist/modules/messaging/index.js.map +1 -0
  158. package/dist/modules/pdf/index.d.ts +287 -0
  159. package/dist/modules/pdf/index.d.ts.map +1 -0
  160. package/dist/modules/pdf/index.js +259 -0
  161. package/dist/modules/pdf/index.js.map +1 -0
  162. package/dist/modules/presentation/index.d.ts +247 -0
  163. package/dist/modules/presentation/index.d.ts.map +1 -0
  164. package/dist/modules/presentation/index.js +12657 -0
  165. package/dist/modules/presentation/index.js.map +1 -0
  166. package/dist/modules/queue/index.d.ts +129 -0
  167. package/dist/modules/queue/index.d.ts.map +1 -0
  168. package/dist/modules/queue/index.js +131 -0
  169. package/dist/modules/queue/index.js.map +1 -0
  170. package/dist/modules/rag/index.d.ts +250 -0
  171. package/dist/modules/rag/index.d.ts.map +1 -0
  172. package/dist/modules/rag/index.js +366 -0
  173. package/dist/modules/rag/index.js.map +1 -0
  174. package/dist/modules/scheduler/index.d.ts +216 -0
  175. package/dist/modules/scheduler/index.d.ts.map +1 -0
  176. package/dist/modules/scheduler/index.js +153 -0
  177. package/dist/modules/scheduler/index.js.map +1 -0
  178. package/dist/modules/skills/index.d.ts +205 -0
  179. package/dist/modules/skills/index.d.ts.map +1 -0
  180. package/dist/modules/skills/index.js +203 -0
  181. package/dist/modules/skills/index.js.map +1 -0
  182. package/dist/modules/tasks/index.d.ts +287 -0
  183. package/dist/modules/tasks/index.d.ts.map +1 -0
  184. package/dist/modules/tasks/index.js +207 -0
  185. package/dist/modules/tasks/index.js.map +1 -0
  186. package/dist/modules/vector-store/index.d.ts +3 -0
  187. package/dist/modules/vector-store/index.js +3 -0
  188. package/dist/modules/web-fetch/index.d.ts +99 -0
  189. package/dist/modules/web-fetch/index.d.ts.map +1 -0
  190. package/dist/modules/web-fetch/index.js +242 -0
  191. package/dist/modules/web-fetch/index.js.map +1 -0
  192. package/dist/object-artifact-store-CMTzCm_G.d.ts +7 -0
  193. package/dist/object-artifact-store-CMTzCm_G.d.ts.map +1 -0
  194. package/dist/object-artifact-store-wZ2j9cto.js +28 -0
  195. package/dist/object-artifact-store-wZ2j9cto.js.map +1 -0
  196. package/dist/pinecone-umY4t6OF.js +190 -0
  197. package/dist/pinecone-umY4t6OF.js.map +1 -0
  198. package/dist/provider-CgDAlg6K.js +34 -0
  199. package/dist/provider-CgDAlg6K.js.map +1 -0
  200. package/dist/qdrant-DMp4NhKR.js +253 -0
  201. package/dist/qdrant-DMp4NhKR.js.map +1 -0
  202. package/dist/resend-BAC38_dA.js +155 -0
  203. package/dist/resend-BAC38_dA.js.map +1 -0
  204. package/dist/s3-CsOaPWMP.js +955 -0
  205. package/dist/s3-CsOaPWMP.js.map +1 -0
  206. package/dist/schemas-ChOAhdo9.js +192 -0
  207. package/dist/schemas-ChOAhdo9.js.map +1 -0
  208. package/dist/slack-Di5BBNpt.js +1455 -0
  209. package/dist/slack-Di5BBNpt.js.map +1 -0
  210. package/dist/sqs-DCwS1i2N.js +225 -0
  211. package/dist/sqs-DCwS1i2N.js.map +1 -0
  212. package/dist/supabase-vector-Dpp9mmJR.js +218 -0
  213. package/dist/supabase-vector-Dpp9mmJR.js.map +1 -0
  214. package/dist/tanstack/index.d.ts +15 -0
  215. package/dist/tanstack/index.d.ts.map +1 -0
  216. package/dist/tanstack/index.js +28 -0
  217. package/dist/tanstack/index.js.map +1 -0
  218. package/dist/teams-DYAHNb39.js +835 -0
  219. package/dist/teams-DYAHNb39.js.map +1 -0
  220. package/dist/telegram-DDXWzkfL.js +734 -0
  221. package/dist/telegram-DDXWzkfL.js.map +1 -0
  222. package/dist/textract-CPLiB22H.js +554 -0
  223. package/dist/textract-CPLiB22H.js.map +1 -0
  224. package/dist/transport-B4vn-XiQ.js +157 -0
  225. package/dist/transport-B4vn-XiQ.js.map +1 -0
  226. package/dist/transport-i96ACAI_.d.ts +46 -0
  227. package/dist/transport-i96ACAI_.d.ts.map +1 -0
  228. package/dist/types-Ccb0DXY9.d.ts +150 -0
  229. package/dist/types-Ccb0DXY9.d.ts.map +1 -0
  230. package/dist/unique-EwBH1JPB.js +19 -0
  231. package/dist/unique-EwBH1JPB.js.map +1 -0
  232. package/dist/vector-store-C3nEO80e.js +193 -0
  233. package/dist/vector-store-C3nEO80e.js.map +1 -0
  234. package/dist/vendors/amazon-sp-api/index.d.ts +526 -0
  235. package/dist/vendors/amazon-sp-api/index.d.ts.map +1 -0
  236. package/dist/vendors/amazon-sp-api/index.js +975 -0
  237. package/dist/vendors/amazon-sp-api/index.js.map +1 -0
  238. package/dist/vendors/bedrock-agentcore-browser/index.d.ts +2 -0
  239. package/dist/vendors/bedrock-agentcore-browser/index.js +2 -0
  240. package/dist/vendors/bedrock-agentcore-code-interpreter/index.d.ts +228 -0
  241. package/dist/vendors/bedrock-agentcore-code-interpreter/index.d.ts.map +1 -0
  242. package/dist/vendors/bedrock-agentcore-code-interpreter/index.js +2 -0
  243. package/dist/vendors/cloudflare-browser/index.d.ts +2 -0
  244. package/dist/vendors/cloudflare-browser/index.js +2 -0
  245. package/dist/vendors/cloudflare-email/index.d.ts +260 -0
  246. package/dist/vendors/cloudflare-email/index.d.ts.map +1 -0
  247. package/dist/vendors/cloudflare-email/index.js +3 -0
  248. package/dist/vendors/cloudflare-sandbox/index.d.ts +565 -0
  249. package/dist/vendors/cloudflare-sandbox/index.d.ts.map +1 -0
  250. package/dist/vendors/cloudflare-sandbox/index.js +2 -0
  251. package/dist/vendors/eventbridge-scheduler/index.d.ts +2 -0
  252. package/dist/vendors/eventbridge-scheduler/index.js +2 -0
  253. package/dist/vendors/gotenberg/index.d.ts +306 -0
  254. package/dist/vendors/gotenberg/index.d.ts.map +1 -0
  255. package/dist/vendors/gotenberg/index.js +2 -0
  256. package/dist/vendors/imessage/index.d.ts +420 -0
  257. package/dist/vendors/imessage/index.d.ts.map +1 -0
  258. package/dist/vendors/imessage/index.js +4 -0
  259. package/dist/vendors/katana/index.d.ts +1570 -0
  260. package/dist/vendors/katana/index.d.ts.map +1 -0
  261. package/dist/vendors/katana/index.js +1639 -0
  262. package/dist/vendors/katana/index.js.map +1 -0
  263. package/dist/vendors/mastra-vector/index.d.ts +120 -0
  264. package/dist/vendors/mastra-vector/index.d.ts.map +1 -0
  265. package/dist/vendors/mastra-vector/index.js +3 -0
  266. package/dist/vendors/pinecone/index.d.ts +75 -0
  267. package/dist/vendors/pinecone/index.d.ts.map +1 -0
  268. package/dist/vendors/pinecone/index.js +3 -0
  269. package/dist/vendors/qdrant/index.d.ts +75 -0
  270. package/dist/vendors/qdrant/index.d.ts.map +1 -0
  271. package/dist/vendors/qdrant/index.js +3 -0
  272. package/dist/vendors/resend/index.d.ts +3 -0
  273. package/dist/vendors/resend/index.js +3 -0
  274. package/dist/vendors/s3/index.d.ts +2 -0
  275. package/dist/vendors/s3/index.js +2 -0
  276. package/dist/vendors/slack/index.d.ts +576 -0
  277. package/dist/vendors/slack/index.d.ts.map +1 -0
  278. package/dist/vendors/slack/index.js +3 -0
  279. package/dist/vendors/sqs/index.d.ts +2 -0
  280. package/dist/vendors/sqs/index.js +2 -0
  281. package/dist/vendors/supabase-vector/index.d.ts +89 -0
  282. package/dist/vendors/supabase-vector/index.d.ts.map +1 -0
  283. package/dist/vendors/supabase-vector/index.js +3 -0
  284. package/dist/vendors/teams/index.d.ts +303 -0
  285. package/dist/vendors/teams/index.d.ts.map +1 -0
  286. package/dist/vendors/teams/index.js +3 -0
  287. package/dist/vendors/telegram/index.d.ts +319 -0
  288. package/dist/vendors/telegram/index.d.ts.map +1 -0
  289. package/dist/vendors/telegram/index.js +3 -0
  290. package/dist/vendors/textract/index.d.ts +2 -0
  291. package/dist/vendors/textract/index.js +2 -0
  292. package/dist/vendors/woocommerce/index.d.ts +1700 -0
  293. package/dist/vendors/woocommerce/index.d.ts.map +1 -0
  294. package/dist/vendors/woocommerce/index.js +1427 -0
  295. package/dist/vendors/woocommerce/index.js.map +1 -0
  296. package/dist/with-auth-CpKqTrGK.js +240 -0
  297. package/dist/with-auth-CpKqTrGK.js.map +1 -0
  298. package/logos/LUCIDE-ATTRIBUTION.txt +4 -0
  299. package/logos/README.md +89 -0
  300. package/logos/amazon.svg +6 -0
  301. package/logos/artifacts.svg +9 -0
  302. package/logos/browser.svg +9 -0
  303. package/logos/calendar.svg +15 -0
  304. package/logos/cloudflare-browser.svg +5 -0
  305. package/logos/cloudflare-email.svg +5 -0
  306. package/logos/cloudflare.svg +4 -0
  307. package/logos/code-sandbox.svg +8 -0
  308. package/logos/content-type.svg +10 -0
  309. package/logos/crypto.svg +7 -0
  310. package/logos/document-extract.svg +12 -0
  311. package/logos/document-render.svg +8 -0
  312. package/logos/document.svg +10 -0
  313. package/logos/email-message.svg +8 -0
  314. package/logos/email.svg +7 -0
  315. package/logos/file-convert.svg +9 -0
  316. package/logos/files.svg +6 -0
  317. package/logos/gotenberg.svg +340 -0
  318. package/logos/image.svg +8 -0
  319. package/logos/imessage.svg +7 -0
  320. package/logos/katana.svg +13 -0
  321. package/logos/mastra.svg +7 -0
  322. package/logos/messaging.svg +7 -0
  323. package/logos/pack-logos.json +48 -0
  324. package/logos/pdf.svg +10 -0
  325. package/logos/pinecone.svg +25 -0
  326. package/logos/presentation.svg +8 -0
  327. package/logos/qdrant.svg +4 -0
  328. package/logos/queue.svg +11 -0
  329. package/logos/rag.svg +18 -0
  330. package/logos/resend.svg +5 -0
  331. package/logos/scheduler.svg +7 -0
  332. package/logos/skills.svg +10 -0
  333. package/logos/slack.svg +14 -0
  334. package/logos/supabase.svg +4 -0
  335. package/logos/tasks.svg +10 -0
  336. package/logos/teams.svg +6 -0
  337. package/logos/telegram.svg +10 -0
  338. package/logos/textract.svg +5 -0
  339. package/logos/vector-store.svg +8 -0
  340. package/logos/web-fetch.svg +8 -0
  341. package/logos/woocommerce.svg +4 -0
  342. package/package.json +373 -0
@@ -0,0 +1,743 @@
1
+ import { n as isToolError, t as ToolError } from "./errors-DoSpNHvs.js";
2
+ import { n as requireAuth } from "./provider-CgDAlg6K.js";
3
+ import { t as HttpService } from "./http-service-DDNCO1s4.js";
4
+ import { n as bytesToBase64, t as base64ToBytes } from "./bytes-BxpimpQx.js";
5
+ import { isPlainObject, isString } from "es-toolkit";
6
+ import { z } from "zod";
7
+ //#region \0rolldown/runtime.js
8
+ var __defProp = Object.defineProperty;
9
+ var __exportAll = (all, no_symbols) => {
10
+ let target = {};
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
16
+ return target;
17
+ };
18
+ //#endregion
19
+ //#region src/vendors/imessage/contracts.ts
20
+ /**
21
+ * Host auth for Photon iMessage over **gRPC** (Node/Bun only), aligned with spectrum-ts cloud.
22
+ *
23
+ * Two layers (do not conflate):
24
+ * 1. **Spectrum Cloud** — `project_id` + `project_secret` → temporary tokens
25
+ * (`POST /projects/{id}/imessage/tokens`), then gRPC to Photon’s managed hosts.
26
+ * 2. **Direct gRPC** — `address` + temporary `token` when the host already has line credentials
27
+ * (same shape as spectrum-ts explicit `clients[]`).
28
+ *
29
+ * Flat object (not a Zod union) so seams can `.extend` for `provider` / `storage`.
30
+ *
31
+ * @see https://github.com/photon-hq/spectrum-ts/blob/main/packages/imessage/src/auth.ts
32
+ * @see https://github.com/photon-hq/advanced-imessage-ts
33
+ */
34
+ const imessageAuthSchema = z.object({
35
+ /** Spectrum Cloud project id (with project_secret). Preferred production path. */
36
+ project_id: z.string().min(1).optional().describe("Spectrum / Photon project id"),
37
+ project_secret: z.string().min(1).optional().describe("Spectrum / Photon project secret (Basic auth to Spectrum Cloud)"),
38
+ /**
39
+ * gRPC host:port for direct line access (e.g. imessage.spectrum.photon.codes:443 or
40
+ * {instanceId}.imsg.photon.codes:443). Required with `token`; omitted when using Spectrum Cloud
41
+ * (address is derived like spectrum-ts).
42
+ */
43
+ address: z.string().min(1).optional().describe("gRPC host:port for direct Advanced iMessage connection"),
44
+ /** Temporary iMessage bearer (not the project secret). Required for direct gRPC; Spectrum mints this. */
45
+ token: z.string().min(1).optional().describe("Temporary iMessage gRPC bearer token"),
46
+ /**
47
+ * Dedicated instance id. With Spectrum Cloud multi-instance responses, required to pick a line;
48
+ * gRPC address becomes `{server}.imsg.photon.codes:443`.
49
+ */
50
+ server: z.string().min(1).optional().describe("Dedicated iMessage instance id (Spectrum dedicated routing)"),
51
+ spectrum_cloud_url: z.url().optional().describe("Spectrum Cloud origin (default https://spectrum.photon.codes)"),
52
+ /**
53
+ * Override shared gRPC host (spectrum-ts `SPECTRUM_IMESSAGE_ADDRESS`).
54
+ * Default `imessage.spectrum.photon.codes:443`.
55
+ */
56
+ spectrum_imessage_address: z.string().min(1).optional().describe("Shared gRPC host override (default imessage.spectrum.photon.codes:443)"),
57
+ tls: z.boolean().optional().describe("gRPC TLS (default true; set false only for local plaintext)")
58
+ }).superRefine((value, ctx) => {
59
+ const hasProjectId = Boolean(value.project_id);
60
+ if (hasProjectId !== Boolean(value.project_secret)) ctx.addIssue({
61
+ code: "custom",
62
+ message: "project_id and project_secret must be provided together for Spectrum Cloud auth"
63
+ });
64
+ if (hasProjectId) return;
65
+ if (!value.token || !value.address) ctx.addIssue({
66
+ code: "custom",
67
+ message: "Provide project_id + project_secret (Spectrum Cloud) or address + token (direct gRPC, spectrum-ts clients shape)"
68
+ });
69
+ });
70
+ function isImessageSpectrumAuth(auth) {
71
+ return Boolean(auth.project_id && auth.project_secret);
72
+ }
73
+ /** Aliases for hosts that want a named schema export (same base + refine). */
74
+ const imessageSpectrumAuthSchema = imessageAuthSchema;
75
+ const imessageGrpcAuthSchema = imessageAuthSchema;
76
+ /** @deprecated Use imessageGrpcAuthSchema — pack is gRPC-only. */
77
+ const imessageMiddlewareAuthSchema = imessageAuthSchema;
78
+ const imessageChatActionSchema = z.enum([
79
+ "typing",
80
+ "upload_photo",
81
+ "record_video",
82
+ "upload_video",
83
+ "record_voice",
84
+ "upload_voice",
85
+ "upload_document",
86
+ "choose_sticker",
87
+ "find_location",
88
+ "record_video_note",
89
+ "upload_video_note"
90
+ ]);
91
+ const imessageSendTextInputSchema = z.object({
92
+ chat_id: z.string().min(1).describe("iMessage chat guid (e.g. any;-;alice@example.com)"),
93
+ text: z.string().min(1).describe("Message text")
94
+ });
95
+ const imessageMessageOutputSchema = z.object({
96
+ message_id: z.string().min(1).describe("Message guid (provider id for journaling)"),
97
+ space_id: z.string().describe("Chat guid (same as chat_id)")
98
+ });
99
+ const imessageEditTextInputSchema = z.object({
100
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
101
+ message_id: z.string().min(1).describe("Message guid to edit"),
102
+ text: z.string().min(1).describe("Replacement text")
103
+ });
104
+ const imessageSendChatActionInputSchema = z.object({
105
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
106
+ action: imessageChatActionSchema.describe("Chat action; non-typing values map to typing start")
107
+ });
108
+ const imessageSetReactionInputSchema = z.object({
109
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
110
+ message_id: z.string().min(1).describe("Message guid to react to"),
111
+ emoji: z.string().min(1).max(64).describe("Tapback name (love, like, dislike, laugh, emphasize, question) or an emoji character (maps to kind emoji)")
112
+ });
113
+ const imessageUnsendInputSchema = z.object({
114
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
115
+ message_id: z.string().min(1).describe("Message guid to unsend")
116
+ });
117
+ const imessageReadInputSchema = z.object({
118
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
119
+ message_id: z.string().min(1).optional().describe("Optional; Advanced iMessage markRead marks the whole chat (field kept for seam parity)")
120
+ });
121
+ const imessageOkOutputSchema = z.object({
122
+ ok: z.boolean(),
123
+ space_id: z.string().optional()
124
+ });
125
+ const MAX_MEDIA_BYTES = 20 * 1024 * 1024;
126
+ /**
127
+ * Clear a reaction via setReaction(isSet=false).
128
+ * `message_id` is the **target** message guid (not a reaction-message id).
129
+ * `emoji` must match what was set (tapback name or emoji character).
130
+ */
131
+ const imessageClearReactionInputSchema = z.object({
132
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
133
+ message_id: z.string().min(1).describe("Target message guid that was reacted to"),
134
+ emoji: z.string().min(1).max(64).describe("Same tapback name or emoji used when setting the reaction")
135
+ });
136
+ const imessageSendMediaInputSchema = z.object({
137
+ chat_id: z.string().min(1).describe("iMessage chat guid"),
138
+ kind: z.enum(["photo", "document"]).describe("Media kind (presentation)"),
139
+ body_base64: z.string().min(1).describe("File body as base64"),
140
+ file_name: z.string().min(1).describe("File name including extension"),
141
+ caption: z.string().optional().describe("Optional caption sent as a follow-up text message"),
142
+ content_type: z.string().optional().describe("Optional MIME type; inferred from file_name when omitted")
143
+ });
144
+ const imessageDownloadFileInputSchema = z.object({
145
+ file_id: z.string().min(1).describe("Attachment guid (from inbound payload or upload)"),
146
+ file_name: z.string().min(1).optional().describe("Preferred file name for the download result"),
147
+ chat_id: z.string().min(1).optional().describe("Chat guid (optional for attachment download; kept for seam parity)")
148
+ });
149
+ const imessageDownloadFileOutputSchema = z.object({
150
+ file_name: z.string(),
151
+ file_size: z.number().optional(),
152
+ body_base64: z.string().describe("Downloaded file body as base64")
153
+ });
154
+ /**
155
+ * Create (or resolve) a chat via Photon `chats.create`.
156
+ * Host-only proactive / contact-delivery path — not auto-run before sendText.
157
+ * One address = 1:1; two or more = group.
158
+ */
159
+ const imessageEnsureChatInputSchema = z.object({
160
+ addresses: z.array(z.string().min(1)).min(1).describe("Peer phone number(s) or email(s). One address creates a 1:1 chat; two or more create a group"),
161
+ message: z.string().min(1).optional().describe("Optional opening text sent in the same create call"),
162
+ client_message_id: z.string().min(1).optional().describe("Optional idempotency key for chat creation and the optional opening send")
163
+ });
164
+ const imessageEnsureChatOutputSchema = z.object({
165
+ chat_id: z.string().min(1).describe("Chat guid for later send, edit, react, or unsend"),
166
+ message_id: z.string().min(1).optional().describe("Guid of the opening message when message was provided and the server returned one")
167
+ });
168
+ //#endregion
169
+ //#region src/vendors/imessage/domain.ts
170
+ var ImessageClientError = class extends ToolError {
171
+ failureKind;
172
+ constructor(input) {
173
+ super(input.message, {
174
+ code: input.code ?? "upstream",
175
+ retryable: input.failureKind === "outcome_unknown",
176
+ cause: input.cause,
177
+ details: {
178
+ failure_kind: input.failureKind,
179
+ ...input.details
180
+ }
181
+ });
182
+ this.name = "ImessageClientError";
183
+ this.failureKind = input.failureKind;
184
+ }
185
+ };
186
+ function isImessageDefiniteRejection(error) {
187
+ return error instanceof ImessageClientError && error.failureKind === "definite_rejection";
188
+ }
189
+ function isImessageOutcomeUnknown(error) {
190
+ return error instanceof ImessageClientError && error.failureKind === "outcome_unknown";
191
+ }
192
+ /**
193
+ * Map free-form emoji / tapback string to Photon SettableMessageReaction.
194
+ * Known tapback names → kind; anything else → { kind: 'emoji', emoji }.
195
+ */
196
+ function toSettableReaction(emoji) {
197
+ const trimmed = emoji.trim();
198
+ switch (trimmed.toLowerCase()) {
199
+ case "love": return { kind: "love" };
200
+ case "like": return { kind: "like" };
201
+ case "dislike": return { kind: "dislike" };
202
+ case "laugh": return { kind: "laugh" };
203
+ case "emphasize": return { kind: "emphasize" };
204
+ case "question": return { kind: "question" };
205
+ default: return {
206
+ kind: "emoji",
207
+ emoji: trimmed
208
+ };
209
+ }
210
+ }
211
+ function messageToOutput(chatId, message) {
212
+ const space = message.chatGuids && message.chatGuids.length > 0 && message.chatGuids[0] ? message.chatGuids[0] : chatId;
213
+ return {
214
+ message_id: message.guid,
215
+ space_id: space
216
+ };
217
+ }
218
+ /** Decode and size-check media base64 for sendMedia. */
219
+ function decodeMediaBytes(bodyBase64) {
220
+ let bytes;
221
+ try {
222
+ bytes = base64ToBytes(bodyBase64);
223
+ } catch (error) {
224
+ throw new ToolError("Invalid base64 body", {
225
+ code: "bad_input",
226
+ cause: error
227
+ });
228
+ }
229
+ if (bytes.byteLength === 0) throw new ToolError("Media body must not be empty", { code: "bad_input" });
230
+ if (bytes.byteLength > 20971520) throw new ToolError("Media exceeds 20 MiB limit", {
231
+ code: "too_large",
232
+ details: {
233
+ max_bytes: MAX_MEDIA_BYTES,
234
+ content_length: bytes.byteLength
235
+ }
236
+ });
237
+ return bytes;
238
+ }
239
+ function parseDownloadChunks(input, chunks) {
240
+ const parts = [];
241
+ let fileName;
242
+ let totalBytes;
243
+ for (const frame of chunks) {
244
+ if (frame.type === "header" && frame.info) {
245
+ if (frame.info.fileName) fileName = frame.info.fileName;
246
+ if (typeof frame.info.totalBytes === "number") totalBytes = frame.info.totalBytes;
247
+ }
248
+ if (frame.type === "primaryChunk" && frame.data) parts.push(frame.data);
249
+ }
250
+ const total = parts.reduce((n, p) => n + p.byteLength, 0);
251
+ const merged = new Uint8Array(total);
252
+ let offset = 0;
253
+ for (const p of parts) {
254
+ merged.set(p, offset);
255
+ offset += p.byteLength;
256
+ }
257
+ return {
258
+ file_name: input.file_name ?? fileName ?? input.file_id,
259
+ ...totalBytes !== void 0 ? { file_size: totalBytes } : total > 0 ? { file_size: total } : {},
260
+ body_base64: bytesToBase64(merged)
261
+ };
262
+ }
263
+ function errorName(error) {
264
+ return error instanceof Error ? error.name : void 0;
265
+ }
266
+ function sdkCode(error) {
267
+ if (!isPlainObject(error)) return void 0;
268
+ const code = error["code"];
269
+ return typeof code === "string" ? code : void 0;
270
+ }
271
+ function sdkRetryable(error) {
272
+ if (!isPlainObject(error)) return void 0;
273
+ const retryable = error["retryable"];
274
+ return typeof retryable === "boolean" ? retryable : void 0;
275
+ }
276
+ /** Map Photon SDK errors to ImessageClientError (definite vs unknown). */
277
+ function mapSdkError(label, error) {
278
+ if (error instanceof ImessageClientError) throw error;
279
+ if (isToolError(error)) throw error;
280
+ const name = errorName(error);
281
+ if (name === "AuthenticationError") throw new ImessageClientError({
282
+ message: error instanceof Error && error.message || `${label}: authentication failed`,
283
+ failureKind: "definite_rejection",
284
+ code: "bad_auth",
285
+ cause: error
286
+ });
287
+ if (name === "NotFoundError") throw new ImessageClientError({
288
+ message: error instanceof Error && error.message || `${label}: not found`,
289
+ failureKind: "definite_rejection",
290
+ code: "not_found",
291
+ cause: error
292
+ });
293
+ if (name === "ValidationError") throw new ImessageClientError({
294
+ message: error instanceof Error && error.message || `${label}: invalid request`,
295
+ failureKind: "definite_rejection",
296
+ code: "bad_input",
297
+ cause: error
298
+ });
299
+ if (name === "RateLimitError") throw new ImessageClientError({
300
+ message: error instanceof Error && error.message || `${label}: rate limited`,
301
+ failureKind: "outcome_unknown",
302
+ code: "rate_limited",
303
+ cause: error
304
+ });
305
+ if (name === "ConnectionError") throw new ImessageClientError({
306
+ message: error instanceof Error && error.message || `${label}: connection failed`,
307
+ failureKind: "outcome_unknown",
308
+ code: "upstream",
309
+ cause: error
310
+ });
311
+ if (name === "IMessageError" || sdkCode(error) !== void 0) {
312
+ const retryable = sdkRetryable(error) === true;
313
+ throw new ImessageClientError({
314
+ message: error instanceof Error && error.message || `${label} failed`,
315
+ failureKind: retryable ? "outcome_unknown" : "definite_rejection",
316
+ code: "upstream",
317
+ cause: error,
318
+ details: { ...sdkCode(error) && { sdk_code: sdkCode(error) } }
319
+ });
320
+ }
321
+ throw new ImessageClientError({
322
+ message: error instanceof Error ? error.message : `${label} request failed`,
323
+ failureKind: "outcome_unknown",
324
+ cause: error
325
+ });
326
+ }
327
+ //#endregion
328
+ //#region src/vendors/imessage/spectrum-cloud.ts
329
+ /**
330
+ * Spectrum Cloud iMessage token exchange + gRPC host resolution (spectrum-ts cloud path).
331
+ *
332
+ * project_id + project_secret → POST /projects/{id}/imessage/tokens → temporary bearer
333
+ * (+ dedicated instance map) → createGrpcClient({ address, token }).
334
+ *
335
+ * @see https://github.com/photon-hq/spectrum-ts/blob/main/packages/core/src/utils/cloud.ts
336
+ * @see https://github.com/photon-hq/spectrum-ts/blob/main/packages/imessage/src/auth.ts
337
+ */
338
+ const DEFAULT_SPECTRUM_CLOUD_URL = "https://spectrum.photon.codes";
339
+ /**
340
+ * Shared-line gRPC host used by spectrum-ts (`SPECTRUM_IMESSAGE_ADDRESS` override).
341
+ * @see packages/imessage/src/auth.ts in spectrum-ts
342
+ */
343
+ const DEFAULT_SPECTRUM_IMESSAGE_GRPC_ADDRESS = "imessage.spectrum.photon.codes:443";
344
+ /** Refresh when less than this many ms remain (or 10% of TTL, whichever is larger, capped by TTL). */
345
+ const REFRESH_SKEW_MS = 6e4;
346
+ function basicAuthHeader(projectId, projectSecret) {
347
+ const raw = `${projectId}:${projectSecret}`;
348
+ return `Basic ${typeof btoa === "function" ? btoa(raw) : Buffer.from(raw, "utf8").toString("base64")}`;
349
+ }
350
+ function asRecord(value) {
351
+ return isPlainObject(value) ? value : void 0;
352
+ }
353
+ function parseExpiresIn(value) {
354
+ if (typeof value === "number" && Number.isFinite(value) && value > 0) return Math.floor(value);
355
+ if (isString(value) && /^\d+$/.test(value)) {
356
+ const n = Number(value);
357
+ if (n > 0) return n;
358
+ }
359
+ return 3600;
360
+ }
361
+ /**
362
+ * Parse Spectrum Cloud success body (`{ succeed, data }` or bare token payload).
363
+ */
364
+ function parseSpectrumTokenResponse(body) {
365
+ const root = asRecord(body);
366
+ if (!root) throw new ToolError("Spectrum Cloud returned a non-object token response", { code: "upstream" });
367
+ const payload = asRecord(root["data"]) ?? root;
368
+ const type = payload["type"];
369
+ if (type === "shared") {
370
+ const token = payload["token"];
371
+ if (!isString(token) || token.length === 0) throw new ToolError("Spectrum Cloud shared token response missing token", { code: "upstream" });
372
+ return {
373
+ type: "shared",
374
+ token,
375
+ expiresIn: parseExpiresIn(payload["expiresIn"] ?? payload["expires_in"])
376
+ };
377
+ }
378
+ if (type === "dedicated") {
379
+ const authRaw = asRecord(payload["auth"]);
380
+ if (!authRaw) throw new ToolError("Spectrum Cloud dedicated token response missing auth map", { code: "upstream" });
381
+ const auth = {};
382
+ for (const [instanceId, token] of Object.entries(authRaw)) if (isString(token) && token.length > 0) auth[instanceId] = token;
383
+ if (Object.keys(auth).length === 0) throw new ToolError("Spectrum Cloud dedicated token response has no instance tokens", { code: "upstream" });
384
+ const numbersRaw = asRecord(payload["numbers"]);
385
+ const numbers = {};
386
+ if (numbersRaw) for (const [instanceId, phone] of Object.entries(numbersRaw)) numbers[instanceId] = isString(phone) ? phone : null;
387
+ return {
388
+ type: "dedicated",
389
+ auth,
390
+ numbers,
391
+ expiresIn: parseExpiresIn(payload["expiresIn"] ?? payload["expires_in"])
392
+ };
393
+ }
394
+ throw new ToolError("Spectrum Cloud token response missing type shared|dedicated", {
395
+ code: "upstream",
396
+ details: { type: type ?? null }
397
+ });
398
+ }
399
+ /**
400
+ * Map Spectrum token payload + optional preferred instance → session fields for createGrpcClient.
401
+ */
402
+ function resolveSpectrumSession(data, preferredServer) {
403
+ if (data.type === "shared") {
404
+ if (preferredServer) throw new ToolError("Spectrum Cloud returned shared routing; server (dedicated instance id) must be omitted", {
405
+ code: "bad_auth",
406
+ details: { server: preferredServer }
407
+ });
408
+ return {
409
+ type: "shared",
410
+ token: data.token,
411
+ expiresIn: data.expiresIn
412
+ };
413
+ }
414
+ const instanceIds = Object.keys(data.auth);
415
+ const server = preferredServer ?? (instanceIds.length === 1 ? instanceIds[0] : void 0);
416
+ if (!server) throw new ToolError("Spectrum Cloud returned multiple dedicated instances; set auth.server to the instance id", {
417
+ code: "bad_auth",
418
+ details: { instance_ids: instanceIds }
419
+ });
420
+ const token = data.auth[server];
421
+ if (!token) throw new ToolError("Spectrum Cloud dedicated response has no token for auth.server", {
422
+ code: "bad_auth",
423
+ details: {
424
+ server,
425
+ instance_ids: instanceIds
426
+ }
427
+ });
428
+ return {
429
+ type: "dedicated",
430
+ token,
431
+ server,
432
+ expiresIn: data.expiresIn,
433
+ ...Object.keys(data.numbers).length > 0 && { numbers: data.numbers }
434
+ };
435
+ }
436
+ /**
437
+ * gRPC `address` spectrum-ts uses after token mint.
438
+ * - shared → `imessage.spectrum.photon.codes:443` (or `spectrum_imessage_address`)
439
+ * - dedicated → `{instanceId}.imsg.photon.codes:443`
440
+ */
441
+ function spectrumImessageGrpcAddress(session, options = {}) {
442
+ if (session.type === "dedicated" && session.server) return `${session.server}.imsg.photon.codes:443`;
443
+ return options.sharedAddress?.trim() || "imessage.spectrum.photon.codes:443";
444
+ }
445
+ async function issueImessageTokens(auth, options = {}) {
446
+ const http = new HttpService({
447
+ baseURL: (auth.spectrum_cloud_url ?? "https://spectrum.photon.codes").replace(/\/$/, ""),
448
+ headers: {
449
+ Authorization: basicAuthHeader(auth.project_id, auth.project_secret),
450
+ Accept: "application/json"
451
+ },
452
+ label: "Spectrum Cloud",
453
+ ...options.fetch && { fetch: options.fetch },
454
+ ...options.signal && { signal: options.signal }
455
+ });
456
+ const path = `/projects/${encodeURIComponent(auth.project_id)}/imessage/tokens`;
457
+ try {
458
+ const { data } = await http.post(path, void 0, { label: "Spectrum Cloud iMessage tokens" });
459
+ return parseSpectrumTokenResponse(data);
460
+ } catch (error) {
461
+ if (error instanceof ToolError) throw error;
462
+ throw new ToolError("Spectrum Cloud iMessage token exchange failed", {
463
+ code: "upstream",
464
+ cause: error
465
+ });
466
+ }
467
+ }
468
+ /**
469
+ * Caches Spectrum temporary tokens and refreshes before expiry.
470
+ * `getBearer` is safe to pass as createGrpcClient `token: async () => …`.
471
+ */
472
+ var SpectrumImessageTokenSource = class {
473
+ #auth;
474
+ #fetch;
475
+ #signal;
476
+ #session;
477
+ #expiresAtMs = 0;
478
+ #refresh;
479
+ constructor(options) {
480
+ this.#auth = options.auth;
481
+ this.#fetch = options.fetch;
482
+ this.#signal = options.signal;
483
+ }
484
+ /** Dedicated instance id after the first successful mint (undefined for shared). */
485
+ get server() {
486
+ return this.#session?.server;
487
+ }
488
+ /** gRPC host:port for the current session (spectrum-ts routing). */
489
+ get grpcAddress() {
490
+ if (!this.#session) return void 0;
491
+ return spectrumImessageGrpcAddress(this.#session, { sharedAddress: this.#auth.spectrum_imessage_address });
492
+ }
493
+ /** Ensure a session exists; returns routing fields for createGrpcClient. */
494
+ async ensureReady() {
495
+ return this.#refreshIfNeeded();
496
+ }
497
+ /** Temporary bearer for Advanced iMessage gRPC. */
498
+ async getBearer() {
499
+ return (await this.#refreshIfNeeded()).token;
500
+ }
501
+ async #refreshIfNeeded() {
502
+ const now = Date.now();
503
+ if (this.#session && now < this.#expiresAtMs) return this.#session;
504
+ if (!this.#refresh) this.#refresh = this.#mint().then((session) => {
505
+ this.#session = session;
506
+ const skew = Math.min(REFRESH_SKEW_MS, Math.max(5e3, Math.floor(session.expiresIn * 100)));
507
+ this.#expiresAtMs = Date.now() + Math.max(1e3, session.expiresIn * 1e3 - skew);
508
+ return session;
509
+ }).finally(() => {
510
+ this.#refresh = void 0;
511
+ });
512
+ return this.#refresh;
513
+ }
514
+ async #mint() {
515
+ return resolveSpectrumSession(await issueImessageTokens(this.#auth, {
516
+ ...this.#fetch && { fetch: this.#fetch },
517
+ ...this.#signal && { signal: this.#signal }
518
+ }), this.#session?.server ?? this.#auth.server);
519
+ }
520
+ };
521
+ //#endregion
522
+ //#region src/vendors/imessage/client.ts
523
+ var client_exports = /* @__PURE__ */ __exportAll({ ImessageClient: () => ImessageClient });
524
+ var ImessageClient = class ImessageClient {
525
+ #auth;
526
+ #options;
527
+ #im;
528
+ #ready;
529
+ #spectrum;
530
+ #grpcAddress;
531
+ constructor(auth, options = {}) {
532
+ const parsed = imessageAuthSchema.safeParse(auth);
533
+ if (!parsed.success) throw new ToolError("Invalid iMessage auth credentials", {
534
+ code: "bad_auth",
535
+ details: { issues: parsed.error.issues.map((issue) => issue.message) }
536
+ });
537
+ this.#auth = parsed.data;
538
+ this.#options = options;
539
+ }
540
+ static fromContext(ctx) {
541
+ const auth = requireAuth(ctx, imessageAuthSchema);
542
+ return new ImessageClient(auth, {
543
+ ...ctx.fetch && { fetch: ctx.fetch },
544
+ ...ctx.signal && { signal: ctx.signal }
545
+ });
546
+ }
547
+ /**
548
+ * Dedicated instance id after Spectrum mint (undefined for shared / direct gRPC).
549
+ * Available after the first outbound call (or after `ready()`).
550
+ */
551
+ get server() {
552
+ if (this.#spectrum) return this.#spectrum.server;
553
+ if (!isImessageSpectrumAuth(this.#auth)) return this.#auth.server;
554
+ }
555
+ /** Resolved gRPC host:port after `ready()` / first call. */
556
+ get grpcAddress() {
557
+ return this.#grpcAddress ?? this.#spectrum?.grpcAddress;
558
+ }
559
+ /** Resolve Spectrum tokens (if needed) and construct the gRPC SDK client. */
560
+ async ready() {
561
+ await this.#sdk();
562
+ }
563
+ /** Release SDK resources. */
564
+ async close() {
565
+ if (this.#im) await this.#im.close();
566
+ }
567
+ async #sdk() {
568
+ if (this.#im) return this.#im;
569
+ this.#ready ??= this.#createSdk().catch((error) => {
570
+ this.#ready = void 0;
571
+ throw error;
572
+ });
573
+ this.#im = await this.#ready;
574
+ return this.#im;
575
+ }
576
+ async #createSdk() {
577
+ const { createGrpcClient } = await import("@photon-ai/advanced-imessage/grpc");
578
+ const auth = this.#auth;
579
+ const tls = auth.tls !== false;
580
+ if (isImessageSpectrumAuth(auth)) {
581
+ const spectrum = new SpectrumImessageTokenSource({
582
+ auth,
583
+ ...this.#options.fetch && { fetch: this.#options.fetch },
584
+ ...this.#options.signal && { signal: this.#options.signal }
585
+ });
586
+ this.#spectrum = spectrum;
587
+ const address = spectrumImessageGrpcAddress(await spectrum.ensureReady(), { sharedAddress: auth.spectrum_imessage_address });
588
+ this.#grpcAddress = address;
589
+ return createGrpcClient({
590
+ address,
591
+ token: async () => spectrum.getBearer(),
592
+ tls: true,
593
+ autoIdempotency: true,
594
+ retry: true
595
+ });
596
+ }
597
+ const token = auth.token;
598
+ const address = auth.address;
599
+ if (!token || !address) throw new ToolError("iMessage direct gRPC auth requires address and token when Spectrum credentials are omitted", { code: "bad_auth" });
600
+ this.#grpcAddress = address;
601
+ return createGrpcClient({
602
+ address,
603
+ token,
604
+ tls,
605
+ autoIdempotency: true,
606
+ retry: true
607
+ });
608
+ }
609
+ /**
610
+ * Create a chat (1:1 or group) via Photon `chats.create`.
611
+ * Host-only: call once for contact / proactive delivery, store `chat_id`, then sendText.
612
+ * Does **not** run automatically before sendText — most threads already exist from inbound user messages.
613
+ */
614
+ async ensureChat(input) {
615
+ try {
616
+ const created = await (await this.#sdk()).chats.create(input.addresses, {
617
+ ...input.message && { message: input.message },
618
+ ...input.client_message_id && { clientMessageId: input.client_message_id }
619
+ });
620
+ const out = { chat_id: created.chat.guid };
621
+ if (created.initialMessage?.guid) out.message_id = created.initialMessage.guid;
622
+ return out;
623
+ } catch (error) {
624
+ mapSdkError("iMessage ensureChat", error);
625
+ }
626
+ }
627
+ async sendText(input) {
628
+ try {
629
+ const message = await (await this.#sdk()).messages.sendText(input.chat_id, input.text);
630
+ return messageToOutput(input.chat_id, message);
631
+ } catch (error) {
632
+ mapSdkError("iMessage sendText", error);
633
+ }
634
+ }
635
+ async editText(input) {
636
+ try {
637
+ const message = await (await this.#sdk()).messages.edit(input.chat_id, input.message_id, input.text);
638
+ return messageToOutput(input.chat_id, message);
639
+ } catch (error) {
640
+ mapSdkError("iMessage editText", error);
641
+ }
642
+ }
643
+ /**
644
+ * Non-typing chat actions map to typing start (presentation parity with other channels).
645
+ */
646
+ async sendChatAction(input) {
647
+ try {
648
+ await (await this.#sdk()).chats.setTyping(input.chat_id, true);
649
+ } catch (error) {
650
+ mapSdkError("iMessage sendChatAction", error);
651
+ }
652
+ }
653
+ async stopTyping(input) {
654
+ try {
655
+ await (await this.#sdk()).chats.setTyping(input.chat_id, false);
656
+ } catch (error) {
657
+ mapSdkError("iMessage stopTyping", error);
658
+ }
659
+ }
660
+ /**
661
+ * Add a tapback/emoji reaction. Returns the resulting message guid (store for journaling).
662
+ * Clear with clearReaction using the **same target message_id + emoji** (setReaction isSet=false).
663
+ */
664
+ async setReaction(input) {
665
+ try {
666
+ const message = await (await this.#sdk()).messages.setReaction(input.chat_id, input.message_id, toSettableReaction(input.emoji), true);
667
+ return messageToOutput(input.chat_id, message);
668
+ } catch (error) {
669
+ mapSdkError("iMessage setReaction", error);
670
+ }
671
+ }
672
+ /**
673
+ * Remove a reaction. `message_id` is the **target** message; `emoji` must match setReaction.
674
+ */
675
+ async clearReaction(input) {
676
+ try {
677
+ await (await this.#sdk()).messages.setReaction(input.chat_id, input.message_id, toSettableReaction(input.emoji), false);
678
+ } catch (error) {
679
+ mapSdkError("iMessage clearReaction", error);
680
+ }
681
+ }
682
+ async unsend(input) {
683
+ try {
684
+ await (await this.#sdk()).messages.unsend(input.chat_id, input.message_id);
685
+ } catch (error) {
686
+ mapSdkError("iMessage unsend", error);
687
+ }
688
+ }
689
+ /** Mark the chat read (Advanced iMessage marks the whole conversation). */
690
+ async read(input) {
691
+ try {
692
+ await (await this.#sdk()).chats.markRead(input.chat_id);
693
+ } catch (error) {
694
+ mapSdkError("iMessage read", error);
695
+ }
696
+ }
697
+ /**
698
+ * Upload bytes then send attachment by GUID. Optional caption as follow-up text.
699
+ */
700
+ async sendMedia(input) {
701
+ try {
702
+ const im = await this.#sdk();
703
+ const data = decodeMediaBytes(input.body_base64);
704
+ const uploaded = await im.attachments.upload({
705
+ fileName: input.file_name,
706
+ data
707
+ });
708
+ const message = await im.messages.sendAttachment(input.chat_id, uploaded.attachment.guid);
709
+ if (input.caption) await im.messages.sendText(input.chat_id, input.caption);
710
+ return messageToOutput(input.chat_id, message);
711
+ } catch (error) {
712
+ mapSdkError("iMessage sendMedia", error);
713
+ }
714
+ }
715
+ /**
716
+ * Download attachment bytes by attachment guid (`file_id`).
717
+ */
718
+ async downloadFile(input) {
719
+ try {
720
+ const im = await this.#sdk();
721
+ const frames = [];
722
+ for await (const frame of im.attachments.downloadStream(input.file_id)) if (frame.type === "header") frames.push({
723
+ type: "header",
724
+ info: {
725
+ ...frame.info.fileName && { fileName: frame.info.fileName },
726
+ ...typeof frame.info.totalBytes === "number" && { totalBytes: frame.info.totalBytes }
727
+ }
728
+ });
729
+ else if (frame.type === "primaryChunk") frames.push({
730
+ type: "primaryChunk",
731
+ data: frame.data
732
+ });
733
+ return parseDownloadChunks(input, frames);
734
+ } catch (error) {
735
+ mapSdkError("iMessage downloadFile", error);
736
+ }
737
+ }
738
+ async answerCallback(_input) {}
739
+ };
740
+ //#endregion
741
+ export { imessageSetReactionInputSchema as A, imessageMessageOutputSchema as C, imessageSendChatActionInputSchema as D, imessageReadInputSchema as E, imessageUnsendInputSchema as M, isImessageSpectrumAuth as N, imessageSendMediaInputSchema as O, imessageGrpcAuthSchema as S, imessageOkOutputSchema as T, imessageDownloadFileInputSchema as _, SpectrumImessageTokenSource as a, imessageEnsureChatInputSchema as b, resolveSpectrumSession as c, isImessageDefiniteRejection as d, isImessageOutcomeUnknown as f, imessageClearReactionInputSchema as g, imessageAuthSchema as h, DEFAULT_SPECTRUM_IMESSAGE_GRPC_ADDRESS as i, imessageSpectrumAuthSchema as j, imessageSendTextInputSchema as k, spectrumImessageGrpcAddress as l, MAX_MEDIA_BYTES as m, client_exports as n, issueImessageTokens as o, toSettableReaction as p, DEFAULT_SPECTRUM_CLOUD_URL as r, parseSpectrumTokenResponse as s, ImessageClient as t, ImessageClientError as u, imessageDownloadFileOutputSchema as v, imessageMiddlewareAuthSchema as w, imessageEnsureChatOutputSchema as x, imessageEditTextInputSchema as y };
742
+
743
+ //# sourceMappingURL=client-CCKGsTeI.js.map