trouteai 1.0.6 → 1.0.8
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.
- package/.build/next/BUILD_ID +1 -1
- package/.build/next/build-manifest.json +3 -3
- package/.build/next/fallback-build-manifest.json +3 -3
- package/.build/next/server/app/(dashboard)/dashboard/activity/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/analytics/combo-health/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/analytics/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/analytics/utilization/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/api-manager/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/audit/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/auto-combo/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/cache/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/combos/[id]/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/combos/live/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/combos/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/combos/playground/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/costs/budget/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/costs/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/costs/pricing/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/costs/quota-share/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/endpoint/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/health/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/limits/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/logs/activity/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/logs/console/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/logs/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/logs/proxy/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/logs/timeline/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/media-providers/[kind]/[id]/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/media-providers/[kind]/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/media-providers/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/onboarding/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/playground/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/provider-stats/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/providers/[id]/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/providers/new/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/providers/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/quota/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/runtime/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/advanced/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/ai/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/appearance/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/cache/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/feature-flags/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/general/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/pricing/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/resilience/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/routing/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/security/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/settings/sidebar/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/system/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/system/proxy/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/dashboard/usage/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/(dashboard)/home/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/400/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/401/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/403/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/408/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/429/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/500/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/502/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/503/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/_global-error.html +1 -1
- package/.build/next/server/app/_global-error.rsc +1 -1
- package/.build/next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.build/next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.build/next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.build/next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/api/combos/test/route.js +156 -156
- package/.build/next/server/app/api/compression/compare/verify/route.js +2 -2
- package/.build/next/server/app/api/models/test/route.js +143 -143
- package/.build/next/server/app/api/models/test-all/route.js +143 -143
- package/.build/next/server/app/api/usage/[connectionId]/route.js +2 -2
- package/.build/next/server/app/api/usage/codex-reset-credit/route.js +2 -2
- package/.build/next/server/app/api/usage/provider-limits/route.js +2 -2
- package/.build/next/server/app/api/v1/antigravity/route.js +125 -125
- package/.build/next/server/app/api/v1/api/chat/route.js +127 -127
- package/.build/next/server/app/api/v1/chat/completions/route.js +133 -133
- package/.build/next/server/app/api/v1/completions/route.js +131 -131
- package/.build/next/server/app/api/v1/messages/count_tokens/route.js +2 -2
- package/.build/next/server/app/api/v1/messages/route.js +130 -130
- package/.build/next/server/app/api/v1/providers/[provider]/chat/completions/route.js +124 -124
- package/.build/next/server/app/api/v1/responses/[...path]/route.js +125 -125
- package/.build/next/server/app/api/v1/responses/route.js +133 -133
- package/.build/next/server/app/api/v1/videos/generations/route.js +2 -2
- package/.build/next/server/app/api/v1/vscode/[token]/api/chat/route.js +131 -131
- package/.build/next/server/app/api/v1/vscode/[token]/chat/completions/route.js +132 -132
- package/.build/next/server/app/api/v1/vscode/[token]/responses/route.js +131 -131
- package/.build/next/server/app/api/v1/vscode/[token]/v1/chat/completions/route.js +132 -132
- package/.build/next/server/app/api/v1/vscode/raw/[token]/api/chat/route.js +131 -131
- package/.build/next/server/app/api/v1/vscode/raw/[token]/chat/completions/route.js +132 -132
- package/.build/next/server/app/api/v1/vscode/raw/[token]/responses/route.js +131 -131
- package/.build/next/server/app/api/v1/vscode/raw/[token]/v1/chat/completions/route.js +132 -132
- package/.build/next/server/app/api/v1beta/models/[...path]/route.js +128 -128
- package/.build/next/server/app/auth/callback/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/callback/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/connect/codex/[token]/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/forbidden/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/forgot-password/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/login/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/maintenance/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/offline/page_client-reference-manifest.js +1 -1
- package/.build/next/server/app/page_client-reference-manifest.js +1 -1
- package/.build/next/server/chunks/{1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0071t6-gy8206.js → 1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0cdytbweqx6b7.js} +1 -1
- package/.build/next/server/chunks/{1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_03uipan87s4vs.js → 1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0dv1_6icxx4nr.js} +1 -1
- package/.build/next/server/chunks/{1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_04qcux733c716.js → 1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0feukx8b--i7y.js} +1 -1
- package/.build/next/server/chunks/{1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_04y--asln23t-.js → 1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0foh2lmr9t9jf.js} +1 -1
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0ieu8lrtllaog.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0jow9no35q-gl.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0k39__s-5wenx.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0lu36e9zlm6y2.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0q3hd0z__qhm1.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0svnbjltkehm0.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0tp3k6-k_smkk.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0tw8hx-r12mrw.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0vdgv0qv9t25q.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_13pu0wi09xd-q.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_16gcrutnx6jpm.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_170l4-im9-rts.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_18ujd4t8o0iap.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1kuob30li3zz4.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1oghu697pywz1.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1oz1ky4cqo5la.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1t1tpwfjdroz-.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1twzsl5g2kx-m.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1u4l5hhlfmkq7.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1wgek1bfzkudf.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1yazcd_f60euz.js +3 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1zg9eixcilibu.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__0y-c0o33nm9k7._.js → [root-of-the-server]__013qtg6e7nrnt._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__0jcn_nom11qn8._.js → [root-of-the-server]__01cuuk82yhow-._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__03j1rri4jmffc._.js +1 -1
- package/.build/next/server/chunks/{[root-of-the-server]__03ce1fmn0qpsk._.js → [root-of-the-server]__04-wq1d8ad7-c._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__09e_jeovzn41x._.js → [root-of-the-server]__04ex4wx450p98._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__0s1n86lqib-r8._.js → [root-of-the-server]__054pm2e42ihgb._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__09miz4mr315ge._.js → [root-of-the-server]__06a582l--8gfi._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__14qrr7cz7ih12._.js → [root-of-the-server]__08mchwc4bo740._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__0cdyf9uauo7s-._.js → [root-of-the-server]__0_potadi-xpgt._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__053e56_stref0._.js → [root-of-the-server]__0au1tn-inyd_g._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__0dnxb-t5a29qw._.js → [root-of-the-server]__0bi89tb8hq7gp._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__0bjb6df6ao16p._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__0b6xbrajo6q7j._.js → [root-of-the-server]__0bn0fnmy3cyov._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__0c8uunduj0rcb._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__0bqjf5vfej0y0._.js → [root-of-the-server]__0cfm4y8lfzabg._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__0h2tv7welidf2._.js +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__0h6jczejtzur4._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__0jboht3yosva1._.js +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__0kmh0llofhi-t._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__19fndg4-8fl2p._.js → [root-of-the-server]__0oe87-hbfx_wt._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__0pkk8q-mwrlhb._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__0pr6ndvl99m80._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__0q4kt78fse6u1._.js +1 -1
- package/.build/next/server/chunks/{[root-of-the-server]__0puajugwbae33._.js → [root-of-the-server]__0qwx0hffq93lu._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__03wxkz1ocd2m9._.js → [root-of-the-server]__0qzppsy_m_vb2._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__0tadcednrqwvh._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__0tmd8acngsii3._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__0urs4jrktsqji._.js → [root-of-the-server]__0vrh-4tf0ft8-._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__0w0-w78j-o7zx._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__0yhdbb9w6oy0w._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__0yovqcjs0srde._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__155hah7mtxxeu._.js → [root-of-the-server]__0yrk_78ixd453._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__0e_cgryo2zwu7._.js → [root-of-the-server]__0z24jgzvrqjf-._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__1-elrzh0r1gn1._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__13g59axrgpk8f._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__0fqufbrh_mxe6._.js → [root-of-the-server]__14htch0up35mq._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__16__ky70mzpki._.js +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__175s6rzt1gxf5._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__183u7xm7s7a0k._.js +3 -0
- package/.build/next/server/chunks/{[root-of-the-server]__1b7gfspxmfn7w._.js → [root-of-the-server]__1_bm64-b9rvps._.js} +2 -2
- package/.build/next/server/chunks/{[root-of-the-server]__0_89zuvif-ac0._.js → [root-of-the-server]__1_u2c9t8ghphk._.js} +2 -2
- package/.build/next/server/chunks/[root-of-the-server]__1asmrtinwnms1._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1cs67f0gx1m2b._.js +1 -1
- package/.build/next/server/chunks/{[root-of-the-server]__0cya_vem8spaz._.js → [root-of-the-server]__1di-si5n-wa-0._.js} +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__1eqvp0su82wa0._.js +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__1f5u7fc6i-lh2._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1gvcl_1847dlk._.js +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__1gvwvri5-zmqs._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1mfz-ys8z6-vj._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1trre9oa-f-0-._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1vwllhi2yaj22._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1waj1qbbu8d0o._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1x9t7o--7d3xv._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1xi0yu215obtp._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1xrpvccwm0tui._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1xxb_la5pyyty._.js +1 -1
- package/.build/next/server/chunks/[root-of-the-server]__1yyq83bab1_34._.js +3 -0
- package/.build/next/server/chunks/[root-of-the-server]__1zvn7n_eg3bv6._.js +3 -0
- package/.build/next/server/chunks/_0-eumrsx9uwoc._.js +3 -3
- package/.build/next/server/chunks/_0-whad0_ydcsy._.js +1 -1
- package/.build/next/server/chunks/{_029oc7_2cayf9._.js → _01jw2l_g1m495._.js} +1 -1
- package/.build/next/server/chunks/_02r_3f8xhg8a_._.js +16 -0
- package/.build/next/server/chunks/{_0-7-wo2rhe742._.js → _03qfav-eclfsv._.js} +1 -1
- package/.build/next/server/chunks/{_0v8bztyjzmwju._.js → _040sjflhcim3n._.js} +2 -2
- package/.build/next/server/chunks/{_045qaiya-q9mx._.js → _06tafvn_2upb9._.js} +1 -1
- package/.build/next/server/chunks/{_0bnzv1p-iih9y._.js → _070swycte4f2y._.js} +1 -1
- package/.build/next/server/chunks/{_0v223bkfoc35x._.js → _08crm5ua26ded._.js} +1 -1
- package/.build/next/server/chunks/{_0cnrejialoejq._.js → _09pw38n0fvjve._.js} +132 -119
- package/.build/next/server/chunks/_0_owpim-84v6c._.js +1 -1
- package/.build/next/server/chunks/_0bjni2b0bk48x._.js +7 -0
- package/.build/next/server/chunks/_0cthudnt9nl4t._.js +3 -0
- package/.build/next/server/chunks/_0dtaqfgy6-5ws._.js +3 -0
- package/.build/next/server/chunks/{_1gwyqrv4jj-h0._.js → _0dx0f1oye7vfm._.js} +1 -1
- package/.build/next/server/chunks/_0gqrj_t8bk-8t._.js +1 -1
- package/.build/next/server/chunks/_0heuo1apizyqe._.js +1 -1
- package/.build/next/server/chunks/{_05uyjdaba145h._.js → _0jbl3xtidh76w._.js} +1 -1
- package/.build/next/server/chunks/_0jzperkk-1ag9._.js +1 -1
- package/.build/next/server/chunks/_0ma7hnwk4_v5i._.js +1 -1
- package/.build/next/server/chunks/_0nntu-lmwlb6z._.js +1 -1
- package/.build/next/server/chunks/_0ntfaxua3a497._.js +3 -0
- package/.build/next/server/chunks/{_1mf3kg0sol0_p._.js → _0pqtuwqkanzsg._.js} +132 -119
- package/.build/next/server/chunks/{_0syxc2wl5qdnf._.js → _0q0iu436_75a8._.js} +1 -1
- package/.build/next/server/chunks/_0qa8wnj0oms8q._.js +3 -0
- package/.build/next/server/chunks/{_0hmkgx75fn7mt._.js → _0r-1igk81_7eg._.js} +1 -1
- package/.build/next/server/chunks/{_0i0eoe3j0-x0v._.js → _0rffd_e2te-9v._.js} +1 -1
- package/.build/next/server/chunks/{_0fr8xxna2d5zn._.js → _0rtwo7u0mrb9r._.js} +1 -1
- package/.build/next/server/chunks/_0srkl-vgqcos7._.js +1 -1
- package/.build/next/server/chunks/_0tjk31-3k5hyf._.js +1 -1
- package/.build/next/server/chunks/_0tu5ehvbm4nc0._.js +3 -0
- package/.build/next/server/chunks/_0u8bko69-zd_z._.js +3 -0
- package/.build/next/server/chunks/_0v2kg-vv66amt._.js +3 -0
- package/.build/next/server/chunks/_0xujjs2b429r3._.js +3 -0
- package/.build/next/server/chunks/_0zvrsdbnkncnv._.js +3 -0
- package/.build/next/server/chunks/{_15efjsoc2b-sk._.js → _0zzir4fs7j_1p._.js} +2 -2
- package/.build/next/server/chunks/_10bcih89e-jn4._.js +3 -0
- package/.build/next/server/chunks/_10fwjeqnb57r-._.js +3 -0
- package/.build/next/server/chunks/_12_v3uivh86bs._.js +3 -0
- package/.build/next/server/chunks/_12ra9yaf_1dyr._.js +650 -0
- package/.build/next/server/chunks/_12rywigtphiop._.js +1 -1
- package/.build/next/server/chunks/_14cqpo0o-pr27._.js +3 -0
- package/.build/next/server/chunks/_14lqp4-f8wqgn._.js +3 -0
- package/.build/next/server/chunks/_159dadvt3pm1n._.js +3 -0
- package/.build/next/server/chunks/_1644hhqg6d_ln._.js +1 -1
- package/.build/next/server/chunks/{_1avfc3einmg1h._.js → _16_wwhbnnhkuh._.js} +1 -1
- package/.build/next/server/chunks/_16an60huh6tbs._.js +9 -9
- package/.build/next/server/chunks/_16i__1nx0epf7._.js +3 -0
- package/.build/next/server/chunks/_178o182dc7ex1._.js +3 -0
- package/.build/next/server/chunks/_188c9_xzcpc31._.js +1 -1
- package/.build/next/server/chunks/_19fzj3u7s0yz1._.js +3 -0
- package/.build/next/server/chunks/_19sfk-pzknkyv._.js +3 -0
- package/.build/next/server/chunks/_1_r1zgsvs713w._.js +3 -0
- package/.build/next/server/chunks/_1b6zyz_ay2ym5._.js +3 -0
- package/.build/next/server/chunks/_1btzlsw6io52c._.js +3 -0
- package/.build/next/server/chunks/{_0b_i4b8q0n1wz._.js → _1ft8yf-b3j8b8._.js} +146 -133
- package/.build/next/server/chunks/_1g8ka5zb3up7z._.js +3 -0
- package/.build/next/server/chunks/_1i00v3yjot-q_._.js +3 -0
- package/.build/next/server/chunks/{_0j524iax5w-bz._.js → _1kwnwtivfzp5u._.js} +1 -1
- package/.build/next/server/chunks/_1n9cbjvt_d82t._.js +1 -1
- package/.build/next/server/chunks/{_1wos-_82xr837._.js → _1q0_qh1mlc-1m._.js} +146 -133
- package/.build/next/server/chunks/{_0u-x3uzfboviu._.js → _1qmyzv3q9s7el._.js} +1 -1
- package/.build/next/server/chunks/_1qqqu7qtmx3if._.js +3 -0
- package/.build/next/server/chunks/_1r-xz7njt1agb._.js +62 -0
- package/.build/next/server/chunks/_1r3w1g8gzsrx3._.js +3 -0
- package/.build/next/server/chunks/{_1zcs33t-he7xd._.js → _1t7-qccr20ews._.js} +10 -10
- package/.build/next/server/chunks/_1uj3ppmpkxnlt._.js +3 -0
- package/.build/next/server/chunks/_1vgt3hw061lvz._.js +3 -0
- package/.build/next/server/chunks/_1xsk0mm2-hw63._.js +3 -0
- package/.build/next/server/chunks/_1yia8a_9rs285._.js +3 -0
- package/.build/next/server/chunks/_1yq_qtnhzgne_._.js +3 -0
- package/.build/next/server/chunks/_1z1_7oxdwqiqe._.js +3 -0
- package/.build/next/server/chunks/{_0zea7hovhgt2_._.js → _1zk9j5avh9do1._.js} +2 -2
- package/.build/next/server/chunks/_1zmyssg1ql6gl._.js +3 -3
- package/.build/next/server/chunks/_1zzqi2vrqln8r._.js +3 -0
- package/.build/next/server/chunks/_20wczne8lusnr._.js +1 -1
- package/.build/next/server/chunks/{node_modules_0_a57i8xt9icf._.js → node_modules_00j-j70vb5l89._.js} +1 -1
- package/.build/next/server/chunks/{node_modules_0-_w__4n53410._.js → node_modules_00rveaxr6xn-1._.js} +1 -1
- package/.build/next/server/chunks/{node_modules_06km3ub1t353p._.js → node_modules_0318sxb9xejre._.js} +1 -1
- package/.build/next/server/chunks/{node_modules_070w8pzva2-b5._.js → node_modules_03eegbwr1ykhv._.js} +1 -1
- package/.build/next/server/chunks/node_modules_04kmq4fi-fcs3._.js +3 -0
- package/.build/next/server/chunks/node_modules_0clpxklowdv39._.js +3 -0
- package/.build/next/server/chunks/node_modules_0ixloym14amfv._.js +3 -0
- package/.build/next/server/chunks/node_modules_0jcobbm12qhmj._.js +3 -0
- package/.build/next/server/chunks/node_modules_0lav-ieym04zb._.js +3 -0
- package/.build/next/server/chunks/node_modules_0meaikpo6sp-0._.js +3 -0
- package/.build/next/server/chunks/node_modules_0qjpghqow25tc._.js +3 -0
- package/.build/next/server/chunks/node_modules_0t3d23hihdgmu._.js +3 -0
- package/.build/next/server/chunks/node_modules_0trsqf3qottck._.js +3 -0
- package/.build/next/server/chunks/node_modules_0voxtqt-anw9e._.js +3 -0
- package/.build/next/server/chunks/node_modules_0vrbvfb6201w6._.js +3 -0
- package/.build/next/server/chunks/node_modules_1-kv_qmpt4341._.js +3 -0
- package/.build/next/server/chunks/node_modules_10rbyfmbpi425._.js +3 -0
- package/.build/next/server/chunks/node_modules_135e3rn3qtd-6._.js +3 -0
- package/.build/next/server/chunks/node_modules_17pyrt2it4bgr._.js +3 -0
- package/.build/next/server/chunks/node_modules_1ir4um6mro95r._.js +3 -0
- package/.build/next/server/chunks/node_modules_1j_0ubaizcezn._.js +3 -0
- package/.build/next/server/chunks/node_modules_1n05kwizfpjo6._.js +3 -0
- package/.build/next/server/chunks/node_modules_1n47vn0307_u5._.js +3 -0
- package/.build/next/server/chunks/node_modules_1srzy9xr2ioyr._.js +3 -0
- package/.build/next/server/chunks/node_modules_1tqglxa-ymtqw._.js +3 -0
- package/.build/next/server/chunks/node_modules_1z6rpfu7winx2._.js +3 -0
- package/.build/next/server/chunks/{node_modules_@aws-sdk_032-tpe7346hb._.js → node_modules_@aws-sdk_03kfydhiseqdg._.js} +2 -2
- package/.build/next/server/chunks/{node_modules_@aws-sdk_04o_8bax4fbo4._.js → node_modules_@aws-sdk_0_s99dpim75pu._.js} +2 -2
- package/.build/next/server/chunks/{node_modules_@aws-sdk_0_at_8j5m5taa._.js → node_modules_@aws-sdk_0bv_r2pcdu10h._.js} +2 -2
- package/.build/next/server/chunks/{node_modules_@aws-sdk_0cpedsd2e8nj9._.js → node_modules_@aws-sdk_0f5qnmpxmag01._.js} +2 -2
- package/.build/next/server/chunks/node_modules_@aws-sdk_0nlcm-f5ytb4h._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0obp77rs96mvi._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0oylq1k5y_3ce._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0qf0zztgs682s._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0rgyt30cubjzf._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0vi2hngy9pnuy._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0x510i9ngxcyf._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0y-e4gqf903o3._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0yhl9bvr9ueqh._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0yqxb4ienz6kj._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_0yttguxby4mdi._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_10101hyu_zjk4._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_123n4jie1tq6a._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_15qb522ckeehe._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1_n1vj3j0xfms._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1ix0scvbr4xd9._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1lza3gi_jvmio._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1mdahx12zwp_1._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1nk8tt26yrxh-._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1ot6491i27kfo._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_1vcgyijr8-gln._.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_204anorh-zvk-._.js +3 -0
- package/.build/next/server/chunks/{node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0-2dpkdybmydz.js → node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_01m33xoynofsl.js} +1 -1
- package/.build/next/server/chunks/{node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_00c1icqvrqz-s.js → node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_06adt_ianv_md.js} +1 -1
- package/.build/next/server/chunks/{node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_039_xf84osnel.js → node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_07njywm0sbeyv.js} +1 -1
- package/.build/next/server/chunks/{node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_03hjwb47vuwm9.js → node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_080lter3o8zcp.js} +1 -1
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_09_cxlxlqf67s.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_09ov7ntve-mx7.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0kbpnxnu2ejlc.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0ki8jbo6k_atz.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0npewtp_nops5.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0q715b8wgpb1u.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0yy3fcwj_b5be.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1-4ppt5kmz50x.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1-ky0eo80twjx.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_11u9jygsvvu5c.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_12s0w02i5mlzh.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_12sb57-_mdan4.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_13be-a641383i.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_14nxcn9iwq7oj.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_15sqaub981ncp.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_16mb7bvgqd72p.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1a96ybufo8-_d.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1epmqjkncfa-t.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1ymjdx7brv1u5.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1zmx4t1zp2plx.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1ztb14nbvq-v8.js +3 -0
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_20swopgb7gs5p.js +3 -0
- package/.build/next/server/chunks/{node_modules_ioredis_built_index_1-s3egdocnznd.js → node_modules_ioredis_built_index_0bym26c4shwf9.js} +1 -1
- package/.build/next/server/chunks/{node_modules_ioredis_built_index_14ex7cglfl3pz.js → node_modules_ioredis_built_index_0olys7xgnfo0i.js} +1 -1
- package/.build/next/server/chunks/{node_modules_ioredis_built_index_1w1hzk4_-8xu5.js → node_modules_ioredis_built_index_14ct1dd055dku.js} +1 -1
- package/.build/next/server/chunks/{node_modules_ioredis_built_index_15mwjswq7fcc7.js → node_modules_ioredis_built_index_1agrynr6yap-q.js} +1 -1
- package/.build/next/server/chunks/{node_modules_ioredis_built_index_1a9ll1mwrmtob.js → node_modules_ioredis_built_index_1ik97n_251xek.js} +1 -1
- package/.build/next/server/chunks/node_modules_ioredis_built_index_1vv514_mvh8ve.js +3 -0
- package/.build/next/server/chunks/open-sse_02t7zn7htyw-9._.js +1 -1
- package/.build/next/server/chunks/open-sse_03goq14q0_x4f._.js +1 -1
- package/.build/next/server/chunks/open-sse_03ipq-9xg4l9m._.js +1 -1
- package/.build/next/server/chunks/open-sse_0bl-irqke65hd._.js +1 -1
- package/.build/next/server/chunks/open-sse_0h0zluguzhqef._.js +16 -3
- package/.build/next/server/chunks/open-sse_0s84hi7h9418d._.js +16 -3
- package/.build/next/server/chunks/open-sse_1b6ivsct5ejh3._.js +1 -1
- package/.build/next/server/chunks/open-sse_1r2up99lm4jtz._.js +1 -1
- package/.build/next/server/chunks/open-sse_1tgbautgb4f7f._.js +16 -3
- package/.build/next/server/chunks/{open-sse_services_02bmh-sbso22m._.js → open-sse_services_00hw3r8y1gfsk._.js} +1 -1
- package/.build/next/server/chunks/open-sse_services_03wu42_5vmj9o._.js +2 -2
- package/.build/next/server/chunks/open-sse_services_0ct5y5fs-6yum._.js +2 -2
- package/.build/next/server/chunks/{open-sse_services_04dvqigm0hy_b._.js → open-sse_services_0faya5lemfn3z._.js} +1 -1
- package/.build/next/server/chunks/{open-sse_services_0884oo1_foqx1._.js → open-sse_services_0fqgcvavo8wg0._.js} +1 -1
- package/.build/next/server/chunks/{open-sse_services_0cjgk3rys3phs._.js → open-sse_services_0gp_perj2ozc7._.js} +1 -1
- package/.build/next/server/chunks/open-sse_services_0luw8b50a275y._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_0lz8kz3o3n32w._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_0o2xbv4-s_hgc._.js +2 -2
- package/.build/next/server/chunks/open-sse_services_0uzit9opfex07._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_10-13kqpampl8._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_11px-eu6wpco1._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_12xf6ogfm7fk6._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_13aor5_u0vw67._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_17to5z2yz9tp5._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1_z10i8xets76._.js +2 -2
- package/.build/next/server/chunks/open-sse_services_1aofhb43cunjk._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1bmzbrj-w51an._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1cfnib8brx231._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1m558021-9l1o._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1mixpyyaadj44._.js +2 -2
- package/.build/next/server/chunks/open-sse_services_1pb9vai4pzp46._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1u1h_rm99qyq_._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1v47txy532v7j._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_1zn2whnlx96gx._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_20qr88u5g_bzt._.js +3 -0
- package/.build/next/server/chunks/open-sse_services_kiroRegion_ts_1plr7t56zivs5._.js +1 -1
- package/.build/next/server/chunks/open-sse_utils_requestLogger_ts_0bd_-kg8s0mnb._.js +1 -1
- package/.build/next/server/chunks/open-sse_utils_requestLogger_ts_0o1bn8tbcrdys._.js +1 -1
- package/.build/next/server/chunks/{src_0gff8n1288m1s._.js → src_06dmt2gh7c2r5._.js} +1 -1
- package/.build/next/server/chunks/src_072_u91zja_z6._.js +1 -1
- package/.build/next/server/chunks/{src_0ogv5rsf3ovzt._.js → src_0iivcw6e2y8b-._.js} +1 -1
- package/.build/next/server/chunks/src_0jsr5vm5qt_kk._.js +1 -1
- package/.build/next/server/chunks/{src_1gr5o5rdqanpt._.js → src_0l9p-6g-6c00r._.js} +1 -1
- package/.build/next/server/chunks/src_1m93lsr72gv4e._.js +1 -1
- package/.build/next/server/chunks/src_1p24y5m9owsdz._.js +1 -1
- package/.build/next/server/chunks/{src_1w9wqtyffs4jp._.js → src_20-a3old2hlv7._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_0t6aj24w2w4um._.js → src_lib_05upj47v7jd8d._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_18c9gtbeeedlu._.js → src_lib_0g6dvcltrlrt1._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_plugins_manager_ts_082ank_n7lv72._.js → src_lib_plugins_manager_ts_06-b_e2ssdrqp._.js} +2 -2
- package/.build/next/server/chunks/{src_lib_plugins_manager_ts_08h-7dzhghsw_._.js → src_lib_plugins_manager_ts_07a371xptxn0i._.js} +2 -2
- package/.build/next/server/chunks/{src_lib_plugins_manager_ts_08obzclzfmgdo._.js → src_lib_plugins_manager_ts_07iwfiw5lpzv6._.js} +2 -2
- package/.build/next/server/chunks/{src_lib_plugins_manager_ts_0_8jhcn7g0hyd._.js → src_lib_plugins_manager_ts_094zfas129qox._.js} +2 -2
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_09x05wttn6gky._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0eicpmorbgq_0._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0j45w1t53tqiq._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0jtsoy2o58_fe._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0k2l6fz_allhv._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0m4u5d2zpf0jx._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0r69m_ija5052._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0rd7v66pzywb8._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0u9_z3h42wsrr._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_12ucso7gp_9we._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_16wp__3_qev5x._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1d_p6ksvmoo3y._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1l-e0sne7qzzx._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1lf_y4ssq-plx._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1qlgxrqwigi2t._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1u2eu34-upcvy._.js +3 -0
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_218376dd7xrc4._.js +3 -0
- package/.build/next/server/chunks/{src_lib_quota_0gw-asus4493x._.js → src_lib_quota_05418fyg4agnh._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_0mglshbqfhgw7._.js → src_lib_quota_05bcp_6tt7jbr._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_0zwicsy-gs0ct._.js → src_lib_quota_0nybt-asgnvf4._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_1o_jx24-m_fom._.js → src_lib_quota_0vqp3tcjqt1dw._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_2002143jitgx6._.js → src_lib_quota_0wb8erb76zq-0._.js} +1 -1
- package/.build/next/server/chunks/src_lib_quota_19hosofplhjh1._.js +3 -0
- package/.build/next/server/chunks/{src_lib_quota_quotaKey_ts_0e9929u5mgny4._.js → src_lib_quota_quotaKey_ts_00sufley9tfda._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_quotaKey_ts_06gq2e2g0ozlr._.js → src_lib_quota_quotaKey_ts_05unnu3n41ko_._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_quotaKey_ts_07_2e5snrn1ck._.js → src_lib_quota_quotaKey_ts_0_9lralwqmbb2._.js} +1 -1
- package/.build/next/server/chunks/{src_lib_quota_quotaKey_ts_0e3c15o4yzmvf._.js → src_lib_quota_quotaKey_ts_0anxeaf_zkp8o._.js} +1 -1
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0ffo874n5oku6._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0jafzf3ifgkuv._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0llm3vdjpfanc._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0o6z11z1bom_m._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0txirnznm274h._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0xuq_g-h5m3c1._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_10_ltppb3vez-._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_151pluvj7g-vc._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1ceheb324j-3o._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1es9tfkkri56i._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1g0ppe_dhr5q1._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1lyayo5r_xxjv._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1mc353kr74tft._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1q-_0jqsbdlh5._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1qd-81-a26uej._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1qg73wxhhll-s._.js +3 -0
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1t-h7vqoh9u3s._.js +3 -0
- package/.build/next/server/chunks/{src_lib_usage_callLogs_ts_0qnepwt2wta77._.js → src_lib_usage_callLogs_ts_1sie3xbxc5_10._.js} +1 -1
- package/.build/next/server/chunks/src_shared_constants_1vndx1xsi1o3x._.js +1 -1
- package/.build/next/server/chunks/{src_shared_services_03_eh-49sw70b._.js → src_shared_services_057p4bz8pl04k._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_04hl1xzqthbh1._.js → src_shared_services_080e2ej5vl6ay._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_0fjvc-g7uuyno._.js → src_shared_services_0eedv-3vaf69y._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_0kg6hc95fd11s._.js → src_shared_services_0erucmxdso94e._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_04z41n7bdg09x._.js → src_shared_services_0lt7_o14ml7sz._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_06s-_f77zvc_v._.js → src_shared_services_0mv_oizuaavj6._.js} +1 -1
- package/.build/next/server/chunks/src_shared_services_0pbe9rzf7waje._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_0yf7zz4c9vtx-._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_0zulbbb3ttk64._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_1-1kghymkipsb._.js +3 -0
- package/.build/next/server/chunks/{src_shared_services_13msbx-c1194y._.js → src_shared_services_106s8shtblhd5._.js} +1 -1
- package/.build/next/server/chunks/src_shared_services_11l3nwnjgyxm-._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_12t1-ga9w38dz._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_14w2j2iqdj9eb._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_176ndx2kuwev7._.js +3 -0
- package/.build/next/server/chunks/{src_shared_services_1jmf68l2lf9nz._.js → src_shared_services_1e0qskhl18qx6._.js} +1 -1
- package/.build/next/server/chunks/src_shared_services_1egld-y_7xfyo._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_1fhzl753fxvsf._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_1rjiu-sbe0cc_._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_1w8ezwxiuwg4-._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_1y_ma3zvgiio6._.js +3 -0
- package/.build/next/server/chunks/src_shared_services_1ypadc9tai46y._.js +3 -0
- package/.build/next/server/chunks/{src_shared_services_modelSyncScheduler_ts_0jprbetg42idf._.js → src_shared_services_modelSyncScheduler_ts_091bx-fd70d-_._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_modelSyncScheduler_ts_1w5s8oci38o86._.js → src_shared_services_modelSyncScheduler_ts_0x1-b0_nhg8oa._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_modelSyncScheduler_ts_0z9wckeen9uzt._.js → src_shared_services_modelSyncScheduler_ts_0zan1i5wv3x1s._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_modelSyncScheduler_ts_1admvvz7wu5mb._.js → src_shared_services_modelSyncScheduler_ts_1xd6j5kaxzekj._.js} +1 -1
- package/.build/next/server/chunks/{src_shared_services_modelSyncScheduler_ts_1nid3ygpp832c._.js → src_shared_services_modelSyncScheduler_ts_1zp-x3g0jwv9s._.js} +1 -1
- package/.build/next/server/chunks/ssr/_0rb4h6lptmehu._.js +1 -1
- package/.build/next/server/chunks/ssr/_1ucg-1lxpwd_3._.js +2 -2
- package/.build/next/server/chunks/ssr/_1wo8wxqh1dk5a._.js +2 -2
- package/.build/next/server/middleware-build-manifest.js +3 -3
- package/.build/next/server/middleware.js +2 -2
- package/.build/next/server/pages/500.html +1 -1
- package/.build/next/static/chunks/{1osm01_w12rhk.js → 273ss8mst5n0x.js} +1 -1
- package/.build/next/static/chunks/{0wxtns-mya-et.css → 36imcs53bs6ue.css} +1 -1
- package/.build/next/static/chunks/{2yhtmu668hmia.js → 41ia4t5lkoy-u.js} +1 -1
- package/open-sse/config/claudeTokens.ts +108 -0
- package/open-sse/executors/base.ts +17 -0
- package/open-sse/executors/kiro.ts +845 -91
- package/open-sse/handlers/chatCore/nonStreamingResponseParse.ts +14 -0
- package/open-sse/handlers/chatCore.ts +23 -3
- package/open-sse/handlers/responseTranslator.ts +29 -5
- package/open-sse/handlers/sseParser.ts +21 -0
- package/open-sse/services/combo/targetExhaustion.ts +16 -1
- package/open-sse/services/combo.ts +2 -0
- package/open-sse/services/kiroRegion.ts +20 -0
- package/open-sse/services/usage/kimi.ts +64 -5
- package/open-sse/services/webSearchResultText.ts +100 -0
- package/open-sse/translator/request/claude-to-openai.ts +194 -3
- package/open-sse/translator/request/openai-to-kiro.ts +165 -11
- package/open-sse/translator/response/kiro-to-openai.ts +16 -0
- package/open-sse/translator/response/openai-to-claude.ts +74 -3
- package/open-sse/utils/contextOverflowError.ts +63 -0
- package/open-sse/utils/finishReason.ts +8 -0
- package/open-sse/utils/pdfText.ts +1252 -0
- package/open-sse/utils/requestLogger.ts +4 -1
- package/open-sse/utils/stream.ts +19 -6
- package/open-sse/utils/streamHelpers.ts +3 -1
- package/open-sse/utils/streamPayloadCollector.ts +3 -0
- package/package.json +1 -1
- package/src/app/api/v1/messages/count_tokens/route.ts +64 -6
- package/src/app/api/v1/messages/route.ts +7 -1
- package/src/domain/quotaCache.ts +4 -2
- package/src/server/authz/pipeline.ts +6 -0
- package/src/shared/components/CommandPalette.tsx +2 -2
- package/src/shared/components/Sidebar.tsx +3 -3
- package/src/shared/utils/anthropicErrorShape.ts +89 -0
- package/src/sse/handlers/chat.ts +30 -0
- package/src/sse/handlers/webSearchEmulation.ts +1181 -0
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0agn1t27_-87q.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0bdbaz8ncan3j.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0ic-xl80j3ahf.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0j-gka-h5--g7.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0jikxjpd83y3m.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0pcsfxk7rl_qj.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_0rour4wnl6mch.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1-vgf7hsozo4d.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1-wk-99yzo_ij.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_11j-oo1fko_w9.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_163fonx9p1t53.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1_scz53f35ozv.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1b31tiezn9knj.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1bc7yeb23me7o.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1cy8wnhh8esbt.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1hcyk-boxbura.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1hjr8tkngjpn2.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1i9ijw0wkft95.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1o4j3aexo9biu.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1pvenj5ob2aem.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_1q3t40dvo4--p.js +0 -3
- package/.build/next/server/chunks/1q96_modules_@aws-sdk_nested-clients_dist-es_submodules_signin_index_2024waa5dd1lu.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0cyc8ns5c-hak._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0hsw8ehbw3i2o._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0jojq4ni9peyl._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0k_9tln3gjdsg._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0sh-ax_s9lxgs._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0yjugdbzmjz__._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0yku0wexi8ghl._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0yt9iwxll_l6u._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__0zgbbqlctz_ss._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1-1xnobnihmvu._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__10y_wajcozqre._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__172v_j4xarr6o._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__176x6fzvqwsiv._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__17ud9_3_ssk8k._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__19ocgqujae39l._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1cwkjoabvk0op._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1jb65mvmckdjg._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1ks8m6fd5ayhs._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1m7e1c6uyafq0._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1my791be0ej2f._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1ohivgmoa4y7_._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1pwuqglvqb8ae._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1q9d4sa50girl._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1qqnlb8mlv5qn._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1sbq18_dr5ht1._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__1wcvw0tlzacfj._.js +0 -3
- package/.build/next/server/chunks/[root-of-the-server]__20gdw36eknl9h._.js +0 -3
- package/.build/next/server/chunks/_0mqzrek7ffz5c._.js +0 -3
- package/.build/next/server/chunks/_0ox6qf339bblb._.js +0 -3
- package/.build/next/server/chunks/_0re9_1xpmi1in._.js +0 -3
- package/.build/next/server/chunks/_0w7y9fwzdv184._.js +0 -3
- package/.build/next/server/chunks/_1--z-c5w3yh_b._.js +0 -3
- package/.build/next/server/chunks/_11dfub0-g5hqx._.js +0 -3
- package/.build/next/server/chunks/_13xv49s2emgbh._.js +0 -12
- package/.build/next/server/chunks/_142m98dl-v5qx._.js +0 -3
- package/.build/next/server/chunks/_16fb5lg934z_y._.js +0 -3
- package/.build/next/server/chunks/_16ldvpp3ltmg_._.js +0 -3
- package/.build/next/server/chunks/_17i9uubpwxtr6._.js +0 -3
- package/.build/next/server/chunks/_18nswcjdn-o_d._.js +0 -3
- package/.build/next/server/chunks/_19d_r4e56lw6c._.js +0 -3
- package/.build/next/server/chunks/_19lsyjj_cdcma._.js +0 -3
- package/.build/next/server/chunks/_1_a8xtb4eim3-._.js +0 -3
- package/.build/next/server/chunks/_1c99m13xvj0dv._.js +0 -3
- package/.build/next/server/chunks/_1do5vraekw7a_._.js +0 -3
- package/.build/next/server/chunks/_1e-2ziz7vbvj9._.js +0 -3
- package/.build/next/server/chunks/_1foat8d-cw4p_._.js +0 -3
- package/.build/next/server/chunks/_1lg1a1-ip82th._.js +0 -3
- package/.build/next/server/chunks/_1lyng1xt6yaki._.js +0 -3
- package/.build/next/server/chunks/_1nprpllrhv5ur._.js +0 -3
- package/.build/next/server/chunks/_1nxn6ans9h-yd._.js +0 -3
- package/.build/next/server/chunks/_1ohylflm1s935._.js +0 -3
- package/.build/next/server/chunks/_1omvf1ucof_yl._.js +0 -3
- package/.build/next/server/chunks/_1p60mk1s2dj0m._.js +0 -3
- package/.build/next/server/chunks/_1p628qecv5bcu._.js +0 -3
- package/.build/next/server/chunks/_1t0wesdzmxm--._.js +0 -3
- package/.build/next/server/chunks/_1tryysi-zw-uk._.js +0 -3
- package/.build/next/server/chunks/_1u2fevomxng1z._.js +0 -3
- package/.build/next/server/chunks/_1u9svjs_bx9zp._.js +0 -3
- package/.build/next/server/chunks/_1ukh92xt_h9ls._.js +0 -3
- package/.build/next/server/chunks/_1v87bx9e8bvly._.js +0 -3
- package/.build/next/server/chunks/_1vf7irr1wo9p-._.js +0 -3
- package/.build/next/server/chunks/_1wkk7z3fobxbo._.js +0 -3
- package/.build/next/server/chunks/node_modules_0_x6ms_t9skng._.js +0 -3
- package/.build/next/server/chunks/node_modules_0gohbx9aorh0u._.js +0 -3
- package/.build/next/server/chunks/node_modules_0kv7lp09lm4-8._.js +0 -3
- package/.build/next/server/chunks/node_modules_0l3c--_iz3xqs._.js +0 -3
- package/.build/next/server/chunks/node_modules_0p85cgv7zv71m._.js +0 -3
- package/.build/next/server/chunks/node_modules_0pkok82ldrbvy._.js +0 -3
- package/.build/next/server/chunks/node_modules_0taa189fdyrvj._.js +0 -3
- package/.build/next/server/chunks/node_modules_0xbbdz3qows09._.js +0 -3
- package/.build/next/server/chunks/node_modules_0z17bntb8cv10._.js +0 -3
- package/.build/next/server/chunks/node_modules_12n0xi55k1732._.js +0 -3
- package/.build/next/server/chunks/node_modules_12w64fw3z-bcd._.js +0 -3
- package/.build/next/server/chunks/node_modules_17q-udh619fx5._.js +0 -3
- package/.build/next/server/chunks/node_modules_19z_pj5419z4n._.js +0 -3
- package/.build/next/server/chunks/node_modules_1kx78kk7zgs6_._.js +0 -3
- package/.build/next/server/chunks/node_modules_1l6a6ml6v2i_k._.js +0 -3
- package/.build/next/server/chunks/node_modules_1lkgfl4ettcxp._.js +0 -3
- package/.build/next/server/chunks/node_modules_1t9hizql924bp._.js +0 -3
- package/.build/next/server/chunks/node_modules_1tdhc46ytvj0n._.js +0 -3
- package/.build/next/server/chunks/node_modules_1uk_qp0gbho8r._.js +0 -3
- package/.build/next/server/chunks/node_modules_1w0h0i7jkq9fa._.js +0 -3
- package/.build/next/server/chunks/node_modules_1xtwpfq69aty8._.js +0 -3
- package/.build/next/server/chunks/node_modules_1zlh23qg1uq5s._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0fukg5x40kwub._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0g1gza5ppvhr8._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0h_fcdlqd8s5n._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0jpc8oc6b6i93._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0rr7gmwwe5-dh._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0v_xskgrff6wd._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_0zuuhl2wpxt8p._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_11ckwzfy422am._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_11d97npmgf-3r._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_12_vv1aumcw9-._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_18d7kh8fes7vc._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1d2_q1k2wkf5s._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1glhxo4bsedyk._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1jk-2_ih5r8hp._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1mq27hyj74pss._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1n6-p7yy8md7l._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1os1eoc8tim1y._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1req4zcx_0cnx._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1v244fqkm56j8._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1wwzw_mr_0uhv._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_1xyy_nekye31j._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_20myne_q7f2m8._.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_04gwvpkl1nug0.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0630cbcbg0avk.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0a--3zhc3833c.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0cig_ru63jzhj.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0e_80iimfmh81.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0hmbodnfjrup6.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0pbaee_84omvg.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0xwupvdbu9jfl.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_0yd50kn037tj7.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1167_x8-auv93.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_126xpn2yg3grm.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_16ku3dxvhzhkk.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_19bzdp_-n6sq0.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1_ik1zykfz6zp.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1dqajoz1ygnbf.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1o4k7zmx1j2bu.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1oavue5eviexc.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1rqp1l_ptnubg.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1rw3-4dmewdr4.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1tyx-v56ebpk_.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_1wn_1b_n7nq-2.js +0 -3
- package/.build/next/server/chunks/node_modules_@aws-sdk_credential-provider-sso_dist-es_loadSso_20yftlrkp9ara.js +0 -3
- package/.build/next/server/chunks/node_modules_ioredis_built_index_1yvlsm3ny3pj9.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0cukrrcbxl1gr._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0ef13xoz5w433._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0hdeb5rg-7ctc._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0jjlzdp9t8t3p._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0jyo433yl_s3-._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0w0o42y4k_0xp._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0x51vcvrd1uy1._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_0yenufzwhjgz0._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_138omazpx4xu1._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_162a5-wghb28k._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1blmj_n8yoazn._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1c2_vovh6b_pe._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1fgkobij47qea._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1iuacwne-axoo._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1ktbqi-1t65pn._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1mdjfnli_1im9._.js +0 -3
- package/.build/next/server/chunks/open-sse_services_1s729m6to90v4._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0b48oh-otx_ol._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0fnwm57tvxp50._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0qdw6u_-fb9qe._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0u63lwdqoezav._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0uw_jlq70rwri._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_0yxhkyvrf6-x_._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1-91nmo9cckkg._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_11dshqgaqa7k2._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_12z3np4ktvyaw._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1548t2uj3kl8c._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_198mvq_7kkncw._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1cax0u9i8n09r._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1dw31gw8gv5b4._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1j3eh7kbz5s33._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1jgvga752m2_v._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1umjhh6i4065t._.js +0 -3
- package/.build/next/server/chunks/src_lib_plugins_manager_ts_1ydcm2zxi9w3m._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_1vpqly464si1q._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0eqloedth3662._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0gsym2up09qbd._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0lqr7nuv40xhn._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0qo8767hpoa2_._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0r56lkpo6ejtl._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0u2q7i-ffa3-0._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_0y54fg642lkx_._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_144c1_26o_xs_._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1a5p04dslzkkr._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1fqs-9wvkwg8u._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1g_t5orpm0h2k._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1kydk56tgu8ni._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1sd-o-ncs0v_b._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1u5q9l5wugo13._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1vebln5zz0jh1._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1x4r4ykpvtsng._.js +0 -3
- package/.build/next/server/chunks/src_lib_quota_quotaKey_ts_1xazcu5ici-w1._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_083ix1a7l974z._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_093xyaxwtg-ji._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_0i9oken9kxj9j._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_0r-8-60-r4v_r._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_0r7xmlmt1k9hy._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_0rg59_7jmlgm-._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_0wme2znpr6_8s._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_126q0wbgkzp5l._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_12se2mvwbr2q0._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_1fwlbkehafca_._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_1m3xkf85ae5xt._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_1obo27zju04g-._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_1rnq7eju312ri._.js +0 -3
- package/.build/next/server/chunks/src_shared_services_1z51753rm-kau._.js +0 -3
- /package/.build/next/static/{9h-Y9U1tfaZmzr5AGgiYn → ScDemTJTEZMscCIzRWSqu}/_buildManifest.js +0 -0
- /package/.build/next/static/{9h-Y9U1tfaZmzr5AGgiYn → ScDemTJTEZMscCIzRWSqu}/_clientMiddlewareManifest.js +0 -0
- /package/.build/next/static/{9h-Y9U1tfaZmzr5AGgiYn → ScDemTJTEZMscCIzRWSqu}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,1252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plain text of a PDF, for upstreams that take no document input (Kiro): Claude Code's Read tool
|
|
3
|
+
* and Anthropic `document` blocks send PDFs as base64. No dependency: objects and object
|
|
4
|
+
* streams are read, Flate streams inflated, pages walked in page-tree order, text operators
|
|
5
|
+
* (Tj, TJ, ', ") decoded through each font's ToUnicode map (simple fonts: one byte per
|
|
6
|
+
* character). Scanned PDFs (images only) and encrypted ones give no text.
|
|
7
|
+
*/
|
|
8
|
+
import { createHash } from "node:crypto";
|
|
9
|
+
import { crc32, deflateSync, inflateRawSync, inflateSync } from "node:zlib";
|
|
10
|
+
|
|
11
|
+
const MAX_PDF_BYTES = 32 * 1024 * 1024;
|
|
12
|
+
const MAX_TEXT_CHARS = 400_000;
|
|
13
|
+
const MAX_STREAM_BYTES = 16 * 1024 * 1024;
|
|
14
|
+
/** Inflated bytes for one stream and for the whole file (a Flate bomb stops here). */
|
|
15
|
+
const MAX_INFLATED_STREAM = 32 * 1024 * 1024;
|
|
16
|
+
const MAX_INFLATED_TOTAL = 128 * 1024 * 1024;
|
|
17
|
+
/** Entries one font's width table or ToUnicode map may hold. */
|
|
18
|
+
const MAX_MAP_ENTRIES = 70_000;
|
|
19
|
+
/** Work time before the pages read so far are returned (the translator runs on the event loop). */
|
|
20
|
+
const MAX_WORK_MS = 1500;
|
|
21
|
+
|
|
22
|
+
type PdfObject = { dict: string; streamStart?: number; streamEnd?: number; inline?: string };
|
|
23
|
+
type CMap = { bytes: number; map: Map<number, string> };
|
|
24
|
+
/** A font as the text extraction needs it: code length, ToUnicode map, glyph widths (1/1000 em). */
|
|
25
|
+
type FontInfo = { bytes: number; cmap?: CMap; widths: Map<number, number>; dw: number };
|
|
26
|
+
|
|
27
|
+
class PdfReader {
|
|
28
|
+
private objs = new Map<number, PdfObject>();
|
|
29
|
+
private decoded = new Map<number, string | null>();
|
|
30
|
+
private inflated = 0;
|
|
31
|
+
constructor(
|
|
32
|
+
private raw: Buffer,
|
|
33
|
+
private s: string
|
|
34
|
+
) {}
|
|
35
|
+
|
|
36
|
+
scan(): void {
|
|
37
|
+
const re = /(\d+)\s+(\d+)\s+obj\b/g;
|
|
38
|
+
let m: RegExpExecArray | null;
|
|
39
|
+
while ((m = re.exec(this.s))) {
|
|
40
|
+
const num = Number(m[1]);
|
|
41
|
+
const bodyStart = m.index + m[0].length;
|
|
42
|
+
const end = this.s.indexOf("endobj", bodyStart);
|
|
43
|
+
if (end === -1) break;
|
|
44
|
+
// Searches stay inside this object's body, so the scan is linear in the file size.
|
|
45
|
+
const body = this.s.slice(bodyStart, end);
|
|
46
|
+
const streamKw = body.indexOf("stream");
|
|
47
|
+
if (streamKw !== -1 && body.slice(streamKw - 3, streamKw) !== "end") {
|
|
48
|
+
let start = bodyStart + streamKw + 6;
|
|
49
|
+
if (this.s[start] === "\r") start++;
|
|
50
|
+
if (this.s[start] === "\n") start++;
|
|
51
|
+
const stop = bodyStart + body.lastIndexOf("endstream");
|
|
52
|
+
this.objs.set(num, {
|
|
53
|
+
dict: body.slice(0, streamKw),
|
|
54
|
+
streamStart: start,
|
|
55
|
+
streamEnd: stop > start ? stop : end,
|
|
56
|
+
});
|
|
57
|
+
} else {
|
|
58
|
+
this.objs.set(num, { dict: body });
|
|
59
|
+
}
|
|
60
|
+
re.lastIndex = end + 6;
|
|
61
|
+
}
|
|
62
|
+
// Objects packed in object streams (/Type /ObjStm).
|
|
63
|
+
for (const [num, obj] of [...this.objs]) {
|
|
64
|
+
if (!/\/Type\s*\/ObjStm\b/.test(obj.dict)) continue;
|
|
65
|
+
const data = this.stream(num);
|
|
66
|
+
const first = Number(/\/First\s+(\d+)/.exec(obj.dict)?.[1]);
|
|
67
|
+
const n = Number(/\/N\s+(\d+)/.exec(obj.dict)?.[1]);
|
|
68
|
+
if (!data || !Number.isFinite(first) || !Number.isFinite(n)) continue;
|
|
69
|
+
const header = data.slice(0, first).trim().split(/\s+/).map(Number);
|
|
70
|
+
for (let i = 0; i < n && i * 2 + 1 < header.length; i++) {
|
|
71
|
+
const objNum = header[i * 2];
|
|
72
|
+
const off = first + header[i * 2 + 1];
|
|
73
|
+
const next =
|
|
74
|
+
i + 1 < n && i * 2 + 3 < header.length ? first + header[i * 2 + 3] : data.length;
|
|
75
|
+
if (!this.objs.has(objNum)) this.objs.set(objNum, { dict: data.slice(off, next) });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
get(num: number): PdfObject | undefined {
|
|
81
|
+
return this.objs.get(num);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The decoded stream of an object (Flate only; latin1 string), or null. */
|
|
85
|
+
stream(num: number): string | null {
|
|
86
|
+
if (this.decoded.has(num)) return this.decoded.get(num) ?? null;
|
|
87
|
+
const obj = this.objs.get(num);
|
|
88
|
+
let out: string | null = null;
|
|
89
|
+
if (obj?.streamStart !== undefined && obj.streamEnd !== undefined) {
|
|
90
|
+
const bytes = this.raw.subarray(
|
|
91
|
+
obj.streamStart,
|
|
92
|
+
Math.min(obj.streamEnd, obj.streamStart + MAX_STREAM_BYTES)
|
|
93
|
+
);
|
|
94
|
+
const filter = /\/Filter\s*(\[[^\]]*\]|\/\w+)/.exec(obj.dict)?.[1] || "";
|
|
95
|
+
if (!filter) out = bytes.toString("latin1");
|
|
96
|
+
else if (
|
|
97
|
+
/^\/FlateDecode$|^\[\s*\/FlateDecode\s*\]$/.test(filter.trim()) &&
|
|
98
|
+
this.inflated < MAX_INFLATED_TOTAL
|
|
99
|
+
) {
|
|
100
|
+
const maxOutputLength = Math.min(MAX_INFLATED_STREAM, MAX_INFLATED_TOTAL - this.inflated);
|
|
101
|
+
try {
|
|
102
|
+
out = inflateSync(bytes, { maxOutputLength }).toString("latin1");
|
|
103
|
+
} catch {
|
|
104
|
+
try {
|
|
105
|
+
out = inflateRawSync(bytes, { maxOutputLength }).toString("latin1");
|
|
106
|
+
} catch {
|
|
107
|
+
out = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
this.inflated += out?.length ?? 0;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
this.decoded.set(num, out);
|
|
114
|
+
return out;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** The text of an object's dictionary, following one indirect reference. */
|
|
118
|
+
dictOf(value: string): string {
|
|
119
|
+
const ref = /^\s*(\d+)\s+\d+\s+R/.exec(value);
|
|
120
|
+
if (ref) return this.objs.get(Number(ref[1]))?.dict || "";
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** The stream bytes as stored (no filter applied), cut to /Length when it is a number. */
|
|
125
|
+
rawStream(num: number): Buffer | null {
|
|
126
|
+
const obj = this.objs.get(num);
|
|
127
|
+
if (obj?.streamStart === undefined || obj.streamEnd === undefined) return null;
|
|
128
|
+
const len = /\/Length\s+(\d+)\b(?!\s+\d+\s+R)/.exec(obj.dict);
|
|
129
|
+
const end = len ? Math.min(obj.streamEnd, obj.streamStart + Number(len[1])) : obj.streamEnd;
|
|
130
|
+
return this.raw.subarray(obj.streamStart, Math.min(end, obj.streamStart + MAX_STREAM_BYTES));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Flate data inflated within the file's budget (image data: not cached). */
|
|
134
|
+
inflate(bytes: Buffer): Buffer | null {
|
|
135
|
+
if (this.inflated >= MAX_INFLATED_TOTAL) return null;
|
|
136
|
+
const maxOutputLength = Math.min(MAX_INFLATED_STREAM, MAX_INFLATED_TOTAL - this.inflated);
|
|
137
|
+
let out: Buffer | null = null;
|
|
138
|
+
try {
|
|
139
|
+
out = inflateSync(bytes, { maxOutputLength });
|
|
140
|
+
} catch {
|
|
141
|
+
try {
|
|
142
|
+
out = inflateRawSync(bytes, { maxOutputLength });
|
|
143
|
+
} catch {
|
|
144
|
+
out = null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
this.inflated += out?.length ?? 0;
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/** The `<< ... >>` that starts at or after `from` (nesting counted). */
|
|
153
|
+
function readDict(s: string, from: number): string {
|
|
154
|
+
const start = s.indexOf("<<", from);
|
|
155
|
+
if (start === -1) return "";
|
|
156
|
+
let depth = 0;
|
|
157
|
+
for (let i = start; i < s.length - 1; i++) {
|
|
158
|
+
if (s[i] === "<" && s[i + 1] === "<") {
|
|
159
|
+
depth++;
|
|
160
|
+
i++;
|
|
161
|
+
} else if (s[i] === ">" && s[i + 1] === ">") {
|
|
162
|
+
depth--;
|
|
163
|
+
i++;
|
|
164
|
+
if (depth === 0) return s.slice(start, i + 1);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return s.slice(start);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** The value after `/Key`: an inline dict, an array, or an indirect reference. */
|
|
171
|
+
function valueOf(dict: string, key: string): string {
|
|
172
|
+
const m = new RegExp(`/${key}\\b\\s*`).exec(dict);
|
|
173
|
+
if (!m) return "";
|
|
174
|
+
const at = m.index + m[0].length;
|
|
175
|
+
if (dict.startsWith("<<", at)) return readDict(dict, at);
|
|
176
|
+
if (dict[at] === "[") {
|
|
177
|
+
const close = dict.indexOf("]", at);
|
|
178
|
+
return close === -1 ? "" : dict.slice(at, close + 1);
|
|
179
|
+
}
|
|
180
|
+
return /^\d+\s+\d+\s+R/.exec(dict.slice(at))?.[0] || "";
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function refsIn(value: string): number[] {
|
|
184
|
+
return [...value.matchAll(/(\d+)\s+\d+\s+R/g)].map((x) => Number(x[1]));
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function hexToBytes(hex: string): number[] {
|
|
188
|
+
const clean = hex.replace(/[^0-9a-fA-F]/g, "");
|
|
189
|
+
const padded = clean.length % 2 ? `${clean}0` : clean;
|
|
190
|
+
const out: number[] = [];
|
|
191
|
+
for (let i = 0; i < padded.length; i += 2) out.push(parseInt(padded.slice(i, i + 2), 16));
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function utf16Hex(hex: string): string {
|
|
196
|
+
const b = hexToBytes(hex);
|
|
197
|
+
let out = "";
|
|
198
|
+
for (let i = 0; i + 1 < b.length; i += 2) out += String.fromCharCode((b[i] << 8) | b[i + 1]);
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function parseCMap(text: string): CMap {
|
|
203
|
+
const map = new Map<number, string>();
|
|
204
|
+
let bytes = 1;
|
|
205
|
+
const cs = /begincodespacerange\s*<([0-9a-fA-F]+)>/.exec(text);
|
|
206
|
+
if (cs) bytes = Math.max(1, Math.ceil(cs[1].length / 2));
|
|
207
|
+
for (const block of text.matchAll(/beginbfchar([\s\S]*?)endbfchar/g)) {
|
|
208
|
+
for (const p of block[1].matchAll(/<([0-9a-fA-F]+)>\s*<([0-9a-fA-F]*)>/g)) {
|
|
209
|
+
if (map.size >= MAX_MAP_ENTRIES) break;
|
|
210
|
+
map.set(parseInt(p[1], 16), utf16Hex(p[2]));
|
|
211
|
+
bytes = Math.max(bytes, Math.ceil(p[1].length / 2));
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
for (const block of text.matchAll(/beginbfrange([\s\S]*?)endbfrange/g)) {
|
|
215
|
+
const re = /<([0-9a-fA-F]+)>\s*<([0-9a-fA-F]+)>\s*(<[0-9a-fA-F]*>|\[[^\]]*\])/g;
|
|
216
|
+
let p: RegExpExecArray | null;
|
|
217
|
+
while ((p = re.exec(block[1]))) {
|
|
218
|
+
const lo = parseInt(p[1], 16);
|
|
219
|
+
const hi = Math.min(parseInt(p[2], 16), lo + 65535);
|
|
220
|
+
bytes = Math.max(bytes, Math.ceil(p[1].length / 2));
|
|
221
|
+
if (p[3].startsWith("[")) {
|
|
222
|
+
const items = [...p[3].matchAll(/<([0-9a-fA-F]*)>/g)].map((x) => utf16Hex(x[1]));
|
|
223
|
+
for (let c = lo; c <= hi && c - lo < items.length && map.size < MAX_MAP_ENTRIES; c++)
|
|
224
|
+
map.set(c, items[c - lo]);
|
|
225
|
+
} else {
|
|
226
|
+
const base = utf16Hex(p[3].slice(1, -1));
|
|
227
|
+
const last = base.charCodeAt(base.length - 1);
|
|
228
|
+
for (let c = lo; c <= hi && map.size < MAX_MAP_ENTRIES; c++)
|
|
229
|
+
map.set(c, base.slice(0, -1) + String.fromCharCode(last + (c - lo)));
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { bytes, map };
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function literalBytes(s: string, start: number): { bytes: number[]; end: number } {
|
|
237
|
+
const out: number[] = [];
|
|
238
|
+
let depth = 1;
|
|
239
|
+
let i = start + 1;
|
|
240
|
+
for (; i < s.length && depth > 0; i++) {
|
|
241
|
+
const c = s[i];
|
|
242
|
+
if (c === "\\") {
|
|
243
|
+
const n = s[++i];
|
|
244
|
+
if (n === "n") out.push(10);
|
|
245
|
+
else if (n === "r") out.push(13);
|
|
246
|
+
else if (n === "t") out.push(9);
|
|
247
|
+
else if (n === "b") out.push(8);
|
|
248
|
+
else if (n === "f") out.push(12);
|
|
249
|
+
else if (n >= "0" && n <= "7") {
|
|
250
|
+
let oct = n;
|
|
251
|
+
while (oct.length < 3 && s[i + 1] >= "0" && s[i + 1] <= "7") oct += s[++i];
|
|
252
|
+
out.push(parseInt(oct, 8) & 255);
|
|
253
|
+
} else if (n === "\r" || n === "\n") {
|
|
254
|
+
if (n === "\r" && s[i + 1] === "\n") i++;
|
|
255
|
+
} else out.push(n.charCodeAt(0) & 255);
|
|
256
|
+
} else if (c === "(") {
|
|
257
|
+
depth++;
|
|
258
|
+
out.push(40);
|
|
259
|
+
} else if (c === ")") {
|
|
260
|
+
depth--;
|
|
261
|
+
if (depth > 0) out.push(41);
|
|
262
|
+
} else out.push(c.charCodeAt(0) & 255);
|
|
263
|
+
}
|
|
264
|
+
return { bytes: out, end: i };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
function codesOf(bytes: number[], size: number): number[] {
|
|
268
|
+
const codes: number[] = [];
|
|
269
|
+
for (let i = 0; i + size - 1 < bytes.length; i += size) {
|
|
270
|
+
let code = 0;
|
|
271
|
+
for (let k = 0; k < size; k++) code = (code << 8) | bytes[i + k];
|
|
272
|
+
codes.push(code);
|
|
273
|
+
}
|
|
274
|
+
return codes;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Text and width (1/1000 em) of a shown string. */
|
|
278
|
+
function decodeShown(bytes: number[], font: FontInfo | undefined): { text: string; width: number } {
|
|
279
|
+
const size = font?.cmap?.map.size ? font.cmap.bytes : font?.bytes || 1;
|
|
280
|
+
let text = "";
|
|
281
|
+
let width = 0;
|
|
282
|
+
for (const code of codesOf(bytes, size)) {
|
|
283
|
+
width += font?.widths.get(code) ?? font?.dw ?? 500;
|
|
284
|
+
if (font?.cmap?.map.size) text += font.cmap.map.get(code) ?? "";
|
|
285
|
+
else if (code >= 32 || code === 9) text += String.fromCharCode(code);
|
|
286
|
+
}
|
|
287
|
+
return { text, width };
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Glyph widths from a simple font's /Widths or a CID font's /W array. */
|
|
291
|
+
function readWidths(
|
|
292
|
+
pdf: PdfReader,
|
|
293
|
+
fontDict: string
|
|
294
|
+
): { widths: Map<number, number>; dw: number; cid: boolean } {
|
|
295
|
+
const widths = new Map<number, number>();
|
|
296
|
+
const isType0 = /\/Subtype\s*\/Type0\b/.test(fontDict);
|
|
297
|
+
if (isType0) {
|
|
298
|
+
const descRef = refsIn(valueOf(fontDict, "DescendantFonts"))[0];
|
|
299
|
+
const desc = descRef !== undefined ? pdf.get(descRef)?.dict || "" : "";
|
|
300
|
+
const dw = Number(/\/DW\s+(\d+)/.exec(desc)?.[1] || 1000);
|
|
301
|
+
let w = valueOf(desc, "W");
|
|
302
|
+
const wRef = /^\s*(\d+)\s+\d+\s+R/.exec(w);
|
|
303
|
+
if (wRef) w = pdf.get(Number(wRef[1]))?.dict || "";
|
|
304
|
+
const tokens = [...w.replace(/^\s*\[|\]\s*$/g, "").matchAll(/\[|\]|[-+]?\d*\.?\d+/g)].map(
|
|
305
|
+
(t) => t[0]
|
|
306
|
+
);
|
|
307
|
+
let i = 0;
|
|
308
|
+
while (i < tokens.length) {
|
|
309
|
+
const first = Number(tokens[i]);
|
|
310
|
+
if (tokens[i + 1] === "[") {
|
|
311
|
+
let c = first;
|
|
312
|
+
i += 2;
|
|
313
|
+
while (i < tokens.length && tokens[i] !== "]") {
|
|
314
|
+
if (widths.size < MAX_MAP_ENTRIES) widths.set(c, Number(tokens[i]));
|
|
315
|
+
c++;
|
|
316
|
+
i++;
|
|
317
|
+
}
|
|
318
|
+
i++;
|
|
319
|
+
} else if (i + 2 < tokens.length) {
|
|
320
|
+
const last = Number(tokens[i + 1]);
|
|
321
|
+
const width = Number(tokens[i + 2]);
|
|
322
|
+
for (let c = first; c <= last && widths.size < MAX_MAP_ENTRIES; c++) widths.set(c, width);
|
|
323
|
+
i += 3;
|
|
324
|
+
} else break;
|
|
325
|
+
}
|
|
326
|
+
return { widths, dw, cid: true };
|
|
327
|
+
}
|
|
328
|
+
const firstChar = Number(/\/FirstChar\s+(\d+)/.exec(fontDict)?.[1] || 0);
|
|
329
|
+
let list = valueOf(fontDict, "Widths");
|
|
330
|
+
const ref = /^\s*(\d+)\s+\d+\s+R/.exec(list);
|
|
331
|
+
if (ref) list = pdf.get(Number(ref[1]))?.dict || "";
|
|
332
|
+
[...list.matchAll(/[-+]?\d*\.?\d+/g)].forEach((m, k) => widths.set(firstChar + k, Number(m[0])));
|
|
333
|
+
const dw = Number(/\/MissingWidth\s+(\d+)/.exec(fontDict)?.[1] || 500);
|
|
334
|
+
return { widths, dw, cid: false };
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/** Text of one page's content stream(s). */
|
|
338
|
+
function contentText(content: string, fonts: Map<string, FontInfo>): string {
|
|
339
|
+
let out = "";
|
|
340
|
+
let font: FontInfo | undefined;
|
|
341
|
+
let fontSize = 12;
|
|
342
|
+
let scale = 1;
|
|
343
|
+
// Pen position on the current line (text space units), and the last line's y.
|
|
344
|
+
let originX = 0;
|
|
345
|
+
let penX = 0;
|
|
346
|
+
let lineY: number | null = null;
|
|
347
|
+
const stack: unknown[] = [];
|
|
348
|
+
const newline = () => {
|
|
349
|
+
if (out && !out.endsWith("\n")) out += "\n";
|
|
350
|
+
};
|
|
351
|
+
const space = () => {
|
|
352
|
+
if (out && !out.endsWith(" ") && !out.endsWith("\n")) out += " ";
|
|
353
|
+
};
|
|
354
|
+
const show = (bytes: number[]) => {
|
|
355
|
+
const shown = decodeShown(bytes, font);
|
|
356
|
+
out += shown.text;
|
|
357
|
+
penX += (shown.width / 1000) * fontSize;
|
|
358
|
+
};
|
|
359
|
+
// A move on the same line: a gap wider than a fifth of the font size is a word space.
|
|
360
|
+
const moveTo = (x: number, y: number | null) => {
|
|
361
|
+
if (y !== null && lineY !== null && Math.abs(y - lineY) > 0.5) newline();
|
|
362
|
+
else if (x - penX > 0.2 * fontSize) space();
|
|
363
|
+
if (y !== null) lineY = y;
|
|
364
|
+
originX = x;
|
|
365
|
+
penX = x;
|
|
366
|
+
};
|
|
367
|
+
const s = content;
|
|
368
|
+
let i = 0;
|
|
369
|
+
while (i < s.length && out.length < MAX_TEXT_CHARS) {
|
|
370
|
+
const c = s[i];
|
|
371
|
+
if (c === "(") {
|
|
372
|
+
const lit = literalBytes(s, i);
|
|
373
|
+
stack.push({ str: lit.bytes });
|
|
374
|
+
i = lit.end;
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
if (c === "<" && s[i + 1] !== "<") {
|
|
378
|
+
const close = s.indexOf(">", i);
|
|
379
|
+
if (close === -1) break;
|
|
380
|
+
stack.push({ str: hexToBytes(s.slice(i + 1, close)) });
|
|
381
|
+
i = close + 1;
|
|
382
|
+
continue;
|
|
383
|
+
}
|
|
384
|
+
if (c === "<" && s[i + 1] === "<") {
|
|
385
|
+
// Inline dictionary (marked content properties): skip it.
|
|
386
|
+
const d = readDict(s, i);
|
|
387
|
+
i += Math.max(2, d.length);
|
|
388
|
+
continue;
|
|
389
|
+
}
|
|
390
|
+
if (c === "[") {
|
|
391
|
+
// TJ array: strings and kerning numbers.
|
|
392
|
+
const parts: Array<number | number[]> = [];
|
|
393
|
+
i++;
|
|
394
|
+
while (i < s.length && s[i] !== "]") {
|
|
395
|
+
if (s[i] === "(") {
|
|
396
|
+
const lit = literalBytes(s, i);
|
|
397
|
+
parts.push(lit.bytes);
|
|
398
|
+
i = lit.end;
|
|
399
|
+
} else if (s[i] === "<") {
|
|
400
|
+
const close = s.indexOf(">", i);
|
|
401
|
+
if (close === -1) break;
|
|
402
|
+
parts.push(hexToBytes(s.slice(i + 1, close)));
|
|
403
|
+
i = close + 1;
|
|
404
|
+
} else if (/[-+.\d]/.test(s[i])) {
|
|
405
|
+
const num = /^[-+]?\d*\.?\d+/.exec(s.slice(i, i + 32));
|
|
406
|
+
if (num) {
|
|
407
|
+
parts.push(Number(num[0]));
|
|
408
|
+
i += num[0].length;
|
|
409
|
+
} else i++;
|
|
410
|
+
} else i++;
|
|
411
|
+
}
|
|
412
|
+
stack.push({ arr: parts });
|
|
413
|
+
i++;
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (c === "/") {
|
|
417
|
+
const name = /^\/[^\s/<>[\]()%]+/.exec(s.slice(i, i + 128));
|
|
418
|
+
stack.push(name ? name[0] : "/");
|
|
419
|
+
i += name ? name[0].length : 1;
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (/[-+.\d]/.test(c)) {
|
|
423
|
+
const num = /^[-+]?\d*\.?\d+/.exec(s.slice(i, i + 32));
|
|
424
|
+
if (num) {
|
|
425
|
+
stack.push(Number(num[0]));
|
|
426
|
+
i += num[0].length;
|
|
427
|
+
continue;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
if (/[A-Za-z'"*]/.test(c)) {
|
|
431
|
+
const op = /^[A-Za-z'"*]+/.exec(s.slice(i, i + 16))?.[0] || c;
|
|
432
|
+
i += op.length;
|
|
433
|
+
const n = (k: number) => {
|
|
434
|
+
const v = stack[stack.length - k];
|
|
435
|
+
return typeof v === "number" ? v : 0;
|
|
436
|
+
};
|
|
437
|
+
const top = stack[stack.length - 1] as
|
|
438
|
+
{ str?: number[]; arr?: Array<number | number[]> } | undefined;
|
|
439
|
+
if (op === "Tf") {
|
|
440
|
+
const name = stack[stack.length - 2];
|
|
441
|
+
font = typeof name === "string" ? fonts.get(name.slice(1)) : undefined;
|
|
442
|
+
fontSize = Math.abs(n(1)) * scale || fontSize;
|
|
443
|
+
} else if (op === "Tj" && top?.str) {
|
|
444
|
+
show(top.str);
|
|
445
|
+
} else if ((op === "'" || op === '"') && top?.str) {
|
|
446
|
+
newline();
|
|
447
|
+
show(top.str);
|
|
448
|
+
} else if (op === "TJ" && top?.arr) {
|
|
449
|
+
for (const part of top.arr) {
|
|
450
|
+
if (Array.isArray(part)) show(part);
|
|
451
|
+
else {
|
|
452
|
+
// A negative adjustment wider than a kerning pair is a word gap (TeX word spaces
|
|
453
|
+
// shrink to about 0.2 em, kerning pairs stay below about 0.12 em).
|
|
454
|
+
if (part < -160) space();
|
|
455
|
+
penX -= (part / 1000) * fontSize;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
} else if (op === "Td" || op === "TD") {
|
|
459
|
+
moveTo(originX + n(2) * scale, lineY === null ? n(1) : lineY + n(1) * scale);
|
|
460
|
+
} else if (op === "Tm") {
|
|
461
|
+
scale = Math.hypot(n(6), n(5)) || 1;
|
|
462
|
+
moveTo(n(2), n(1));
|
|
463
|
+
} else if (op === "T*") {
|
|
464
|
+
newline();
|
|
465
|
+
penX = originX;
|
|
466
|
+
} else if (op === "BT") {
|
|
467
|
+
originX = 0;
|
|
468
|
+
penX = 0;
|
|
469
|
+
} else if (op === "BI") {
|
|
470
|
+
// Inline image: skip its data up to EI.
|
|
471
|
+
const ei = s.indexOf("EI", i);
|
|
472
|
+
i = ei === -1 ? s.length : ei + 2;
|
|
473
|
+
}
|
|
474
|
+
stack.length = 0;
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
i++;
|
|
478
|
+
}
|
|
479
|
+
return out;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* `images`: the file has image objects (a scanned page is one image, with no text).
|
|
484
|
+
* `pageChars`: characters (no white space) of each page that was read.
|
|
485
|
+
*/
|
|
486
|
+
type PdfText = { text: string; pages: number; images: boolean; pageChars: number[] };
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Claude Code sends the same PDF again on every later turn of a conversation: the last results
|
|
490
|
+
* are kept by content hash (a few entries, text only).
|
|
491
|
+
*/
|
|
492
|
+
const CACHE_ENTRIES = 8;
|
|
493
|
+
const cache = new Map<string, PdfText | null>();
|
|
494
|
+
|
|
495
|
+
function cacheKeyOf(base64: string): string | null {
|
|
496
|
+
if (typeof base64 !== "string" || base64.length < 44) return null;
|
|
497
|
+
if (base64.length > Math.ceil((MAX_PDF_BYTES * 4) / 3) + 4) return null;
|
|
498
|
+
return createHash("sha256").update(base64).digest("base64url");
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function cached<T>(store: Map<string, T>, key: string, max: number, make: () => T): T {
|
|
502
|
+
if (store.has(key)) {
|
|
503
|
+
const hit = store.get(key) as T;
|
|
504
|
+
store.delete(key);
|
|
505
|
+
store.set(key, hit);
|
|
506
|
+
return hit;
|
|
507
|
+
}
|
|
508
|
+
let value: T;
|
|
509
|
+
try {
|
|
510
|
+
value = make();
|
|
511
|
+
} catch {
|
|
512
|
+
value = null as T;
|
|
513
|
+
}
|
|
514
|
+
store.set(key, value);
|
|
515
|
+
if (store.size > max) store.delete(store.keys().next().value as string);
|
|
516
|
+
return value;
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
export function extractPdfText(base64: string): PdfText | null {
|
|
520
|
+
const key = cacheKeyOf(base64);
|
|
521
|
+
if (!key) return null;
|
|
522
|
+
return cached(cache, key, CACHE_ENTRIES, () => extract(Buffer.from(base64, "base64")));
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
type OpenPdf = { pdf: PdfReader; s: string; pages: Array<{ num: number; resources: string }> };
|
|
526
|
+
|
|
527
|
+
/** Objects scanned and pages listed in page-tree order (resources inherited from parents). */
|
|
528
|
+
function openPdf(raw: Buffer): OpenPdf | null {
|
|
529
|
+
if (raw.length < 32 || raw.length > MAX_PDF_BYTES) return null;
|
|
530
|
+
const s = raw.toString("latin1");
|
|
531
|
+
if (!s.startsWith("%PDF")) return null;
|
|
532
|
+
if (/\/Encrypt\s+\d+\s+\d+\s+R/.test(s.slice(-4096)) || /\/Encrypt\s*<</.test(s.slice(-4096)))
|
|
533
|
+
return null;
|
|
534
|
+
const pdf = new PdfReader(raw, s);
|
|
535
|
+
pdf.scan();
|
|
536
|
+
const pages: Array<{ num: number; resources: string }> = [];
|
|
537
|
+
const seen = new Set<number>();
|
|
538
|
+
const visit = (num: number, inherited: string, depth: number) => {
|
|
539
|
+
if (depth > 32 || pages.length > 5000 || seen.has(num)) return;
|
|
540
|
+
seen.add(num);
|
|
541
|
+
const dict = pdf.get(num)?.dict || "";
|
|
542
|
+
const resources = valueOf(dict, "Resources") || inherited;
|
|
543
|
+
if (/\/Type\s*\/Pages\b/.test(dict)) {
|
|
544
|
+
for (const kid of refsIn(valueOf(dict, "Kids"))) visit(kid, resources, depth + 1);
|
|
545
|
+
} else if (/\/Type\s*\/Page\b/.test(dict)) {
|
|
546
|
+
pages.push({ num, resources });
|
|
547
|
+
}
|
|
548
|
+
};
|
|
549
|
+
const rootRef =
|
|
550
|
+
/\/Root\s+(\d+)\s+\d+\s+R/.exec(s.slice(-8192)) || /\/Root\s+(\d+)\s+\d+\s+R/.exec(s);
|
|
551
|
+
const catalog = rootRef ? pdf.get(Number(rootRef[1]))?.dict || "" : "";
|
|
552
|
+
const treeRoot = refsIn(valueOf(catalog, "Pages"))[0];
|
|
553
|
+
if (treeRoot !== undefined) visit(treeRoot, "", 0);
|
|
554
|
+
if (pages.length === 0) return null;
|
|
555
|
+
return { pdf, s, pages };
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function extract(raw: Buffer): PdfText | null {
|
|
559
|
+
const started = Date.now();
|
|
560
|
+
const opened = openPdf(raw);
|
|
561
|
+
if (!opened) return null;
|
|
562
|
+
const { pdf, s, pages } = opened;
|
|
563
|
+
|
|
564
|
+
const fontCache = new Map<number, FontInfo>();
|
|
565
|
+
const fontInfo = (fontNum: number): FontInfo => {
|
|
566
|
+
const cachedFont = fontCache.get(fontNum);
|
|
567
|
+
if (cachedFont) return cachedFont;
|
|
568
|
+
const dict = pdf.get(fontNum)?.dict || "";
|
|
569
|
+
const ref = refsIn(valueOf(dict, "ToUnicode"))[0];
|
|
570
|
+
const text = ref !== undefined ? pdf.stream(ref) : null;
|
|
571
|
+
const { widths, dw, cid } = readWidths(pdf, dict);
|
|
572
|
+
const info: FontInfo = {
|
|
573
|
+
bytes: cid ? 2 : 1,
|
|
574
|
+
cmap: text ? parseCMap(text) : undefined,
|
|
575
|
+
widths,
|
|
576
|
+
dw,
|
|
577
|
+
};
|
|
578
|
+
fontCache.set(fontNum, info);
|
|
579
|
+
return info;
|
|
580
|
+
};
|
|
581
|
+
const fontsOf = (resources: string): Map<string, FontInfo> => {
|
|
582
|
+
const fonts = new Map<string, FontInfo>();
|
|
583
|
+
const fontDict = pdf.dictOf(valueOf(pdf.dictOf(resources), "Font"));
|
|
584
|
+
for (const m of fontDict.matchAll(/\/([^\s/<>[\]()%]+)\s+(\d+)\s+\d+\s+R/g)) {
|
|
585
|
+
fonts.set(m[1], fontInfo(Number(m[2])));
|
|
586
|
+
}
|
|
587
|
+
return fonts;
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
const texts: string[] = [];
|
|
591
|
+
const pageChars: number[] = [];
|
|
592
|
+
let total = 0;
|
|
593
|
+
for (const page of pages) {
|
|
594
|
+
if (Date.now() - started > MAX_WORK_MS) {
|
|
595
|
+
texts.push(`[Pages ${texts.length + 1} to ${pages.length} were not read: time limit]`);
|
|
596
|
+
break;
|
|
597
|
+
}
|
|
598
|
+
const dict = pdf.get(page.num)?.dict || "";
|
|
599
|
+
const contents = refsIn(valueOf(dict, "Contents"));
|
|
600
|
+
const fonts = fontsOf(page.resources);
|
|
601
|
+
const body = contents.map((c) => pdf.stream(c) || "").join("\n");
|
|
602
|
+
const text = contentText(body, fonts)
|
|
603
|
+
.split("\n")
|
|
604
|
+
.map((line) => line.replace(/\s+/g, " ").trim())
|
|
605
|
+
.join("\n")
|
|
606
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
607
|
+
.trim();
|
|
608
|
+
texts.push(text);
|
|
609
|
+
pageChars.push(text.replace(/\s+/g, "").length);
|
|
610
|
+
total += text.length;
|
|
611
|
+
if (total > MAX_TEXT_CHARS) break;
|
|
612
|
+
}
|
|
613
|
+
const joined = texts
|
|
614
|
+
.map((t, i) => (texts.length > 1 ? `[Page ${i + 1}]\n${t}` : t))
|
|
615
|
+
.join("\n\n")
|
|
616
|
+
.slice(0, MAX_TEXT_CHARS);
|
|
617
|
+
return {
|
|
618
|
+
text: joined,
|
|
619
|
+
pages: pages.length,
|
|
620
|
+
images: /\/Subtype\s*\/Image\b/.test(s),
|
|
621
|
+
pageChars,
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// ── Scanned pages as images ─────────────────────────────────────────────────────────────────
|
|
626
|
+
//
|
|
627
|
+
// A scanned page is one big image and no text. For a model that reads images, the page image
|
|
628
|
+
// goes along: JPEG (DCTDecode) as it is stored, Flate / uncompressed pixels (gray, RGB, CMYK,
|
|
629
|
+
// indexed; 1-16 bits) re-encoded as PNG at most 1568 px on the long side (Claude scales larger
|
|
630
|
+
// images down anyway), CCITT G3/G4 fax images (most office scanners) decoded and re-encoded as
|
|
631
|
+
// PNG. JBIG2 and JPEG 2000 images are not decoded.
|
|
632
|
+
|
|
633
|
+
/** One scanned page as an image a model can read. */
|
|
634
|
+
export type PdfPageImage = { page: number; mediaType: "image/jpeg" | "image/png"; data: string };
|
|
635
|
+
/** `unreadable`: wanted pages whose image could not be converted (format, size, time). */
|
|
636
|
+
export type PdfPageImages = { images: PdfPageImage[]; unreadable: number[] };
|
|
637
|
+
|
|
638
|
+
export const MAX_PDF_PAGE_IMAGES = 20;
|
|
639
|
+
const MAX_IMAGE_BYTES = 3_750_000;
|
|
640
|
+
const MAX_IMAGES_TOTAL_BYTES = 12 * 1024 * 1024;
|
|
641
|
+
const MAX_IMAGE_EDGE = 1568;
|
|
642
|
+
const MAX_IMAGE_PIXELS = 60_000_000;
|
|
643
|
+
const MAX_IMAGE_WORK_MS = 4000;
|
|
644
|
+
const imageCache = new Map<string, PdfPageImages | null>();
|
|
645
|
+
|
|
646
|
+
/** Images of the given pages (1-based), largest image of each page; cached for repeated turns. */
|
|
647
|
+
export function extractPdfPageImages(base64: string, pagesWanted: number[]): PdfPageImages | null {
|
|
648
|
+
const key = cacheKeyOf(base64);
|
|
649
|
+
if (!key) return null;
|
|
650
|
+
const want = [...new Set(pagesWanted.filter((p) => Number.isInteger(p) && p > 0))]
|
|
651
|
+
.sort((a, b) => a - b)
|
|
652
|
+
.slice(0, MAX_PDF_PAGE_IMAGES);
|
|
653
|
+
if (!want.length) return { images: [], unreadable: [] };
|
|
654
|
+
return cached(imageCache, `${key}:${want.join(",")}`, 2, () =>
|
|
655
|
+
pageImages(Buffer.from(base64, "base64"), want)
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
function pageImages(raw: Buffer, want: number[]): PdfPageImages | null {
|
|
660
|
+
const started = Date.now();
|
|
661
|
+
const opened = openPdf(raw);
|
|
662
|
+
if (!opened) return null;
|
|
663
|
+
const { pdf, pages } = opened;
|
|
664
|
+
const images: PdfPageImage[] = [];
|
|
665
|
+
const unreadable: number[] = [];
|
|
666
|
+
let totalBytes = 0;
|
|
667
|
+
for (const pageNo of want) {
|
|
668
|
+
const page = pages[pageNo - 1];
|
|
669
|
+
if (!page) continue;
|
|
670
|
+
if (Date.now() - started > MAX_IMAGE_WORK_MS) {
|
|
671
|
+
unreadable.push(pageNo);
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
const found = largestImage(pdf, page.resources, 0, new Set());
|
|
675
|
+
let out: { mediaType: "image/jpeg" | "image/png"; bytes: Buffer } | null = null;
|
|
676
|
+
try {
|
|
677
|
+
out = found ? modelImage(pdf, found.num, found.dict) : null;
|
|
678
|
+
} catch {
|
|
679
|
+
out = null;
|
|
680
|
+
}
|
|
681
|
+
if (!out || totalBytes + out.bytes.length > MAX_IMAGES_TOTAL_BYTES) {
|
|
682
|
+
unreadable.push(pageNo);
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
685
|
+
totalBytes += out.bytes.length;
|
|
686
|
+
images.push({ page: pageNo, mediaType: out.mediaType, data: out.bytes.toString("base64") });
|
|
687
|
+
}
|
|
688
|
+
return { images, unreadable };
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
/** The image XObject with the most pixels on a page (looking one level into Form XObjects). */
|
|
692
|
+
function largestImage(
|
|
693
|
+
pdf: PdfReader,
|
|
694
|
+
resources: string,
|
|
695
|
+
depth: number,
|
|
696
|
+
seen: Set<number>
|
|
697
|
+
): { num: number; dict: string; area: number } | null {
|
|
698
|
+
const xobjects = pdf.dictOf(valueOf(pdf.dictOf(resources), "XObject"));
|
|
699
|
+
let best: { num: number; dict: string; area: number } | null = null;
|
|
700
|
+
for (const m of xobjects.matchAll(/\/[^\s/<>[\]()%]+\s+(\d+)\s+\d+\s+R/g)) {
|
|
701
|
+
const num = Number(m[1]);
|
|
702
|
+
if (seen.has(num)) continue;
|
|
703
|
+
seen.add(num);
|
|
704
|
+
const dict = pdf.get(num)?.dict || "";
|
|
705
|
+
if (/\/Subtype\s*\/Image\b/.test(dict)) {
|
|
706
|
+
const area = numberIn(dict, "Width") * numberIn(dict, "Height");
|
|
707
|
+
if (!best || area > best.area) best = { num, dict, area };
|
|
708
|
+
} else if (/\/Subtype\s*\/Form\b/.test(dict) && depth < 2) {
|
|
709
|
+
const inner = largestImage(pdf, valueOf(dict, "Resources"), depth + 1, seen);
|
|
710
|
+
if (inner && (!best || inner.area > best.area)) best = inner;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
return best;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
function numberIn(dict: string, key: string): number {
|
|
717
|
+
const m = new RegExp(`/${key}\\s+(\\d+)\\b(?!\\s+\\d+\\s+R)`).exec(dict);
|
|
718
|
+
return m ? Number(m[1]) : 0;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
type ColorSpace = {
|
|
722
|
+
kind: "gray" | "rgb" | "cmyk" | "indexed" | "unknown";
|
|
723
|
+
/** Indexed: palette as RGB triples, and the highest index. */
|
|
724
|
+
palette?: Uint8Array;
|
|
725
|
+
hival?: number;
|
|
726
|
+
};
|
|
727
|
+
|
|
728
|
+
function colorSpaceOf(pdf: PdfReader, value: string, depth = 0): ColorSpace {
|
|
729
|
+
const v = value.trim();
|
|
730
|
+
const name = /^\/(\w+)/.exec(v)?.[1];
|
|
731
|
+
if (name) {
|
|
732
|
+
if (name === "DeviceGray" || name === "CalGray" || name === "G") return { kind: "gray" };
|
|
733
|
+
if (name === "DeviceRGB" || name === "CalRGB" || name === "RGB") return { kind: "rgb" };
|
|
734
|
+
if (name === "DeviceCMYK" || name === "CMYK") return { kind: "cmyk" };
|
|
735
|
+
return { kind: "unknown" };
|
|
736
|
+
}
|
|
737
|
+
if (depth > 3) return { kind: "unknown" };
|
|
738
|
+
const ref = /^(\d+)\s+\d+\s+R/.exec(v);
|
|
739
|
+
if (ref) return colorSpaceOf(pdf, pdf.get(Number(ref[1]))?.dict || "", depth + 1);
|
|
740
|
+
if (!v.startsWith("[")) return { kind: "unknown" };
|
|
741
|
+
const inner = v.slice(1, v.lastIndexOf("]") === -1 ? v.length : v.lastIndexOf("]")).trim();
|
|
742
|
+
const head = /^\/(\w+)/.exec(inner)?.[1] || "";
|
|
743
|
+
const rest = inner.slice(head.length + 1).trim();
|
|
744
|
+
if (head === "ICCBased") {
|
|
745
|
+
const icc = /^(\d+)\s+\d+\s+R/.exec(rest);
|
|
746
|
+
const n = icc ? numberIn(pdf.get(Number(icc[1]))?.dict || "", "N") : 0;
|
|
747
|
+
return n === 1
|
|
748
|
+
? { kind: "gray" }
|
|
749
|
+
: n === 3
|
|
750
|
+
? { kind: "rgb" }
|
|
751
|
+
: n === 4
|
|
752
|
+
? { kind: "cmyk" }
|
|
753
|
+
: { kind: "unknown" };
|
|
754
|
+
}
|
|
755
|
+
if (head === "CalGray") return { kind: "gray" };
|
|
756
|
+
if (head === "CalRGB" || head === "Lab")
|
|
757
|
+
return head === "CalRGB" ? { kind: "rgb" } : { kind: "unknown" };
|
|
758
|
+
if (head === "Indexed" || head === "I") {
|
|
759
|
+
// [/Indexed base hival lookup]: base is a name, a reference or an array.
|
|
760
|
+
let baseText = "";
|
|
761
|
+
let after = "";
|
|
762
|
+
if (rest.startsWith("/")) {
|
|
763
|
+
baseText = /^\/\w+/.exec(rest)?.[0] || "";
|
|
764
|
+
after = rest.slice(baseText.length).trim();
|
|
765
|
+
} else if (/^\d+\s+\d+\s+R/.test(rest)) {
|
|
766
|
+
baseText = /^\d+\s+\d+\s+R/.exec(rest)?.[0] || "";
|
|
767
|
+
after = rest.slice(baseText.length).trim();
|
|
768
|
+
} else if (rest.startsWith("[")) {
|
|
769
|
+
const close = rest.indexOf("]");
|
|
770
|
+
baseText = rest.slice(0, close + 1);
|
|
771
|
+
after = rest.slice(close + 1).trim();
|
|
772
|
+
}
|
|
773
|
+
const base = colorSpaceOf(pdf, baseText, depth + 1);
|
|
774
|
+
const hivalMatch = /^(\d+)/.exec(after);
|
|
775
|
+
if (!hivalMatch || (base.kind !== "gray" && base.kind !== "rgb" && base.kind !== "cmyk")) {
|
|
776
|
+
return { kind: "unknown" };
|
|
777
|
+
}
|
|
778
|
+
const hival = Math.min(255, Number(hivalMatch[1]));
|
|
779
|
+
const lookupText = after.slice(hivalMatch[0].length).trim();
|
|
780
|
+
let lookup: Buffer | null = null;
|
|
781
|
+
if (lookupText.startsWith("<")) {
|
|
782
|
+
lookup = Buffer.from(hexToBytes(lookupText.slice(1, lookupText.indexOf(">"))));
|
|
783
|
+
} else if (lookupText.startsWith("(")) {
|
|
784
|
+
lookup = Buffer.from(literalBytes(lookupText, 0).bytes);
|
|
785
|
+
} else {
|
|
786
|
+
const lref = /^(\d+)\s+\d+\s+R/.exec(lookupText);
|
|
787
|
+
const text = lref ? pdf.stream(Number(lref[1])) : null;
|
|
788
|
+
lookup = text !== null ? Buffer.from(text, "latin1") : null;
|
|
789
|
+
}
|
|
790
|
+
if (!lookup) return { kind: "unknown" };
|
|
791
|
+
const comps = base.kind === "gray" ? 1 : base.kind === "rgb" ? 3 : 4;
|
|
792
|
+
const palette = new Uint8Array((hival + 1) * 3);
|
|
793
|
+
for (let i = 0; i <= hival; i++) {
|
|
794
|
+
const o = i * comps;
|
|
795
|
+
const [r, g, b] =
|
|
796
|
+
comps === 1
|
|
797
|
+
? [lookup[o] ?? 0, lookup[o] ?? 0, lookup[o] ?? 0]
|
|
798
|
+
: comps === 3
|
|
799
|
+
? [lookup[o] ?? 0, lookup[o + 1] ?? 0, lookup[o + 2] ?? 0]
|
|
800
|
+
: cmykToRgb(lookup[o] ?? 0, lookup[o + 1] ?? 0, lookup[o + 2] ?? 0, lookup[o + 3] ?? 0);
|
|
801
|
+
palette.set([r, g, b], i * 3);
|
|
802
|
+
}
|
|
803
|
+
return { kind: "indexed", palette, hival };
|
|
804
|
+
}
|
|
805
|
+
return { kind: "unknown" };
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function cmykToRgb(c: number, m: number, y: number, k: number): [number, number, number] {
|
|
809
|
+
return [255 - Math.min(255, c + k), 255 - Math.min(255, m + k), 255 - Math.min(255, y + k)];
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
function modelImage(
|
|
813
|
+
pdf: PdfReader,
|
|
814
|
+
num: number,
|
|
815
|
+
dict: string
|
|
816
|
+
): { mediaType: "image/jpeg" | "image/png"; bytes: Buffer } | null {
|
|
817
|
+
const width = numberIn(dict, "Width");
|
|
818
|
+
const height = numberIn(dict, "Height");
|
|
819
|
+
if (!width || !height || width * height > MAX_IMAGE_PIXELS) return null;
|
|
820
|
+
const filterMatch = /\/Filter\s*(\[[^\]]*\]|\/\w+)/.exec(dict)?.[1] || "";
|
|
821
|
+
const filters = filterMatch.match(/\/\w+/g) || [];
|
|
822
|
+
if (filters.length > 1) return null;
|
|
823
|
+
const filter = filters[0] || "";
|
|
824
|
+
const imageMask = /\/ImageMask\s+true\b/.test(dict);
|
|
825
|
+
const cs: ColorSpace = imageMask
|
|
826
|
+
? { kind: "gray" }
|
|
827
|
+
: colorSpaceOf(pdf, /\/ColorSpace\s*(\/\w+|\[[^\]]*\]|\d+\s+\d+\s+R)/.exec(dict)?.[1] || "");
|
|
828
|
+
const decode = /\/Decode\s*\[\s*([^\]]*)\]/.exec(dict)?.[1].trim().split(/\s+/).map(Number) || [];
|
|
829
|
+
// Gray / masks with /Decode [1 0] are stored inverted. An image mask paints its 0 samples.
|
|
830
|
+
const inverted = cs.kind === "gray" && decode.length >= 2 && decode[0] === 1 && decode[1] === 0;
|
|
831
|
+
|
|
832
|
+
if (filter === "/DCTDecode" || filter === "/DCT") {
|
|
833
|
+
if (cs.kind === "cmyk" || cs.kind === "unknown") return null;
|
|
834
|
+
const bytes = pdf.rawStream(num);
|
|
835
|
+
if (!bytes || bytes.length > MAX_IMAGE_BYTES || bytes[0] !== 0xff || bytes[1] !== 0xd8) {
|
|
836
|
+
return null;
|
|
837
|
+
}
|
|
838
|
+
return { mediaType: "image/jpeg", bytes: Buffer.from(bytes) };
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
const stored = pdf.rawStream(num);
|
|
842
|
+
if (!stored) return null;
|
|
843
|
+
const parms = valueOf(dict, "DecodeParms") || valueOf(dict, "DP");
|
|
844
|
+
let samples: Buffer | null = null;
|
|
845
|
+
let bpc = imageMask ? 1 : numberIn(dict, "BitsPerComponent") || 8;
|
|
846
|
+
if (filter === "/CCITTFaxDecode" || filter === "/CCF") {
|
|
847
|
+
const fax = decodeCcitt(stored, {
|
|
848
|
+
k: Number(/\/K\s+(-?\d+)/.exec(parms)?.[1] || 0),
|
|
849
|
+
columns: numberIn(parms, "Columns") || 1728,
|
|
850
|
+
rows: numberIn(parms, "Rows") || height,
|
|
851
|
+
blackIs1: /\/BlackIs1\s+true\b/.test(parms),
|
|
852
|
+
byteAlign: /\/EncodedByteAlign\s+true\b/.test(parms),
|
|
853
|
+
});
|
|
854
|
+
if (!fax || fax.columns !== width) return null;
|
|
855
|
+
samples = fax.data;
|
|
856
|
+
bpc = 1;
|
|
857
|
+
} else if (filter === "/FlateDecode" || filter === "/Fl") {
|
|
858
|
+
const inflated = pdf.inflate(Buffer.from(stored));
|
|
859
|
+
if (!inflated) return null;
|
|
860
|
+
samples = inflated;
|
|
861
|
+
} else if (filter === "") {
|
|
862
|
+
samples = Buffer.from(stored);
|
|
863
|
+
} else {
|
|
864
|
+
return null; // JBIG2, JPEG 2000, LZW, RunLength, ...
|
|
865
|
+
}
|
|
866
|
+
if (cs.kind === "unknown" || ![1, 2, 4, 8, 16].includes(bpc)) return null;
|
|
867
|
+
const comps = cs.kind === "rgb" ? 3 : cs.kind === "cmyk" ? 4 : 1;
|
|
868
|
+
const rowBytes = Math.ceil((width * comps * bpc) / 8);
|
|
869
|
+
const predictor = numberIn(parms, "Predictor");
|
|
870
|
+
if (predictor >= 10) {
|
|
871
|
+
samples = pngUnfilter(samples, rowBytes, Math.max(1, Math.ceil((comps * bpc) / 8)), height);
|
|
872
|
+
if (!samples) return null;
|
|
873
|
+
} else if (predictor > 1) {
|
|
874
|
+
return null; // TIFF predictor 2: rare, not handled
|
|
875
|
+
}
|
|
876
|
+
if (samples.length < rowBytes * Math.min(height, 1)) return null;
|
|
877
|
+
return {
|
|
878
|
+
mediaType: "image/png",
|
|
879
|
+
bytes: pixelsToPng(samples, width, height, comps, bpc, cs, inverted, rowBytes),
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
/** Undo PNG row filters (Flate /Predictor 10-15): one filter byte before every row. */
|
|
884
|
+
function pngUnfilter(data: Buffer, rowBytes: number, bpp: number, rows: number): Buffer | null {
|
|
885
|
+
const out = Buffer.alloc(rowBytes * rows);
|
|
886
|
+
for (let y = 0; y < rows; y++) {
|
|
887
|
+
const off = y * (rowBytes + 1);
|
|
888
|
+
if (off + 1 + rowBytes > data.length) break; // a short stream: keep the rows that came
|
|
889
|
+
const type = data[off];
|
|
890
|
+
const row = y * rowBytes;
|
|
891
|
+
const prev = row - rowBytes;
|
|
892
|
+
for (let x = 0; x < rowBytes; x++) {
|
|
893
|
+
const a = x >= bpp ? out[row + x - bpp] : 0;
|
|
894
|
+
const b = y > 0 ? out[prev + x] : 0;
|
|
895
|
+
const c = x >= bpp && y > 0 ? out[prev + x - bpp] : 0;
|
|
896
|
+
let v = data[off + 1 + x];
|
|
897
|
+
if (type === 1) v += a;
|
|
898
|
+
else if (type === 2) v += b;
|
|
899
|
+
else if (type === 3) v += (a + b) >> 1;
|
|
900
|
+
else if (type === 4) {
|
|
901
|
+
const p = a + b - c;
|
|
902
|
+
const pa = Math.abs(p - a);
|
|
903
|
+
const pb = Math.abs(p - b);
|
|
904
|
+
const pc = Math.abs(p - c);
|
|
905
|
+
v += pa <= pb && pa <= pc ? a : pb <= pc ? b : c;
|
|
906
|
+
} else if (type !== 0) return null;
|
|
907
|
+
out[row + x] = v & 255;
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
return out;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/** Packed samples -> 8-bit gray or RGB, scaled down to MAX_IMAGE_EDGE, as a PNG file. */
|
|
914
|
+
function pixelsToPng(
|
|
915
|
+
samples: Buffer,
|
|
916
|
+
width: number,
|
|
917
|
+
height: number,
|
|
918
|
+
comps: number,
|
|
919
|
+
bpc: number,
|
|
920
|
+
cs: ColorSpace,
|
|
921
|
+
inverted: boolean,
|
|
922
|
+
rowBytes: number
|
|
923
|
+
): Buffer {
|
|
924
|
+
const outComps = cs.kind === "gray" ? 1 : 3;
|
|
925
|
+
// Area average down to at most MAX_IMAGE_EDGE on the long side.
|
|
926
|
+
const scale = Math.max(1, Math.max(width, height) / MAX_IMAGE_EDGE);
|
|
927
|
+
const ow = Math.max(1, Math.round(width / scale));
|
|
928
|
+
const oh = Math.max(1, Math.round(height / scale));
|
|
929
|
+
const colOf = new Uint32Array(width);
|
|
930
|
+
for (let x = 0; x < width; x++) colOf[x] = Math.min(ow - 1, Math.floor((x * ow) / width));
|
|
931
|
+
const sums = new Float64Array(ow * oh * outComps);
|
|
932
|
+
const counts = new Uint32Array(ow * oh);
|
|
933
|
+
const max = (1 << Math.min(bpc, 8)) - 1;
|
|
934
|
+
const sampleAt = (rowStart: number, index: number): number => {
|
|
935
|
+
if (bpc === 8) return samples[rowStart + index] ?? 0;
|
|
936
|
+
if (bpc === 16) return samples[rowStart + index * 2] ?? 0;
|
|
937
|
+
const bit = index * bpc;
|
|
938
|
+
const byte = samples[rowStart + (bit >> 3)] ?? 0;
|
|
939
|
+
const value = (byte >> (8 - bpc - (bit & 7))) & max;
|
|
940
|
+
return cs.kind === "indexed" ? value : Math.round((value * 255) / max);
|
|
941
|
+
};
|
|
942
|
+
for (let y = 0; y < height; y++) {
|
|
943
|
+
const rowStart = y * rowBytes;
|
|
944
|
+
if (rowStart >= samples.length) break;
|
|
945
|
+
const oy = Math.min(oh - 1, Math.floor((y * oh) / height));
|
|
946
|
+
for (let x = 0; x < width; x++) {
|
|
947
|
+
const o = oy * ow + colOf[x];
|
|
948
|
+
counts[o]++;
|
|
949
|
+
const base = o * outComps;
|
|
950
|
+
if (cs.kind === "gray") {
|
|
951
|
+
const g = sampleAt(rowStart, x);
|
|
952
|
+
sums[base] += inverted ? 255 - g : g;
|
|
953
|
+
} else if (cs.kind === "rgb") {
|
|
954
|
+
sums[base] += sampleAt(rowStart, x * 3);
|
|
955
|
+
sums[base + 1] += sampleAt(rowStart, x * 3 + 1);
|
|
956
|
+
sums[base + 2] += sampleAt(rowStart, x * 3 + 2);
|
|
957
|
+
} else if (cs.kind === "cmyk") {
|
|
958
|
+
const [r, g, b] = cmykToRgb(
|
|
959
|
+
sampleAt(rowStart, x * 4),
|
|
960
|
+
sampleAt(rowStart, x * 4 + 1),
|
|
961
|
+
sampleAt(rowStart, x * 4 + 2),
|
|
962
|
+
sampleAt(rowStart, x * 4 + 3)
|
|
963
|
+
);
|
|
964
|
+
sums[base] += r;
|
|
965
|
+
sums[base + 1] += g;
|
|
966
|
+
sums[base + 2] += b;
|
|
967
|
+
} else {
|
|
968
|
+
const i = Math.min(sampleAt(rowStart, x), cs.hival ?? 0) * 3;
|
|
969
|
+
const pal = cs.palette as Uint8Array;
|
|
970
|
+
sums[base] += pal[i];
|
|
971
|
+
sums[base + 1] += pal[i + 1];
|
|
972
|
+
sums[base + 2] += pal[i + 2];
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
const lineLen = ow * outComps;
|
|
977
|
+
const rawRows = Buffer.alloc((lineLen + 1) * oh);
|
|
978
|
+
for (let y = 0; y < oh; y++) {
|
|
979
|
+
for (let x = 0; x < ow; x++) {
|
|
980
|
+
const o = y * ow + x;
|
|
981
|
+
const n = counts[o] || 1;
|
|
982
|
+
for (let c = 0; c < outComps; c++) {
|
|
983
|
+
rawRows[y * (lineLen + 1) + 1 + x * outComps + c] = Math.round(sums[o * outComps + c] / n);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
}
|
|
987
|
+
return encodePng(ow, oh, outComps === 1 ? 0 : 2, rawRows);
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
const PNG_SIGNATURE = Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
991
|
+
|
|
992
|
+
function encodePng(width: number, height: number, colorType: 0 | 2, filteredRows: Buffer): Buffer {
|
|
993
|
+
const chunk = (type: string, data: Buffer) => {
|
|
994
|
+
const head = Buffer.alloc(4);
|
|
995
|
+
head.writeUInt32BE(data.length);
|
|
996
|
+
const body = Buffer.concat([Buffer.from(type, "latin1"), data]);
|
|
997
|
+
const crc = Buffer.alloc(4);
|
|
998
|
+
crc.writeUInt32BE(crc32(body) >>> 0);
|
|
999
|
+
return Buffer.concat([head, body, crc]);
|
|
1000
|
+
};
|
|
1001
|
+
const ihdr = Buffer.alloc(13);
|
|
1002
|
+
ihdr.writeUInt32BE(width, 0);
|
|
1003
|
+
ihdr.writeUInt32BE(height, 4);
|
|
1004
|
+
ihdr[8] = 8;
|
|
1005
|
+
ihdr[9] = colorType;
|
|
1006
|
+
return Buffer.concat([
|
|
1007
|
+
PNG_SIGNATURE,
|
|
1008
|
+
chunk("IHDR", ihdr),
|
|
1009
|
+
chunk("IDAT", deflateSync(filteredRows, { level: 6 })),
|
|
1010
|
+
chunk("IEND", Buffer.alloc(0)),
|
|
1011
|
+
]);
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
// ── CCITT fax decoding (T.4 / T.6: G3 1-D, G3 2-D, G4), for scanned black-and-white pages ──
|
|
1015
|
+
|
|
1016
|
+
// Run-length codes, ITU-T T.4 tables 2 and 3: "bits" -> run length.
|
|
1017
|
+
const WHITE_TERMINATING =
|
|
1018
|
+
"00110101 000111 0111 1000 1011 1100 1110 1111 10011 10100 00111 01000 001000 000011 110100 " +
|
|
1019
|
+
"110101 101010 101011 0100111 0001100 0001000 0010111 0000011 0000100 0101000 0101011 0010011 " +
|
|
1020
|
+
"0100100 0011000 00000010 00000011 00011010 00011011 00010010 00010011 00010100 00010101 " +
|
|
1021
|
+
"00010110 00010111 00101000 00101001 00101010 00101011 00101100 00101101 00000100 00000101 " +
|
|
1022
|
+
"00001010 00001011 01010010 01010011 01010100 01010101 00100100 00100101 01011000 01011001 " +
|
|
1023
|
+
"01011010 01011011 01001010 01001011 00110010 00110011 00110100";
|
|
1024
|
+
const WHITE_MAKEUP =
|
|
1025
|
+
"11011 10010 010111 0110111 00110110 00110111 01100100 01100101 01101000 01100111 011001100 " +
|
|
1026
|
+
"011001101 011010010 011010011 011010100 011010101 011010110 011010111 011011000 011011001 " +
|
|
1027
|
+
"011011010 011011011 010011000 010011001 010011010 011000 010011011";
|
|
1028
|
+
const BLACK_TERMINATING =
|
|
1029
|
+
"0000110111 010 11 10 011 0011 0010 00011 000101 000100 0000100 0000101 0000111 00000100 " +
|
|
1030
|
+
"00000111 000011000 0000010111 0000011000 0000001000 00001100111 00001101000 00001101100 " +
|
|
1031
|
+
"00000110111 00000101000 00000010111 00000011000 000011001010 000011001011 000011001100 " +
|
|
1032
|
+
"000011001101 000001101000 000001101001 000001101010 000001101011 000011010010 000011010011 " +
|
|
1033
|
+
"000011010100 000011010101 000011010110 000011010111 000001101100 000001101101 000011011010 " +
|
|
1034
|
+
"000011011011 000001010100 000001010101 000001010110 000001010111 000001100100 000001100101 " +
|
|
1035
|
+
"000001010010 000001010011 000000100100 000000110111 000000111000 000000100111 000000101000 " +
|
|
1036
|
+
"000001011000 000001011001 000000101011 000000101100 000001011010 000001100110 000001100111";
|
|
1037
|
+
const BLACK_MAKEUP =
|
|
1038
|
+
"0000001111 000011001000 000011001001 000001011011 000000110011 000000110100 000000110101 " +
|
|
1039
|
+
"0000001101100 0000001101101 0000001001010 0000001001011 0000001001100 0000001001101 " +
|
|
1040
|
+
"0000001110010 0000001110011 0000001110100 0000001110101 0000001110110 0000001110111 " +
|
|
1041
|
+
"0000001010010 0000001010011 0000001010100 0000001010101 0000001011010 0000001011011 " +
|
|
1042
|
+
"0000001100100 0000001100101";
|
|
1043
|
+
// Extended make-up codes 1792-2560, the same for both colours.
|
|
1044
|
+
const EXTENDED_MAKEUP =
|
|
1045
|
+
"00000001000 00000001100 00000001101 000000010010 000000010011 000000010100 000000010101 " +
|
|
1046
|
+
"000000010110 000000010111 000000011100 000000011101 000000011110 000000011111";
|
|
1047
|
+
|
|
1048
|
+
type RunTable = Map<string, number>;
|
|
1049
|
+
let runTables: [RunTable, RunTable] | null = null;
|
|
1050
|
+
|
|
1051
|
+
function faxRunTables(): [RunTable, RunTable] {
|
|
1052
|
+
if (runTables) return runTables;
|
|
1053
|
+
const build = (terminating: string, makeup: string): RunTable => {
|
|
1054
|
+
const t: RunTable = new Map();
|
|
1055
|
+
terminating.split(" ").forEach((code, i) => t.set(code, i));
|
|
1056
|
+
makeup.split(" ").forEach((code, i) => t.set(code, (i + 1) * 64));
|
|
1057
|
+
EXTENDED_MAKEUP.split(" ").forEach((code, i) => t.set(code, 1792 + i * 64));
|
|
1058
|
+
return t;
|
|
1059
|
+
};
|
|
1060
|
+
runTables = [build(WHITE_TERMINATING, WHITE_MAKEUP), build(BLACK_TERMINATING, BLACK_MAKEUP)];
|
|
1061
|
+
return runTables;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
type FaxParams = {
|
|
1065
|
+
k: number;
|
|
1066
|
+
columns: number;
|
|
1067
|
+
rows: number;
|
|
1068
|
+
blackIs1: boolean;
|
|
1069
|
+
byteAlign: boolean;
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1072
|
+
/** CCITT fax data -> 1-bit rows (PDF's meaning: black is 0 unless BlackIs1). Null on bad data. */
|
|
1073
|
+
function decodeCcitt(data: Buffer, p: FaxParams): { data: Buffer; columns: number } | null {
|
|
1074
|
+
const columns = p.columns;
|
|
1075
|
+
if (columns <= 0 || columns > 32768) return null;
|
|
1076
|
+
const rowBytes = Math.ceil(columns / 8);
|
|
1077
|
+
const maxRows = Math.max(1, Math.min(p.rows || 65536, 65536));
|
|
1078
|
+
const tables = faxRunTables();
|
|
1079
|
+
const totalBits = data.length * 8;
|
|
1080
|
+
let pos = 0;
|
|
1081
|
+
const bit = (): number => {
|
|
1082
|
+
if (pos >= totalBits) return -1;
|
|
1083
|
+
const b = (data[pos >> 3] >> (7 - (pos & 7))) & 1;
|
|
1084
|
+
pos++;
|
|
1085
|
+
return b;
|
|
1086
|
+
};
|
|
1087
|
+
/** One run (make-up codes then a terminating code) of the given colour; -1 on bad data. */
|
|
1088
|
+
const run = (color: number): number => {
|
|
1089
|
+
const table = tables[color];
|
|
1090
|
+
let total = 0;
|
|
1091
|
+
for (;;) {
|
|
1092
|
+
let code = "";
|
|
1093
|
+
let len = -1;
|
|
1094
|
+
while (code.length < 13) {
|
|
1095
|
+
const b = bit();
|
|
1096
|
+
if (b < 0) return -1;
|
|
1097
|
+
code += b;
|
|
1098
|
+
const hit = table.get(code);
|
|
1099
|
+
if (hit !== undefined) {
|
|
1100
|
+
len = hit;
|
|
1101
|
+
break;
|
|
1102
|
+
}
|
|
1103
|
+
}
|
|
1104
|
+
if (len < 0) return -1;
|
|
1105
|
+
total += len;
|
|
1106
|
+
if (len < 64) return total;
|
|
1107
|
+
}
|
|
1108
|
+
};
|
|
1109
|
+
/** An EOL (11+ zero bits then a 1) at the current position: consumed, true. */
|
|
1110
|
+
const eol = (): boolean => {
|
|
1111
|
+
const start = pos;
|
|
1112
|
+
let zeros = 0;
|
|
1113
|
+
for (;;) {
|
|
1114
|
+
const b = bit();
|
|
1115
|
+
if (b === 0) zeros++;
|
|
1116
|
+
else if (b === 1 && zeros >= 11) return true;
|
|
1117
|
+
else break;
|
|
1118
|
+
}
|
|
1119
|
+
pos = start;
|
|
1120
|
+
return false;
|
|
1121
|
+
};
|
|
1122
|
+
type Mode = "V" | "H" | "P" | "EOL" | "BAD";
|
|
1123
|
+
const mode = (): { m: Mode; d: number } => {
|
|
1124
|
+
let code = "";
|
|
1125
|
+
for (;;) {
|
|
1126
|
+
const b = bit();
|
|
1127
|
+
if (b < 0) return { m: "EOL", d: 0 };
|
|
1128
|
+
code += b;
|
|
1129
|
+
switch (code) {
|
|
1130
|
+
case "1":
|
|
1131
|
+
return { m: "V", d: 0 };
|
|
1132
|
+
case "011":
|
|
1133
|
+
return { m: "V", d: 1 };
|
|
1134
|
+
case "010":
|
|
1135
|
+
return { m: "V", d: -1 };
|
|
1136
|
+
case "001":
|
|
1137
|
+
return { m: "H", d: 0 };
|
|
1138
|
+
case "0001":
|
|
1139
|
+
return { m: "P", d: 0 };
|
|
1140
|
+
case "000011":
|
|
1141
|
+
return { m: "V", d: 2 };
|
|
1142
|
+
case "000010":
|
|
1143
|
+
return { m: "V", d: -2 };
|
|
1144
|
+
case "0000011":
|
|
1145
|
+
return { m: "V", d: 3 };
|
|
1146
|
+
case "0000010":
|
|
1147
|
+
return { m: "V", d: -3 };
|
|
1148
|
+
case "0000001":
|
|
1149
|
+
return { m: "BAD", d: 0 }; // uncompressed-mode extension: not handled
|
|
1150
|
+
case "0000000": {
|
|
1151
|
+
// EOL / EOFB: more zeros, then a 1
|
|
1152
|
+
for (;;) {
|
|
1153
|
+
const z = bit();
|
|
1154
|
+
if (z !== 0) return { m: "EOL", d: 0 };
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
|
|
1161
|
+
const out = Buffer.alloc(rowBytes * maxRows, p.blackIs1 ? 0x00 : 0xff);
|
|
1162
|
+
let ref: number[] = []; // changing elements of the line above (all white at the start)
|
|
1163
|
+
let rows = 0;
|
|
1164
|
+
while (rows < maxRows && pos < totalBits) {
|
|
1165
|
+
if (p.byteAlign && p.k < 0) pos = (pos + 7) & ~7;
|
|
1166
|
+
let twoD = p.k < 0;
|
|
1167
|
+
if (p.k >= 0) {
|
|
1168
|
+
if (eol() && eol()) break; // RTC: end of data
|
|
1169
|
+
}
|
|
1170
|
+
if (p.k > 0) {
|
|
1171
|
+
const tag = bit();
|
|
1172
|
+
if (tag < 0) break;
|
|
1173
|
+
twoD = tag === 0;
|
|
1174
|
+
}
|
|
1175
|
+
const cur: number[] = [];
|
|
1176
|
+
let ok = true;
|
|
1177
|
+
let ended = false;
|
|
1178
|
+
if (twoD) {
|
|
1179
|
+
let a0 = -1;
|
|
1180
|
+
let color = 0;
|
|
1181
|
+
while (a0 < columns) {
|
|
1182
|
+
let i = 0;
|
|
1183
|
+
while (i < ref.length && (ref[i] <= a0 || (i & 1) !== color)) i++;
|
|
1184
|
+
const b1 = i < ref.length ? ref[i] : columns;
|
|
1185
|
+
const b2 = i + 1 < ref.length ? ref[i + 1] : columns;
|
|
1186
|
+
const { m, d } = mode();
|
|
1187
|
+
if (m === "V") {
|
|
1188
|
+
const a1 = Math.max(0, Math.min(columns, b1 + d));
|
|
1189
|
+
if (a1 < a0) {
|
|
1190
|
+
ok = false;
|
|
1191
|
+
break;
|
|
1192
|
+
}
|
|
1193
|
+
if (a1 < columns) cur.push(a1);
|
|
1194
|
+
a0 = a1;
|
|
1195
|
+
color ^= 1;
|
|
1196
|
+
} else if (m === "H") {
|
|
1197
|
+
const r1 = run(color);
|
|
1198
|
+
const r2 = r1 < 0 ? -1 : run(color ^ 1);
|
|
1199
|
+
if (r1 < 0 || r2 < 0) {
|
|
1200
|
+
ok = false;
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
const start = Math.max(a0, 0);
|
|
1204
|
+
const a1 = Math.min(columns, start + r1);
|
|
1205
|
+
const a2 = Math.min(columns, a1 + r2);
|
|
1206
|
+
if (a1 < columns) cur.push(a1);
|
|
1207
|
+
if (a2 < columns) cur.push(a2);
|
|
1208
|
+
a0 = a2;
|
|
1209
|
+
} else if (m === "P") {
|
|
1210
|
+
a0 = b2;
|
|
1211
|
+
} else {
|
|
1212
|
+
if (m === "EOL") ended = true;
|
|
1213
|
+
else ok = false;
|
|
1214
|
+
break;
|
|
1215
|
+
}
|
|
1216
|
+
}
|
|
1217
|
+
} else {
|
|
1218
|
+
let a0 = 0;
|
|
1219
|
+
let color = 0;
|
|
1220
|
+
while (a0 < columns) {
|
|
1221
|
+
const r = run(color);
|
|
1222
|
+
if (r < 0) {
|
|
1223
|
+
ok = false;
|
|
1224
|
+
break;
|
|
1225
|
+
}
|
|
1226
|
+
a0 += r;
|
|
1227
|
+
if (a0 < columns) cur.push(a0);
|
|
1228
|
+
color ^= 1;
|
|
1229
|
+
}
|
|
1230
|
+
if (p.byteAlign && p.k === 0 && ok) pos = (pos + 7) & ~7;
|
|
1231
|
+
}
|
|
1232
|
+
if (ended && cur.length === 0) break; // EOFB
|
|
1233
|
+
if (!ok) break;
|
|
1234
|
+
// Paint the black spans of this row.
|
|
1235
|
+
const rowStart = rows * rowBytes;
|
|
1236
|
+
for (let j = 0; j < cur.length; j += 2) {
|
|
1237
|
+
const from = cur[j];
|
|
1238
|
+
const to = j + 1 < cur.length ? cur[j + 1] : columns;
|
|
1239
|
+
for (let x = from; x < to; x++) {
|
|
1240
|
+
const byte = rowStart + (x >> 3);
|
|
1241
|
+
const mask = 0x80 >> (x & 7);
|
|
1242
|
+
if (p.blackIs1) out[byte] |= mask;
|
|
1243
|
+
else out[byte] &= ~mask;
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
rows++;
|
|
1247
|
+
ref = cur;
|
|
1248
|
+
if (ended) break;
|
|
1249
|
+
}
|
|
1250
|
+
if (rows === 0) return null;
|
|
1251
|
+
return { data: out, columns };
|
|
1252
|
+
}
|