aimeat 2.0.0 → 2.1.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 (412) hide show
  1. package/dist/locales/en.json +35 -1
  2. package/dist/locales/fi.json +35 -1
  3. package/dist/public/components/LinkPreview.js +101 -0
  4. package/dist/public/components/NotificationBell.js +18 -1
  5. package/dist/public/css/theme.css +57 -7
  6. package/dist/public/css/views/admin.css +8 -1
  7. package/dist/public/css/views/app-grant.css +18 -0
  8. package/dist/public/css/views/inbox.css +46 -0
  9. package/dist/public/css/views/portfolio.css +46 -0
  10. package/dist/public/css/views/profile.css +29 -4
  11. package/dist/public/js/services/apps.js +19 -3
  12. package/dist/public/js/services/messages-ai-prompts.js +38 -0
  13. package/dist/public/js/services/messages.js +26 -4
  14. package/dist/public/js/services/notebook.js +76 -0
  15. package/dist/public/js/services/unfurl.js +43 -0
  16. package/dist/public/lib/samples/LICENSE.md +11 -0
  17. package/dist/public/lib/samples/bass/A1.mp3 +0 -0
  18. package/dist/public/lib/samples/bass/B2.mp3 +0 -0
  19. package/dist/public/lib/samples/bass/D2.mp3 +0 -0
  20. package/dist/public/lib/samples/bass/E1.mp3 +0 -0
  21. package/dist/public/lib/samples/bass/E3.mp3 +0 -0
  22. package/dist/public/lib/samples/bass/G2.mp3 +0 -0
  23. package/dist/public/lib/samples/epiano/C2.mp3 +0 -0
  24. package/dist/public/lib/samples/epiano/C3.mp3 +0 -0
  25. package/dist/public/lib/samples/epiano/C4.mp3 +0 -0
  26. package/dist/public/lib/samples/epiano/C5.mp3 +0 -0
  27. package/dist/public/lib/samples/epiano/C6.mp3 +0 -0
  28. package/dist/public/lib/samples/epiano/G2.mp3 +0 -0
  29. package/dist/public/lib/samples/epiano/G3.mp3 +0 -0
  30. package/dist/public/lib/samples/epiano/G4.mp3 +0 -0
  31. package/dist/public/lib/samples/epiano/G5.mp3 +0 -0
  32. package/dist/public/lib/samples/guitar-steel/A2.mp3 +0 -0
  33. package/dist/public/lib/samples/guitar-steel/A4.mp3 +0 -0
  34. package/dist/public/lib/samples/guitar-steel/B3.mp3 +0 -0
  35. package/dist/public/lib/samples/guitar-steel/D3.mp3 +0 -0
  36. package/dist/public/lib/samples/guitar-steel/E2.mp3 +0 -0
  37. package/dist/public/lib/samples/guitar-steel/E4.mp3 +0 -0
  38. package/dist/public/lib/samples/guitar-steel/E5.mp3 +0 -0
  39. package/dist/public/lib/samples/guitar-steel/G3.mp3 +0 -0
  40. package/dist/public/lib/samples/organ/C2.mp3 +0 -0
  41. package/dist/public/lib/samples/organ/C3.mp3 +0 -0
  42. package/dist/public/lib/samples/organ/C4.mp3 +0 -0
  43. package/dist/public/lib/samples/organ/C5.mp3 +0 -0
  44. package/dist/public/lib/samples/organ/C6.mp3 +0 -0
  45. package/dist/public/lib/samples/organ/G2.mp3 +0 -0
  46. package/dist/public/lib/samples/organ/G3.mp3 +0 -0
  47. package/dist/public/lib/samples/organ/G4.mp3 +0 -0
  48. package/dist/public/lib/samples/organ/G5.mp3 +0 -0
  49. package/dist/public/lib/samples/strings/C2.mp3 +0 -0
  50. package/dist/public/lib/samples/strings/C3.mp3 +0 -0
  51. package/dist/public/lib/samples/strings/C4.mp3 +0 -0
  52. package/dist/public/lib/samples/strings/C5.mp3 +0 -0
  53. package/dist/public/lib/samples/strings/C6.mp3 +0 -0
  54. package/dist/public/lib/samples/strings/G2.mp3 +0 -0
  55. package/dist/public/lib/samples/strings/G3.mp3 +0 -0
  56. package/dist/public/lib/samples/strings/G4.mp3 +0 -0
  57. package/dist/public/lib/samples/strings/G5.mp3 +0 -0
  58. package/dist/public/lib/samples/trumpet/A3.mp3 +0 -0
  59. package/dist/public/lib/samples/trumpet/A4.mp3 +0 -0
  60. package/dist/public/lib/samples/trumpet/A5.mp3 +0 -0
  61. package/dist/public/lib/samples/trumpet/C4.mp3 +0 -0
  62. package/dist/public/lib/samples/trumpet/C5.mp3 +0 -0
  63. package/dist/public/lib/samples/trumpet/E3.mp3 +0 -0
  64. package/dist/public/lib/samples/trumpet/E4.mp3 +0 -0
  65. package/dist/public/lib/samples/trumpet/E5.mp3 +0 -0
  66. package/dist/public/spa.html +2 -0
  67. package/dist/public/views/app-grant.js +24 -4
  68. package/dist/public/views/portfolio.js +61 -6
  69. package/dist/public/views/profile/apps-tab.js +18 -1
  70. package/dist/public/views/profile/inbox-tab/ai-actions.js +86 -0
  71. package/dist/public/views/profile/inbox-tab/components.js +124 -9
  72. package/dist/public/views/profile/inbox-tab/helpers.js +26 -0
  73. package/dist/public/views/profile/inbox-tab/panels.js +18 -3
  74. package/dist/public/views/profile/inbox-tab/use-thread-ux.js +18 -1
  75. package/dist/public/views/profile/inbox-tab.js +46 -49
  76. package/dist/public/views/profile/landing-page.cards.js +7 -0
  77. package/dist/public/views/profile/landing-page.js +12 -1
  78. package/dist/public/views/profile/skills-tab.js +1 -1
  79. package/dist/public/views/public-workspace-viewer.js +1 -1
  80. package/dist/public/views/start.js +2 -1
  81. package/dist/scripts/build-sdk-libs.d.ts +16 -0
  82. package/dist/scripts/build-sdk-libs.d.ts.map +1 -0
  83. package/dist/scripts/build-sdk-libs.js +112 -0
  84. package/dist/scripts/build-sdk-libs.js.map +1 -0
  85. package/dist/src/cli/connect/auth.d.ts +15 -0
  86. package/dist/src/cli/connect/auth.d.ts.map +1 -1
  87. package/dist/src/cli/connect/auth.js +25 -6
  88. package/dist/src/cli/connect/auth.js.map +1 -1
  89. package/dist/src/cli/connect/keychain.d.ts +9 -0
  90. package/dist/src/cli/connect/keychain.d.ts.map +1 -1
  91. package/dist/src/cli/connect/keychain.js +21 -8
  92. package/dist/src/cli/connect/keychain.js.map +1 -1
  93. package/dist/src/cli/connect/mcp/tools/exchange.d.ts +18 -0
  94. package/dist/src/cli/connect/mcp/tools/exchange.d.ts.map +1 -0
  95. package/dist/src/cli/connect/mcp/tools/exchange.js +170 -0
  96. package/dist/src/cli/connect/mcp/tools/exchange.js.map +1 -0
  97. package/dist/src/cli/connect/mcp/tools/index.d.ts.map +1 -1
  98. package/dist/src/cli/connect/mcp/tools/index.js +2 -0
  99. package/dist/src/cli/connect/mcp/tools/index.js.map +1 -1
  100. package/dist/src/cli/connect/tool-call-defs-exchange.d.ts +3 -0
  101. package/dist/src/cli/connect/tool-call-defs-exchange.d.ts.map +1 -0
  102. package/dist/src/cli/connect/tool-call-defs-exchange.js +146 -0
  103. package/dist/src/cli/connect/tool-call-defs-exchange.js.map +1 -0
  104. package/dist/src/cli/connect/tool-call.d.ts.map +1 -1
  105. package/dist/src/cli/connect/tool-call.js +2 -0
  106. package/dist/src/cli/connect/tool-call.js.map +1 -1
  107. package/dist/src/commerce/session-service.d.ts +14 -0
  108. package/dist/src/commerce/session-service.d.ts.map +1 -1
  109. package/dist/src/commerce/session-service.js +1 -1
  110. package/dist/src/commerce/session-service.js.map +1 -1
  111. package/dist/src/data/app-templates/shells.d.ts +7 -3
  112. package/dist/src/data/app-templates/shells.d.ts.map +1 -1
  113. package/dist/src/data/app-templates/shells.js +10 -6
  114. package/dist/src/data/app-templates/shells.js.map +1 -1
  115. package/dist/src/data/appdev-pitfalls.d.ts +2 -0
  116. package/dist/src/data/appdev-pitfalls.d.ts.map +1 -1
  117. package/dist/src/data/appdev-pitfalls.js +24 -1
  118. package/dist/src/data/appdev-pitfalls.js.map +1 -1
  119. package/dist/src/generated/api-types.d.ts +1565 -9
  120. package/dist/src/generated/api-types.d.ts.map +1 -1
  121. package/dist/src/mcp/annotations.d.ts.map +1 -1
  122. package/dist/src/mcp/annotations.js +20 -0
  123. package/dist/src/mcp/annotations.js.map +1 -1
  124. package/dist/src/mcp/apps.d.ts.map +1 -1
  125. package/dist/src/mcp/apps.js +8 -4
  126. package/dist/src/mcp/apps.js.map +1 -1
  127. package/dist/src/mcp/catalog/definitions/exchange.d.ts +18 -0
  128. package/dist/src/mcp/catalog/definitions/exchange.d.ts.map +1 -0
  129. package/dist/src/mcp/catalog/definitions/exchange.js +182 -0
  130. package/dist/src/mcp/catalog/definitions/exchange.js.map +1 -0
  131. package/dist/src/mcp/catalog/definitions.d.ts.map +1 -1
  132. package/dist/src/mcp/catalog/definitions.js +2 -0
  133. package/dist/src/mcp/catalog/definitions.js.map +1 -1
  134. package/dist/src/mcp/catalog/scopes.d.ts.map +1 -1
  135. package/dist/src/mcp/catalog/scopes.js +22 -0
  136. package/dist/src/mcp/catalog/scopes.js.map +1 -1
  137. package/dist/src/mcp/catalog/surfaces.d.ts.map +1 -1
  138. package/dist/src/mcp/catalog/surfaces.js +14 -0
  139. package/dist/src/mcp/catalog/surfaces.js.map +1 -1
  140. package/dist/src/mcp/exchange-run.d.ts +5 -0
  141. package/dist/src/mcp/exchange-run.d.ts.map +1 -0
  142. package/dist/src/mcp/exchange-run.js +226 -0
  143. package/dist/src/mcp/exchange-run.js.map +1 -0
  144. package/dist/src/mcp/exchange.d.ts +5 -0
  145. package/dist/src/mcp/exchange.d.ts.map +1 -0
  146. package/dist/src/mcp/exchange.js +351 -0
  147. package/dist/src/mcp/exchange.js.map +1 -0
  148. package/dist/src/mcp/extensions.d.ts.map +1 -1
  149. package/dist/src/mcp/extensions.js +11 -0
  150. package/dist/src/mcp/extensions.js.map +1 -1
  151. package/dist/src/mcp/index.d.ts.map +1 -1
  152. package/dist/src/mcp/index.js +6 -2
  153. package/dist/src/mcp/index.js.map +1 -1
  154. package/dist/src/models/app-tool-schemas.d.ts +55 -1
  155. package/dist/src/models/app-tool-schemas.d.ts.map +1 -1
  156. package/dist/src/models/app-tool-schemas.js +20 -1
  157. package/dist/src/models/app-tool-schemas.js.map +1 -1
  158. package/dist/src/models/offer-schemas.d.ts +2 -2
  159. package/dist/src/models/schemas.d.ts +1 -0
  160. package/dist/src/models/schemas.d.ts.map +1 -1
  161. package/dist/src/models/schemas.js +3 -0
  162. package/dist/src/models/schemas.js.map +1 -1
  163. package/dist/src/routes/agents/device-auth.d.ts +4 -0
  164. package/dist/src/routes/agents/device-auth.d.ts.map +1 -1
  165. package/dist/src/routes/agents/device-auth.js +19 -4
  166. package/dist/src/routes/agents/device-auth.js.map +1 -1
  167. package/dist/src/routes/app-grants.d.ts +6 -0
  168. package/dist/src/routes/app-grants.d.ts.map +1 -1
  169. package/dist/src/routes/app-grants.js +35 -2
  170. package/dist/src/routes/app-grants.js.map +1 -1
  171. package/dist/src/routes/apps/fork-manage.d.ts.map +1 -1
  172. package/dist/src/routes/apps/fork-manage.js +24 -1
  173. package/dist/src/routes/apps/fork-manage.js.map +1 -1
  174. package/dist/src/routes/apps/publish.d.ts +2 -0
  175. package/dist/src/routes/apps/publish.d.ts.map +1 -1
  176. package/dist/src/routes/apps/publish.js +27 -1
  177. package/dist/src/routes/apps/publish.js.map +1 -1
  178. package/dist/src/routes/apps-cost.d.ts +25 -0
  179. package/dist/src/routes/apps-cost.d.ts.map +1 -0
  180. package/dist/src/routes/apps-cost.js +107 -0
  181. package/dist/src/routes/apps-cost.js.map +1 -0
  182. package/dist/src/routes/exchange-market.d.ts +28 -0
  183. package/dist/src/routes/exchange-market.d.ts.map +1 -0
  184. package/dist/src/routes/exchange-market.js +454 -0
  185. package/dist/src/routes/exchange-market.js.map +1 -0
  186. package/dist/src/routes/exchange.d.ts +33 -0
  187. package/dist/src/routes/exchange.d.ts.map +1 -0
  188. package/dist/src/routes/exchange.js +395 -0
  189. package/dist/src/routes/exchange.js.map +1 -0
  190. package/dist/src/routes/extensions/entitlement-gate.d.ts +33 -0
  191. package/dist/src/routes/extensions/entitlement-gate.d.ts.map +1 -0
  192. package/dist/src/routes/extensions/entitlement-gate.js +143 -0
  193. package/dist/src/routes/extensions/entitlement-gate.js.map +1 -0
  194. package/dist/src/routes/extensions/manifest.d.ts +9 -0
  195. package/dist/src/routes/extensions/manifest.d.ts.map +1 -1
  196. package/dist/src/routes/extensions/manifest.js +33 -1
  197. package/dist/src/routes/extensions/manifest.js.map +1 -1
  198. package/dist/src/routes/extensions/paywall.d.ts.map +1 -1
  199. package/dist/src/routes/extensions/paywall.js +9 -0
  200. package/dist/src/routes/extensions/paywall.js.map +1 -1
  201. package/dist/src/routes/federation-sync/messaging.d.ts.map +1 -1
  202. package/dist/src/routes/federation-sync/messaging.js +3 -1
  203. package/dist/src/routes/federation-sync/messaging.js.map +1 -1
  204. package/dist/src/routes/ghii/recovery.d.ts +2 -0
  205. package/dist/src/routes/ghii/recovery.d.ts.map +1 -1
  206. package/dist/src/routes/ghii/recovery.js +7 -0
  207. package/dist/src/routes/ghii/recovery.js.map +1 -1
  208. package/dist/src/routes/ghii/register-login.d.ts +4 -0
  209. package/dist/src/routes/ghii/register-login.d.ts.map +1 -1
  210. package/dist/src/routes/ghii/register-login.js +45 -22
  211. package/dist/src/routes/ghii/register-login.js.map +1 -1
  212. package/dist/src/routes/ghii/web-verify.d.ts +5 -0
  213. package/dist/src/routes/ghii/web-verify.d.ts.map +1 -1
  214. package/dist/src/routes/ghii/web-verify.js +24 -3
  215. package/dist/src/routes/ghii/web-verify.js.map +1 -1
  216. package/dist/src/routes/libs/sdk-serve.d.ts +11 -0
  217. package/dist/src/routes/libs/sdk-serve.d.ts.map +1 -0
  218. package/dist/src/routes/libs/sdk-serve.js +53 -0
  219. package/dist/src/routes/libs/sdk-serve.js.map +1 -0
  220. package/dist/src/routes/libs.d.ts +7 -1
  221. package/dist/src/routes/libs.d.ts.map +1 -1
  222. package/dist/src/routes/libs.js +65 -146
  223. package/dist/src/routes/libs.js.map +1 -1
  224. package/dist/src/routes/messages.d.ts +3 -0
  225. package/dist/src/routes/messages.d.ts.map +1 -1
  226. package/dist/src/routes/messages.js +9 -0
  227. package/dist/src/routes/messages.js.map +1 -1
  228. package/dist/src/routes/notifications.d.ts +6 -3
  229. package/dist/src/routes/notifications.d.ts.map +1 -1
  230. package/dist/src/routes/notifications.js +32 -3
  231. package/dist/src/routes/notifications.js.map +1 -1
  232. package/dist/src/routes/organisms/workspace-access.d.ts.map +1 -1
  233. package/dist/src/routes/organisms/workspace-access.js +38 -20
  234. package/dist/src/routes/organisms/workspace-access.js.map +1 -1
  235. package/dist/src/routes/unfurl.d.ts +27 -0
  236. package/dist/src/routes/unfurl.d.ts.map +1 -0
  237. package/dist/src/routes/unfurl.js +180 -0
  238. package/dist/src/routes/unfurl.js.map +1 -0
  239. package/dist/src/routes/upload.d.ts +2 -0
  240. package/dist/src/routes/upload.d.ts.map +1 -1
  241. package/dist/src/routes/upload.js +7 -0
  242. package/dist/src/routes/upload.js.map +1 -1
  243. package/dist/src/routes/webmcp.d.ts +3 -0
  244. package/dist/src/routes/webmcp.d.ts.map +1 -1
  245. package/dist/src/routes/webmcp.js +55 -0
  246. package/dist/src/routes/webmcp.js.map +1 -1
  247. package/dist/src/server-bootstrap/routes-loader.d.ts +1 -0
  248. package/dist/src/server-bootstrap/routes-loader.d.ts.map +1 -1
  249. package/dist/src/server-bootstrap/routes-loader.js +8 -0
  250. package/dist/src/server-bootstrap/routes-loader.js.map +1 -1
  251. package/dist/src/services/agent-face.d.ts +10 -2
  252. package/dist/src/services/agent-face.d.ts.map +1 -1
  253. package/dist/src/services/agent-face.js +10 -4
  254. package/dist/src/services/agent-face.js.map +1 -1
  255. package/dist/src/services/app-tool-interfaces.d.ts +37 -0
  256. package/dist/src/services/app-tool-interfaces.d.ts.map +1 -0
  257. package/dist/src/services/app-tool-interfaces.js +101 -0
  258. package/dist/src/services/app-tool-interfaces.js.map +1 -0
  259. package/dist/src/services/build-app-prompt.d.ts +3 -0
  260. package/dist/src/services/build-app-prompt.d.ts.map +1 -1
  261. package/dist/src/services/build-app-prompt.js +12 -1
  262. package/dist/src/services/build-app-prompt.js.map +1 -1
  263. package/dist/src/services/contacts.d.ts +25 -1
  264. package/dist/src/services/contacts.d.ts.map +1 -1
  265. package/dist/src/services/contacts.js +30 -0
  266. package/dist/src/services/contacts.js.map +1 -1
  267. package/dist/src/services/entitlement-money.d.ts +55 -0
  268. package/dist/src/services/entitlement-money.d.ts.map +1 -0
  269. package/dist/src/services/entitlement-money.js +68 -0
  270. package/dist/src/services/entitlement-money.js.map +1 -0
  271. package/dist/src/services/exchange-market.d.ts +247 -0
  272. package/dist/src/services/exchange-market.d.ts.map +1 -0
  273. package/dist/src/services/exchange-market.js +254 -0
  274. package/dist/src/services/exchange-market.js.map +1 -0
  275. package/dist/src/services/exchange-proposals.d.ts +47 -0
  276. package/dist/src/services/exchange-proposals.d.ts.map +1 -0
  277. package/dist/src/services/exchange-proposals.js +71 -0
  278. package/dist/src/services/exchange-proposals.js.map +1 -0
  279. package/dist/src/services/exchange-work.d.ts +30 -0
  280. package/dist/src/services/exchange-work.d.ts.map +1 -0
  281. package/dist/src/services/exchange-work.js +43 -0
  282. package/dist/src/services/exchange-work.js.map +1 -0
  283. package/dist/src/services/message-send.d.ts.map +1 -1
  284. package/dist/src/services/message-send.js +4 -1
  285. package/dist/src/services/message-send.js.map +1 -1
  286. package/dist/src/services/metered-entitlements.d.ts +203 -0
  287. package/dist/src/services/metered-entitlements.d.ts.map +1 -0
  288. package/dist/src/services/metered-entitlements.js +264 -0
  289. package/dist/src/services/metered-entitlements.js.map +1 -0
  290. package/dist/src/services/notify.d.ts +7 -0
  291. package/dist/src/services/notify.d.ts.map +1 -1
  292. package/dist/src/services/notify.js +35 -0
  293. package/dist/src/services/notify.js.map +1 -1
  294. package/dist/src/services/owner-memory.d.ts +16 -0
  295. package/dist/src/services/owner-memory.d.ts.map +1 -1
  296. package/dist/src/services/owner-memory.js +23 -0
  297. package/dist/src/services/owner-memory.js.map +1 -1
  298. package/dist/src/services/owner-provisioning.d.ts +5 -0
  299. package/dist/src/services/owner-provisioning.d.ts.map +1 -1
  300. package/dist/src/services/owner-provisioning.js +20 -2
  301. package/dist/src/services/owner-provisioning.js.map +1 -1
  302. package/dist/src/storage/providers/postgres-kysely/methods/apps.d.ts +1 -0
  303. package/dist/src/storage/providers/postgres-kysely/methods/apps.d.ts.map +1 -1
  304. package/dist/src/storage/providers/postgres-kysely/methods/apps.js +2 -0
  305. package/dist/src/storage/providers/postgres-kysely/methods/apps.js.map +1 -1
  306. package/dist/src/storage/providers/postgres-kysely/methods/identity.d.ts +1 -0
  307. package/dist/src/storage/providers/postgres-kysely/methods/identity.d.ts.map +1 -1
  308. package/dist/src/storage/providers/postgres-kysely/methods/identity.js +4 -0
  309. package/dist/src/storage/providers/postgres-kysely/methods/identity.js.map +1 -1
  310. package/dist/src/storage/providers/postgres-kysely/migrations/0011_unique_verified_email.sql +25 -0
  311. package/dist/src/storage/providers/sqlite/methods/apps.d.ts +1 -0
  312. package/dist/src/storage/providers/sqlite/methods/apps.d.ts.map +1 -1
  313. package/dist/src/storage/providers/sqlite/methods/apps.js +2 -0
  314. package/dist/src/storage/providers/sqlite/methods/apps.js.map +1 -1
  315. package/dist/src/storage/providers/sqlite/methods/identity-nodes.d.ts +1 -0
  316. package/dist/src/storage/providers/sqlite/methods/identity-nodes.d.ts.map +1 -1
  317. package/dist/src/storage/providers/sqlite/methods/identity-nodes.js +4 -0
  318. package/dist/src/storage/providers/sqlite/methods/identity-nodes.js.map +1 -1
  319. package/dist/src/storage/providers/sqlite/schema.d.ts.map +1 -1
  320. package/dist/src/storage/providers/sqlite/schema.js +20 -0
  321. package/dist/src/storage/providers/sqlite/schema.js.map +1 -1
  322. package/dist/src/storage/repositories/app.repository.d.ts +0 -0
  323. package/dist/src/storage/repositories/app.repository.d.ts.map +1 -1
  324. package/dist/src/storage/repositories/identity.repository.d.ts +6 -0
  325. package/dist/src/storage/repositories/identity.repository.d.ts.map +1 -1
  326. package/dist/src/storage/types/apps.d.ts +1 -0
  327. package/dist/src/storage/types/apps.d.ts.map +1 -1
  328. package/dist/src/storage/types/organisms-federation.d.ts +21 -0
  329. package/dist/src/storage/types/organisms-federation.d.ts.map +1 -1
  330. package/dist/src/utils/app-mobile-lint.d.ts +17 -0
  331. package/dist/src/utils/app-mobile-lint.d.ts.map +1 -0
  332. package/dist/src/utils/app-mobile-lint.js +40 -0
  333. package/dist/src/utils/app-mobile-lint.js.map +1 -0
  334. package/dist/static/app-catalog/_template.html +12 -77
  335. package/dist/static/app-catalog/js/apps-io.js +51 -165
  336. package/dist/static/app-catalog/js/cost.js +100 -0
  337. package/dist/static/app-catalog/js/db.js +23 -93
  338. package/dist/static/app-catalog/js/detail.js +158 -24
  339. package/dist/static/app-catalog/js/favorites.js +71 -0
  340. package/dist/static/app-catalog/js/i18n-data.js +90 -16
  341. package/dist/static/app-catalog/js/main.js +23 -103
  342. package/dist/static/app-catalog/js/migrate.js +88 -0
  343. package/dist/static/app-catalog/js/monetize.js +1 -1
  344. package/dist/static/app-catalog/js/promote.js +70 -0
  345. package/dist/static/app-catalog/js/render.js +26 -139
  346. package/dist/static/app-catalog/js/server-io.js +126 -223
  347. package/dist/static/app-catalog/js/settings.js +11 -204
  348. package/dist/static/app-catalog/styles/app-catalog.css +40 -0
  349. package/dist/static/app-catalog.html +790 -912
  350. package/dist/static/sdk-libs/_core/config.js +52 -0
  351. package/dist/static/sdk-libs/_core/http.js +52 -0
  352. package/dist/static/sdk-libs/_core/namespace.js +33 -0
  353. package/dist/static/sdk-libs/_core/sdk-globals.d.ts +50 -0
  354. package/dist/static/sdk-libs/_core/session.js +66 -0
  355. package/dist/static/sdk-libs/agentface/index.js +102 -0
  356. package/dist/static/sdk-libs/agents/index.js +267 -0
  357. package/dist/static/sdk-libs/ai/index.js +153 -0
  358. package/dist/static/sdk-libs/audio/core.js +111 -0
  359. package/dist/static/sdk-libs/audio/index.js +380 -0
  360. package/dist/static/sdk-libs/audio/instruments.js +369 -0
  361. package/dist/static/sdk-libs/auth/config.js +46 -0
  362. package/dist/static/sdk-libs/auth/crypto.js +166 -0
  363. package/dist/static/sdk-libs/auth/events.js +27 -0
  364. package/dist/static/sdk-libs/auth/i18n.js +64 -0
  365. package/dist/static/sdk-libs/auth/index.js +37 -0
  366. package/dist/static/sdk-libs/auth/modal.js +545 -0
  367. package/dist/static/sdk-libs/auth/pill.js +167 -0
  368. package/dist/static/sdk-libs/auth/session.js +792 -0
  369. package/dist/static/sdk-libs/auth/signup.js +232 -0
  370. package/dist/static/sdk-libs/auth/theme.js +96 -0
  371. package/dist/static/sdk-libs/capabilities/index.js +179 -0
  372. package/dist/static/sdk-libs/commerce/index.js +243 -0
  373. package/dist/static/sdk-libs/data/index.js +188 -0
  374. package/dist/static/sdk-libs/dist/aimeat-agentface.js +91 -0
  375. package/dist/static/sdk-libs/dist/aimeat-agents.js +315 -0
  376. package/dist/static/sdk-libs/dist/aimeat-ai.js +168 -0
  377. package/dist/static/sdk-libs/dist/aimeat-audio.js +979 -0
  378. package/dist/static/sdk-libs/dist/aimeat-auth.js +1831 -0
  379. package/dist/static/sdk-libs/dist/aimeat-capabilities.js +177 -0
  380. package/dist/static/sdk-libs/dist/aimeat-commerce.js +265 -0
  381. package/dist/static/sdk-libs/dist/aimeat-data.js +205 -0
  382. package/dist/static/sdk-libs/dist/aimeat-editor.js +299 -0
  383. package/dist/static/sdk-libs/dist/aimeat-header.js +270 -0
  384. package/dist/static/sdk-libs/dist/aimeat-intake.js +94 -0
  385. package/dist/static/sdk-libs/dist/aimeat-live.js +265 -0
  386. package/dist/static/sdk-libs/dist/aimeat-markdown.js +602 -0
  387. package/dist/static/sdk-libs/dist/aimeat-organism.js +394 -0
  388. package/dist/static/sdk-libs/dist/aimeat-portfolio-standalone.js +90 -0
  389. package/dist/static/sdk-libs/dist/aimeat-social.js +157 -0
  390. package/dist/static/sdk-libs/dist/aimeat-speech.js +300 -0
  391. package/dist/static/sdk-libs/dist/aimeat-storage.js +210 -0
  392. package/dist/static/sdk-libs/dist/aimeat-tunnel.js +383 -0
  393. package/dist/static/sdk-libs/dist/aimeat-wallet.js +118 -0
  394. package/dist/static/sdk-libs/dist/aimeat-webmcp.js +187 -0
  395. package/dist/static/sdk-libs/dist/aimeat-work.js +213 -0
  396. package/dist/static/sdk-libs/dist/aimeat-workflows.js +147 -0
  397. package/dist/static/sdk-libs/editor/index.js +229 -0
  398. package/dist/static/sdk-libs/header/index.js +249 -0
  399. package/dist/static/sdk-libs/intake/index.js +75 -0
  400. package/dist/static/sdk-libs/live/index.js +156 -0
  401. package/dist/static/sdk-libs/markdown/index.js +522 -0
  402. package/dist/static/sdk-libs/organism/index.js +381 -0
  403. package/dist/static/sdk-libs/portfolio-standalone/index.js +78 -0
  404. package/dist/static/sdk-libs/social/index.js +140 -0
  405. package/dist/static/sdk-libs/speech/index.js +321 -0
  406. package/dist/static/sdk-libs/storage/index.js +189 -0
  407. package/dist/static/sdk-libs/tunnel/index.js +428 -0
  408. package/dist/static/sdk-libs/wallet/index.js +115 -0
  409. package/dist/static/sdk-libs/webmcp/index.js +185 -0
  410. package/dist/static/sdk-libs/work/index.js +191 -0
  411. package/dist/static/sdk-libs/workflows/index.js +113 -0
  412. package/package.json +5 -2
