agenttwin 0.3.21 → 0.3.22

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 (408) hide show
  1. package/dist/api.js +2113 -609
  2. package/dist/dashboard/assets/dashboard/agent-home.css +7 -7
  3. package/dist/dashboard/assets/dashboard/bay-morning.webp +0 -0
  4. package/dist/dashboard/assets/dashboard/golden-gate-afternoon.webp +0 -0
  5. package/dist/dashboard/assets/dashboard/golden-gate-portrait.webp +0 -0
  6. package/dist/dashboard/assets/dashboard/moonlit-coast.webp +0 -0
  7. package/dist/dashboard/assets/next/static/chunks/5663-403316746afad10e.js +1 -0
  8. package/dist/dashboard/assets/next/static/chunks/app/dashboard/{page-9c11295678539a5f.js → page-0e0392368e0a891e.js} +1 -1
  9. package/dist/dashboard/assets/next/static/chunks/app/docs/[[...slug]]/page-4981ea4966b19e3e.js +1 -0
  10. package/dist/dashboard/assets/next/static/chunks/app/onboarding/page-dd4ac0f5f36e6bfa.js +1 -0
  11. package/dist/dashboard/assets/next/static/chunks/app/v2/dashboard/{page-34574448d210c775.js → page-de0fe6d84be21e6a.js} +1 -1
  12. package/dist/dashboard/assets/next/static/chunks/app/v2/onboarding/page-360cbffc57981f6b.js +1 -0
  13. package/dist/dashboard/assets/next/static/chunks/app/v2/{page-07c8054d57c9089b.js → page-3e86fffabfa87d88.js} +1 -1
  14. package/dist/dashboard/assets/next/static/chunks/{webpack-40324749d289e4a5.js → webpack-be6e526fd530c797.js} +1 -1
  15. package/dist/dashboard/assets/next/static/css/{42045de5f39b50ca.css → 37d81e1d2804cc5f.css} +1 -1
  16. package/dist/dashboard/assets/next/static/css/69ec1bae997c3bb0.css +1 -0
  17. package/dist/dashboard/assets/next/static/css/ad85402a1595e56e.css +1 -0
  18. package/dist/dashboard/assets/next/static/css/{4bbe78c2fe206b92.css → da981fb878a02b8c.css} +1 -1
  19. package/dist/dashboard/assets/next/static/media/bay-morning.82669113.webp +0 -0
  20. package/dist/dashboard/assets/next/static/media/golden-gate-afternoon.0aa49492.webp +0 -0
  21. package/dist/dashboard/assets/next/static/media/golden-gate-portrait.89fc667a.webp +0 -0
  22. package/dist/dashboard/assets/next/static/media/moonlit-coast.09739ef4.webp +0 -0
  23. package/dist/dashboard/index.html +2 -2
  24. package/dist/engine.js +6385 -4973
  25. package/dist/gateway.js +2194 -604
  26. package/dist/twins/catalog.json +6020 -0
  27. package/dist/twins/engine/v2/THIRD-PARTY.txt +25 -0
  28. package/dist/twins/engine/v2/chunks/2CHBP57N.mjs +8 -0
  29. package/dist/twins/engine/v2/chunks/4CPL6MPF.mjs +30 -0
  30. package/dist/twins/engine/v2/chunks/OYLYKZGD.mjs +2 -0
  31. package/dist/twins/engine/v2/chunks/SQSP35HM.mjs +38 -0
  32. package/dist/twins/engine/v2/chunks/YSJQQVUM.mjs +2 -0
  33. package/dist/twins/engine/v2/react-dom_client.mjs +272 -0
  34. package/dist/twins/engine/v2/react-dom_server.mjs +263 -0
  35. package/dist/twins/engine/v2/react.mjs +2 -0
  36. package/dist/twins/engine/v2/react_jsx-runtime.mjs +31 -0
  37. package/dist/twins/engine/v2/volter_world-core.mjs +195 -0
  38. package/dist/twins/engine/v2/volter_world-core_app-route.mjs +2 -0
  39. package/dist/twins/engine/v2/volter_world-core_network-policy.mjs +2 -0
  40. package/dist/twins/engine/v3/THIRD-PARTY.txt +65 -0
  41. package/dist/twins/engine/v3/chunks/2CHBP57N.mjs +8 -0
  42. package/dist/twins/engine/v3/chunks/2YSSPA5O.mjs +65 -0
  43. package/dist/twins/engine/v3/chunks/5PWRY4UK.mjs +154 -0
  44. package/dist/twins/engine/v3/chunks/7XRKSFFJ.mjs +2 -0
  45. package/dist/twins/engine/v3/chunks/AWOWH2H5.mjs +2 -0
  46. package/dist/twins/engine/v3/chunks/C46M5U3Q.mjs +2 -0
  47. package/dist/twins/engine/v3/chunks/MFH2VZPP.mjs +2 -0
  48. package/dist/twins/engine/v3/chunks/MWCO5UV3.mjs +2 -0
  49. package/dist/twins/engine/v3/chunks/N5BL5RDF.mjs +313 -0
  50. package/dist/twins/engine/v3/chunks/O7HGPMXG.mjs +2 -0
  51. package/dist/twins/engine/v3/chunks/OYLYKZGD.mjs +2 -0
  52. package/dist/twins/engine/v3/chunks/PLB7HTON.mjs +8 -0
  53. package/dist/twins/engine/v3/chunks/TY4LDBVH.mjs +7 -0
  54. package/dist/twins/engine/v3/chunks/VDIRUSCM.mjs +2 -0
  55. package/dist/twins/engine/v3/chunks/WGUCFQK6.mjs +2 -0
  56. package/dist/twins/engine/v3/chunks/WPATONSC.mjs +2 -0
  57. package/dist/twins/engine/v3/react_jsx-runtime.mjs +2 -0
  58. package/dist/twins/engine/v3/volter_world-core.mjs +2 -0
  59. package/dist/twins/engine/v3/volter_world-ui.mjs +559 -0
  60. package/dist/twins/packs/ahrefs/LICENSE +202 -0
  61. package/dist/twins/packs/ahrefs/NOTICE +7 -0
  62. package/dist/twins/packs/ahrefs/index.mjs +2 -0
  63. package/dist/twins/packs/ai-gateway/LICENSE +202 -0
  64. package/dist/twins/packs/ai-gateway/NOTICE +7 -0
  65. package/dist/twins/packs/ai-gateway/index.mjs +14 -0
  66. package/dist/twins/packs/airtable/LICENSE +202 -0
  67. package/dist/twins/packs/airtable/NOTICE +7 -0
  68. package/dist/twins/packs/airtable/index.mjs +2 -0
  69. package/dist/twins/packs/algolia/LICENSE +202 -0
  70. package/dist/twins/packs/algolia/NOTICE +7 -0
  71. package/dist/twins/packs/algolia/index.mjs +2 -0
  72. package/dist/twins/packs/ambientcg/LICENSE +202 -0
  73. package/dist/twins/packs/ambientcg/NOTICE +7 -0
  74. package/dist/twins/packs/ambientcg/index.mjs +2 -0
  75. package/dist/twins/packs/anthropic/LICENSE +202 -0
  76. package/dist/twins/packs/anthropic/NOTICE +7 -0
  77. package/dist/twins/packs/anthropic/index.mjs +18 -0
  78. package/dist/twins/packs/assemblyai/LICENSE +202 -0
  79. package/dist/twins/packs/assemblyai/NOTICE +7 -0
  80. package/dist/twins/packs/assemblyai/index.mjs +11 -0
  81. package/dist/twins/packs/aws/LICENSE +202 -0
  82. package/dist/twins/packs/aws/NOTICE +7 -0
  83. package/dist/twins/packs/aws/index.mjs +2 -0
  84. package/dist/twins/packs/azure/LICENSE +202 -0
  85. package/dist/twins/packs/azure/NOTICE +7 -0
  86. package/dist/twins/packs/azure/index.mjs +38 -0
  87. package/dist/twins/packs/azureformrecognizer/LICENSE +202 -0
  88. package/dist/twins/packs/azureformrecognizer/NOTICE +7 -0
  89. package/dist/twins/packs/azureformrecognizer/index.mjs +3 -0
  90. package/dist/twins/packs/bitly/LICENSE +202 -0
  91. package/dist/twins/packs/bitly/NOTICE +7 -0
  92. package/dist/twins/packs/bitly/index.mjs +2 -0
  93. package/dist/twins/packs/bluesky/LICENSE +202 -0
  94. package/dist/twins/packs/bluesky/NOTICE +7 -0
  95. package/dist/twins/packs/bluesky/index.mjs +30 -0
  96. package/dist/twins/packs/calcom/LICENSE +202 -0
  97. package/dist/twins/packs/calcom/NOTICE +7 -0
  98. package/dist/twins/packs/calcom/index.mjs +2 -0
  99. package/dist/twins/packs/clerk/LICENSE +202 -0
  100. package/dist/twins/packs/clerk/NOTICE +7 -0
  101. package/dist/twins/packs/clerk/index.mjs +5 -0
  102. package/dist/twins/packs/cloudflare/LICENSE +202 -0
  103. package/dist/twins/packs/cloudflare/NOTICE +7 -0
  104. package/dist/twins/packs/cloudflare/index.mjs +79 -0
  105. package/dist/twins/packs/cohere/LICENSE +202 -0
  106. package/dist/twins/packs/cohere/NOTICE +7 -0
  107. package/dist/twins/packs/cohere/index.mjs +2 -0
  108. package/dist/twins/packs/datadog/LICENSE +202 -0
  109. package/dist/twins/packs/datadog/NOTICE +7 -0
  110. package/dist/twins/packs/datadog/index.mjs +3 -0
  111. package/dist/twins/packs/deepinfra/LICENSE +202 -0
  112. package/dist/twins/packs/deepinfra/NOTICE +7 -0
  113. package/dist/twins/packs/deepinfra/index.mjs +13 -0
  114. package/dist/twins/packs/deepseek/LICENSE +202 -0
  115. package/dist/twins/packs/deepseek/NOTICE +7 -0
  116. package/dist/twins/packs/deepseek/index.mjs +12 -0
  117. package/dist/twins/packs/discord/LICENSE +202 -0
  118. package/dist/twins/packs/discord/NOTICE +7 -0
  119. package/dist/twins/packs/discord/index.mjs +2 -0
  120. package/dist/twins/packs/duckduckgo/LICENSE +202 -0
  121. package/dist/twins/packs/duckduckgo/NOTICE +7 -0
  122. package/dist/twins/packs/duckduckgo/index.mjs +532 -0
  123. package/dist/twins/packs/dynadot/LICENSE +202 -0
  124. package/dist/twins/packs/dynadot/NOTICE +7 -0
  125. package/dist/twins/packs/dynadot/index.mjs +2 -0
  126. package/dist/twins/packs/e2b/LICENSE +202 -0
  127. package/dist/twins/packs/e2b/NOTICE +7 -0
  128. package/dist/twins/packs/e2b/index.mjs +2 -0
  129. package/dist/twins/packs/elevenlabs/LICENSE +202 -0
  130. package/dist/twins/packs/elevenlabs/NOTICE +7 -0
  131. package/dist/twins/packs/elevenlabs/index.mjs +4 -0
  132. package/dist/twins/packs/expo/LICENSE +202 -0
  133. package/dist/twins/packs/expo/NOTICE +7 -0
  134. package/dist/twins/packs/expo/index.mjs +2 -0
  135. package/dist/twins/packs/fal/LICENSE +202 -0
  136. package/dist/twins/packs/fal/NOTICE +7 -0
  137. package/dist/twins/packs/fal/index.mjs +2 -0
  138. package/dist/twins/packs/figma/LICENSE +202 -0
  139. package/dist/twins/packs/figma/NOTICE +7 -0
  140. package/dist/twins/packs/figma/index.mjs +2 -0
  141. package/dist/twins/packs/firecrawl/LICENSE +202 -0
  142. package/dist/twins/packs/firecrawl/NOTICE +7 -0
  143. package/dist/twins/packs/firecrawl/index.mjs +9 -0
  144. package/dist/twins/packs/fireworks/LICENSE +202 -0
  145. package/dist/twins/packs/fireworks/NOTICE +7 -0
  146. package/dist/twins/packs/fireworks/index.mjs +13 -0
  147. package/dist/twins/packs/fly/LICENSE +202 -0
  148. package/dist/twins/packs/fly/NOTICE +7 -0
  149. package/dist/twins/packs/fly/index.mjs +2 -0
  150. package/dist/twins/packs/gcs/LICENSE +202 -0
  151. package/dist/twins/packs/gcs/NOTICE +7 -0
  152. package/dist/twins/packs/gcs/index.mjs +8 -0
  153. package/dist/twins/packs/gemini/LICENSE +202 -0
  154. package/dist/twins/packs/gemini/NOTICE +7 -0
  155. package/dist/twins/packs/gemini/index.mjs +7 -0
  156. package/dist/twins/packs/github/LICENSE +202 -0
  157. package/dist/twins/packs/github/NOTICE +7 -0
  158. package/dist/twins/packs/github/index.mjs +75153 -0
  159. package/dist/twins/packs/googleads/LICENSE +202 -0
  160. package/dist/twins/packs/googleads/NOTICE +7 -0
  161. package/dist/twins/packs/googleads/index.mjs +3 -0
  162. package/dist/twins/packs/googlemaps/LICENSE +202 -0
  163. package/dist/twins/packs/googlemaps/NOTICE +7 -0
  164. package/dist/twins/packs/googlemaps/index.mjs +2 -0
  165. package/dist/twins/packs/googleoauth/LICENSE +202 -0
  166. package/dist/twins/packs/googleoauth/NOTICE +7 -0
  167. package/dist/twins/packs/googleoauth/index.mjs +2 -0
  168. package/dist/twins/packs/hackernews/LICENSE +202 -0
  169. package/dist/twins/packs/hackernews/NOTICE +7 -0
  170. package/dist/twins/packs/hackernews/index.mjs +35 -0
  171. package/dist/twins/packs/huggingface/LICENSE +202 -0
  172. package/dist/twins/packs/huggingface/NOTICE +7 -0
  173. package/dist/twins/packs/huggingface/index.mjs +9 -0
  174. package/dist/twins/packs/inngest/LICENSE +202 -0
  175. package/dist/twins/packs/inngest/NOTICE +7 -0
  176. package/dist/twins/packs/inngest/index.mjs +2 -0
  177. package/dist/twins/packs/instagram/LICENSE +202 -0
  178. package/dist/twins/packs/instagram/NOTICE +7 -0
  179. package/dist/twins/packs/instagram/index.mjs +2 -0
  180. package/dist/twins/packs/jira/LICENSE +202 -0
  181. package/dist/twins/packs/jira/NOTICE +7 -0
  182. package/dist/twins/packs/jira/index.mjs +2 -0
  183. package/dist/twins/packs/langfuse/LICENSE +202 -0
  184. package/dist/twins/packs/langfuse/NOTICE +7 -0
  185. package/dist/twins/packs/langfuse/index.mjs +2 -0
  186. package/dist/twins/packs/linear/LICENSE +202 -0
  187. package/dist/twins/packs/linear/NOTICE +7 -0
  188. package/dist/twins/packs/linear/index.mjs +52866 -0
  189. package/dist/twins/packs/linkedin/LICENSE +202 -0
  190. package/dist/twins/packs/linkedin/NOTICE +7 -0
  191. package/dist/twins/packs/linkedin/index.mjs +78 -0
  192. package/dist/twins/packs/livekit/LICENSE +202 -0
  193. package/dist/twins/packs/livekit/NOTICE +7 -0
  194. package/dist/twins/packs/livekit/index.mjs +2 -0
  195. package/dist/twins/packs/mailgun/LICENSE +202 -0
  196. package/dist/twins/packs/mailgun/NOTICE +7 -0
  197. package/dist/twins/packs/mailgun/index.mjs +13 -0
  198. package/dist/twins/packs/mapbox/LICENSE +202 -0
  199. package/dist/twins/packs/mapbox/NOTICE +7 -0
  200. package/dist/twins/packs/mapbox/index.mjs +2 -0
  201. package/dist/twins/packs/merge/LICENSE +202 -0
  202. package/dist/twins/packs/merge/NOTICE +7 -0
  203. package/dist/twins/packs/merge/index.mjs +4 -0
  204. package/dist/twins/packs/mistral/LICENSE +202 -0
  205. package/dist/twins/packs/mistral/NOTICE +7 -0
  206. package/dist/twins/packs/mistral/index.mjs +6 -0
  207. package/dist/twins/packs/mixpanel/LICENSE +202 -0
  208. package/dist/twins/packs/mixpanel/NOTICE +8 -0
  209. package/dist/twins/packs/mixpanel/index.mjs +2 -0
  210. package/dist/twins/packs/mongodb/LICENSE +202 -0
  211. package/dist/twins/packs/mongodb/NOTICE +7 -0
  212. package/dist/twins/packs/mongodb/index.mjs +8 -0
  213. package/dist/twins/packs/moonshot/LICENSE +202 -0
  214. package/dist/twins/packs/moonshot/NOTICE +7 -0
  215. package/dist/twins/packs/moonshot/index.mjs +18 -0
  216. package/dist/twins/packs/notion/LICENSE +202 -0
  217. package/dist/twins/packs/notion/NOTICE +7 -0
  218. package/dist/twins/packs/notion/index.mjs +2 -0
  219. package/dist/twins/packs/npm-registry/LICENSE +202 -0
  220. package/dist/twins/packs/npm-registry/NOTICE +7 -0
  221. package/dist/twins/packs/npm-registry/index.mjs +2 -0
  222. package/dist/twins/packs/oa-treasury/LICENSE +202 -0
  223. package/dist/twins/packs/oa-treasury/NOTICE +8 -0
  224. package/dist/twins/packs/oa-treasury/index.mjs +16 -0
  225. package/dist/twins/packs/openai/LICENSE +202 -0
  226. package/dist/twins/packs/openai/NOTICE +7 -0
  227. package/dist/twins/packs/openai/index.mjs +3473 -0
  228. package/dist/twins/packs/openrouter/LICENSE +202 -0
  229. package/dist/twins/packs/openrouter/NOTICE +7 -0
  230. package/dist/twins/packs/openrouter/index.mjs +2 -0
  231. package/dist/twins/packs/openweather/LICENSE +202 -0
  232. package/dist/twins/packs/openweather/NOTICE +7 -0
  233. package/dist/twins/packs/openweather/index.mjs +2 -0
  234. package/dist/twins/packs/paypal/LICENSE +202 -0
  235. package/dist/twins/packs/paypal/NOTICE +7 -0
  236. package/dist/twins/packs/paypal/index.mjs +51 -0
  237. package/dist/twins/packs/pinecone/LICENSE +202 -0
  238. package/dist/twins/packs/pinecone/NOTICE +7 -0
  239. package/dist/twins/packs/pinecone/index.mjs +2 -0
  240. package/dist/twins/packs/plain/LICENSE +202 -0
  241. package/dist/twins/packs/plain/NOTICE +8 -0
  242. package/dist/twins/packs/plain/index.mjs +18426 -0
  243. package/dist/twins/packs/planetscale/LICENSE +202 -0
  244. package/dist/twins/packs/planetscale/NOTICE +7 -0
  245. package/dist/twins/packs/planetscale/index.mjs +18 -0
  246. package/dist/twins/packs/polar/LICENSE +202 -0
  247. package/dist/twins/packs/polar/NOTICE +7 -0
  248. package/dist/twins/packs/polar/index.mjs +2 -0
  249. package/dist/twins/packs/polyhaven/LICENSE +202 -0
  250. package/dist/twins/packs/polyhaven/NOTICE +7 -0
  251. package/dist/twins/packs/polyhaven/index.mjs +3 -0
  252. package/dist/twins/packs/postmark/LICENSE +202 -0
  253. package/dist/twins/packs/postmark/NOTICE +7 -0
  254. package/dist/twins/packs/postmark/index.mjs +12 -0
  255. package/dist/twins/packs/reddit/LICENSE +202 -0
  256. package/dist/twins/packs/reddit/NOTICE +7 -0
  257. package/dist/twins/packs/reddit/index.mjs +324 -0
  258. package/dist/twins/packs/redis/LICENSE +202 -0
  259. package/dist/twins/packs/redis/NOTICE +7 -0
  260. package/dist/twins/packs/redis/index.mjs +2 -0
  261. package/dist/twins/packs/replicate/LICENSE +202 -0
  262. package/dist/twins/packs/replicate/NOTICE +7 -0
  263. package/dist/twins/packs/replicate/index.mjs +2 -0
  264. package/dist/twins/packs/resend/LICENSE +202 -0
  265. package/dist/twins/packs/resend/NOTICE +7 -0
  266. package/dist/twins/packs/resend/index.mjs +139 -0
  267. package/dist/twins/packs/runhuman/LICENSE +202 -0
  268. package/dist/twins/packs/runhuman/NOTICE +7 -0
  269. package/dist/twins/packs/runhuman/index.mjs +3 -0
  270. package/dist/twins/packs/scrapecreators/LICENSE +202 -0
  271. package/dist/twins/packs/scrapecreators/NOTICE +7 -0
  272. package/dist/twins/packs/scrapecreators/index.mjs +2 -0
  273. package/dist/twins/packs/segment/LICENSE +202 -0
  274. package/dist/twins/packs/segment/NOTICE +8 -0
  275. package/dist/twins/packs/segment/index.mjs +2 -0
  276. package/dist/twins/packs/sendblue/LICENSE +202 -0
  277. package/dist/twins/packs/sendblue/NOTICE +7 -0
  278. package/dist/twins/packs/sendblue/index.mjs +2 -0
  279. package/dist/twins/packs/sendgrid/LICENSE +202 -0
  280. package/dist/twins/packs/sendgrid/NOTICE +8 -0
  281. package/dist/twins/packs/sendgrid/index.mjs +4 -0
  282. package/dist/twins/packs/sentry/LICENSE +202 -0
  283. package/dist/twins/packs/sentry/NOTICE +7 -0
  284. package/dist/twins/packs/sentry/index.mjs +5 -0
  285. package/dist/twins/packs/sigstore/LICENSE +202 -0
  286. package/dist/twins/packs/sigstore/NOTICE +7 -0
  287. package/dist/twins/packs/sigstore/index.mjs +12 -0
  288. package/dist/twins/packs/slack/LICENSE +202 -0
  289. package/dist/twins/packs/slack/NOTICE +7 -0
  290. package/dist/twins/packs/slack/index.mjs +66 -0
  291. package/dist/twins/packs/smtp/LICENSE +202 -0
  292. package/dist/twins/packs/smtp/NOTICE +7 -0
  293. package/dist/twins/packs/smtp/index.mjs +3 -0
  294. package/dist/twins/packs/snowflake/LICENSE +202 -0
  295. package/dist/twins/packs/snowflake/NOTICE +8 -0
  296. package/dist/twins/packs/snowflake/index.mjs +30 -0
  297. package/dist/twins/packs/stigg/LICENSE +202 -0
  298. package/dist/twins/packs/stigg/NOTICE +8 -0
  299. package/dist/twins/packs/stigg/index.mjs +22194 -0
  300. package/dist/twins/packs/stream/LICENSE +202 -0
  301. package/dist/twins/packs/stream/NOTICE +7 -0
  302. package/dist/twins/packs/stream/index.mjs +2 -0
  303. package/dist/twins/packs/stripe/LICENSE +202 -0
  304. package/dist/twins/packs/stripe/NOTICE +7 -0
  305. package/dist/twins/packs/stripe/index.mjs +211 -0
  306. package/dist/twins/packs/supabase/LICENSE +202 -0
  307. package/dist/twins/packs/supabase/NOTICE +7 -0
  308. package/dist/twins/packs/supabase/index.mjs +2 -0
  309. package/dist/twins/packs/supermemory/LICENSE +202 -0
  310. package/dist/twins/packs/supermemory/NOTICE +7 -0
  311. package/dist/twins/packs/supermemory/index.mjs +2 -0
  312. package/dist/twins/packs/svix/LICENSE +202 -0
  313. package/dist/twins/packs/svix/NOTICE +7 -0
  314. package/dist/twins/packs/svix/index.mjs +2 -0
  315. package/dist/twins/packs/tavily/LICENSE +202 -0
  316. package/dist/twins/packs/tavily/NOTICE +7 -0
  317. package/dist/twins/packs/tavily/index.mjs +2 -0
  318. package/dist/twins/packs/telegram/LICENSE +202 -0
  319. package/dist/twins/packs/telegram/NOTICE +7 -0
  320. package/dist/twins/packs/telegram/index.mjs +11 -0
  321. package/dist/twins/packs/temporal/LICENSE +202 -0
  322. package/dist/twins/packs/temporal/NOTICE +7 -0
  323. package/dist/twins/packs/temporal/index.mjs +44 -0
  324. package/dist/twins/packs/tiktok/LICENSE +202 -0
  325. package/dist/twins/packs/tiktok/NOTICE +7 -0
  326. package/dist/twins/packs/tiktok/index.mjs +2 -0
  327. package/dist/twins/packs/tinybird/LICENSE +202 -0
  328. package/dist/twins/packs/tinybird/NOTICE +7 -0
  329. package/dist/twins/packs/tinybird/index.mjs +50 -0
  330. package/dist/twins/packs/togetherai/LICENSE +202 -0
  331. package/dist/twins/packs/togetherai/NOTICE +7 -0
  332. package/dist/twins/packs/togetherai/index.mjs +11 -0
  333. package/dist/twins/packs/tremendous/LICENSE +202 -0
  334. package/dist/twins/packs/tremendous/NOTICE +7 -0
  335. package/dist/twins/packs/tremendous/index.mjs +2 -0
  336. package/dist/twins/packs/tripo/LICENSE +202 -0
  337. package/dist/twins/packs/tripo/NOTICE +7 -0
  338. package/dist/twins/packs/tripo/index.mjs +9 -0
  339. package/dist/twins/packs/tunnel/LICENSE +202 -0
  340. package/dist/twins/packs/tunnel/NOTICE +7 -0
  341. package/dist/twins/packs/tunnel/index.mjs +2 -0
  342. package/dist/twins/packs/twelvelabs/LICENSE +202 -0
  343. package/dist/twins/packs/twelvelabs/NOTICE +7 -0
  344. package/dist/twins/packs/twelvelabs/index.mjs +5 -0
  345. package/dist/twins/packs/twilio/LICENSE +202 -0
  346. package/dist/twins/packs/twilio/NOTICE +7 -0
  347. package/dist/twins/packs/twilio/index.mjs +2 -0
  348. package/dist/twins/packs/twitch/LICENSE +202 -0
  349. package/dist/twins/packs/twitch/NOTICE +7 -0
  350. package/dist/twins/packs/twitch/index.mjs +68 -0
  351. package/dist/twins/packs/upstash/LICENSE +202 -0
  352. package/dist/twins/packs/upstash/NOTICE +7 -0
  353. package/dist/twins/packs/upstash/index.mjs +14 -0
  354. package/dist/twins/packs/upstashvector/LICENSE +202 -0
  355. package/dist/twins/packs/upstashvector/NOTICE +7 -0
  356. package/dist/twins/packs/upstashvector/index.mjs +3 -0
  357. package/dist/twins/packs/vercel/LICENSE +202 -0
  358. package/dist/twins/packs/vercel/NOTICE +7 -0
  359. package/dist/twins/packs/vercel/index.mjs +10 -0
  360. package/dist/twins/packs/veriff/LICENSE +202 -0
  361. package/dist/twins/packs/veriff/NOTICE +7 -0
  362. package/dist/twins/packs/veriff/index.mjs +2 -0
  363. package/dist/twins/packs/vgauth/LICENSE +202 -0
  364. package/dist/twins/packs/vgauth/NOTICE +7 -0
  365. package/dist/twins/packs/vgauth/index.mjs +2 -0
  366. package/dist/twins/packs/vital/LICENSE +202 -0
  367. package/dist/twins/packs/vital/NOTICE +7 -0
  368. package/dist/twins/packs/vital/index.mjs +2 -0
  369. package/dist/twins/packs/volteridentity/LICENSE +202 -0
  370. package/dist/twins/packs/volteridentity/NOTICE +7 -0
  371. package/dist/twins/packs/volteridentity/index.mjs +2 -0
  372. package/dist/twins/packs/webrisk/LICENSE +202 -0
  373. package/dist/twins/packs/webrisk/NOTICE +7 -0
  374. package/dist/twins/packs/webrisk/index.mjs +2 -0
  375. package/dist/twins/packs/worldlabs/LICENSE +202 -0
  376. package/dist/twins/packs/worldlabs/NOTICE +7 -0
  377. package/dist/twins/packs/worldlabs/index.mjs +2 -0
  378. package/dist/twins/packs/x/LICENSE +202 -0
  379. package/dist/twins/packs/x/NOTICE +7 -0
  380. package/dist/twins/packs/x/index.mjs +63 -0
  381. package/dist/twins/packs/xai/LICENSE +202 -0
  382. package/dist/twins/packs/xai/NOTICE +7 -0
  383. package/dist/twins/packs/xai/index.mjs +4 -0
  384. package/dist/twins/packs/xidentity/LICENSE +202 -0
  385. package/dist/twins/packs/xidentity/NOTICE +8 -0
  386. package/dist/twins/packs/xidentity/index.mjs +209 -0
  387. package/dist/twins/packs/youtube/LICENSE +202 -0
  388. package/dist/twins/packs/youtube/NOTICE +7 -0
  389. package/dist/twins/packs/youtube/index.mjs +5 -0
  390. package/dist/worker.js +442 -18
  391. package/dist/world-host.js +928 -91
  392. package/package.json +5 -4
  393. package/dist/dashboard/assets/dashboard/bay-morning.png +0 -0
  394. package/dist/dashboard/assets/dashboard/golden-gate-afternoon.png +0 -0
  395. package/dist/dashboard/assets/dashboard/golden-gate-portrait.png +0 -0
  396. package/dist/dashboard/assets/dashboard/moonlit-coast.png +0 -0
  397. package/dist/dashboard/assets/next/static/chunks/2868-424d32cfc8ae81c9.js +0 -1
  398. package/dist/dashboard/assets/next/static/chunks/app/docs/[[...slug]]/page-f9fca2c08f779fa0.js +0 -1
  399. package/dist/dashboard/assets/next/static/chunks/app/onboarding/page-bc480c9258e5cc4d.js +0 -1
  400. package/dist/dashboard/assets/next/static/chunks/app/v2/onboarding/page-f04c0b236abaead3.js +0 -1
  401. package/dist/dashboard/assets/next/static/css/4af3c8ca0da0f48b.css +0 -1
  402. package/dist/dashboard/assets/next/static/css/6b8edde77e493a51.css +0 -1
  403. package/dist/dashboard/assets/next/static/media/bay-morning.1a9f358c.png +0 -0
  404. package/dist/dashboard/assets/next/static/media/golden-gate-afternoon.3e7cea58.png +0 -0
  405. package/dist/dashboard/assets/next/static/media/golden-gate-portrait.7941528f.png +0 -0
  406. package/dist/dashboard/assets/next/static/media/moonlit-coast.bbe901a1.png +0 -0
  407. /package/dist/dashboard/assets/next/static/{5ub3D2yzS8DE7w2qZd1nv → 8f121VqXS9LLPMmYd1SRn}/_buildManifest.js +0 -0
  408. /package/dist/dashboard/assets/next/static/{5ub3D2yzS8DE7w2qZd1nv → 8f121VqXS9LLPMmYd1SRn}/_ssgManifest.js +0 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,8 @@
1
+ @agenttwin/twin-oa-treasury
2
+
3
+ Contains @volter/twin-oa-treasury 0.1.37 by Volter (https://github.com/volter-ai),
4
+ licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ Modified by AgentTwin: bundled and minified into one file; only code reachable from the pack's
7
+ fetch factory is included; shared modules are imported from the AgentTwin twin engine.
8
+ The upstream package declares Apache-2.0 but ships no LICENSE file; LICENSE is the license's standard text.
@@ -0,0 +1,16 @@
1
+ import{createRequire as __atReq}from'node:module';const require=__atReq(import.meta.url);
2
+ import{worldNow as kr}from"../../engine/v2/volter_world-core.mjs";import{applyTwinWrite as sr,projectResources as ar,worldNow as or}from"../../engine/v2/volter_world-core.mjs";var le="twin-admin-token",pe="twin-hmac-secret",fe="twin-webhook-secret";function ee(e){let t="";for(let r of e)t+=String.fromCharCode(r);return btoa(t).replaceAll("+","-").replaceAll("/","_").replaceAll("=","")}function er(e){return ee(new TextEncoder().encode(e))}function tr(e){let t=e.replaceAll("-","+").replaceAll("_","/")+"=".repeat((4-e.length%4)%4),r=atob(t),n=new Uint8Array(r.length);for(let s=0;s<r.length;s++)n[s]=r.charCodeAt(s);return n}async function me(e,t){let r=await crypto.subtle.importKey("raw",new TextEncoder().encode(e),{name:"HMAC",hash:"SHA-256"},!1,["sign"]),n=await crypto.subtle.sign("HMAC",r,new TextEncoder().encode(t));return new Uint8Array(n)}async function ye(e,t){let r=er(JSON.stringify(t));return`${r}.${ee(await me(e,r))}`}async function ge(e,t,r){if(!t)return null;let[n,s,o]=t.split(".");if(!n||!s||o!==void 0)return null;let a=ee(await me(e,n));if(!Je(s,a))return null;let u;try{u=JSON.parse(new TextDecoder().decode(tr(n)))}catch{return null}return!u.run_id||!u.repo||!u.actor||!Array.isArray(u.models)||Date.parse(u.expires_at)<=r?null:u}var Ke=["model","machine-seconds","labor","media","rent","procurement","other"];function he(e){return typeof e=="string"&&Ke.includes(e)}var te="model-proxy",re=/^[a-z0-9][a-z0-9-]{2,39}$/;function ve(e){if(!e)return null;let[t,r,n,s]=e.split(".");return t!=="sup"||!r||!n||s!==void 0||!re.test(r)?null:{id:r,secret:n}}function ne(e,t){let r=2166136261;for(let s=0;s<e.length;s+=1)r^=e.charCodeAt(s),r=Math.imul(r,16777619)>>>0;let n=new Uint8Array(t);for(let s=0;s<t;s+=1)r^=s+2654435769>>>0,r=Math.imul(r,16777619)>>>0,r^=r>>>15,r=Math.imul(r,625341585)>>>0,n[s]=r>>>24&255;return n}function se(e){let t=[...ne(e,16)].map(r=>r.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-4${t.slice(13,16)}-8${t.slice(17,20)}-${t.slice(20,32)}`}function Se(e){return ee(ne(e,32))}function Ve(e){let t="abcdefghijklmnopqrstuvwxyz0123456789",r="sup-";for(let n of ne(e,8))r+=t[n%t.length];return r}async function X(e){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(e));return[...new Uint8Array(t)].map(r=>r.toString(16).padStart(2,"0")).join("")}async function Ze(e,t){return`sha256=${[...await me(e,t)].map(n=>n.toString(16).padStart(2,"0")).join("")}`}async function Te(e,t,r){return r?Je(r,await Ze(e,t)):!1}var ze="ABCDEFGHJKMNPQRSTUVWXYZ23456789";function ke(e){let t=[...ne(e,12)].map(r=>ze[r%ze.length]);return`SPON-${t.slice(0,4).join("")}-${t.slice(4,8).join("")}-${t.slice(8,12).join("")}`}function Je(e,t){let r=new TextEncoder().encode(e),n=new TextEncoder().encode(t),s=Math.max(r.length,n.length),o=r.length^n.length;for(let a=0;a<s;a++)o|=(r[a]??0)^(n[a]??0);return o===0}var Me={mean_usd_cents:50,strength_days:3,var_shape:2,var_scale:2500};function Oe(e,t,r=Me){let n=t.length,s=t.reduce((N,L)=>N+L,0),o=n?s/n:0,a=t.reduce((N,L)=>N+(L-o)**2,0),{mean_usd_cents:u,strength_days:i,var_shape:_,var_scale:c}=r,d=i+n,f=(i*u+s)/d,y=_+n/2,h=c+.5*a+i*n*(o-u)**2/(2*d),R=2*y,T=Math.sqrt(h/(y*d)),G=rr(.9,R),C=Math.max(.1,f-G*T),j=f+G*T,q=e>0;return{burn_per_day_usd_cents:Math.round(f),burn_lo_usd_cents:Math.round(C),burn_hi_usd_cents:Math.round(j),runway_days:q&&f>0?e/f:null,runway_lo_days:q?e/j:null,runway_hi_days:q?e/C:null,days_observed:n,confident:n>=3&&j/C<=4}}function rr(e,t){let r=nr(e);if(!Number.isFinite(t)||t>200)return r;let n=r**3,s=r**5,o=r**7,a=(n+r)/4,u=(5*s+16*n+3*r)/96,i=(3*o+19*s+17*n-15*r)/384;return r+a/t+u/t**2+i/t**3}function nr(e){let t=[-39.69683028665376,220.9460984245205,-275.9285104469687,138.357751867269,-30.66479806614716,2.506628277459239],r=[-54.47609879822406,161.5858368580409,-155.6989798598866,66.80131188771972,-13.28068155288572],n=[-.007784894002430293,-.3223964580411365,-2.400758277161838,-2.549732539343734,4.374664141464968,2.938163982698783],s=[.007784695709041462,.3224671290700398,2.445134137142996,3.754408661907416],o=.02425,a=1-o;if(e<o){let i=Math.sqrt(-2*Math.log(e));return(((((n[0]*i+n[1])*i+n[2])*i+n[3])*i+n[4])*i+n[5])/((((s[0]*i+s[1])*i+s[2])*i+s[3])*i+1)}if(e<=a){let i=e-.5,_=i*i;return(((((t[0]*_+t[1])*_+t[2])*_+t[3])*_+t[4])*_+t[5])*i/(((((r[0]*_+r[1])*_+r[2])*_+r[3])*_+r[4])*_+1)}let u=Math.sqrt(-2*Math.log(1-e));return-(((((n[0]*u+n[1])*u+n[2])*u+n[3])*u+n[4])*u+n[5])/((((s[0]*u+s[1])*u+s[2])*u+s[3])*u+1)}var V=460,be=116,P={bg:"#0d1117",border:"#30363d",track:"#21262d",text:"#e6edf3",muted:"#8b949e",green:"#3fb950",amber:"#d29922",red:"#f85149",gray:"#6e7681"};function Z(e){return`$${(e/100).toFixed(2)}`}function ae(e){return e.replace(/[<>&'"]/g,t=>t==="<"?"&lt;":t===">"?"&gt;":t==="&"?"&amp;":t==="'"?"&apos;":"&quot;")}var xe=e=>e>9999?"9999+":String(Math.max(0,Math.round(e)));function Re(e){let t=e.granted_in_usd_cents-e.granted_out_usd_cents,r=e.balance_usd_cents,n=P.gray,s=0,o,a,u;if(!e.funded||t<=0)o="Not yet funded",a="Sponsor to start funding the agents",u="runway = balance \xF7 a Bayesian estimate of daily spend";else if(e.paused||r<=0)n=P.red,o="Funding needed \u2014 agents paused",a=`${Z(0)} left of ${Z(t)} sponsored`,u="add funds to resume";else{s=Math.max(.02,Math.min(1,r/t)),n=s>.25?P.green:P.amber,o=`${Z(r)} left of ${Z(t)}`;let f=e.runway_days!==null?xe(e.runway_days):"?",y=e.runway_lo_days!==null?xe(e.runway_lo_days):"?",h=e.runway_hi_days!==null?xe(e.runway_hi_days):"?";a=`~${f} days of runway \xB7 ~${Z(e.burn_per_day_usd_cents)}/day`,u=`Bayesian: posterior $/day from ${e.days_observed}d + prior \xB7 80% CI ${y}\u2013${h} days`}let i=16,_=52,c=V-i*2,d=Math.round(c*s);return`<?xml version="1.0" encoding="UTF-8"?>
3
+ <svg xmlns="http://www.w3.org/2000/svg" width="${V}" height="${be}" viewBox="0 0 ${V} ${be}" role="img" aria-label="Funding: ${ae(o)}">
4
+ <rect x="0.5" y="0.5" width="${V-1}" height="${be-1}" rx="11" fill="${P.bg}" stroke="${P.border}"/>
5
+ <circle cx="${i+5}" cy="22" r="5" fill="${n}"/>
6
+ <text x="${i+18}" y="26" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif" font-size="14" font-weight="700" fill="${P.text}">${ae(o)}</text>
7
+ <text x="${V-i}" y="26" text-anchor="end" font-family="-apple-system,BlinkMacSystemFont,Segoe UI,Helvetica,Arial,sans-serif" font-size="11" font-weight="600" fill="${P.muted}">\u26FD funding</text>
8
+ <rect x="${i}" y="${_}" width="${c}" height="12" rx="6" fill="${P.track}"/>
9
+ ${d>0?`<rect x="${i}" y="${_}" width="${d}" height="12" rx="6" fill="${n}"/>`:""}
10
+ <text x="${i}" y="${_+28}" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="11" fill="${P.muted}">${ae(a)}</text>
11
+ <text x="${i}" y="${_+46}" font-family="ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" font-size="9" fill="${P.gray}">${ae(u)}</text>
12
+ </svg>`}var tt="oa-treasury",rt=500,ur=200,ir=200,cr=200,Qe=10*6e4,nt=14;function Ae(e={}){return{max_active_runs_global:10,max_active_runs_per_repo:3,max_active_runs_per_actor:1,max_active_runs_system:4,max_runs_per_repo_per_day:500,max_runs_per_actor_per_day:200,max_runs_per_issue_per_day:50,max_global_daily_usd_cents:5e3,enforce_account_balance:!1,...e}}function _r(e,t){return`${e}:${t}`}function w(e,t){let r=`${e}:`;return ar(tt,t).filter(n=>n.type===e&&n.id.startsWith(r)&&n._deleted!==!0).map(n=>({...n,id:n.id.slice(r.length)}))}function b(e,t,r){return w(e,r).find(n=>n.id===t)}async function $(e,t,r,n,s,o){let u=(b(e,t,s)?.rev??0)+1,{resource:i}=await sr(tt,{operation:n,subjectType:e,subjectId:_r(e,t),fields:{...r,rev:u},occurredAt:new Date(o).toISOString(),actor:{kind:"agent"}},s);return{...i,id:t}}function oe(e,t,r,n,s){let o=new Date(t).toISOString(),a=w(e,r).length;for(let u=a;u<=a+1e3;u+=1){let i=n(`${e}:${o}:${u}`);if(!s(i))return i}throw new Error(`oa-treasury: could not mint a free ${e} id after 1000 ordinals`)}function H(e){return new Date(e).toISOString().slice(0,10)}function et(e){return{day_key:H(e),consumed_usd_cents:0,reserved_usd_cents:0,active_global:0,active_system:0,active_by_repo:{},active_by_actor:{},runs_by_repo_day:{},runs_by_actor_day:{},runs_by_issue_day:{},reservations:{},applied_keys:[],flows:[],total_minted_usd_cents:0}}function O(e){let t=b("rail","global",e);if(!t)return et(0);let r=t.state;return r?structuredClone(r):et(0)}async function A(e,t,r,n){await $("rail","global",{state:e},t,r,n)}function U(e,t){let r=H(t);e.day_key!==r&&(e.day_key=r,e.consumed_usd_cents=0,e.reserved_usd_cents=0,e.runs_by_repo_day={},e.runs_by_actor_day={},e.runs_by_issue_day={},e.reservations={})}function B(e,t){for(let[r,n]of Object.entries(e.reservations))n.expires_at_ms<t&&(e.reserved_usd_cents=Math.max(0,e.reserved_usd_cents-n.amount),delete e.reservations[r])}function st(e,t){let r=O(e);return U(r,t),B(r,t),r}function dr(e,t){return e.applied_keys.includes(t)?!0:(e.applied_keys.push(t),e.applied_keys=e.applied_keys.slice(-rt),!1)}function Ee(e,t){return e.applied_keys.includes(t)}function $e(e,t){e.applied_keys.push(t),e.applied_keys=e.applied_keys.slice(-rt)}function Ue(e,t){e.flows.push(t),e.flows=e.flows.slice(-ur)}function lr(){return{granted_in_usd_cents:0,granted_out_usd_cents:0,consumed_usd_cents:0,daily_spend:{},sponsors:[],sponsors_active:{}}}function ue(e,t){let r=b("account",e,t);if(!r)return;let n=r.state;return n?structuredClone(n):void 0}function x(e,t){return ue(e,t)??lr()}async function E(e,t,r,n,s){await $("account",e,{state:t},r,n,s)}function k(e,t){let r=ue(e,t);return r?r.granted_in_usd_cents-r.granted_out_usd_cents-r.consumed_usd_cents:0}function Y(e,t,r=Date.parse(or())){let n=st(t,r),s=0;for(let o of Object.values(n.reservations))o.account===e&&(s+=o.amount);for(let o of w("reserve",t))o.status==="held"&&o.account===e&&o.expires_at_ms>r&&(s+=o.amount_usd_cents);return s}function ie(e,t){let r=e.findIndex(n=>n.login===t.login);r>=0?e[r]=t:e.push(t)}function pr(e,t,r){e.daily_spend[t]=(e.daily_spend[t]??0)+r;let n=Object.keys(e.daily_spend).sort();for(;n.length>nt;){let s=n.shift();delete e.daily_spend[s]}}function fr(e,t,r,n){e.supplier_spend??={},e.supplier_spend[t]??={},e.supplier_spend[t][r]=(e.supplier_spend[t][r]??0)+n;let s=Object.keys(e.supplier_spend[t]).sort();for(;s.length>90;)delete e.supplier_spend[t][s.shift()]}function Ce(e,t,r,n,s,o){let a=Number.isFinite(n)?Math.max(0,n):0;e.consumed_usd_cents+=a,pr(e,H(o),a),e.last_activity_ms=o,a>0&&(e.consumed_by_category??={},e.consumed_by_category[s.category]=(e.consumed_by_category[s.category]??0)+a,fr(e,s.supplier,H(o),a),Ue(t,{kind:"consume",to:r,amount_usd_cents:a,ts:new Date(o).toISOString(),category:s.category,supplier:s.supplier,item:s.item,issue:s.issue,actor:s.actor,job_ref:s.job_ref,receipt_ref:s.receipt_ref}))}async function J(e,t,r,n,s,o){if(!r||!Number.isFinite(n)||n<=0)return{ok:!1,error:"invalid_amount"};let a=O(e);if(U(a,t),B(a,t),s&&dr(a,s))return{ok:!0,idempotent:!0,account:r,balance_usd_cents:k(r,e)};let u=x(r,e),i=Math.floor(n);return u.granted_in_usd_cents+=i,o?.login&&ie(u.sponsors,o),a.total_minted_usd_cents+=i,Ue(a,{kind:"mint",to:r,amount_usd_cents:i,sponsor_login:o?.login,ts:new Date(t).toISOString()}),await E(r,u,"account.mint",e,t),await A(a,"rail.mint",e,t),{ok:!0,account:r,balance_usd_cents:k(r,e)}}async function Pe(e,t,r,n,s,o){if(!r||!n||r===n||!Number.isFinite(s)||s<=0)return{ok:!1,error:"invalid_grant"};let a=O(e);if(U(a,t),B(a,t),o){if(Ee(a,o))return{ok:!0,idempotent:!0,from_balance_usd_cents:k(r,e),to_balance_usd_cents:k(n,e)};$e(a,o),await A(a,"rail.grant_key",e,t)}if(k(r,e)<s)return{ok:!1,error:"insufficient_balance",from_balance_usd_cents:k(r,e)};let u=x(r,e),i=x(n,e),_=Math.floor(s);u.granted_out_usd_cents+=_,i.granted_in_usd_cents+=_;let c=O(e);return U(c,t),B(c,t),Ue(c,{kind:"grant",from:r,to:n,amount_usd_cents:_,ts:new Date(t).toISOString()}),await E(r,u,"account.grant_out",e,t),await E(n,i,"account.grant_in",e,t),await A(c,"rail.grant",e,t),{ok:!0,from:r,to:n,amount_usd_cents:_,from_balance_usd_cents:k(r,e),to_balance_usd_cents:k(n,e)}}async function at(e,t,r,n){let s=x(r,e),o=Object.values(s.sponsors_active).reduce((u,i)=>u+(i.monthly_usd_cents??0),0);if(o<=0)return{ok:!0,credited:!1,monthly_total_usd_cents:0};let a=await J(e,t,r,o,n);if(a.ok&&!a.idempotent){let u=x(r,e);for(let i of Object.values(u.sponsors_active))ie(u.sponsors,i);await E(r,u,"account.accrue_sponsors",e,t)}return{...a,monthly_total_usd_cents:o}}async function De(e,t,r,n){if(!n?.login)return{ok:!1,error:"invalid_sponsor"};let s=x(r,e),o={...n,monthly_usd_cents:Math.max(0,Math.floor(n.monthly_usd_cents??0))};return s.sponsors_active[n.login]=o,ie(s.sponsors,o),await E(r,s,"account.sponsor_upsert",e,t),{ok:!0,active_sponsors:Object.keys(x(r,e).sponsors_active).length}}async function ot(e,t,r,n){let s=x(r,e);return delete s.sponsors_active[n],await E(r,s,"account.sponsor_remove",e,t),{ok:!0}}async function ut(e,t,r,n,s){if(n!=="listed"&&n!=="hidden"&&n!=="banned")return{ok:!1,error:"invalid_moderation"};let o=x(r,e);return o.moderation=n,s===void 0?delete o.moderation_reason:o.moderation_reason=s,await E(r,o,"account.moderate",e,t),{ok:!0,account:r,moderation:n}}async function it(e,t,r){if(!Number.isFinite(r.amount_usd_cents)||r.amount_usd_cents<=0)return{ok:!1,error:"invalid_amount"};let n=r.code&&String(r.code).trim()||oe("coupon",t,e,ke,o=>b("coupon",o,e)!==void 0);if(b("coupon",n,e))return{ok:!1,error:"coupon_exists"};let s={code:n,amount_usd_cents:Math.floor(r.amount_usd_cents),...r.from!==void 0?{from:r.from}:{},...r.sponsor!==void 0?{sponsor:r.sponsor}:{},...r.expires_at!==void 0?{expires_at:r.expires_at}:{},redeemed_at:null,redeemed_to:null,created_at:new Date(t).toISOString()};return await $("coupon",n,s,"coupon.create",e,t),{ok:!0,coupon:s}}function mr(e){let{rev:t,id:r,...n}=e,s={};for(let[o,a]of Object.entries(n))!o.startsWith("_")&&o!=="type"&&o!=="updatedAt"&&(s[o]=a);return s}function ct(e){return{ok:!0,coupons:w("coupon",e).map(mr)}}async function _t(e,t,r,n){if(!n)return{ok:!1,error:"redeem_account_required"};let s=b("coupon",r,e);if(!s)return{ok:!1,error:"coupon_not_found"};if(s.redeemed_at)return{ok:!1,error:"coupon_already_redeemed"};if(typeof s.expires_at=="string"&&Date.parse(s.expires_at)<=t)return{ok:!1,error:"coupon_expired"};let o=s.amount_usd_cents,a=s.sponsor;if(typeof s.from=="string"&&s.from){let u=await Pe(e,t,s.from,n,o,`coupon:${r}`);if(!u.ok)return u}else await J(e,t,n,o,`coupon:${r}`,a);if(await $("coupon",r,{redeemed_at:new Date(t).toISOString(),redeemed_to:n},"coupon.redeem",e,t),a?.login){let u=x(n,e);ie(u.sponsors,a),await E(n,u,"account.coupon_sponsor",e,t)}return{ok:!0,amount_usd_cents:o,account:n,sponsor:a??null}}function M(e){return{id:e.id,name:e.name,...e.url!==void 0&&e.url!==null?{url:e.url}:{},categories:e.categories,created_at:e.created_at,revoked:!!e.revoked}}async function dt(e,t,r){let n=typeof r.name=="string"?r.name.trim():"",s=Array.isArray(r.categories)?r.categories:[],o=s.filter(he);if(!n||o.length===0||o.length!==s.length)return{ok:!1,error:"invalid_supplier"};let a;if(r.id!==void 0){if(typeof r.id!="string"||!re.test(r.id)||r.id===te)return{ok:!1,error:"invalid_supplier_id"};a=r.id}else a=oe("supplier",t,e,Ve,f=>b("supplier",f,e)!==void 0);if(b("supplier",a,e))return{ok:!1,error:"supplier_exists",id:a};let u=Se(`supplier_secret:${new Date(t).toISOString()}:${a}:0`),i=await X(u),_=typeof r.url=="string"&&r.url?r.url:void 0,c={name:n,..._!==void 0?{url:_}:{},categories:[...new Set(o)],secret_hash:i,created_at:new Date(t).toISOString()},d=await $("supplier",a,c,"supplier.create",e,t);return{ok:!0,supplier:M(d),token:`sup.${a}.${u}`}}function lt(e){return{ok:!0,suppliers:w("supplier",e).map(M)}}async function pt(e,t,r){let n=b("supplier",r,e);if(!n)return{ok:!1,error:"supplier_not_found"};let s=Se(`supplier_secret:${new Date(t).toISOString()}:${r}:${(n.rev??0)+1}`),o=await $("supplier",r,{secret_hash:await X(s)},"supplier.rotate",e,t);return{ok:!0,supplier:M(o),token:`sup.${r}.${s}`}}async function ft(e,t,r){if(!b("supplier",r,e))return{ok:!1,error:"supplier_not_found"};let s=await $("supplier",r,{revoked:!0},"supplier.revoke",e,t);return{ok:!0,supplier:M(s)}}async function mt(e,t,r,n,s,o){if(!r||!n)return{ok:!1,error:"invalid_request"};let a=x(r,e);if(s===null||s===0)return a.supplier_caps&&delete a.supplier_caps[n],await E(r,a,"account.cap_clear",e,t),{ok:!0,account:r,supplier:n,cap:null};if(typeof s!="number"||!Number.isInteger(s)||s<=0)return{ok:!1,error:"invalid_cap"};let u=typeof o=="number"&&Number.isInteger(o)&&o>=1?Math.min(o,90):30;return a.supplier_caps??={},a.supplier_caps[n]={max_usd_cents:s,window_days:u},await E(r,a,"account.cap_set",e,t),{ok:!0,account:r,supplier:n,cap:{max_usd_cents:s,window_days:u}}}function Ie(e,t){if(!t||typeof t.id!="string"||!t.secret_hash)return null;let r=b("supplier",t.id,e);return!r||r.revoked||r.secret_hash!==t.secret_hash?null:r}function yt(e,t={}){return typeof e!="number"||!Number.isInteger(e)||(t.allowZero?e<0:e<=0)?null:e}function z(e){return typeof e!="string"?void 0:e.trim().slice(0,300)||void 0}async function W(e,t){let r=w("reserve",e);for(let s of r)s.status==="held"&&s.expires_at_ms<=t&&await $("reserve",s.id,{status:"expired",closed_at_ms:t},"reserve.expire",e,t);let n=w("reserve",e).filter(s=>s.status!=="held").sort((s,o)=>(s.closed_at_ms??0)-(o.closed_at_ms??0));for(;n.length>ir;){let s=n.shift();await $("reserve",s.id,{_deleted:!0},"reserve.prune",e,t)}}function gt(e,t,r,n,s,o){let a=e.supplier_caps?.[r];if(!a)return null;let u=0;for(let c of w("reserve",o))c.status==="held"&&c.account===t&&c.supplier===r&&(u+=c.amount_usd_cents);let i=new Date(s-(a.window_days-1)*864e5).toISOString().slice(0,10),_=0;for(let[c,d]of Object.entries(e.supplier_spend?.[r]??{}))c>=i&&(_+=d);return u+_+n>a.max_usd_cents?{ok:!1,error:"supplier_cap_exceeded",account:t,supplier:r,max_usd_cents:a.max_usd_cents,window_days:a.window_days,in_flight_usd_cents:u,rolling_spend_usd_cents:_}:null}function ht(e,t){let r=typeof e.account=="string"&&e.account?e.account:null,n=yt(e.amount_usd_cents),s=z(e.item),o=typeof e.key=="string"?e.key.trim():void 0,a=o||void 0,u=e.category;return!r||n===null||!s||t.keyRequired&&(!a||a.length>128)||!t.keyRequired&&a!==void 0&&a.length>128||!he(u)?null:{account:r,amount:n,category:u,item:s,...a?{key:a}:{},...z(e.job_ref)?{job_ref:z(e.job_ref)}:{},...z(e.receipt_ref)?{receipt_ref:z(e.receipt_ref)}:{}}}async function vt(e,t,r,n,s){let o=O(e);U(o,t),await A(o,"rail.rollover",e,t),await W(e,t);let a=ht(s,{keyRequired:!0});if(!a)return{ok:!1,error:"invalid_request"};let u=n.id,i=n.categories;if(!i.includes(a.category))return{ok:!1,error:"category_not_allowed",category:a.category,allowed:i};let _=`supplier:${u}:consume:${a.key}`;if(o=O(e),Ee(o,_))return{ok:!0,idempotent:!0,account:a.account,balance_usd_cents:k(a.account,e)};let c=x(a.account,e);if(c.moderation==="banned")return{ok:!1,error:"account_banned",account:a.account};let d=gt(c,a.account,u,a.amount,t,e);return d||(r.enforce_account_balance&&a.amount>k(a.account,e)-Y(a.account,e,t)?{ok:!1,error:"account_balance_exhausted",account:a.account,balance_usd_cents:k(a.account,e),reserved_usd_cents:Y(a.account,e,t)}:($e(o,_),Ce(c,o,a.account,a.amount,{category:a.category,supplier:u,item:a.item,job_ref:a.job_ref,receipt_ref:a.receipt_ref},t),await E(a.account,c,"account.supplier_consume",e,t),await A(o,"rail.supplier_consume",e,t),{ok:!0,account:a.account,amount_usd_cents:a.amount,category:a.category,balance_usd_cents:k(a.account,e)}))}var yr=604800,gr=3600;function we(e){return{reserve_id:e.id,supplier:e.supplier,account:e.account,amount_usd_cents:e.amount_usd_cents,category:e.category,item:e.item,...e.job_ref!==void 0&&e.job_ref!==null?{job_ref:e.job_ref}:{},...e.receipt_ref!==void 0&&e.receipt_ref!==null?{receipt_ref:e.receipt_ref}:{},status:e.status,created_at:e.created_at,expires_at:new Date(e.expires_at_ms).toISOString(),...e.settled_usd_cents!==void 0&&e.settled_usd_cents!==null?{settled_usd_cents:e.settled_usd_cents}:{}}}async function St(e,t,r,n,s){let o=O(e);U(o,t),await A(o,"rail.rollover",e,t),await W(e,t);let a=ht(s,{keyRequired:!1});if(!a)return{ok:!1,error:"invalid_request"};let u=n.id,i=n.categories;if(!i.includes(a.category))return{ok:!1,error:"category_not_allowed",category:a.category,allowed:i};let _=a.key?`rsv:${u}:${a.key}`:`rsv_${oe("reserve",t,e,se,T=>b("reserve",`rsv_${T}`,e)!==void 0)}`,c=b("reserve",_,e);if(c)return c.status==="held"?{ok:!0,idempotent:!0,...we(c)}:{ok:!1,error:"reserve_closed",reserve_id:_,status:c.status};if(a.key){let T=O(e);if(Ee(T,`supplier:${u}:reserve:${a.key}`))return{ok:!1,error:"reserve_closed",reserve_id:_}}let d=x(a.account,e);if(d.moderation==="banned")return{ok:!1,error:"account_banned",account:a.account};let f=gt(d,a.account,u,a.amount,t,e);if(f)return f;if(r.enforce_account_balance&&a.amount>k(a.account,e)-Y(a.account,e,t))return{ok:!1,error:"account_balance_exhausted",account:a.account,balance_usd_cents:k(a.account,e),reserved_usd_cents:Y(a.account,e,t)};let y=gr;if(s.ttl_seconds!==void 0){if(typeof s.ttl_seconds!="number"||!Number.isInteger(s.ttl_seconds)||s.ttl_seconds<=0)return{ok:!1,error:"invalid_ttl"};y=Math.min(s.ttl_seconds,yr)}if(a.key){let T=O(e);$e(T,`supplier:${u}:reserve:${a.key}`),await A(T,"rail.reserve_key",e,t)}let h={supplier:u,account:a.account,amount_usd_cents:a.amount,category:a.category,item:a.item,...a.job_ref?{job_ref:a.job_ref}:{},status:"held",created_at:new Date(t).toISOString(),expires_at_ms:t+y*1e3,settled_usd_cents:null,closed_at_ms:null,receipt_ref:null},R=await $("reserve",_,h,"reserve.create",e,t);return await E(a.account,x(a.account,e),"account.touch",e,t),{ok:!0,...we(R),spendable_usd_cents:k(a.account,e)-Y(a.account,e,t)}}async function Tt(e,t,r,n){await W(e,t);let s=typeof n.reserve_id=="string"?n.reserve_id:"",o=s?b("reserve",s,e):void 0;if(!o||o.supplier!==r.id)return{ok:!1,error:"reserve_not_found"};if(o.status==="settled")return{ok:!0,idempotent:!0,reserve_id:s,settled_usd_cents:o.settled_usd_cents??0,account:o.account};if(o.status!=="held")return{ok:!1,error:"reserve_closed",reserve_id:s,status:o.status};let a=yt(n.amount_usd_cents,{allowZero:!0});if(a===null)return{ok:!1,error:"invalid_request"};let u=o.amount_usd_cents;if(a>u)return{ok:!1,error:"settle_exceeds_reserve",reserve_id:s,amount_usd_cents:a,reserved_usd_cents:u};let i=z(n.receipt_ref);if(await $("reserve",s,{status:"settled",settled_usd_cents:a,closed_at_ms:t,...i?{receipt_ref:i}:{}},"reserve.settle",e,t),a>0){let _=o.account,c=x(_,e),d=O(e);U(d,t),B(d,t),Ce(c,d,_,a,{category:o.category,supplier:r.id,item:o.item,job_ref:o.job_ref??void 0,receipt_ref:i},t),await E(_,c,"account.settle",e,t),await A(d,"rail.settle",e,t)}return{ok:!0,reserve_id:s,account:o.account,settled_usd_cents:a,released_usd_cents:u-a,balance_usd_cents:k(o.account,e)}}async function kt(e,t,r,n){await W(e,t);let s=n?b("reserve",n,e):void 0;return!s||s.supplier!==r.id?{ok:!1,error:"reserve_not_found"}:s.status!=="held"?{ok:!0,idempotent:!0,reserve_id:n,status:s.status}:(await $("reserve",n,{status:"released",closed_at_ms:t},"reserve.release",e,t),{ok:!0,reserve_id:n,status:"released",released_usd_cents:s.amount_usd_cents})}async function bt(e,t,r,n){await W(e,t);let s=n?b("reserve",n,e):void 0;return!s||s.supplier!==r.id?{ok:!1,error:"reserve_not_found"}:{ok:!0,...we(s)}}function D(e,t){let r=b("run",e,t);if(!r)return;let n=r.state;return n?structuredClone(n):void 0}async function I(e,t,r,n,s){t.run_updated_at=new Date(s).toISOString(),await $("run",e,{state:t},r,n,s)}function xt(e,t){return`run_${oe("run",t,e,se,r=>b("run",`run_${r}`,e)!==void 0)}`}var hr=new Set(["agent","review","triage"]);async function Ot(e,t,r){let n=D(r.run_id,e);if(n?.claims)return{ok:!1,error:"run_already_exists"};let s=n?{...n,claims:r,created_at:new Date(t).toISOString()}:{claims:r,revoked:!1,consumed_usd_cents:0,reserved_usd_cents:0,request_count:0,reservations:{},events:[],session:null,created_at:new Date(t).toISOString(),run_updated_at:new Date(t).toISOString(),active:!1,system:!1,started_at_ms:t};return await I(r.run_id,s,"run.init",e,t),{ok:!0}}function Rt(e,t,r){let n=[];for(let s of w("run",t)){let o=s.state;if(!o?.active)continue;let a=Date.parse(o.claims.expires_at);Number.isFinite(a)&&a<=r&&(Ne(e,o),n.push(s.id))}return n}function Ne(e,t){t.active&&(t.active=!1,t.system?e.active_system=Math.max(0,e.active_system-1):(e.active_global=Math.max(0,e.active_global-1),e.active_by_repo[t.claims.repo]=Math.max(0,(e.active_by_repo[t.claims.repo]??0)-1),e.active_by_actor[t.claims.actor]=Math.max(0,(e.active_by_actor[t.claims.actor]??0)-1)))}async function wt(e,t,r,n){let s=O(e);U(s,t);let o=Rt(s,e,t);for(let f of o){let y=D(f,e);y&&(y.active=!1,await I(f,y,"run.reap",e,t))}if(D(r.run_id,e)?.registered)return{ok:!1,error:"run_already_registered"};let u=!hr.has(r.purpose??"agent");if(u){if(s.active_system>=n.max_active_runs_system)return{ok:!1,error:"system_active_run_limit_reached"}}else{if(s.active_global>=n.max_active_runs_global)return{ok:!1,error:"global_active_run_limit_reached"};if((s.active_by_repo[r.repo]??0)>=n.max_active_runs_per_repo)return{ok:!1,error:"repo_active_run_limit_reached"};if((s.active_by_actor[r.actor]??0)>=n.max_active_runs_per_actor)return{ok:!1,error:"actor_active_run_limit_reached"};if((s.runs_by_repo_day[r.repo]??0)>=n.max_runs_per_repo_per_day)return{ok:!1,error:"repo_daily_run_limit_reached"};if((s.runs_by_actor_day[r.actor]??0)>=n.max_runs_per_actor_per_day)return{ok:!1,error:"actor_daily_run_limit_reached"};let f=`${r.repo}#${r.issue}`;if((s.runs_by_issue_day[f]??0)>=n.max_runs_per_issue_per_day)return{ok:!1,error:"issue_daily_run_limit_reached"}}if(ue(r.repo,e)?.moderation==="banned")return{ok:!1,error:"account_banned",account:r.repo};if(n.enforce_account_balance&&k(r.repo,e)<=0)return{ok:!1,error:"account_unfunded",account:r.repo,balance_usd_cents:k(r.repo,e)};let _=x(r.repo,e);_.last_activity_ms=t,u?s.active_system+=1:(s.active_global+=1,s.active_by_repo[r.repo]=(s.active_by_repo[r.repo]??0)+1,s.active_by_actor[r.actor]=(s.active_by_actor[r.actor]??0)+1),s.runs_by_repo_day[r.repo]=(s.runs_by_repo_day[r.repo]??0)+1,s.runs_by_actor_day[r.actor]=(s.runs_by_actor_day[r.actor]??0)+1;let c=`${r.repo}#${r.issue}`;s.runs_by_issue_day[c]=(s.runs_by_issue_day[c]??0)+1;let d=D(r.run_id,e)??{claims:void 0,revoked:!1,consumed_usd_cents:0,reserved_usd_cents:0,request_count:0,reservations:{},events:[],session:null,created_at:new Date(t).toISOString(),run_updated_at:new Date(t).toISOString(),active:!1,system:!1,started_at_ms:t};return d.active=!0,d.system=u,d.started_at_ms=t,d.registered=!0,await I(r.run_id,d,"run.register",e,t),await E(r.repo,_,"account.run_register",e,t),await A(s,"rail.register",e,t),{ok:!0}}async function At(e,t,r){let n=D(r,e);if(n?.active){let s=O(e);Ne(s,n),await I(r,n,"run.complete",e,t),await A(s,"rail.complete",e,t)}return{ok:!0}}async function Fe(e,t,r){let n=D(r,e);if(n)n.revoked=!0,await I(r,n,"run.revoke",e,t);else{let s={claims:void 0,revoked:!0,consumed_usd_cents:0,reserved_usd_cents:0,request_count:0,reservations:{},events:[],session:null,created_at:new Date(t).toISOString(),run_updated_at:new Date(t).toISOString(),active:!1,system:!1,started_at_ms:t};await I(r,s,"run.revoke",e,t)}return await At(e,t,r),{ok:!0,run_id:r}}function K(e,t,r){let n=D(r,e);if(!n){let s=new Date(t).toISOString();return{claims:null,revoked:!1,consumed_usd_cents:0,reserved_usd_cents:0,request_count:0,recent_events:[],session:null,created_at:s,updated_at:s}}return{claims:n.claims??null,revoked:n.revoked,consumed_usd_cents:n.consumed_usd_cents,reserved_usd_cents:n.reserved_usd_cents,request_count:n.request_count,recent_events:n.events,session:n.session,created_at:n.created_at,updated_at:n.run_updated_at}}async function Et(e,t,r,n,s,o){let a=D(n,e),u=se(`model_reserve:${new Date(t).toISOString()}:${n}:${a?.request_count??0}`);if(o&&o.length&&a&&(a.session={updated_at:new Date(t).toISOString(),turns:o.slice(-20)}),!a?.claims)return{ok:!1,error:"run_not_found"};if(a.revoked)return{ok:!1,error:"run_revoked"};if(Date.parse(a.claims.expires_at)<=t)return{ok:!1,error:"run_expired"};if(a.request_count>=a.claims.max_requests)return{ok:!1,error:"request_limit_reached"};let i=a.claims.max_usd_cents-a.consumed_usd_cents-a.reserved_usd_cents;if(s>i)return{ok:!1,error:"spend_limit_reached"};a.request_count+=1,a.reserved_usd_cents+=s,a.reservations[u]={amount:s,expires_at_ms:t+Qe},await I(n,a,"run.reserve",e,t);let _=O(e);U(_,t),B(_,t),await W(e,t);let c=a.claims.repo,d=async y=>{let h=D(n,e),R=h.reservations[u];return R&&(h.reserved_usd_cents=Math.max(0,h.reserved_usd_cents-R.amount),h.request_count=Math.max(0,h.request_count-1),delete h.reservations[u],await I(n,h,"run.release",e,t)),{ok:!1,error:y}};if(ue(c,e)?.moderation==="banned")return d("account_banned");if(r.enforce_account_balance&&s>k(c,e)-Y(c,e,t))return d("account_balance_exhausted");let f=r.max_global_daily_usd_cents-_.consumed_usd_cents-_.reserved_usd_cents;return s>f?d("global_daily_spend_limit_reached"):(_.reservations[u]={amount:s,expires_at_ms:t+Qe,account:c,issue:a.claims.issue,actor:a.claims.actor,run_id:n},_.reserved_usd_cents+=s,await A(_,"rail.model_reserve",e,t),{ok:!0,request_id:u,remaining_run_usd_cents:i-s,remaining_global_usd_cents:f-s})}async function $t(e,t,r,n,s,o){let a=Number.isFinite(s)?Math.max(0,s):0,u=D(r,e);if(u){let y=u.reservations[n];y&&(u.reserved_usd_cents=Math.max(0,u.reserved_usd_cents-y.amount),delete u.reservations[n]),u.consumed_usd_cents+=a,u.events.push(o),u.events=u.events.slice(-cr),await I(r,u,"run.consume",e,t)}let i=O(e);U(i,t);let _=i.reservations[n],c,d,f;if(_&&(i.reserved_usd_cents=Math.max(0,i.reserved_usd_cents-_.amount),c=_.account,d=_.issue,f=_.actor,delete i.reservations[n]),i.consumed_usd_cents+=a,c){let y=x(c,e);Ce(y,i,c,a,{category:"model",supplier:te,issue:d,actor:f},t),await E(c,y,"account.model_consume",e,t)}await A(i,"rail.model_consume",e,t)}function vr(e,t){let r=Object.keys(e.daily_spend).sort();if(r.length===0)return[];let n=[],s=new Date(`${r[0]}T00:00:00.000Z`).getTime(),o=new Date(`${H(t)}T00:00:00.000Z`).getTime();for(let a=s;a<=o;a+=864e5)n.push(e.daily_spend[H(a)]??0);return n.slice(-nt)}function Sr(e){let t=Object.values(e.sponsors_active),r=new Set(t.map(n=>n.login));return[...t,...e.sponsors.filter(n=>!r.has(n.login))]}async function Q(e,t,r){await W(e,t);let n=x(r,e),s=n.granted_in_usd_cents-n.granted_out_usd_cents-n.consumed_usd_cents,o=Y(r,e,t),a=n.granted_in_usd_cents>0,u=Oe(s,vr(n,t)),i=n.pulled_est,_=i!==void 0&&Object.keys(n.daily_spend).length===0&&i.balance_usd_cents===s;return{account:r,funded:a,paused:a&&s<=0,balance_usd_cents:s,granted_in_usd_cents:n.granted_in_usd_cents,granted_out_usd_cents:n.granted_out_usd_cents,consumed_usd_cents:n.consumed_usd_cents,reserved_usd_cents:o,spendable_usd_cents:s-o,consumed_by_category:{...n.consumed_by_category??{}},burn_per_day_usd_cents:_?i.burn_per_day_usd_cents:u.burn_per_day_usd_cents,runway_days:_?i.runway_days:a?u.runway_days:null,runway_lo_days:_?i.runway_lo_days:a?u.runway_lo_days:null,runway_hi_days:_?i.runway_hi_days:a?u.runway_hi_days:null,days_observed:_?i.days_observed:u.days_observed,runway_confident:_?i.runway_confident:a&&u.confident,sponsors:Sr(n)}}function je(e,t){let r=st(e,t),n={};for(let u of w("account",e)){let i=u.state,{pulled_est:_,...c}=i;n[u.id]={...c,balance_usd_cents:i.granted_in_usd_cents-i.granted_out_usd_cents-i.consumed_usd_cents}}let s={};for(let u of w("supplier",e))s[u.id]=M(u);let o={};for(let u of w("reserve",e)){let{id:i,rev:_,...c}=u,d={};for(let[f,y]of Object.entries(c))f.startsWith("_")||f==="type"||f==="updatedAt"||y===null||(d[f]=y);o[u.id]=d}let a={};for(let u of w("run",e)){let i=u.state;i?.claims&&(a[u.id]={repo:i.claims.repo,issue:i.claims.issue,actor:i.claims.actor,active:i.active,system:i.system,expires_at_ms:Date.parse(i.claims.expires_at)||void 0,...i.claims.github_run_id?{github_run_id:i.claims.github_run_id}:{},purpose:i.claims.purpose,started_at_ms:i.started_at_ms,consumed_usd_cents:i.consumed_usd_cents,request_count:i.request_count})}return{day_key:r.day_key||H(t),active_global:r.active_global,active_system:r.active_system,active_by_repo:r.active_by_repo,active_by_actor:r.active_by_actor,runs_by_repo_day:r.runs_by_repo_day,runs_by_actor_day:r.runs_by_actor_day,runs_by_issue_day:r.runs_by_issue_day,consumed_usd_cents:r.consumed_usd_cents,reserved_usd_cents:r.reserved_usd_cents,runs:a,accounts:n,suppliers:s,supplier_reserves:o}}async function Ut(e,t){let r=O(e);U(r,t),B(r,t);let n=r.active_global,s=Rt(r,e,t);for(let a of s){let u=D(a,e);u&&(u.active=!1,await I(a,u,"run.reap",e,t))}await A(r,"rail.reap",e,t);let o=[];for(let a of w("run",e)){let u=a.state;u?.active&&o.push({run_id:a.id,repo:u.claims.repo,actor:u.claims.actor,expires_at_ms:Date.parse(u.claims.expires_at)||null})}return{ok:!0,reaped:n-r.active_global,active_global:r.active_global,active_system:r.active_system,active_by_actor:r.active_by_actor,active_by_repo:r.active_by_repo,still_active:o}}async function Ct(e,t,r){let n=O(e);U(n,t),B(n,t);let s=0;for(let o of w("run",e)){let a=o.state;a?.active&&a.claims.repo===r&&(Ne(n,a),await I(o.id,a,"run.reap_repo",e,t),s+=1)}return await A(n,"rail.reap_repo",e,t),{ok:!0,repo:r,freed:s,active_global:n.active_global}}async function Pt(e,t){let r=O(e);U(r,t),B(r,t);let n=r.consumed_usd_cents;return r.consumed_usd_cents=0,await A(r,"rail.reset_daily",e,t),{ok:!0,day_key:r.day_key,cleared_consumed_usd_cents:n,consumed_usd_cents:0,reserved_usd_cents:r.reserved_usd_cents}}var ce={"gpt-4o-mini":{provider:"openai",input_usd_per_mtok:.15,output_usd_per_mtok:.6},"gpt-4.1-mini":{provider:"openai",input_usd_per_mtok:.4,output_usd_per_mtok:1.6},"gpt-4o":{provider:"openai",input_usd_per_mtok:2.5,output_usd_per_mtok:10},"gpt-5.4-mini":{provider:"openai",input_usd_per_mtok:.75,output_usd_per_mtok:4.5},"gpt-5.4":{provider:"openai",input_usd_per_mtok:2.5,output_usd_per_mtok:15},"gpt-5-mini":{provider:"openai",input_usd_per_mtok:.25,output_usd_per_mtok:2},"claude-sonnet-4-6":{provider:"anthropic",input_usd_per_mtok:3,output_usd_per_mtok:15,cache_write_multiplier:1.25,cache_read_multiplier:.1},"claude-haiku-4-5":{provider:"anthropic",input_usd_per_mtok:1,output_usd_per_mtok:5,cache_write_multiplier:1.25,cache_read_multiplier:.1},"deepseek/deepseek-v4-flash":{provider:"openrouter",input_usd_per_mtok:.5,output_usd_per_mtok:1.5}},_e=4096,Dt=30;function Le(e,t,r=2e3){let n=r/1e6*e.input_usd_per_mtok*Math.max(1,e.cache_write_multiplier??1),s=t/1e6*e.output_usd_per_mtok;return Math.max(1,Math.ceil((n+s)*100))}function Ye(e){return Math.max(2e3,new TextEncoder().encode(e).byteLength)}function Be(e,t,r){if(!(t.input_tokens!==void 0||t.output_tokens!==void 0))return r;let s=(t.input_tokens??0)/1e6*e.input_usd_per_mtok,o=(t.output_tokens??0)/1e6*e.output_usd_per_mtok,a=(t.cache_creation_input_tokens??0)/1e6*e.input_usd_per_mtok*(e.cache_write_multiplier??1),u=(t.cache_read_input_tokens??0)/1e6*e.input_usd_per_mtok*(e.cache_read_multiplier??1);return Math.max(0,Number(((s+o+a+u)*100).toFixed(6)))}function It(e){return ce[e]??{provider:"openrouter",input_usd_per_mtok:Dt,output_usd_per_mtok:Dt}}function Nt(e,t){return{input_tokens:Math.ceil(new TextEncoder().encode(e).byteLength/4),output_tokens:Math.max(1,Math.ceil(t.length/4))}}function Ft(e){let t=Array.isArray(e.messages)?e.messages:[],r="";for(let s of t){let o=s;if(o?.role==="user"){if(typeof o.content=="string")r=o.content;else if(Array.isArray(o.content)){let a=o.content.find(u=>u?.type==="text");typeof a?.text=="string"&&(r=a.text)}}}return`[twin-stub:oa-treasury] deterministic completion (echo: ${r.slice(0,120)})`}function jt(e,t,r,n,s){return{id:`msg_twin_${e.run_id}_${s}`,type:"message",role:"assistant",model:t,content:[{type:"text",text:r}],stop_reason:"end_turn",stop_sequence:null,usage:{input_tokens:n.input_tokens,output_tokens:n.output_tokens}}}function Lt(e){let t=e.usage,r=e.content[0].text;return[{event:"message_start",data:{type:"message_start",message:{...e,content:[],stop_reason:null,usage:{input_tokens:t.input_tokens,output_tokens:0}}}},{event:"content_block_start",data:{type:"content_block_start",index:0,content_block:{type:"text",text:""}}},{event:"content_block_delta",data:{type:"content_block_delta",index:0,delta:{type:"text_delta",text:r}}},{event:"content_block_stop",data:{type:"content_block_stop",index:0}},{event:"message_delta",data:{type:"message_delta",delta:{stop_reason:"end_turn",stop_sequence:null},usage:{output_tokens:t.output_tokens}}},{event:"message_stop",data:{type:"message_stop"}}].map(s=>`event: ${s.event}
13
+ data: ${JSON.stringify(s.data)}
14
+
15
+ `).join("")}function l(e,t=400){return{status:t,body:{error:{code:e}}}}function S(){return l("method_not_allowed",405)}function g(e,t=200,r){return{status:t,body:e,...r?{headers:r}:{}}}function F(e){if(e===void 0||e==="")return null;try{return JSON.parse(e)}catch{return null}}function Ht(e){let t={};for(let[r,n]of Object.entries(e??{}))t[r.toLowerCase()]=n;return t}function Xt(e){return e.authorization?.match(/^Bearer\s+(.+)$/i)?.[1]??null}function br(e){return Xt(e)??e["x-api-key"]??null}function Yt(e){switch(e){case"supplier_auth_failed":return 401;case"category_not_allowed":case"account_banned":return 403;case"account_balance_exhausted":case"supplier_cap_exceeded":return 402;case"reserve_not_found":return 404;case"reserve_closed":return 409;default:return 400}}var xr=[/^\/v1\/runs\/mint$/,/^\/v1\/runs\/[^/]+\/exchange$/,/^\/v1\/runs\/[^/]+\/revoke$/,/^\/v1\/accounts\/.+\/grant$/];function Or(e){let t=e.occurredAt?Date.parse(e.occurredAt):NaN;return Number.isFinite(t)?t:Date.parse(kr())}async function qe(e){let t=e.method.toUpperCase(),[r]=e.path.split("?"),n=r??"/",s=Ht(e.headers),o=e.options??{},a=o.adminToken??le,u=o.hmacSecret??pe,i=o.webhookSecret??fe,_=Ae(o.limits??{}),c=Or(e),d=e.root,f=!!(s["x-admin-token"]&&a&&s["x-admin-token"]===a);if(e.readOnly&&t!=="GET"&&t!=="HEAD")return{status:405,body:{error:"read_only: this twin was started read-only; omit readOnly to accept writes"}};if(n==="/healthz")return{status:200,body:"ok",contentType:"text/plain;charset=UTF-8"};if(n==="/"||n==="/health"||n==="/favicon.svg"||n==="/favicon.ico"||n.startsWith("/p/"))return l("not_found",404);if(n==="/admin/runs/mint")return wr(e,d,c,f,u,o,_);if(n==="/admin/limits/status")return f?t!=="GET"?S():g(je(d,c)):l("auth_failed",401);if(n==="/admin/limits/reap")return f?t!=="POST"?S():g(await Ut(d,c)):l("auth_failed",401);if(n==="/admin/limits/reset-daily")return f?t!=="POST"?S():g(await Pt(d,c)):l("auth_failed",401);let y=n.match(/^\/admin\/accounts\/([^/]+)\/reap-runs$/);if(y)return f?t!=="POST"?S():g(await Ct(d,c,decodeURIComponent(y[1]))):l("auth_failed",401);if(n==="/webhooks/github-sponsors")return Ur(e,d,c,i,o.defaultSponsorAccount??o.defaultFundingAccount??"volter-ai/open-autonomy");let h=n.match(/^\/admin\/accounts\/([^/]+)\/(mint|grant|accrue)$/);if(h){if(!f)return l("auth_failed",401);if(t!=="POST")return S();let m=decodeURIComponent(h[1]),p=F(e.body)??{};if(h[2]==="mint")return typeof p.amount_usd_cents!="number"?l("invalid_request"):g(await J(d,c,m,p.amount_usd_cents,p.key,p.sponsor));if(h[2]==="grant"){if(!p.to||typeof p.amount_usd_cents!="number")return l("invalid_request");let v=await Pe(d,c,m,p.to,p.amount_usd_cents,p.key);return g(v,v.ok?200:400)}return p.key?g(await at(d,c,m,p.key)):l("invalid_request")}let R=n.match(/^\/admin\/accounts\/([^/]+)\/(profile|moderate|sync)$/);if(R){if(!f)return l("auth_failed",401);if(t!=="POST")return S();if(R[2]!=="moderate")return l("not_found",404);let m=decodeURIComponent(R[1]),p=F(e.body)??{};return p.status?g(await ut(d,c,m,p.status,p.reason)):l("invalid_request")}if(n==="/admin/coupons"){if(!f)return l("auth_failed",401);if(t==="GET")return g(ct(d));if(t!=="POST")return S();let m=F(e.body);if(!m||typeof m.amount_usd_cents!="number")return l("invalid_request");let p=await it(d,c,m);return g(p,p.ok?200:409)}if(n==="/v1/coupons/redeem"){if(t!=="POST")return S();let m=F(e.body);if(!m?.code||!m.account)return l("invalid_request");let p=await _t(d,c,m.code,m.account);if(p.ok)return g(p);let v=p.error==="coupon_not_found"?404:p.error==="coupon_already_redeemed"?409:400;return g(p,v)}if(n==="/admin/suppliers"){if(!f)return l("auth_failed",401);if(t==="GET")return g(lt(d));if(t!=="POST")return S();let m=F(e.body);if(!m||typeof m.name!="string"||!Array.isArray(m.categories))return l("invalid_request");let p=await dt(d,c,m);return g(p,p.ok?200:p.error==="supplier_exists"?409:400)}let T=n.match(/^\/admin\/suppliers\/([^/]+)\/(rotate|revoke)$/);if(T){if(!f)return l("auth_failed",401);if(t!=="POST")return S();let m=decodeURIComponent(T[1]),p=T[2]==="rotate"?await pt(d,c,m):await ft(d,c,m);return g(p,p.ok?200:404)}let G=n.match(/^\/admin\/accounts\/([^/]+)\/supplier-cap$/);if(G){if(!f)return l("auth_failed",401);if(t!=="POST")return S();let m=decodeURIComponent(G[1]),p=F(e.body);if(!p||typeof p.supplier!="string"||!p.supplier)return l("invalid_request");let v=await mt(d,c,m,p.supplier,p.max_usd_cents,p.window_days);return g(v,v.ok?200:400)}if(n==="/v1/supplier/consume"||n==="/v1/supplier/reserve"||n==="/v1/supplier/settle"||n==="/v1/supplier/release"){if(t!=="POST")return S();let m=await Bt(s);if(!m)return l("supplier_auth_failed",401);let p=F(e.body);if(!p)return l("invalid_json");let v=Ie(d,m);if(!v)return g({ok:!1,error:"supplier_auth_failed"},401);let de=n==="/v1/supplier/consume"?await vt(d,c,_,v,p):n==="/v1/supplier/reserve"?await St(d,c,_,v,p):n==="/v1/supplier/settle"?await Tt(d,c,v,p):await kt(d,c,v,String(p.reserve_id??""));return g(de,de.ok?200:Yt(de.error))}let C=n.match(/^\/v1\/supplier\/reserves\/([^/]+)$/);if(C){if(t!=="GET")return S();let m=await Bt(s);if(!m)return l("supplier_auth_failed",401);let p=Ie(d,m);if(!p)return g({ok:!1,error:"supplier_auth_failed"},401);let v=await bt(d,c,p,decodeURIComponent(C[1]));return g(v,v.ok?200:Yt(v.error))}if(xr.some(m=>m.test(n)))return t!=="POST"?S():l("auth_failed",401);let j=n.match(/^\/v1\/accounts\/([^/]+)\/runway\.svg$/);if(j)return Gt(d,c,decodeURIComponent(j[1]),t);let q=n.match(/^\/v1\/accounts\/([^/]+)$/);if(q)return t!=="GET"?S():g(await Q(d,c,decodeURIComponent(q[1])));if(n==="/v1/funding")return t!=="GET"?S():g(await Q(d,c,o.defaultFundingAccount??"volter-ai/open-autonomy"));if(n==="/v1/funding/runway.svg")return Gt(d,c,o.defaultFundingAccount??"volter-ai/open-autonomy",t);let N=n.match(/^\/admin\/runs\/([^/]+)(?:\/(revoke))?$/);if(N){if(!f)return l("auth_failed",401);let m=decodeURIComponent(N[1]);return N[2]==="revoke"?t!=="POST"?S():(await Fe(d,c,m),g({ok:!0,run_id:m})):t!=="GET"?S():g(K(d,c,m))}let L=n.match(/^\/v1\/runs\/([^/]+)$/);if(L){let m=await Ge(s,u,d,c);if(!m)return l("auth_failed",401);let p=decodeURIComponent(L[1]);return p!==m.run_id?l("forbidden_run",403):g(K(d,c,p))}let He=n.match(/^\/v1\/runs\/([^/]+)\/session$/);if(He){if(t!=="GET")return S();let m=await Ge(s,u,d,c);if(!m)return l("auth_failed",401);let p=decodeURIComponent(He[1]),v=K(d,c,p);return v.claims?v.claims.repo!==m.repo?l("forbidden_run",403):g({run_id:p,repo:v.claims.repo,issue:v.claims.issue,actor:v.claims.actor,purpose:v.claims.purpose,request_count:v.request_count??0,consumed_usd_cents:v.consumed_usd_cents??0,session:v.session??{updated_at:"",turns:[]}}):l("run_not_found",404)}let Xe=await Ge(s,u,d,c);return Xe?n==="/v1/messages"?Ar(e,d,c,_,Xe,o):l("not_found",404):l("auth_failed",401)}async function Bt(e){let t=ve(Xt(e));return t?{id:t.id,secret_hash:await X(t.secret)}:null}async function Ge(e,t,r,n){let s=await ge(t,br(e),n);if(!s)return null;let o=K(r,n,s.run_id);return o.revoked||!o.claims||o.claims.run_id!==s.run_id?null:o.claims}async function Gt(e,t,r,n){if(n!=="GET")return S();let s=await Q(e,t,r);return{status:200,body:Re(s),contentType:"image/svg+xml; charset=utf-8",headers:{"cache-control":"max-age=300, s-maxage=300"}}}function Rr(e){return!e||typeof e!="object"?l("invalid_request"):!e.repo||!/^[^/\s]+\/[^/\s]+$/.test(e.repo)?l("invalid_repo"):!Number.isInteger(e.issue)||e.issue<0?l("invalid_issue"):!e.actor||typeof e.actor!="string"?l("invalid_actor"):!Array.isArray(e.models)||e.models.length===0||e.models.some(t=>typeof t!="string"||!t)?l("invalid_models"):e.max_usd_cents!==void 0&&(!Number.isInteger(e.max_usd_cents)||e.max_usd_cents<=0)?l("invalid_max_usd_cents"):e.max_requests!==void 0&&(!Number.isInteger(e.max_requests)||e.max_requests<=0)?l("invalid_max_requests"):e.expires_in_seconds!==void 0&&(!Number.isInteger(e.expires_in_seconds)||e.expires_in_seconds<=0)?l("invalid_expires_in_seconds"):e.github_run_id!==void 0&&typeof e.github_run_id!="string"?l("invalid_github_run_id"):e.github_run_attempt!==void 0&&typeof e.github_run_attempt!="string"?l("invalid_github_run_attempt"):e.github_workflow_ref!==void 0&&typeof e.github_workflow_ref!="string"?l("invalid_github_workflow_ref"):null}async function wr(e,t,r,n,s,o,a){if(!n)return l("auth_failed",401);if(e.method.toUpperCase()!=="POST")return S();let u=F(e.body);if(!u)return l("invalid_json");let i=Rr(u);if(i)return i;let _=u.max_usd_cents??(typeof u.max_usd=="number"?Math.round(u.max_usd*100):void 0)??o.defaultMaxUsdCents??500,c=u.max_requests??o.defaultMaxRequests??200,d=u.expires_in_seconds??o.defaultExpiresSeconds??7200;if(_>(o.maxRunUsdCents??500))return l("run_spend_cap_too_high",400);if(c>(o.maxRunRequests??200))return l("run_request_cap_too_high",400);let f=u.run_id??xt(t,r),y={run_id:f,repo:u.repo,issue:u.issue,actor:u.actor,max_usd_cents:_,max_requests:c,models:u.models,expires_at:new Date(r+d*1e3).toISOString(),purpose:u.purpose??"agent",...u.github_run_id!==void 0?{github_run_id:u.github_run_id}:{},...u.github_run_attempt!==void 0?{github_run_attempt:u.github_run_attempt}:{},...u.github_workflow_ref!==void 0?{github_workflow_ref:u.github_workflow_ref}:{}},h=await Ot(t,r,y);if(!h.ok)return l(h.error,409);let R=await wt(t,r,y,a);if(!R.ok)return await Fe(t,r,f),l(R.error,429);let T=await ye(s,y);return g({ok:!0,run:y,token:T})}async function Ar(e,t,r,n,s,o){if(e.method.toUpperCase()!=="POST")return S();let a=e.body??"",u=o.maxBodyBytes??1024*1024;if(new TextEncoder().encode(a).byteLength>u)return l("body_too_large",413);let i=F(a);if(!i)return l("invalid_json",400);let _=typeof i.model=="string"?i.model:"";if(!s.models.includes(_))return l("model_not_allowed",403);let c=ce[_];if(c&&c.provider==="openai")return l("model_price_not_configured",403);let d=It(_),f=typeof i.max_tokens=="number"?i.max_tokens:_e,y=Math.max(1,Math.min(f,_e)),h=Le(d,y,Ye(a)),R=Kt(i),T=await Et(t,r,n,s.run_id,h,R);if(!T.ok)return l(T.error,402);let G=Ft(i),C=Nt(a,G),j=Be(d,C,h),q=K(t,r,s.run_id),N=jt(s,_,G,C,q.request_count);await $t(t,r,s.run_id,T.request_id,j,{request_id:T.request_id,provider:"openrouter",model:_,route:"/openrouter/v1/messages",reserved_usd_cents:h,actual_usd_cents:j,input_tokens:C.input_tokens,output_tokens:C.output_tokens,outcome:"ok",created_at:new Date(r).toISOString()});let L={"x-agent-proxy-remaining-usd-cents":String(T.remaining_run_usd_cents),"x-agent-proxy-remaining-global-usd-cents":String(T.remaining_global_usd_cents),"cache-control":"no-store"};return i.stream===!0?{status:200,body:Lt(N),contentType:"text/event-stream",headers:L}:g(N,200,L)}var Er=12,qt=1400;function zt(e){return e.replace(/sk_live_[A-Za-z0-9]{12,}/g,"[redacted]").replace(/rk_live_[A-Za-z0-9]{12,}/g,"[redacted]").replace(/ghp_[A-Za-z0-9]{30,}/g,"[redacted]").replace(/github_pat_[A-Za-z0-9_]{30,}/g,"[redacted]").replace(/gho_[A-Za-z0-9]{30,}/g,"[redacted]").replace(/sk-ant-[A-Za-z0-9_-]{20,}/g,"[redacted]").replace(/sk-or-v1-[A-Za-z0-9]{20,}/g,"[redacted]").replace(/xox[baprs]-[A-Za-z0-9-]{10,}/g,"[redacted]")}function Wt(e,t=300){let r=typeof e=="string"?e:JSON.stringify(e??"");return r.length>t?`${r.slice(0,t)}\u2026`:r}function $r(e){if(typeof e=="string")return e;if(!Array.isArray(e))return"";let t=[];for(let r of e){if(!r||typeof r!="object")continue;let n=r;n.type==="text"&&typeof n.text=="string"?t.push(n.text):n.type==="thinking"&&typeof n.thinking=="string"?t.push(`[thinking] ${n.thinking}`):n.type==="tool_use"?t.push(`[tool: ${String(n.name??"?")}] ${Wt(n.input)}`):n.type==="tool_result"?t.push(`[tool result] ${Wt(n.content)}`):n.type==="image"?t.push("[image]"):typeof n.type=="string"&&t.push(`[${n.type}]`)}return t.join(`
16
+ `)}function Kt(e){let t=Array.isArray(e.messages)?e.messages:[],r=[];for(let n of t.slice(-Er)){if(!n||typeof n!="object")continue;let s=n,o=typeof s.role=="string"?s.role:"unknown",a=zt($r(s.content)).trim();a.length>qt&&(a=`${a.slice(0,qt)}\u2026`),a&&r.push({role:o,text:a})}return r}async function Ur(e,t,r,n,s){if(e.method.toUpperCase()!=="POST")return S();if(!n)return l("webhook_not_configured",503);let o=Ht(e.headers),a=o["x-github-event"],u=e.body??"";if(!await Te(n,u,o["x-hub-signature-256"]??null))return l("invalid_signature",401);if(a==="ping")return g({ok:!0,pong:!0});if(a!=="sponsorship")return g({ok:!0,ignored:a});let i=F(u),_=i?.action,c=i?.sponsorship,d=c?.sponsor?.login;if(!d||!c?.tier)return l("invalid_payload",400);let f=c.tier.monthly_price_in_cents??0,y={login:d,...c.sponsor?.avatar_url?{avatar_url:c.sponsor.avatar_url}:{},monthly_usd_cents:f};switch(_){case"created":if(c.tier.is_one_time){let h=`onetime:${c.node_id??`${d}:${c.created_at??""}`}`;await J(t,r,s,f,h,y)}else await De(t,r,s,y);break;case"tier_changed":case"edited":c.tier.is_one_time||await De(t,r,s,y);break;case"cancelled":await ot(t,r,s,d);break;default:break}return g({ok:!0,action:_})}import{serveHttp as Qr}from"../../engine/v2/volter_world-core.mjs";import{worldNow as Cr,statefulTwinManifest as Pr}from"../../engine/v2/volter_world-core.mjs";function Vt(e={}){let{root:t,readOnly:r,...n}=e;return async function(o){let a=new URL(o.url);if(o.method==="GET"&&a.pathname.replace(/\/+$/,"")==="/twin")return Response.json(Pr({vendor:"oa-treasury",twinOf:"the Open Autonomy treasury (agent-model-proxy economy layer)",stores:"accounts, balances, mints and grants \u2014 the org's money"}));let u=o.method!=="GET"&&o.method!=="HEAD"?await o.text():"",i={};o.headers.forEach((_,c)=>{i[c.toLowerCase()]=_});try{let _=await qe({method:o.method,path:a.pathname+(a.search||""),body:u,headers:i,readOnly:r??!1,occurredAt:Cr(),...t!==void 0?{root:t}:{},options:n});return _.contentType!==void 0?new Response(String(_.body),{status:_.status,headers:{"content-type":_.contentType,..._.headers??{}}}):new Response(JSON.stringify(_.body),{status:_.status,headers:{"content-type":"application/json",..._.headers??{}}})}catch(_){return console.error("[oa-treasury-twin] unhandled error",_),new Response(JSON.stringify({error:{code:"internal_error"}}),{status:500,headers:{"content-type":"application/json"}})}}}import{syncPull as pn}from"../../engine/v2/volter_world-core.mjs";import{declareRateBudget as Dr,rateBudgetPath as sn,rateBudgetWeight as an,RateBudget as on,RateBudgetError as un}from"../../engine/v2/volter_world-core.mjs";import{RateBudgetError as Nr}from"../../engine/v2/volter_world-core.mjs";var Ir="oa-treasury",Zt=6e4,Jt=60,Mt=300,Qt={other:2};var We={windowMs:Zt,ceiling:Jt,defaultWeight:Qt.other,maxRetryAfterSeconds:Mt,rules:[],reason:"Self-owned vendor: the Open Autonomy treasury worker (volter-ai/open-autonomy services/agent-model-proxy). Its first-party sources \u2014 the service README and wrangler.toml, reviewed 2026-08-23 in the read-only clone this twin is built against, alongside the live wrangler-dev probe run \u2014 publish NO scalar request-rate limit (the MAX_* vars bound run slots and spend, not request rates; Cloudflare Workers platform limits apply upstream and are not restated by the service). With the governing limit unpublished, this ceiling is pinned to the kernel's conservative fallback (60 units / 60s at weight 2 = 30 calls/min) rather than invented \u2014 no more permissive than an undeclared vendor already gets. All modeled calls are uniform cheap reads (funding snapshot, supplier list, limits status); no tier split exists to weight differently."};Dr(Ir,We);export{Vt as createTwinFetch};
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,7 @@
1
+ @agenttwin/twin-openai
2
+
3
+ Contains @volter/twin-openai 3.0.3 by Volter (https://github.com/volter-ai),
4
+ licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ Modified by AgentTwin: bundled and minified into one file; only code reachable from the pack's
7
+ fetch factory is included; shared modules are imported from the AgentTwin twin engine.