@@ -0,0 +1,315 @@
1
+ // GENERATED FILE — do not edit directly. Source: src/static/sdk-libs/agents/ (+ _core/).
2
+ // Rebuild: pnpm build:sdk · Served at /v1/libs/aimeat-agents.js (with a per-node config prelude).
3
+ "use strict";
4
+ (() => {
5
+ // src/static/sdk-libs/_core/session.js
6
+ function getSession(libLabel) {
7
+ const auth = window.AIMEAT && window.AIMEAT.auth;
8
+ if (!auth) {
9
+ throw new Error("AIMEAT.auth is required. Include aimeat-auth.js before " + (libLabel || "this library"));
10
+ }
11
+ const s = auth.getSession();
12
+ if (!s) throw new Error("Not logged in. Call AIMEAT.auth.login() first.");
13
+ return s;
14
+ }
15
+ function authFetch(path, opts, libLabel) {
16
+ return getSession(libLabel).fetch(path, opts);
17
+ }
18
+ function makeSession(libLabel) {
19
+ return {
20
+ getSession: () => getSession(libLabel),
21
+ authFetch: (path, opts) => authFetch(path, opts, libLabel)
22
+ };
23
+ }
24
+
25
+ // src/static/sdk-libs/_core/namespace.js
26
+ function namespace() {
27
+ if (!window.AIMEAT) window.AIMEAT = {};
28
+ return window.AIMEAT;
29
+ }
30
+ function attach(key, value) {
31
+ const ns = namespace();
32
+ ns[key] = value;
33
+ return ns;
34
+ }
35
+
36
+ // src/static/sdk-libs/agents/index.js
37
+ var { authFetch: authFetch2 } = makeSession("aimeat-agents.js");
38
+ var enc = encodeURIComponent;
39
+ function unwrap(r, action) {
40
+ if (!r || !r.ok) {
41
+ var err = (
42
+ /** @type {Error & { code?: string }} */
43
+ new Error(r && r.error && r.error.message || action + " failed")
44
+ );
45
+ err.code = r && r.error && r.error.code || "UNKNOWN";
46
+ throw err;
47
+ }
48
+ return r.data;
49
+ }
50
+ var _agentsCache = null;
51
+ var _cancelSetCache = null;
52
+ var agents = {
53
+ /** List the owner's agents. opts.activeOnly filters to ones seen recently.
54
+ * opts.fresh bypasses the 30s cache. */
55
+ async list(opts) {
56
+ var now = Date.now();
57
+ if (!(opts && opts.fresh) && _agentsCache && now - _agentsCache.t < 3e4) return _agentsCache.v;
58
+ var data = unwrap(await authFetch2("/v1/agents"), "list agents");
59
+ var v = data.agents || [];
60
+ _agentsCache = { v, t: now };
61
+ return opts && opts.activeOnly ? v.filter(function(a) {
62
+ return !!a.last_seen;
63
+ }) : v;
64
+ },
65
+ /** One agent by name (or GAII), or null. */
66
+ async get(name) {
67
+ var all = await agents.list();
68
+ return all.find(function(a) {
69
+ return a.name === name || a.gaii === name;
70
+ }) || null;
71
+ },
72
+ /** Commission a task for an agent. Returns the created task ({ id, status, ... }).
73
+ * Created 'queued' by default; task-runner agents auto-activate it. */
74
+ async createTask(name, task) {
75
+ if (!task || !task.description) throw new Error("createTask requires { description }");
76
+ var body = {
77
+ title: task.title || task.description.slice(0, 80),
78
+ description: task.description,
79
+ status: task.status || "queued"
80
+ };
81
+ var data = unwrap(await authFetch2("/v1/agents/" + enc(name) + "/tasks", {
82
+ method: "POST",
83
+ body: JSON.stringify(body)
84
+ }), "create task");
85
+ return data.task;
86
+ },
87
+ /** Get a single task. */
88
+ async getTask(name, id) {
89
+ return unwrap(await authFetch2("/v1/agents/" + enc(name) + "/tasks/" + enc(id)), "get task").task;
90
+ },
91
+ /** List an agent's tasks. opts.status filters (queued|active|done|failed|...). */
92
+ async tasks(name, opts) {
93
+ var q = "?per_page=100" + (opts && opts.status ? "&status=" + enc(opts.status) : "");
94
+ return unwrap(await authFetch2("/v1/agents/" + enc(name) + "/tasks" + q), "list tasks").tasks || [];
95
+ },
96
+ /** The task's event log (oldest-first). */
97
+ async events(name, id) {
98
+ return unwrap(await authFetch2("/v1/agents/" + enc(name) + "/tasks/" + enc(id) + "/events"), "list events").events || [];
99
+ },
100
+ /** Live-watch a task: calls onUpdate(task, events) on every server change
101
+ * (SSE) plus a periodic poll as a safety net. Returns an unsubscribe fn. */
102
+ watch(name, id, onUpdate, opts) {
103
+ var stopped = false, es = null, pollTimer = null, debTimer = null;
104
+ var pollMs = opts && opts.pollMs || 15e3;
105
+ async function refresh() {
106
+ if (stopped) return;
107
+ try {
108
+ var task = await agents.getTask(name, id);
109
+ var events = await agents.events(name, id);
110
+ if (!stopped && typeof onUpdate === "function") onUpdate(task, events);
111
+ } catch {
112
+ }
113
+ }
114
+ function debounced() {
115
+ clearTimeout(debTimer);
116
+ debTimer = setTimeout(refresh, 400);
117
+ }
118
+ refresh();
119
+ pollTimer = setInterval(refresh, pollMs);
120
+ (async function() {
121
+ try {
122
+ var tk = unwrap(await authFetch2("/v1/events/ticket", { method: "POST" }), "open event stream");
123
+ if (stopped || !tk || !tk.ticket) return;
124
+ es = new EventSource("/v1/events?ticket=" + enc(tk.ticket));
125
+ es.onmessage = debounced;
126
+ } catch {
127
+ }
128
+ })();
129
+ return function unsubscribe() {
130
+ stopped = true;
131
+ if (es) {
132
+ try {
133
+ es.close();
134
+ } catch {
135
+ }
136
+ es = null;
137
+ }
138
+ clearInterval(pollTimer);
139
+ clearTimeout(debTimer);
140
+ };
141
+ },
142
+ /** Read the task's published deliverable (task.deliverableKey) from the
143
+ * agent's memory. Returns { key, value } | { key, gone:true } | null. */
144
+ async deliverable(name, id) {
145
+ var task = await agents.getTask(name, id);
146
+ var key = task && task.deliverableKey;
147
+ if (!key) return null;
148
+ var data = unwrap(await authFetch2("/v1/memory?agent=" + enc(task.agentGaii) + "&prefix=" + enc(key) + "&per_page=20"), "read deliverable");
149
+ var items = data.items || [];
150
+ var found = items.find(function(i) {
151
+ return i.key === key;
152
+ });
153
+ return found ? { key, value: found.value } : { key, gone: true };
154
+ },
155
+ /** Read a specific memory entry under an agent's namespace (or null). */
156
+ async memory(name, key) {
157
+ var a = await agents.get(name);
158
+ var gaii = a && a.gaii || name;
159
+ var data = unwrap(await authFetch2("/v1/memory?agent=" + enc(gaii) + "&prefix=" + enc(key) + "&per_page=20"), "read agent memory");
160
+ var items = data.items || [];
161
+ var found = items.find(function(i) {
162
+ return i.key === key;
163
+ });
164
+ return found ? found.value : null;
165
+ },
166
+ /** Agent questions awaiting an answer: outbound option-prompts with no reply
167
+ * yet. Each is { message_id, prompt_id, question, options, allow_other }. */
168
+ async pendingPrompts(name) {
169
+ var data = unwrap(await authFetch2("/v1/agents/" + enc(name) + "/messages?per_page=100"), "list messages");
170
+ var msgs = data.messages || [];
171
+ var answered = {};
172
+ msgs.forEach(function(m) {
173
+ var pa = m.metadata && (m.metadata.promptAnswer || m.metadata.prompt_answer);
174
+ var pid = pa && (pa.promptId || pa.prompt_id);
175
+ if (pid) answered[pid] = true;
176
+ });
177
+ var out = [];
178
+ msgs.forEach(function(m) {
179
+ if (m.direction !== "outbound") return;
180
+ var p = m.metadata && m.metadata.prompt;
181
+ if (!p) return;
182
+ var pid = p.promptId || p.prompt_id;
183
+ if (!pid || answered[pid]) return;
184
+ out.push({
185
+ message_id: m.id,
186
+ prompt_id: pid,
187
+ question: p.question,
188
+ options: p.options || [],
189
+ allow_other: (p.allowOther != null ? p.allowOther : p.allow_other) !== false
190
+ });
191
+ });
192
+ return out;
193
+ },
194
+ /** Answer an agent's option-prompt (owner -> agent). choice is the chosen
195
+ * option text, or free text when is_other is true. */
196
+ async answerPrompt(name, ans) {
197
+ if (!ans || !ans.prompt_id || !ans.choice) throw new Error("answerPrompt requires { prompt_id, choice }");
198
+ return unwrap(await authFetch2("/v1/agents/" + enc(name) + "/messages", {
199
+ method: "POST",
200
+ body: JSON.stringify({
201
+ content: ans.choice,
202
+ direction: "inbound",
203
+ metadata: { prompt_answer: { prompt_id: ans.prompt_id, choice: ans.choice, is_other: !!ans.is_other } }
204
+ })
205
+ }), "answer prompt");
206
+ },
207
+ /** Commission + watch until done/failed/stalled, then resolve
208
+ * { task, deliverable }. Best for task-runner agents (which auto-activate).
209
+ * opts: { onProgress(task, events), timeoutMs, pollMs }. */
210
+ async run(name, task, opts) {
211
+ var created = await agents.createTask(name, task);
212
+ var id = created.id;
213
+ return await new Promise(function(resolve, reject) {
214
+ var done = false, to = null;
215
+ var stop = agents.watch(name, id, async function(t, events) {
216
+ if (opts && opts.onProgress) {
217
+ try {
218
+ opts.onProgress(t, events);
219
+ } catch {
220
+ }
221
+ }
222
+ if (!done && (t.status === "done" || t.status === "failed" || t.status === "stalled")) {
223
+ done = true;
224
+ if (to) clearTimeout(to);
225
+ stop();
226
+ var deliverable = t.status === "done" ? await agents.deliverable(name, id).catch(function() {
227
+ return null;
228
+ }) : null;
229
+ resolve({ task: t, deliverable });
230
+ }
231
+ }, opts);
232
+ if (opts && opts.timeoutMs > 0) {
233
+ to = setTimeout(function() {
234
+ if (!done) {
235
+ done = true;
236
+ stop();
237
+ var e = (
238
+ /** @type {Error & { code?: string, taskId?: string }} */
239
+ new Error("run() timed out")
240
+ );
241
+ e.code = "TIMEOUT";
242
+ e.taskId = id;
243
+ reject(e);
244
+ }
245
+ }, opts.timeoutMs);
246
+ }
247
+ });
248
+ },
249
+ /** Cooperative-cancel a task. Writes a cancel marker the worker daemon
250
+ * honours before its next kickoff (so abandoned/speculative subtasks never
251
+ * start), AND, for immediate effect, natively pauses an active task or
252
+ * deletes a queued one (owner-only ops; best-effort). Returns
253
+ * { marked:true, native:'paused'|'deleted'|null }. */
254
+ async cancelTask(name, taskId, opts) {
255
+ await authFetch2("/v1/memory", { method: "POST", body: JSON.stringify({
256
+ key: "agents.cancel.task." + taskId,
257
+ value: [taskId],
258
+ visibility: "owner"
259
+ }) });
260
+ var native = null;
261
+ try {
262
+ var t = await agents.getTask(name, taskId);
263
+ var st = t && t.status;
264
+ if (st === "active") {
265
+ var r = await authFetch2("/v1/agents/" + enc(name) + "/tasks/" + enc(taskId) + "/pause", { method: "POST" });
266
+ if (r && r.ok) native = "paused";
267
+ } else if (st === "queued" || st === "draft") {
268
+ var r2 = await authFetch2("/v1/agents/" + enc(name) + "/tasks/" + enc(taskId), { method: "DELETE" });
269
+ if (r2 && r2.ok) native = "deleted";
270
+ }
271
+ } catch {
272
+ }
273
+ if (opts && opts.invalidate !== false) _cancelSetCache = null;
274
+ return { marked: true, native };
275
+ },
276
+ /** Cancel a whole run/batch: write one marker listing many task ids
277
+ * (key agents.cancel.run.<run>). Workers union all agents.cancel.* markers. */
278
+ async cancelRun(run, taskIds) {
279
+ if (!run || !Array.isArray(taskIds)) throw new Error("cancelRun requires (run, taskIds[])");
280
+ await authFetch2("/v1/memory", { method: "POST", body: JSON.stringify({
281
+ key: "agents.cancel.run." + run,
282
+ value: taskIds.map(String),
283
+ visibility: "owner"
284
+ }) });
285
+ _cancelSetCache = null;
286
+ return { marked: true, count: taskIds.length };
287
+ },
288
+ /** The set (array) of task ids cancelled via any agents.cancel.* marker
289
+ * visible to the owner. 10s cache. */
290
+ async cancelledTaskIds(opts) {
291
+ var now = Date.now();
292
+ if (!(opts && opts.fresh) && _cancelSetCache && now - _cancelSetCache.t < 1e4) return _cancelSetCache.v;
293
+ var data = unwrap(await authFetch2("/v1/memory?owner_scope=true&prefix=" + enc("agents.cancel.") + "&per_page=100"), "read cancel markers");
294
+ var set = {};
295
+ (data.items || []).forEach(function(it) {
296
+ var v2 = it.value;
297
+ if (Array.isArray(v2)) v2.forEach(function(x) {
298
+ set[String(x)] = true;
299
+ });
300
+ else if (v2 && typeof v2 === "object") Object.keys(v2).forEach(function(k) {
301
+ set[k] = true;
302
+ });
303
+ });
304
+ var v = Object.keys(set);
305
+ _cancelSetCache = { v, t: now };
306
+ return v;
307
+ },
308
+ /** Clear the cached agent list (call after creating/deleting an agent). */
309
+ invalidateCache() {
310
+ _agentsCache = null;
311
+ _cancelSetCache = null;
312
+ }
313
+ };
314
+ attach("agents", agents);
315
+ })();
@@ -0,0 +1,168 @@
1
+ // GENERATED FILE — do not edit directly. Source: src/static/sdk-libs/ai/ (+ _core/).
2
+ // Rebuild: pnpm build:sdk · Served at /v1/libs/aimeat-ai.js (with a per-node config prelude).
3
+ "use strict";
4
+ (() => {
5
+ // src/static/sdk-libs/_core/session.js
6
+ function getSession(libLabel) {
7
+ const auth = window.AIMEAT && window.AIMEAT.auth;
8
+ if (!auth) {
9
+ throw new Error("AIMEAT.auth is required. Include aimeat-auth.js before " + (libLabel || "this library"));
10
+ }
11
+ const s = auth.getSession();
12
+ if (!s) throw new Error("Not logged in. Call AIMEAT.auth.login() first.");
13
+ return s;
14
+ }
15
+ function authFetch(path, opts, libLabel) {
16
+ return getSession(libLabel).fetch(path, opts);
17
+ }
18
+ function makeSession(libLabel) {
19
+ return {
20
+ getSession: () => getSession(libLabel),
21
+ authFetch: (path, opts) => authFetch(path, opts, libLabel)
22
+ };
23
+ }
24
+
25
+ // src/static/sdk-libs/_core/namespace.js
26
+ function namespace() {
27
+ if (!window.AIMEAT) window.AIMEAT = {};
28
+ return window.AIMEAT;
29
+ }
30
+ function attach(key, value) {
31
+ const ns = namespace();
32
+ ns[key] = value;
33
+ return ns;
34
+ }
35
+
36
+ // src/static/sdk-libs/ai/index.js
37
+ var { authFetch: authFetch2 } = makeSession("aimeat-ai.js");
38
+ var _availCache = null;
39
+ var _modelsCache = null;
40
+ var ai = {
41
+ /**
42
+ * Returns true if the user has AI configured (an OpenRouter key, or a keyless
43
+ * self-hosted provider). Cached 60 seconds. Apps should call this before showing
44
+ * "Use AI" buttons. Uses GET /v1/ai/available, which an app-grant token (a sandboxed
45
+ * app on the isolated app origin) can call with the ai:use scope — unlike the
46
+ * owner-only /v1/openrouter/settings. Falls back to that settings probe on older nodes.
47
+ */
48
+ async isAvailable() {
49
+ const now = Date.now();
50
+ if (_availCache && now - _availCache.t < 6e4) return _availCache.v;
51
+ try {
52
+ const r = await authFetch2("/v1/ai/available");
53
+ if (r && r.ok && r.data && typeof r.data.available === "boolean") {
54
+ _availCache = { v: r.data.available, t: now };
55
+ return r.data.available;
56
+ }
57
+ const s = await authFetch2("/v1/openrouter/settings");
58
+ const v = !!(s && s.ok && s.data && (s.data.hasApiKey || s.data.has_api_key));
59
+ _availCache = { v, t: now };
60
+ return v;
61
+ } catch {
62
+ return false;
63
+ }
64
+ },
65
+ /**
66
+ * Run a single completion. Returns { content, model, usage, budget }.
67
+ * Throws an Error with .code set on quota/permission/auth failures.
68
+ *
69
+ * Recognized error codes (see routes/ai.ts):
70
+ * NO_API_KEY — user hasn't set up a key yet
71
+ * QUOTA_EXHAUSTED — daily user budget hit
72
+ * APP_QUOTA_EXHAUSTED — per-app daily quota hit
73
+ * APP_NOT_ALLOWED — app_id not in user's allowlist
74
+ * APP_ID_REQUIRED — user has an allowlist; app must pass app_id
75
+ * INVALID_API_KEY — provider rejected the key
76
+ * RATE_LIMITED — provider rate limit
77
+ * PROVIDER_ERROR — upstream provider failed
78
+ */
79
+ async complete(opts) {
80
+ if (!opts || typeof opts !== "object") throw new Error("opts object required");
81
+ if (!opts.prompt) throw new Error("opts.prompt required");
82
+ const body = {
83
+ prompt: opts.prompt,
84
+ systemPrompt: opts.systemPrompt,
85
+ model: opts.model,
86
+ modelRole: opts.modelRole,
87
+ temperature: opts.temperature,
88
+ top_p: opts.top_p,
89
+ max_tokens: opts.max_tokens,
90
+ app_id: opts.app_id
91
+ };
92
+ const r = await authFetch2("/v1/ai/complete", {
93
+ method: "POST",
94
+ body: JSON.stringify(body)
95
+ });
96
+ if (!r || !r.ok) {
97
+ const code = r && r.error && r.error.code || "UNKNOWN";
98
+ const msg = r && r.error && r.error.message || "AI call failed";
99
+ const err = (
100
+ /** @type {Error & { code?: string }} */
101
+ new Error(msg)
102
+ );
103
+ err.code = code;
104
+ throw err;
105
+ }
106
+ return r.data;
107
+ },
108
+ /**
109
+ * Convenience: complete + JSON.parse. Adds a "return ONLY valid JSON"
110
+ * suffix to systemPrompt. On parse failure, retries ONCE with a stronger
111
+ * instruction. Further failures throw — the user can retry by clicking.
112
+ */
113
+ async completeJson(opts) {
114
+ const suffix = "\nReturn ONLY valid JSON, no prose, no markdown fences.";
115
+ const first = await ai.complete({
116
+ ...opts,
117
+ systemPrompt: (opts.systemPrompt || "") + suffix
118
+ });
119
+ try {
120
+ return { ...first, parsed: JSON.parse(first.content) };
121
+ } catch {
122
+ const retry = await ai.complete({
123
+ ...opts,
124
+ systemPrompt: (opts.systemPrompt || "") + suffix + "\nIMPORTANT: your previous attempt was not valid JSON. Output ONLY the JSON object, starting with { and ending with }. No other text.",
125
+ temperature: typeof opts.temperature === "number" ? Math.max(0, opts.temperature - 0.3) : 0.2
126
+ });
127
+ try {
128
+ return { ...retry, parsed: JSON.parse(retry.content) };
129
+ } catch {
130
+ const err = (
131
+ /** @type {Error & { code?: string }} */
132
+ new Error("AI returned invalid JSON twice. Original response: " + retry.content.slice(0, 200))
133
+ );
134
+ err.code = "JSON_PARSE_FAILED";
135
+ throw err;
136
+ }
137
+ }
138
+ },
139
+ /**
140
+ * List the models the user's account can hit. Cached 1 hour.
141
+ */
142
+ async models() {
143
+ const now = Date.now();
144
+ if (_modelsCache && now - _modelsCache.t < 36e5) return _modelsCache.v;
145
+ const r = await authFetch2("/v1/openrouter/models");
146
+ if (!r || !r.ok) throw new Error(r && r.error && r.error.message || "Failed to list models");
147
+ const v = r.data && r.data.models ? r.data.models : [];
148
+ _modelsCache = { v, t: now };
149
+ return v;
150
+ },
151
+ /**
152
+ * Today's spend snapshot (owner-only). Useful for "AI used: $0.04 / $1.00".
153
+ */
154
+ async usage() {
155
+ const r = await authFetch2("/v1/ai/usage");
156
+ if (!r || !r.ok) throw new Error(r && r.error && r.error.message || "Failed to read usage");
157
+ return r.data;
158
+ },
159
+ /**
160
+ * Clear browser-side caches. Call after the user toggles their key/budget.
161
+ */
162
+ invalidateCache() {
163
+ _availCache = null;
164
+ _modelsCache = null;
165
+ }
166
+ };
167
+ attach("ai", ai);
168
+ })();