thursday-agent 0.1.2 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.next/BUILD_ID +1 -1
- package/.next/app-path-routes-manifest.json +1 -0
- package/.next/build-manifest.json +3 -3
- package/.next/prerender-manifest.json +3 -3
- package/.next/routes-manifest.json +6 -0
- package/.next/server/app/_global-error/page.js.nft.json +1 -1
- package/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_global-error.html +1 -1
- package/.next/server/app/_global-error.rsc +1 -1
- package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
- package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
- package/.next/server/app/_not-found/page.js.nft.json +1 -1
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/.next/server/app/_not-found.html +1 -1
- package/.next/server/app/_not-found.rsc +13 -13
- package/.next/server/app/_not-found.segments/_full.segment.rsc +13 -13
- package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +12 -12
- package/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
- package/.next/server/app/api/artifact/route.js +1 -1
- package/.next/server/app/api/artifact/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/notes/route/app-paths-manifest.json +3 -0
- package/.next/server/app/api/bot/notes/route/build-manifest.json +12 -0
- package/.next/server/app/api/bot/notes/route/server-reference-manifest.json +4 -0
- package/.next/server/app/api/bot/notes/route.js +14 -0
- package/.next/server/app/api/bot/notes/route.js.map +5 -0
- package/.next/server/app/api/bot/notes/route.js.nft.json +1 -0
- package/.next/server/app/api/bot/notes/route_client-reference-manifest.js +3 -0
- package/.next/server/app/api/bot/route.js +4 -4
- package/.next/server/app/api/bot/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/task/[id]/route.js +6 -6
- package/.next/server/app/api/bot/task/[id]/route.js.nft.json +1 -1
- package/.next/server/app/api/bot/task/route.js +6 -6
- package/.next/server/app/api/bot/task/route.js.nft.json +1 -1
- package/.next/server/app/api/config/route.js +3 -3
- package/.next/server/app/api/config/route.js.nft.json +1 -1
- package/.next/server/app/api/events/route.js +1 -1
- package/.next/server/app/api/events/route.js.nft.json +1 -1
- package/.next/server/app/api/file/[...path]/route.js +1 -1
- package/.next/server/app/api/file/[...path]/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/catalog/route.js +6 -6
- package/.next/server/app/api/llm-model/catalog/route.js.nft.json +1 -1
- package/.next/server/app/api/llm-model/route.js +3 -3
- package/.next/server/app/api/llm-model/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/[name]/route.js +3 -3
- package/.next/server/app/api/mcp/[name]/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/oauth/callback/route.js +5 -5
- package/.next/server/app/api/mcp/oauth/callback/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/route.js +3 -3
- package/.next/server/app/api/mcp/route.js.nft.json +1 -1
- package/.next/server/app/api/mcp/tools/route.js +3 -3
- package/.next/server/app/api/mcp/tools/route.js.nft.json +1 -1
- package/.next/server/app/api/memory/route.js +7 -7
- package/.next/server/app/api/memory/route.js.nft.json +1 -1
- package/.next/server/app/api/memory/tidy/route.js +10 -11
- package/.next/server/app/api/memory/tidy/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/[source]/[name]/route.js +1 -1
- package/.next/server/app/api/skills/[source]/[name]/route.js.nft.json +1 -1
- package/.next/server/app/api/skills/route.js +1 -1
- package/.next/server/app/api/skills/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/call/route.js +8 -8
- package/.next/server/app/api/thursday/call/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/skills/route.js +8 -8
- package/.next/server/app/api/thursday/skills/route.js.nft.json +1 -1
- package/.next/server/app/api/thursday/tool-call/route.js +11 -12
- package/.next/server/app/api/thursday/tool-call/route.js.nft.json +1 -1
- package/.next/server/app/api/workspace/route.js +1 -1
- package/.next/server/app/api/workspace/route.js.nft.json +1 -1
- package/.next/server/app/artifact/[...path]/page/server-reference-manifest.json +1 -1
- package/.next/server/app/artifact/[...path]/page.js +3 -3
- package/.next/server/app/artifact/[...path]/page.js.nft.json +1 -1
- package/.next/server/app/artifact/[...path]/page_client-reference-manifest.js +1 -1
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -1
- package/.next/server/app/page/server-reference-manifest.json +63 -41
- package/.next/server/app/page.js +7 -7
- package/.next/server/app/page.js.nft.json +1 -1
- package/.next/server/app/page_client-reference-manifest.js +1 -1
- package/.next/server/app-paths-manifest.json +1 -0
- package/.next/server/chunks/0d-b_next_dist_server_app-render_after-task-async-storage_external_0-exn7p.js +3 -0
- package/.next/server/chunks/{[root-of-the-server]__0t_dqaj._.js → [root-of-the-server]__0-npkh_._.js} +1 -1
- package/.next/server/chunks/[root-of-the-server]__005var5._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__019dx9f._.js +2 -2
- package/.next/server/chunks/[root-of-the-server]__02va5wz._.js +3 -0
- package/.next/server/chunks/{[root-of-the-server]__1mzp_el._.js → [root-of-the-server]__04_8spk._.js} +2 -2
- package/.next/server/chunks/[root-of-the-server]__06t77t4._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0bed6hu._.js +4 -4
- package/.next/server/chunks/[root-of-the-server]__0cro2dz._.js +5 -0
- package/.next/server/chunks/[root-of-the-server]__0emr6go._.js +3 -0
- package/.next/server/chunks/[root-of-the-server]__0le4d-p._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__0m8ywyo._.js +5 -5
- package/.next/server/chunks/{[root-of-the-server]__113fqg5._.js → [root-of-the-server]__0p32jfz._.js} +3 -3
- package/.next/server/chunks/[root-of-the-server]__0phdgco._.js +4 -4
- package/.next/server/chunks/[root-of-the-server]__0wvgrsl._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__11j52t0._.js +5 -0
- package/.next/server/chunks/{[root-of-the-server]__0j_n5l3._.js → [root-of-the-server]__1692zrv._.js} +2 -2
- package/.next/server/chunks/[root-of-the-server]__16thabu._.js +1 -1
- package/.next/server/chunks/[root-of-the-server]__173nhwf._.js +3 -3
- package/.next/server/chunks/[root-of-the-server]__1bn73ih._.js +10 -0
- package/.next/server/chunks/[root-of-the-server]__1bqhuh9._.js +4 -4
- package/.next/server/chunks/[root-of-the-server]__1ccon1w._.js +10 -0
- package/.next/server/chunks/[root-of-the-server]__1cqizfq._.js +1 -1
- package/.next/server/chunks/{[root-of-the-server]__1u_qvc7._.js → [root-of-the-server]__1fboj2j._.js} +2 -2
- package/.next/server/chunks/{[root-of-the-server]__1dow0bz._.js → [root-of-the-server]__1oli73c._.js} +2 -2
- package/.next/server/chunks/[root-of-the-server]__1txedx6._.js +4 -4
- package/.next/server/chunks/[root-of-the-server]__1untqv8._.js +5 -0
- package/.next/server/chunks/_0-73of8._.js +55 -0
- package/.next/server/chunks/{_2050gwn._.js → _00_584r._.js} +66 -28
- package/.next/server/chunks/{_0y8is-s._.js → _03a0897._.js} +1 -1
- package/.next/server/chunks/_05h2cii._.js +1 -1
- package/.next/server/chunks/_06mxlgn._.js +1 -1
- package/.next/server/chunks/_0a351g7._.js +1 -1
- package/.next/server/chunks/{_0hin38_._.js → _0khihjk._.js} +5 -5
- package/.next/server/chunks/_0kjjmag._.js +1 -1
- package/.next/server/chunks/{_1t8fv7b._.js → _0n74zsf._.js} +5 -5
- package/.next/server/chunks/_0nn99o2._.js +3 -0
- package/.next/server/chunks/_0pppbb5._.js +10 -6
- package/.next/server/chunks/{_1icgbi8._.js → _0rnf-6n._.js} +5 -5
- package/.next/server/chunks/_0u10wmw._.js +55 -0
- package/.next/server/chunks/{_0kl37zl._.js → _0vnutv9._.js} +1 -1
- package/.next/server/chunks/_0wp4le3._.js +1 -1
- package/.next/server/chunks/_0y5fg-x._.js +1 -1
- package/.next/server/chunks/_106co2o._.js +3 -0
- package/.next/server/chunks/_12bbv5i._.js +10 -6
- package/.next/server/chunks/_15hq89o._.js +1 -1
- package/.next/server/chunks/_15q1pig._.js +1 -1
- package/.next/server/chunks/_18-1wcc._.js +55 -0
- package/.next/server/chunks/_19wg5yn._.js +138 -0
- package/.next/server/chunks/_1_5mnq4._.js +18 -0
- package/.next/server/chunks/_1bt95p9._.js +55 -0
- package/.next/server/chunks/_1cbk7ms._.js +9 -9
- package/.next/server/chunks/_1drgfx4._.js +18 -0
- package/.next/server/chunks/_1drv2et._.js +10 -6
- package/.next/server/chunks/{_10qam6o._.js → _1e48czp._.js} +5 -5
- package/.next/server/chunks/{_1skgy7b._.js → _1kg70wc._.js} +5 -5
- package/.next/server/chunks/_1php4eq._.js +1 -1
- package/.next/server/chunks/_1rysr-r._.js +10 -0
- package/.next/server/chunks/_1u3rwbr._.js +3 -0
- package/.next/server/chunks/_1x7p319._.js +1 -1
- package/.next/server/chunks/_1yuv4vp._.js +1 -1
- package/.next/server/chunks/_next-internal_server_app_api_bot_notes_route_actions_0qcsyu7.js +3 -0
- package/.next/server/chunks/config_ts_1g4sz5o._.js +1 -1
- package/.next/server/chunks/features_bot_task_query_ts_11xuzl3._.js +1 -1
- package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0228f43._.js → node_modules_consola_dist_chunks_prompt_mjs_02s3hjt._.js} +1 -1
- package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0ir-vo2._.js → node_modules_consola_dist_chunks_prompt_mjs_06067w6._.js} +1 -1
- package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0otw8ef._.js → node_modules_consola_dist_chunks_prompt_mjs_096ais_._.js} +1 -1
- package/.next/server/chunks/{node_modules_consola_dist_chunks_prompt_mjs_0tf290y._.js → node_modules_consola_dist_chunks_prompt_mjs_0a1rd09._.js} +1 -1
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0gzvgfv._.js +3 -0
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0j61-ma._.js +3 -0
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0tvkfgh._.js +3 -0
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_11zjo-1._.js +3 -0
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1pycqsq._.js +3 -0
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1tpvamf._.js +3 -0
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1y9-wcr._.js +3 -0
- package/.next/server/chunks/ssr/[externals]__0dizgek._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__0f6s48x._.js +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__0m1b5ky._.js +3 -0
- package/.next/server/chunks/ssr/{[root-of-the-server]__0dfwvr4._.js → [root-of-the-server]__0un-erv._.js} +2 -2
- package/.next/server/chunks/ssr/[root-of-the-server]__1-mnhyd._.js +5 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__1bww500._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1mzi-ju._.js +1 -1
- package/.next/server/chunks/ssr/[root-of-the-server]__1qfqvmg._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1vcdast._.js +3 -0
- package/.next/server/chunks/ssr/[root-of-the-server]__1xwnu-h._.js +3 -0
- package/.next/server/chunks/ssr/_03webdr._.js +3 -0
- package/.next/server/chunks/ssr/{_0gd4vaa._.js → _040sk32._.js} +71 -29
- package/.next/server/chunks/ssr/_077-g6s._.js +1 -1
- package/.next/server/chunks/ssr/{_0lc_7c8._.js → _09ja_w1._.js} +2 -2
- package/.next/server/chunks/ssr/{_1dcxzqe._.js → _0f_b_9s._.js} +2 -2
- package/.next/server/chunks/ssr/_0h7zdni._.js +1 -1
- package/.next/server/chunks/ssr/_0lu1n_x._.js +3 -0
- package/.next/server/chunks/ssr/_0sf1isi._.js +1 -1
- package/.next/server/chunks/ssr/_0su6_08._.js +3 -0
- package/.next/server/chunks/ssr/{_0nso8tp._.js → _0w5bgak._.js} +2 -2
- package/.next/server/chunks/ssr/{_19_o9d-._.js → _0x_nu5e._.js} +2 -2
- package/.next/server/chunks/ssr/_1-teee5._.js +3 -3
- package/.next/server/chunks/ssr/_13punpm._.js +1 -1
- package/.next/server/chunks/ssr/{_0ay6b01._.js → _1ciyoo3._.js} +2 -2
- package/.next/server/chunks/ssr/_1e-dgz0._.js +1 -1
- package/.next/server/chunks/ssr/_1fq7zgb._.js +1 -1
- package/.next/server/chunks/ssr/{_0cvjbuz._.js → _1g6l4uj._.js} +2 -2
- package/.next/server/chunks/ssr/{_0q_2f2x._.js → _1lip4th._.js} +2 -2
- package/.next/server/chunks/ssr/_1m3bsfr._.js +3 -0
- package/.next/server/chunks/ssr/_1mznrxk._.js +1 -1
- package/.next/server/chunks/ssr/_1ruzehw._.js +3 -0
- package/.next/server/chunks/ssr/_1vyd1ji._.js +3 -0
- package/.next/server/chunks/ssr/features_bot_components_bot-setting_tsx_01ajft6._.js +2 -2
- package/.next/server/chunks/ssr/features_config_components_14jqgy4._.js +1 -1
- package/.next/server/chunks/ssr/features_config_components_config-setting_tsx_0xfwqdg._.js +1 -1
- package/.next/server/chunks/ssr/features_connectors_components_mcp-setting_tsx_0jmbgvp._.js +1 -1
- package/.next/server/chunks/ssr/features_memory_components_memory-setting_tsx_0oa43sw._.js +1 -1
- package/.next/server/chunks/ssr/lib_realtime_12wg_dd._.js +27 -0
- package/.next/server/chunks/ssr/lib_realtime_15h_v1v._.js +27 -0
- package/.next/server/chunks/ssr/{node_modules_108wd2o._.js → node_modules_004qlr4._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1ub40gk._.js → node_modules_01qnv-a._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1y8_3vg._.js → node_modules_04n7mjs._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0_j7-g4._.js → node_modules_08d8bke._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0y2-av4._.js → node_modules_09xhur7._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_043-236._.js → node_modules_0_n241r._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0ls96je._.js → node_modules_0iz1rzd._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0xwx4u-._.js → node_modules_0kl7-tn._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1jatz7w._.js → node_modules_0kxz4gt._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1t0y5jt._.js → node_modules_0lrjk5t._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_13f2md6._.js → node_modules_0m93zeg._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1nhw9qg._.js → node_modules_0n1kj4p._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1k29j1j._.js → node_modules_0ndvxub._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_16i4o_3._.js → node_modules_13r44jq._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0fbw5-u._.js → node_modules_17lrt3y._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1d-is1o._.js → node_modules_18_dk7_._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1hn_sd5._.js → node_modules_19dp7ko._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_20ynonm._.js → node_modules_1dwguw_._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_00d6675._.js → node_modules_1hd-5tv._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1ee8gav._.js → node_modules_1hn8z1f._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0bue6gy._.js → node_modules_1n5ygqe._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1_588_4._.js → node_modules_1q0p85z._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0ipn1ho._.js → node_modules_1toafc-._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_0_fvxnt._.js → node_modules_1xyd7ov._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_1v0077l._.js → node_modules_1zu988w._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_06kvvuo._.js → node_modules_20yebtj._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_092s8nx._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_0m9a4y0._.js} +1 -1
- package/.next/server/chunks/ssr/{node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_1nvexgu._.js → node_modules_@mermaid-js_parser_dist_chunks_mermaid-parser_core_13w_wy9._.js} +1 -1
- package/.next/server/chunks/ssr/node_modules_consola_dist_chunks_prompt_mjs_05cwqv2._.js +47 -0
- package/.next/server/middleware-build-manifest.js +3 -3
- package/.next/server/pages/404.html +1 -1
- package/.next/server/pages/500.html +1 -1
- package/.next/server/server-reference-manifest.js +1 -1
- package/.next/server/server-reference-manifest.json +64 -42
- package/.next/static/chunks/05b6nx_o3_f_n.js +1 -0
- package/.next/static/chunks/{3aquirz5h71da.js → 07kl352c-lvcz.js} +1 -1
- package/.next/static/chunks/0dmns-gi0raa4.js +1 -0
- package/.next/static/chunks/0oc4_xoia77dg.css +1 -0
- package/.next/static/chunks/0pheo8m3a-rzi.js +1 -0
- package/.next/static/chunks/{2ihkf6l2jowo9.js → 18vhba44l1fc9.js} +3 -3
- package/.next/static/chunks/19i8h2t-5evjx.js +1 -0
- package/.next/static/chunks/{1gy3bbv7usnjo.js → 1c5fcj473025q.js} +1 -1
- package/.next/static/chunks/1pi_hbmjw-f-z.js +1 -0
- package/.next/static/chunks/{0tydnn2kybibk.js → 1twt6k09vg4np.js} +1 -1
- package/.next/static/chunks/{21rk8w7bda-su.js → 28gotuisldmom.js} +1 -1
- package/.next/static/chunks/{3xxa2j56-f3nm.js → 2998p0y7k1c8z.js} +1 -1
- package/.next/static/chunks/2l233xfycjpd8.js +1 -0
- package/.next/static/chunks/2p5n7pa3c40t-.js +2 -0
- package/.next/static/chunks/2ru1q132af7h7.js +1 -0
- package/.next/static/chunks/{2fq_86jvq9ymq.js → 2t8wqycwg3y04.js} +2 -2
- package/.next/static/chunks/32z_ypgtchw48.js +1 -0
- package/.next/static/chunks/{247d-r95j8xs0.js → 33pyjb3xd1iez.js} +1 -1
- package/.next/static/chunks/3786h5vayt80-.js +28 -0
- package/.next/static/chunks/3_h9txt3tq8t8.js +28 -0
- package/.next/static/chunks/{1khakdu_iuedc.js → 3ard_noqapnw1.js} +1 -1
- package/.next/static/chunks/{1fr5m75pwtyic.js → 3omud5xunrk1f.js} +1 -1
- package/.next/static/chunks/42dnrkbph9e-1.js +1 -0
- package/app/api/events/app-event.client.ts +24 -0
- package/app/api/events/app-event.server.ts +45 -0
- package/app/api/events/app-event.ts +44 -0
- package/app/api/llm-model/catalog/route.ts +12 -0
- package/app/api/llm-model/route.ts +21 -0
- package/app/api/query-key.ts +144 -0
- package/app/api/thursday/tool-call/route.ts +67 -0
- package/components/ui/button-group.tsx +45 -0
- package/components/ui/custom-icon.tsx +259 -0
- package/components/ui/dropdown-menu.tsx +271 -0
- package/components/ui/folded-text.tsx +68 -0
- package/components/ui/input-group.tsx +157 -0
- package/components/ui/json-view.tsx +240 -0
- package/components/ui/shiny-text.tsx +141 -0
- package/components/ui/text-type.tsx +213 -0
- package/components/ui/theme-sync.tsx +9 -0
- package/database/migrations/{20260908030742_rainy_marvel_zombies → 20260909060813_optimal_sabretooth}/migration.sql +7 -0
- package/database/migrations/{20260908030742_rainy_marvel_zombies → 20260909060813_optimal_sabretooth}/snapshot.json +54 -1
- package/database/migrations/20260909063821_bitter_tenebrous/migration.sql +1 -0
- package/database/migrations/20260909063821_bitter_tenebrous/snapshot.json +1285 -0
- package/docs/how-it-works.md +59 -0
- package/docs/images/keeps-going.png +0 -0
- package/docs/images/task-thread.png +0 -0
- package/docs/images/two-minds.png +0 -0
- package/features/ai/load-tools.ts +55 -5
- package/features/ai/prompts/bot.prompt.ts +121 -26
- package/features/ai/prompts/memory-tidy.prompt.ts +7 -1
- package/features/ai/prompts/prompt-helper.ts +31 -5
- package/features/ai/prompts/thursday.prompt.ts +2 -0
- package/features/ai/tools/bot.tool.ts +37 -18
- package/features/ai/tools/mcp.tool.ts +5 -5
- package/features/ai/tools/memory.tool.ts +17 -10
- package/features/ai/tools/studio.tool.ts +5 -5
- package/features/ai/tools/tool-name.ts +2 -0
- package/features/ai/tools/workspace.tool.ts +33 -5
- package/features/bot/bot.action.ts +31 -4
- package/features/bot/bot.notes.ts +120 -0
- package/features/bot/bot.query.ts +56 -1
- package/features/bot/bot.run.ts +43 -3
- package/features/bot/bot.runner.ts +94 -20
- package/features/bot/bot.schema.ts +17 -0
- package/features/bot/components/bot-room.tsx +405 -306
- package/features/bot/components/bot-setting.tsx +123 -20
- package/features/bot/task.query.ts +18 -5
- package/features/memory/components/memory-setting.tsx +11 -2
- package/features/memory/memory.query.ts +9 -2
- package/features/memory/memory.schema.ts +30 -0
- package/features/skills/components/skills-setting.tsx +9 -1
- package/features/workspace/workspace.ts +136 -3
- package/hooks/use-draft.ts +37 -0
- package/hooks/use-hotkey.ts +105 -0
- package/hooks/use-object-state.ts +51 -0
- package/hooks/use-on-visible.ts +72 -0
- package/hooks/use-theme.ts +106 -0
- package/hooks/use-wake-word.ts +262 -0
- package/lib/realtime/realtime.driver.ts +34 -1
- package/lib/realtime/realtime.protocol.ts +6 -0
- package/lib/sandbox.ts +9 -1
- package/lib/tokens.ts +19 -0
- package/package.json +1 -1
- package/.next/server/chunks/[root-of-the-server]__02kt8yn._.js +0 -10
- package/.next/server/chunks/[root-of-the-server]__0h59di-._.js +0 -5
- package/.next/server/chunks/[root-of-the-server]__0qjqtwo._.js +0 -5
- package/.next/server/chunks/[root-of-the-server]__0yk6s3w._.js +0 -5
- package/.next/server/chunks/[root-of-the-server]__0z3gelv._.js +0 -3
- package/.next/server/chunks/[root-of-the-server]__11w_7_3._.js +0 -3
- package/.next/server/chunks/[root-of-the-server]__1_0q_9w._.js +0 -3
- package/.next/server/chunks/[root-of-the-server]__1gmn1cs._.js +0 -10
- package/.next/server/chunks/_0fzqt2y._.js +0 -100
- package/.next/server/chunks/_0jgm3b8._.js +0 -55
- package/.next/server/chunks/_0ks6_sg._.js +0 -55
- package/.next/server/chunks/_0tzfesa._.js +0 -3
- package/.next/server/chunks/_0zmestz._.js +0 -55
- package/.next/server/chunks/_12nr4xc._.js +0 -3
- package/.next/server/chunks/_1hzrsvg._.js +0 -55
- package/.next/server/chunks/_1uj4_io._.js +0 -10
- package/.next/server/chunks/_1yldgo4._.js +0 -55
- package/.next/server/chunks/features_0scmr4i._.js +0 -3
- package/.next/server/chunks/features_bot_bot_query_ts_12mgkl2._.js +0 -3
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_0ykklj0._.js +0 -3
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1ryg3wh._.js +0 -3
- package/.next/server/chunks/node_modules_consola_dist_chunks_prompt_mjs_1vwbnq_._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__01id-v3._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__0b-0i32._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__185grso._.js +0 -3
- package/.next/server/chunks/ssr/[root-of-the-server]__1minz8_._.js +0 -3
- package/.next/server/chunks/ssr/_0j4v8of._.js +0 -3
- package/.next/server/chunks/ssr/_0l81bzy._.js +0 -3
- package/.next/server/chunks/ssr/_10uvw3l._.js +0 -3
- package/.next/server/chunks/ssr/_1jbv7m1._.js +0 -3
- package/.next/server/chunks/ssr/lib_realtime_0aetuyp._.js +0 -24
- package/.next/server/chunks/ssr/lib_realtime_18k_aj-._.js +0 -24
- package/.next/server/chunks/ssr/node_modules_zod_v4_classic_errors_05xv7vp.js +0 -3
- package/.next/static/chunks/0yysv1gzin17t.js +0 -1
- package/.next/static/chunks/1keib_gt066gc.js +0 -1
- package/.next/static/chunks/28g42tw8tsvhd.js +0 -1
- package/.next/static/chunks/2cwjgkt_hoyhj.js +0 -22
- package/.next/static/chunks/2rbf1fpd8n80-.js +0 -22
- package/.next/static/chunks/2ukj8k69y89um.js +0 -1
- package/.next/static/chunks/2wngeetfnzxkp.js +0 -2
- package/.next/static/chunks/388-t2v72jh39.css +0 -1
- package/.next/static/chunks/3fqvc0cg-atq_.js +0 -1
- package/.next/static/chunks/3p4egvfjxpatb.js +0 -1
- package/.next/static/chunks/3qe1w1ei-huhl.js +0 -1
- package/.next/static/chunks/3y40riycdip-i.js +0 -1
- package/.next/static/chunks/45a6zbtkelph9.js +0 -1
- /package/.next/static/{X34BUd9bfdH27ripuwwBm → YR4NWcDDuzwLbTTU7U7Vr}/_buildManifest.js +0 -0
- /package/.next/static/{X34BUd9bfdH27ripuwwBm → YR4NWcDDuzwLbTTU7U7Vr}/_clientMiddlewareManifest.js +0 -0
- /package/.next/static/{X34BUd9bfdH27ripuwwBm → YR4NWcDDuzwLbTTU7U7Vr}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
module.exports=[851372,e=>e.a(async(t,o)=>{try{var a=e.i(687388),n=e.i(353885),s=e.i(265143),r=e.i(148831),i=e.i(619898),l=e.i(636882),h=e.i(786025),u=e.i(640911),d=e.i(41444),c=e.i(660948),p=e.i(54282),w=t([s,r,i,c]);async function y(e,t,o,d){var w,y,$,S,O,x,A,_;let E,j,I,M=await (0,h.openWorkspace)(),L=e.trim(),[q,B,C,W,P,U,R,Y,H]=await Promise.all([(0,l.loadSkills)(M),(0,i.listNoteIndex)(),(0,i.listAlwaysLoaded)(),(0,c.listConnectedToolNames)(),(0,r.findPinnedTools)(L),(0,s.listJobBots)(),(0,s.readBotNote)(L),(0,s.readBotNotesOn)(),(0,h.readMachineTools)(M)]),J=o?[]:U.filter(e=>e.name!==L),F=[o?(w=L,y=o,[`You are ${w}, a worker. ${y} is holding a job Thursday handed them and has handed one part of it to you. The user speaks to Thursday and to nobody else; you never address them, and what you hand back goes into ${y}'s report as-is. This thread is drawn on their screen while you work: not written to them, but not private either. ${(0,p.nowLine)()}`,m,g].join("\n\n")):($=L,[`You are ${$}, a worker. Thursday handed you a job while she keeps talking to the user — they speak to her and to nobody else, and what she reads them out of your report is the only part of this that reaches them. You are not in that conversation and never address the user. This thread is drawn on their screen while you work, though: not written to them, but not private either. ${(0,p.nowLine)()}`,m,g].join("\n\n")),(S=B,O=C,E=`## Memory
|
|
2
|
+
|
|
3
|
+
What the user's assistant knows about them. Thursday keeps it as she talks with them, and everyone reads it.
|
|
4
|
+
|
|
5
|
+
Yours to read, and to add to when the work turns up something about *them* that outlives the job; what the job itself turned up goes in your report. It describes the user, not you: how they are named and spoken to is hers to use with them, not yours to borrow. What you learn about this machine is not memory — that is your own instructions, below.`,j=O.length?`Already known:
|
|
6
|
+
|
|
7
|
+
${(0,p.carriedLines)(O)}`:"",I=`path — what is under it (facts) "what the user calls it"
|
|
8
|
+
|
|
9
|
+
${(0,p.noteLines)(S)}
|
|
10
|
+
|
|
11
|
+
A topic not listed is one nobody knows anything about.`,[E,j,I].filter(Boolean).join("\n\n")),Y?(x=R,`## Your own instructions
|
|
12
|
+
|
|
13
|
+
What you wrote to yourself on earlier jobs here, to get better at this machine. Only you read it, and it is the one thing that reaches your next job. What belongs in it is what working here is like — the command that turns out to be the right one, the flag it needs, the tool this platform does not have. Not what the user is like: that is Memory, above, and everyone reads that one.
|
|
14
|
+
|
|
15
|
+
${x??"Empty. What usually goes in first is whatever you had to find out before you could start."}
|
|
16
|
+
|
|
17
|
+
(${x?.length??0}/${a.BOT_NOTES.chars} characters)`):"",function(e,t){let o=new Set(t.map(e=>`${e.server}/${e.name}`)),a=e.filter(e=>!o.has(`${e.server}/${e.name}`));if(0===a.length)return"";let s=o.size?" What is not listed above you are already holding — it is in your tools.":"";return`## Connected tools
|
|
18
|
+
|
|
19
|
+
${(0,p.mcpToolLines)(a)}
|
|
20
|
+
|
|
21
|
+
Names only: \`${n.TOOL_NAMES.tool_search}\` returns what each one takes, \`${n.TOOL_NAMES.tool_call}\` runs one.${s}`}(W,P),(A=q,0===A.length?"":`## Skills
|
|
22
|
+
|
|
23
|
+
Written-down methods. When the job is one of these, read it with \`${n.TOOL_NAMES.load_skill}\` before starting.
|
|
24
|
+
|
|
25
|
+
${(0,p.skillLines)(A)}`),b(M.cwd,H,d),(_=J,0===_.length?"":`## Bots
|
|
26
|
+
|
|
27
|
+
${_.map(e=>`- **${e.name}** — ${e.description}`).join("\n")}
|
|
28
|
+
|
|
29
|
+
These lines were written for the user, who reads them on their own screen: where one says "you" it means them, not you.
|
|
30
|
+
|
|
31
|
+
A part of your job another bot is for goes to \`${n.TOOL_NAMES.ask_bot}\`, because their tools and their practice are the reason they exist. What you build is made of what they bring back, so send for it before you build. A part you could finish in a couple of commands is yours; one that would take a run of its own is theirs. The job stays yours and you report; they see only your brief — not the call, not this thread.`),o?T(o):k,o?v(o):N,f(t)].filter(Boolean).join("\n\n");return(0,p.logPromptSize)("bot",F),u.logger.debug(`bot prompt
|
|
32
|
+
${F}`),{text:F,peers:J.map(e=>e.name),opening:null}}[s,r,i,c]=w.then?(await w)():w;let m=`**You are on a real computer — the user's own.** You have a shell and a filesystem, and the job is done, not described: where there is no tool for something, write one — in \`node\` unless they asked for another language, the runtime this app itself runs on. Reach for \`${n.TOOL_NAMES.bash}\` before concluding that something cannot be done, but after the roster, not instead of it: a script you write to do another bot's job is the long way round.
|
|
33
|
+
|
|
34
|
+
**What is missing gets installed**, onto the machine once they say yes. What is already there is nobody's question — Environment says what this machine has.
|
|
35
|
+
|
|
36
|
+
**Bring back the thing itself** — their own machine, their own accounts, their own copy of whatever they sent you for — not a smaller safer version of it, and not a note on why you did not.`,g="**Never present a guess as a result.** She says it out loud as fact. Say which part is unverified and why.",f=e=>e?.trim()?`## Owner's instructions
|
|
37
|
+
|
|
38
|
+
Written by the person this bot works for. Where these and anything above disagree, these win.
|
|
39
|
+
|
|
40
|
+
${e.trim()}`:"",b=(e,t,o)=>{var s;let r,i;return`## Environment
|
|
41
|
+
|
|
42
|
+
Current Cwd: ${e}
|
|
43
|
+
Platform: ${process.platform}
|
|
44
|
+
${s=t,r=(e,t)=>`${e}: ${t.found.length?t.found.join(", "):"none"}.${t.missing.length?` Not here: ${t.missing.join(", ")}.`:""}`,i=s.managers.found.includes("pnpm")?" Use pnpm, not npm — this workspace is fenced for it (`pnpm-workspace.yaml`, `.npmrc`).":"",[r("Runtimes",s.runtimes),`${r("Package managers",s.managers)}${i}`,null===s.browser?"":s.browser?"Browser: installed.":"Browser: not installed — `playwright-cli install-browser chromium` puts one there."].filter(Boolean).join("\n")}
|
|
45
|
+
|
|
46
|
+
Read off this machine as the job opened, so it is current: reach for what is here instead of checking for it.
|
|
47
|
+
|
|
48
|
+
Your workspace — \`${n.TOOL_NAMES.bash}\` runs here. Everything you write goes in one of these, and they are kept apart because what is in them lives for different lengths of time:
|
|
49
|
+
|
|
50
|
+
- \`${a.PATHS.artifacts}/\` — finished work the user opens, one entry per result. Theirs, and it stays.
|
|
51
|
+
- \`${a.PATHS.projects}/\` — code you build, one folder each. It outlives this job, and a project's dependencies install inside it, never at the workspace root.
|
|
52
|
+
- \`${o?.scratch??a.PATHS.scratch}/\` — this job's working material. It goes when the job does, so nothing here is worth keeping.
|
|
53
|
+
- \`${o?.own??a.PATHS.bots}/\` — yours, across every job you run here. A script you wrote once and will want again, a table you built. Your own instructions can name what is in it.
|
|
54
|
+
|
|
55
|
+
Never the directory above — that is the app you run in; outside the workspace, only where the user pointed you.`},k=`## Asking
|
|
56
|
+
|
|
57
|
+
What you cannot get for yourself — a decision between real options, a detail only the conversation has, a go-ahead before deleting or sending — goes to \`${n.TOOL_NAMES.ask_thursday}\`, once, with everything in it. Ask before you start, not after an hour; never ask what one command would tell you.
|
|
58
|
+
|
|
59
|
+
A job that arrives without its shape — several ways to do it, no telling what it is for, a scale nobody named — is planned before it is built: put the plan up in two or three lines with what you need decided. A job asked for as one thing is built, not proposed.
|
|
60
|
+
|
|
61
|
+
A request that says buy, pay, top up is the go-ahead — press the button. Only what is theirs alone stops the job: a password, a one-time code, a passkey, a permission on their machine. Set it up one action away, ask, and carry on when the answer comes back.`,T=e=>`## Asking
|
|
62
|
+
|
|
63
|
+
What you cannot get for yourself goes to \`${n.TOOL_NAMES.ask_back}\`: ${e} handed you this part and answers from what they have. They cannot take a question to the user, so for what is the user's alone take the safer reading and say so in what you hand back. Ask before you start, once, whole.`,$=`Your steps are capped at ${a.BOT_RUN.steps}; running long, report what you have with \`complete: false\` while the summary is still yours to write.`,N=`## Finishing
|
|
64
|
+
|
|
65
|
+
Every job ends with \`${n.TOOL_NAMES.report}\`, in the user's language, written to be heard — she reads it out loud. **The job ends in the thing that was asked for**: an action with the action done, photos in a page with the photos in it, a comparison in a table. Anything that does not fit in a few lines is a file under \`${a.PATHS.artifacts}/\`, and the report names its path — it becomes a link on their screen. In a \`.md\`, images only by absolute route (\`/api/file/${a.PATHS.artifacts}/…\`).
|
|
66
|
+
|
|
67
|
+
\`complete: false\` when part of the request is genuinely undone — say where you got to and the user decides. ${$}`,v=e=>`## Finishing
|
|
68
|
+
|
|
69
|
+
Every part ends with \`${n.TOOL_NAMES.report}\`; what you hand back goes into ${e}'s own report. Hand back what the brief asked for, in the shape it asked for, with everything you learned that bears on it — exact values, the paths of files you wrote, what did not work. They cannot see your thread, so long is right here. \`complete: false\` when part of the brief is undone, with where you got to. ${$}`;e.s(["OPENING_TURNS",0,10,"buildTaskOpening",0,function(e){let t=e.conversation.filter(e=>e.text.trim());if(!t.length)return e.request;let o=t.map(e=>`${"user"===e.role?"user":"thursday"}: ${(0,d.clip)(e.text,160)}`);return`${e.request}
|
|
70
|
+
|
|
71
|
+
## The call, just before this reached you
|
|
72
|
+
|
|
73
|
+
A detail that is not in the request may be here — a name, a number, which one of two. The request wins where they disagree, with one exception: when they asked out loud for something to be *done* and the request only asks about it, the doing is the job.
|
|
74
|
+
|
|
75
|
+
${o.join("\n")}`},"loadBotPrompt",0,y]),o()}catch(e){o(e)}},!1),982388,e=>e.a(async(t,o)=>{try{var a=e.i(68356),n=e.i(847841),s=e.i(907855),r=e.i(687388),i=e.i(353885),l=e.i(640911),h=e.i(268486),u=e.i(265143),d=t([u]);[u]=d.then?(await d)():d;let p=(0,h.createKeyedLock)();async function c(e){return p(e.bot,async()=>{let t=await (0,u.readBotNote)(e.bot),o=t;try{var h,d;await (0,a.generateText)({model:e.model,messages:[{role:"user",content:(h=t,d=e.want,`You keep one worker's notes. It is an agent with a shell on this machine; the notes are its own, read at the start of every job it runs and by nobody else. They hold what this machine has taught it — the command that works here, the flag without which something fails, the tool this platform does not have. Write what the worker found, never what it proposed.
|
|
76
|
+
|
|
77
|
+
Four things do not belong, however true today: what is in a folder right now, what a job produced, anything about the person the work is for, and how to satisfy the worker's own tools (\`report\`, \`write_file\`, \`bash\` — those belong to the app it runs inside and change with it). A program *on the machine* is the opposite and does belong.
|
|
78
|
+
|
|
79
|
+
Nor does how the worker should behave. Whoever owns it writes that separately and it outranks these, so a note about manner or language is either already said or about to be overruled.
|
|
80
|
+
|
|
81
|
+
The change is applied to what is already there, not written over it. Say the notes read \`Tests here run with npm.\` and then \`Chromium needs --no-sandbox or it exits.\` The worker asks for the npm line to be corrected to pnpm: both lines come back, the first now reading \`Tests here run with pnpm.\` and the second word for word as it was. Added, corrected or dropped is one line moving; everything the request did not name is untouched.
|
|
82
|
+
|
|
83
|
+
${h?"The notes as they stand:":"There are no notes yet — the fence below is empty because nothing has been written, not because the notes say so."}
|
|
84
|
+
|
|
85
|
+
\`\`\`
|
|
86
|
+
${h??""}
|
|
87
|
+
\`\`\`
|
|
88
|
+
|
|
89
|
+
The worker asks for this change:
|
|
90
|
+
|
|
91
|
+
${d.trim()}
|
|
92
|
+
|
|
93
|
+
Hand back the whole thing as it should now read, keeping what the request does not touch. Only what belongs inside the fence, never a word about it, and nothing at all when the request holds nothing that belongs. At most ${r.BOT_NOTES.chars} characters, which is a ceiling and not a target.`)}],abortSignal:e.signal,tools:{[i.TOOL_NAMES.update_notes]:(0,n.tool)({description:"Hand back the updated prompt.",inputSchema:s.object({prompt:s.string().max(r.BOT_NOTES.chars).describe(`The whole prompt as it should now read, at most ${r.BOT_NOTES.chars} characters.`)}),execute:async({prompt:t})=>(await (0,u.writeBotNote)(e.bot,t),o=t.trim()||null,"Saved.")})},toolChoice:"required",stopWhen:[(0,a.stepCountIs)(3),(0,a.hasToolCall)(i.TOOL_NAMES.update_notes)]})}catch(t){l.logger.warn(`notes pass for ${e.bot} failed: ${t}`)}return o})}e.s(["hasNotesRequest",0,e=>!!e?.trim(),"keepNotes",0,c]),o()}catch(e){o(e)}},!1),585099,e=>e.a(async(t,o)=>{try{var a=e.i(68356),n=e.i(847841),s=e.i(687388),r=e.i(159479),i=e.i(386075),l=e.i(851372),h=e.i(316172),u=e.i(353885),d=e.i(944971),c=e.i(786025),p=e.i(640911),w=e.i(53748),y=e.i(388439),m=e.i(41444),g=e.i(982388),f=e.i(265143),b=e.i(780274),k=t([r,i,l,g,f,b]);[r,i,l,g,f,b]=k.then?(await k)():k;let O=s.BOT_RUN.steps,x=s.BOT_RUN.compactAt;async function T(e,t){var o,s;let d,w,m,k,T=t.depth??0,j=t.parent??null,I=e.bot.trim(),M=e=>t.emit({...e,bot:I,parent:j}),L=await (0,f.findJobBot)(I);if(!L)return void await M({type:"error",message:`No bot named "${e.bot}". Use a name from the list.`});let q=await ((o=L).provider&&o.model?(0,i.getTextModel)({provider:o.provider,model:o.model}):(0,i.resolveDefaultModel)().then(i.getTextModel)),[B,C]=await Promise.all([t.taskId?(0,c.openJobScratch)(t.taskId,(await (0,b.findTask)(t.taskId))?.label??"job"):null,(0,c.openBotFolder)(I)]),[W,P]=await Promise.all([(0,l.loadBotPrompt)(I,L.systemPrompt,"askedBy"in e?e.askedBy:null,{scratch:B,own:C}),(0,r.loadTools)({target:"bot",bot:I,taskId:t.taskId,model:q})]),U="messages"in e?e.messages:[{role:"user",content:(s=e,(d=s.context?.trim())?`${s.request}
|
|
94
|
+
|
|
95
|
+
## What ${s.askedBy} already knows
|
|
96
|
+
|
|
97
|
+
${d}`:s.request)}],R={left:3},Y=T>=1?function(e,t,o){let a={...e};delete a[u.TOOL_NAMES.ask_thursday];let{answer:s}=o;return s?{...a,[u.TOOL_NAMES.ask_back]:(0,n.tool)({description:h.askBackSpec.description,inputSchema:h.askBackSpec.parameters,execute:async({question:e})=>(t.left-=1,s(e))})}:a}(P,R,t):function(e,t){if(0===t.peers.length)return e;let o={...e,[u.TOOL_NAMES.ask_bot]:(0,n.tool)({description:h.askBotSpec.description,inputSchema:h.askBotSpec.parameters,execute:async({bot:e,request:a,context:n},s)=>{let r=t.options.taskId?`${t.options.taskId}-${s.toolCallId.slice(0,8)}`:null,i=[],l=async n=>{let r=await v({model:t.model,instructions:t.instructions,tools:o,messages:s.messages,asked:{bot:e,request:a},question:n,signal:t.options.signal});return await t.emit({type:"answered",question:n,...r}),i.push({question:n,answer:r.text}),r.text};try{var h;let o=await N({bot:e,request:a,context:n,askedBy:t.name},{...t.options,depth:t.depth+1,parent:s.toolCallId,taskId:r,answer:l});return i.length?`${o}
|
|
98
|
+
|
|
99
|
+
${h=e,i.map(({question:e,answer:t})=>`(On the way ${h} asked you: "${e}" — you answered: "${t}")`).join("\n")}`:o}finally{r&&(0,c.closeJobShell)(r)}}})};return o}(P,{name:I,model:q.model,instructions:W.text,peers:W.peers,depth:T,options:t,emit:M}),H={compact:null,interjections:[]},J=new a.ToolLoopAgent({model:q.model,instructions:W.text,tools:Y,stopWhen:[(0,a.stepCountIs)(O),A,(0,a.hasToolCall)(u.TOOL_NAMES.ask_thursday)],prepareStep:async({stepNumber:e,steps:o,messages:a})=>{let n=e<O-1?{}:{activeTools:[u.TOOL_NAMES.report],toolChoice:{type:"tool",toolName:u.TOOL_NAMES.report}};!n.activeTools&&R.left<=0&&(n={...n,activeTools:Object.keys(Y).filter(e=>e!==u.TOOL_NAMES.ask_back)});let s=o.at(-1)?.usage.inputTokens??0,r=Math.max(s,a.reduce((e,t)=>e+(0,y.estimateTokens)("string"==typeof t.content?t.content:JSON.stringify(t.content))+4,0)),i=a;if(r>x&&a.length>=2){let e=await $(q.model,Y,a,{signal:t.signal,budget:x});p.logger.debug(`compacted ${a.length} messages at ${r} tokens (budget ${x})`),H.compact={type:"compact",text:e.text,usage:e.usage,messages:a.length,tokens:r},i=[{role:"user",content:e.text}]}let l=e>0?t.notes?.()??[]:[];return(l.length&&(H.interjections.push(...l),i=[...i,...l.map(e=>({role:"user",content:e}))]),i===a)?n:{...n,messages:i}}}),F=(w=[],m=[],k=!1,{push(e){let t=m.shift();t?t(e):w.push(e)},take(){let e=w.shift();return e?Promise.resolve(e):k?Promise.resolve(null):new Promise(e=>m.push(e))},end(){for(let e of(k=!0,m.splice(0)))e(null)}}),G=await J.stream({messages:U,abortSignal:t.signal,onStepEnd:e=>F.push({messages:e.response.messages,usage:E(e.usage)})}),D="",K=null,z=null,Q=null,V=null;t.signal?.addEventListener("abort",()=>F.end(),{once:!0});try{for await(let e of G.fullStream)switch(e.type){case"start-step":for(let e of(H.compact&&(await M(H.compact),H.compact=null),H.interjections.splice(0)))await M({type:"interjection",text:e});break;case"text-delta":D+=e.text;break;case"text-end":{let e=D.trim();if(D="",!e)break;K=e,await M({type:"text",text:e});break}case"tool-call":if(e.toolName===u.TOOL_NAMES.ask_thursday){let t=e.input;z={id:e.toolCallId,question:String(t.question??""),options:(0,b.optionsOf)(t.options)}}else if(e.toolName===u.TOOL_NAMES.report){let t=e.input;Q={text:String(t.result??"").trim(),complete:!1!==t.complete},V=function(e){let t=e?.notes,o="string"==typeof t?t.trim():"";return o&&!_.has(o.toLowerCase())?o:null}(e.input)}await M({type:"tool",id:e.toolCallId,name:e.toolName,input:e.input});break;case"tool-result":e.toolName===u.TOOL_NAMES.report&&Q&&!(0,h.reportAccepted)(e.output)&&(Q={text:`${Q.text}
|
|
100
|
+
|
|
101
|
+
${S(e.output)}`,complete:!1}),await M({type:"tool-result",id:e.toolCallId,name:e.toolName,output:e.output});break;case"finish-step":{let e=await F.take();e&&await M({type:"step",...e,budget:x});break}case"error":await M({type:"error",message:(0,i.modelErrorToString)(e.error)});return}}finally{F.end()}try{await G.response}catch(e){await M({type:"error",message:(0,i.modelErrorToString)(e)});return}if(z)return void await M({type:"waiting",...z});if(Q){await M({type:"report",...Q}),(0,g.hasNotesRequest)(V)&&await (0,f.readBotNotesOn)()&&await (0,g.keepNotes)({bot:I,model:q.model,want:V,signal:t.signal});return}await M({type:"report",text:K??"Stopped without handing anything back.",complete:!1})}let A=({steps:e})=>e.at(-1)?.toolResults.some(e=>e.toolName===u.TOOL_NAMES.report&&(0,h.reportAccepted)(e.output))??!1,_=new Set(["null","none","n/a","-","없음"]);async function $(e,t,o,n){try{let r,{text:i,usage:l}=await (0,a.generateText)({model:e,tools:t,toolChoice:"none",messages:[...o,{role:"user",content:(r=(e=>{let{min:t,max:o,perTokens:a}=s.BOT_RUN.summaryWords;return Math.min(o,Math.max(t,Math.round(e/a)))})(n.budget),`Compact your context. Everything above is your own work on this job so far; after this message it is replaced by what you write now, and you carry on from that alone. Write what a fresh copy of you needs to continue without re-reading anything:
|
|
102
|
+
|
|
103
|
+
- The job as it was given — the request, quoted, and the details from the call that matter.
|
|
104
|
+
- What you have done and what you found, with the exact values: numbers, names, urls, dates, ids, error messages.
|
|
105
|
+
- Files you wrote or read, by path, and what each holds.
|
|
106
|
+
- What is still left to do, in order, and any decision or answer you are waiting on.
|
|
107
|
+
- What did not work, so it is not tried again.
|
|
108
|
+
|
|
109
|
+
Plain text, under ${r} words. No preamble and no headings about the summary itself — start with the job.`)}],abortSignal:n.signal}),h=i.trim();if(h)return{text:`The context was compacted here. Below is your own summary of the job up to this point; continue from it.
|
|
110
|
+
|
|
111
|
+
${h}`,usage:E(l)}}catch(e){if(n.signal?.aborted)throw e;throw Error(`Could not compact the context (${(0,i.modelErrorToString)(e)}).`)}throw Error("The summary of the context came back empty, so there is nothing to carry on from.")}let E=e=>({input:e.inputTokens??0,output:e.outputTokens??0});async function N(e,t){let o="",a=null;return await T(e,{...t,emit:async e=>{"report"===e.type&&(o=e.complete?e.text:`${e.text}
|
|
112
|
+
|
|
113
|
+
(As far as they got — they ran out of steps.)`),"error"===e.type&&(a=e.message),await t.emit(e)}}),a&&(0,w.publicError)(a),o}async function v(e){try{let t,o,{text:n,usage:s}=await (0,a.generateText)({model:e.model,system:e.instructions,tools:e.tools,toolChoice:"none",messages:[...e.messages,{role:"user",content:(t=e.asked,o=e.question,`You handed one part of your job to ${t.bot}:
|
|
114
|
+
|
|
115
|
+
> ${t.request.trim()}
|
|
116
|
+
|
|
117
|
+
Before going on, they ask you:
|
|
118
|
+
|
|
119
|
+
> ${o.trim()}
|
|
120
|
+
|
|
121
|
+
Answer from what you already have — the request as it reached you, the call it came out of, what you found before asking them. A few lines, plain text, and nothing else: no tools run here. If it is not in what you have, say so rather than guess, and say which way to go without it.`)}],abortSignal:e.signal});return{text:n.trim()||"They had nothing to add. Go on with your best reading, and say what you assumed in what you hand back.",usage:E(s)}}catch(t){if(e.signal?.aborted)throw t;return p.logger.warn(`ask_back: ${(0,i.modelErrorToString)(t)}`),{text:`No answer came back (${(0,i.modelErrorToString)(t)}). Go on with your best reading, and say what you assumed in what you hand back.`,usage:d.NO_TOKENS}}}function S(e){return"string"==typeof e?e:e&&"object"==typeof e&&"value"in e?"string"==typeof e.value?e.value:JSON.stringify(e.value??""):JSON.stringify(e??"")}e.s(["condenseThread",0,function(e,t=s.BOT_RUN.resumeMessages){let[o,...a]=e,n=[],r=(e,t)=>{let o=t.trim();if(!o)return;let a=n.at(-1);a?.role===e?a.content=`${a.content}
|
|
122
|
+
|
|
123
|
+
${o}`:n.push({role:e,content:o})};for(let e of a)if("user"===e.role)r("user","string"==typeof e.content?e.content:e.content.flatMap(e=>"text"===e.type?[e.text]:[]).join("\n"));else if("assistant"===e.role){if("string"==typeof e.content){r("assistant",e.content);continue}for(let t of e.content)"text"===t.type?r("assistant",t.text):"tool-call"===t.type&&r("assistant",function(e){let t=e.input??{};return e.toolName===u.TOOL_NAMES.ask_thursday?`(asked Thursday: ${String(t.question??"")})`:e.toolName===u.TOOL_NAMES.ask_back?`(asked back: ${String(t.question??"")})`:e.toolName===u.TOOL_NAMES.ask_bot?`(asked ${String(t.bot??"")} for: ${String(t.request??"")})`:e.toolName===u.TOOL_NAMES.report?`(handed back: ${(0,m.clip)(String(t.result??""),300)})`:`[${e.toolName} ${(0,b.toolLine)(e.toolName,t)}]`}(t))}else if("tool"===e.role)for(let t of e.content)"tool-result"===t.type&&(t.toolName===u.TOOL_NAMES.ask_thursday||t.toolName===u.TOOL_NAMES.ask_back?r("user",S(t.output)):t.toolName===u.TOOL_NAMES.ask_bot&&r("assistant",`(they answered: ${(0,m.clip)(S(t.output),600)})`));let i=n.slice(-t);return o?[o,...i]:i},"runBot",0,T]),o()}catch(e){o(e)}},!1),39803,e=>e.a(async(t,o)=>{try{var a=e.i(89171),n=e.i(380690),s=e.i(687388),r=e.i(386075),i=e.i(851372),l=e.i(353885),h=e.i(22676),u=e.i(629668),d=e.i(786025),c=e.i(167004),p=e.i(640911),w=e.i(53748),y=e.i(268486),m=e.i(585099),g=e.i(944971),f=e.i(780274),b=t([r,i,h,m,f]);[r,i,h,m,f]=b.then?(await b)():b;let x=globalThis.__botRuns??=new Map,A=globalThis.__botTaskLock??=(0,y.createKeyedLock)();async function k(e){let t=e.callId?await (0,h.listCallTurns)(e.callId,i.OPENING_TURNS):[],o=(0,i.buildTaskOpening)({request:e.request,conversation:t}),a=await (0,f.insertTask)({...e,opening:o});return N(a.id,{bot:e.bot,messages:[{role:"user",content:o}]}),a.id}async function T(e,t){return A(e,async()=>{var o,a;let n,s=await (0,f.findTask)(e);s||(0,w.publicError)("No such job.");let r=x.get(e);if(r&&"running"===s.status&&r.note(t))return void p.logger.debug(`task ${e}: interjection queued`);r&&(r.stop.abort(),await r.done);let{reply:i,as:h}=(o=s,a=t,n="waiting"===o.status?o.pending:null,n?.toolCallId?{as:"answer",reply:{role:"tool",content:[{type:"tool-result",toolCallId:n.toolCallId,toolName:l.TOOL_NAMES.ask_thursday,output:{type:"text",value:a}}]}}:{as:"running"===o.status?"interruption":"waiting"===o.status?"answer":"follow-up",reply:{role:"user",content:a}});p.logger.debug(`task ${e}: ${h}`);let u=await (0,f.listThread)(e);await (0,f.upsertMessage)(e,await (0,f.lastSeq)(e)+1,{bot:null,parent:null,...i}),await (0,f.updateTask)(e,{status:"running",outcome:null,pending:null,reported:!1,endedAt:null}),N(e,{bot:s.bot,messages:(0,m.condenseThread)([...u,i])})})}async function $(e){return A(e,async()=>{await (0,f.findTask)(e)||(0,w.publicError)("No such job."),x.get(e)?.stop.abort(),await (0,f.updateTask)(e,{status:"failed",outcome:"Cancelled.",pending:null,reported:!0,endedAt:new Date}),(0,d.closeJobShell)(e)})}function N(e,t){let o=new AbortController,n=()=>{},s=new Promise(e=>{n=e}),r=[];x.set(e,{stop:o,done:s,note:t=>!!x.has(e)&&(r.push(t),!0)}),(0,a.after)(()=>v(e,t,o.signal,r).catch(t=>{p.logger.error(`task ${e}`,t)}).finally(n))}class _{taskId;seq;steps;constructor(e,t){this.taskId=e,this.steps=new Map,this.seq=t}async note(e){await (0,f.upsertMessage)(this.taskId,++this.seq,{bot:null,parent:null,role:"user",content:e,note:!0})}step(e){let t=`${e.bot} ${e.parent??""}`,o=this.steps.get(t);return o||(o={assistant:null,tool:null,parts:{assistant:[],tool:[]}},this.steps.set(t,o)),o}write(e,t,o,a={}){let n={bot:t.bot,parent:t.parent,role:o.role,content:o.content,compact:a.compact??!1,note:a.note??!1};return(0,f.upsertMessage)(this.taskId,e,n)}async on(e){let t=this.step(e);switch(e.type){case"text":return t.assistant??=++this.seq,t.parts.assistant.push({type:"text",text:e.text}),this.write(t.assistant,e,{role:"assistant",content:t.parts.assistant});case"tool":return t.assistant??=++this.seq,t.parts.assistant.push({type:"tool-call",toolCallId:e.id,toolName:e.name,input:e.input}),this.write(t.assistant,e,{role:"assistant",content:t.parts.assistant});case"tool-result":return t.assistant??=++this.seq,t.tool??=++this.seq,t.parts.tool.push({type:"tool-result",toolCallId:e.id,toolName:e.name,output:"string"==typeof e.output?{type:"text",value:e.output}:{type:"json",value:e.output}}),this.write(t.tool,e,{role:"tool",content:t.parts.tool});case"step":{let o=[t.assistant,t.tool];this.steps.delete(`${e.bot} ${e.parent??""}`);let a=new Set;for(let[t,n]of e.messages.entries()){let s=o[t]??++this.seq;a.add(s),await this.write(s,e,n)}let n=o.filter(e=>null!==e&&!a.has(e));n.length&&await (0,f.deleteMessages)(this.taskId,n);return}case"compact":return this.write(++this.seq,e,{role:"user",content:e.text},{compact:!0,note:!0});case"interjection":return this.write(++this.seq,e,{role:"user",content:e.text});default:return}}}async function v(e,t,o,a){let i=new _(e,await (0,f.lastSeq)(e)),l=null,h=null;try{await (0,m.runBot)(t,{signal:o,taskId:e,notes:()=>a.splice(0),emit:async t=>{await i.on(t),"step"===t.type&&await (0,f.addTaskUsage)(e,t.usage,t.parent?null:{tokens:t.usage.input,budget:t.budget}),("compact"===t.type||"answered"===t.type)&&await (0,f.addTaskUsage)(e,t.usage),t.parent||("waiting"===t.type?l={status:"waiting",outcome:t.question,pending:{toolCallId:t.id,options:t.options}}:"report"===t.type?l={status:t.complete?"done":"waiting",outcome:t.text,pending:t.complete?null:{toolCallId:null,options:[g.TASK_CONTINUE]}}:"error"===t.type&&(h=t.message,l={status:"failed",outcome:S(t.message),pending:null}))}})}catch(e){h=(0,r.modelErrorToString)(e),l={status:"failed",outcome:S(h),pending:null}}finally{x.delete(e)}if(o.aborted)return;let c=l??{status:"failed",outcome:"Stopped without handing anything back.",pending:null};"failed"===c.status&&await i.note(`The run stopped here: ${h??c.outcome}`).catch(t=>p.logger.warn(`task ${e}: break not written`,t));try{await (0,f.updateTask)(e,{...c,reported:!1,endedAt:"waiting"===c.status?null:new Date})}catch(t){p.logger.error(`task ${e}: could not record how it ended`,t);return}"waiting"!==c.status&&(0,d.closeJobShell)(e);let w=await (0,f.findTask)(e);if(w){if(a.length){let t=a.splice(0).join("\n\n");p.logger.debug(`task ${e}: interjection after the run ended — resuming`),T(e,t).catch(t=>{p.logger.error(`task ${e}: late interjection`,t)});return}if(await O(w.label,c),"done"===c.status){var y;let t,o=(y=c.outcome,(t=(0,u.pathsIn)(y)).find(e=>e.startsWith(`${s.PATHS.artifacts}/`))??t[0]??null);o&&n.appEvents.emit({type:"artifact",taskId:e,label:w.label,path:o})}}}function S(e){return`The run broke: ${e}
|
|
124
|
+
|
|
125
|
+
Everything it had done is still here — answer to pick it back up.`}async function O(e,t){if(0!==n.appEventStream.watchers&&await (0,h.isAnyCallLive)())return;let o="waiting"===t.status?`${e} — needs you`:e;(0,c.desktopNotify)(o,t.outcome)}e.s(["answerTask",0,T,"cancelTask",0,$,"startTask",0,k]),o()}catch(e){o(e)}},!1),167004,e=>{"use strict";var t=e.i(874533),o=e.i(687388);let a=`on run argv
|
|
126
|
+
display notification (item 2 of argv) with title (item 1 of argv)
|
|
127
|
+
end run`,n=`
|
|
128
|
+
$ErrorActionPreference = 'Stop'
|
|
129
|
+
[void][Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime]
|
|
130
|
+
$xml = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
|
|
131
|
+
$text = $xml.GetElementsByTagName('text')
|
|
132
|
+
[void]$text.Item(0).AppendChild($xml.CreateTextNode($env:NOTIFY_TITLE))
|
|
133
|
+
[void]$text.Item(1).AppendChild($xml.CreateTextNode($env:NOTIFY_BODY))
|
|
134
|
+
$id = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\WindowsPowerShell\\v1.0\\powershell.exe'
|
|
135
|
+
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($id).Show([Windows.UI.Notifications.ToastNotification]::new($xml))
|
|
136
|
+
`,s={darwin:(e,t)=>["osascript",["-e",a,"--",e,t]],win32:()=>["powershell.exe",["-NoProfile","-NonInteractive","-Command",n]],linux:(e,t)=>["notify-send",["--app-name",o.APP_NAME,"--",e,t]]};e.s(["desktopNotify",0,function(e,o){let a=e.slice(0,80),n=o.slice(0,200),r=s[process.platform]?.(a,n);if(!r)return;let[i,l]=r;(0,t.execFile)(i,l,{env:{...process.env,NOTIFY_TITLE:a,NOTIFY_BODY:n},timeout:1e4,windowsHide:!0},()=>{})}])}];
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=_19wg5yn._.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports=[528790,e=>e.a(async(t,i)=>{try{let d,h;var s,r=e.i(902157),n=e.i(750227),l=e.i(418520),a=e.i(219756),o=e.i(687388),u=e.i(41444),c=t([l,a]);[l,a]=c.then?(await c)():c;let f=o.DB_FILE_NAME.replace(/^file:/,"");(0,r.mkdirSync)((0,n.dirname)(f),{recursive:!0});let m=globalThis.__dbClient??=(s=((d=(0,l.createClient)({url:o.DB_FILE_NAME,timeout:5e3})).execute("PRAGMA journal_mode = WAL"),d),h=(0,u.PromiseChain)(),{...s,execute:(...e)=>h(()=>s.execute(...e)),batch:(...e)=>h(()=>s.batch(...e)),executeMultiple:(...e)=>h(()=>s.executeMultiple(...e)),migrate:(...e)=>h(()=>s.migrate(...e)),async transaction(...e){let t,i=await new Promise(e=>{let t,i=new Promise(e=>{t=e});h(async()=>{e(t),await i})});try{t=await s.transaction(...e)}catch(e){throw i(),e}let r=!1,n=()=>{r||(r=!0,i())};return{execute:(...e)=>t.execute(...e),batch:(...e)=>t.batch(...e),executeMultiple:(...e)=>t.executeMultiple(...e),get closed(){return t.closed},commit:()=>t.commit().finally(n),rollback:()=>t.rollback().finally(n),close:()=>{try{t.close()}finally{n()}}}}}),p=(0,a.drizzle)({client:m});e.s(["database",0,p]),i()}catch(e){i(e)}},!1),613240,e=>{"use strict";var t=e.i(646683),i=e.i(201440),s=e.i(616918),r=e.i(937540),n=e.i(380568),l=e.i(75799);let a=(0,l.sqliteTable)("bot",{name:(0,n.text)("name").primaryKey(),description:(0,n.text)("description").notNull(),systemPrompt:(0,n.text)("system_prompt"),icon:(0,n.text)("icon",{mode:"json"}).$type(),provider:(0,n.text)("provider").$type(),model:(0,n.text)("model"),createdAt:(0,r.int)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),o=(0,l.sqliteTable)("bot_note",{bot:(0,n.text)("bot").primaryKey(),text:(0,n.text)("text").notNull(),updatedAt:(0,r.int)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),u=(0,l.sqliteTable)("mcp_server",{name:(0,n.text)("name").primaryKey(),config:(0,n.text)("config",{mode:"json"}).notNull().$type(),toolsSyncedAt:(0,r.int)("tools_synced_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),lastError:(0,n.text)("last_error"),oauth:(0,n.text)("oauth",{mode:"json"}).$type(),createdAt:(0,r.int)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),c=(0,l.sqliteTable)("mcp_tool",{id:(0,r.int)("id").primaryKey({autoIncrement:!0}),serverName:(0,n.text)("server_name").notNull().references(()=>u.name,{onDelete:"cascade"}),name:(0,n.text)("name").notNull(),description:(0,n.text)("description"),inputSchema:(0,n.text)("input_schema",{mode:"json"}).$type(),outputSchema:(0,n.text)("output_schema",{mode:"json"}).$type()},e=>[(0,s.unique)("uq_mcp_tool_server_name").on(e.serverName,e.name)]),d=(0,l.sqliteTable)("bot_mcp_tool",{botName:(0,n.text)().notNull().references(()=>a.name,{onDelete:"cascade"}),toolId:(0,r.int)("tool_id").notNull().references(()=>c.id,{onDelete:"cascade"})},e=>[(0,i.primaryKey)({columns:[e.botName,e.toolId]})]),h=(0,l.sqliteTable)("task",{id:(0,n.text)("id").primaryKey(),bot:(0,n.text)("bot").notNull(),label:(0,n.text)("label").notNull(),request:(0,n.text)("request").notNull(),status:(0,n.text)("status").notNull().$type(),outcome:(0,n.text)("outcome"),pending:(0,n.text)("pending",{mode:"json"}).$type(),reported:(0,r.int)("reported",{mode:"boolean"}).notNull().default(!1),callId:(0,n.text)("call_id"),inputTokens:(0,r.int)("input_tokens").notNull().default(0),outputTokens:(0,r.int)("output_tokens").notNull().default(0),contextTokens:(0,r.int)("context_tokens").notNull().default(0),contextBudget:(0,r.int)("context_budget").notNull().default(0),createdAt:(0,r.int)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,r.int)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),endedAt:(0,r.int)("ended_at",{mode:"timestamp"})}),f=(0,l.sqliteTable)("task_message",{id:(0,r.int)("id").primaryKey({autoIncrement:!0}),taskId:(0,n.text)("task_id").notNull().references(()=>h.id,{onDelete:"cascade"}),seq:(0,r.int)("seq").notNull(),bot:(0,n.text)("bot"),parent:(0,n.text)("parent"),role:(0,n.text)("role").notNull().$type(),content:(0,n.text)("content",{mode:"json"}).notNull().$type(),compact:(0,r.int)("compact",{mode:"boolean"}).notNull().default(!1),note:(0,r.int)("note",{mode:"boolean"}).notNull().default(!1),createdAt:(0,r.int)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>[(0,s.unique)("uq_task_message_seq").on(e.taskId,e.seq)]),m=(0,l.sqliteTable)("call",{id:(0,n.text)("id").primaryKey(),provider:(0,n.text)("provider").notNull(),model:(0,n.text)("model").notNull(),startedAt:(0,r.int)("started_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),endedAt:(0,r.int)("ended_at",{mode:"timestamp"}),tidiedAt:(0,r.int)("tidied_at",{mode:"timestamp"})}),p=(0,l.sqliteTable)("call_message",{callId:(0,n.text)("call_id").notNull().references(()=>m.id,{onDelete:"cascade"}),id:(0,n.text)("id").notNull(),seq:(0,r.int)("seq").notNull(),role:(0,n.text)("role").notNull().$type(),tool:(0,n.text)("tool"),text:(0,n.text)("text").notNull(),at:(0,r.int)("at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>[(0,i.primaryKey)({columns:[e.callId,e.id]}),(0,t.index)("idx_call_message_call").on(e.callId,e.seq)]),y=(0,l.sqliteTable)("memory_note",{id:(0,r.int)("id").primaryKey({autoIncrement:!0}),path:(0,n.text)("path").notNull().unique(),description:(0,n.text)("description").notNull(),aliases:(0,n.text)("aliases",{mode:"json"}).$type().default([]),ownedByUser:(0,r.int)("owned_by_user",{mode:"boolean"}).notNull().default(!1),hits:(0,r.int)("hits").notNull().default(0),lastReadAt:(0,r.int)("last_read_at",{mode:"timestamp"}),createdAt:(0,r.int)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),updatedAt:(0,r.int)("updated_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)}),g=(0,l.sqliteTable)("memory_fact",{id:(0,r.int)("id").primaryKey({autoIncrement:!0}),noteId:(0,r.int)("note_id").notNull().references(()=>y.id,{onDelete:"cascade"}),text:(0,n.text)("text").notNull(),isLatest:(0,r.int)("is_latest",{mode:"boolean"}).notNull().default(!0),alwaysLoad:(0,r.int)("always_load",{mode:"boolean"}).notNull().default(!1),source:(0,n.text)("source").$type(),createdAt:(0,r.int)("created_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date)},e=>[(0,t.index)("idx_memory_fact_note").on(e.noteId,e.isLatest),(0,t.index)("idx_memory_fact_always").on(e.alwaysLoad,e.isLatest)]),b=(0,l.sqliteTable)("memory_tidy_run",{id:(0,n.text)("id").primaryKey(),status:(0,n.text)("status").notNull().$type(),provider:(0,n.text)("provider").notNull(),model:(0,n.text)("model").notNull(),callIds:(0,n.text)("call_ids",{mode:"json"}).notNull().$type(),messages:(0,r.int)("messages").notNull().default(0),changes:(0,n.text)("changes",{mode:"json"}).notNull().$type().default([]),error:(0,n.text)("error"),inputTokens:(0,r.int)("input_tokens").notNull().default(0),outputTokens:(0,r.int)("output_tokens").notNull().default(0),startedAt:(0,r.int)("started_at",{mode:"timestamp"}).notNull().$defaultFn(()=>new Date),endedAt:(0,r.int)("ended_at",{mode:"timestamp"})}),q=(0,l.sqliteTable)("config",{key:(0,n.text)("key").primaryKey(),value:(0,n.text)("value").notNull()});e.s(["botMcpToolTable",0,d,"botNoteTable",0,o,"botTable",0,a,"callMessageTable",0,p,"callTable",0,m,"configTable",0,q,"mcpServerTable",0,u,"mcpToolTable",0,c,"memoryFactTable",0,g,"memoryNoteTable",0,y,"memoryTidyRunTable",0,b,"taskMessageTable",0,f,"taskTable",0,h])},41444,e=>{"use strict";e.s(["PromiseChain",0,()=>{let e=Promise.resolve();return t=>{let i=e.then(()=>t());return e=i.catch(()=>{}),i}},"clip",0,function(e,t){let i=e.replace(/\s+/g," ").trim();return i.length>t?`${i.slice(0,t-1).trimEnd()}…`:i},"errorToString",0,function(e){return e instanceof Error?e.message:String(e)}])},999884,e=>{"use strict";var t=e.i(844988),i=e.i(518899),s=class{static [t.entityKind]="ConsoleLogWriter";write(e){console.log(e)}},r=class{static [t.entityKind]="DefaultLogger";writer;constructor(e){this.writer=e?.writer??new s}logQuery(e,t){let i=t.map(e=>{try{return JSON.stringify(e)}catch{return String(e)}}),s=i.length?` -- params: [${i.join(", ")}]`:"";this.writer.write(`Query: ${e}${s}`)}},n=class{static [t.entityKind]="NoopLogger";logQuery(){}},l=e.i(704313),a=class{static [t.entityKind]="QueryPromise";[Symbol.toStringTag]="QueryPromise";catch(e){return this.then(void 0,e)}finally(e){return this.then(t=>(e?.(),t),t=>{throw e?.(),t})}then(e,t){return this.execute().then(e,t)}},o=i,u=class e extends o.SQL{static [t.entityKind]="SQLiteCountBuilder";dialect;session;static buildCount(e,t,i){let s=o.sql`select count(*) from ${e}${o.sql` where ${t}`.if(t)}`;return i?o.sql`(${s})`:s}constructor(t){super(e.buildCount(t.source,t.filters,!0).queryChunks),this.countConfig=t,this.dialect=t.dialect,this.session=t.session,this.mapWith(e=>"number"==typeof e?e:Number(e??0))}executableSql;build(){if(!this.executableSql){let{source:t,filters:i}=this.countConfig;this.executableSql=e.buildCount(t,i)}return this.dialect.sqlToQuery(this.executableSql)}},c=class extends u{static [t.entityKind]="SQLiteAsyncCountBuilder";constructor(e){super(e)}executeRaw(e){return this.session.prepareQuery(this.build(),"arrays",!1,"all",e=>{let t=e[0]?.[0];return"number"==typeof t?t:t?Number(t):0}).execute(e)}async execute(e){return await this.executeRaw(e)}};(0,l.applyMixins)(c,[a]);var d=class extends c{static [t.entityKind]="SQLiteSyncCountBuilder";sync(e){return this.executeRaw(e).sync()}},h=class{static [t.entityKind]="SQLiteRelationalQueryBuilderV2";constructor(e,t,i,s,r,n,l,a=f){this.mode=e,this.schema=t,this.table=i,this.tableConfig=s,this.dialect=r,this.session=n,this.forbidJsonb=l,this.builder=a}findMany(e){return new this.builder(this.mode,this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,"many",this.forbidJsonb)}findFirst(e){return new this.builder(this.mode,this.schema,this.table,this.tableConfig,this.dialect,this.session,e??!0,"first",this.forbidJsonb)}},f=class{static [t.entityKind]="SQLiteRelationalQueryV2";mode;table;resultKind;constructor(e,t,i,s,r,n,l,a,o){this.schema=t,this.tableConfig=s,this.dialect=r,this.session=n,this.config=l,this.forbidJsonb=o,this.resultKind=e,this.mode=a,this.table=i}getSQL(){return this._getQuery().sql}_getQuery(){let e=this.forbidJsonb?i.sql`json`:i.sql`jsonb`;return this.dialect.buildRelationalQuery({schema:this.schema,table:this.table,tableConfig:this.tableConfig,queryConfig:this.config,mode:this.mode,jsonb:e})}_toSQL(){let e=this._getQuery();return{query:e,builtQuery:this.dialect.sqlToQuery(e.sql)}}toSQL(){return this._toSQL().builtQuery}},m=class extends f{static [t.entityKind]="SQLiteAsyncRelationalQueryV2";_prepare(e=!1){let{query:t,builtQuery:i}=this._toSQL(),s=this.dialect.mapperGenerators.relationalRows({isFirst:"first"===this.mode,parseJson:!0,parseJsonIfString:!1,rootJsonMappers:!1,selection:t.selection,arrayModeRoot:!0});return this.session.prepareQuery(i,"arrays",e,"all",s)}prepare(){return this._prepare(!0)}async execute(e){return this._prepare().execute(e)}},p=class extends m{static [t.entityKind]="SQLiteSyncRelationalQueryV2";sync(e){return this._prepare().execute(e).sync()}};(0,l.applyMixins)(m,[a]);var y=e.i(792352),g=e.i(156325),b=e.i(88274),q=e.i(923277),S=e.i(369e3),w=class{static [t.entityKind]="ColumnTableAliasProxyHandler";constructor(e,t){this.table=e,this.ignoreColumnAlias=t}get(e,t){return"table"===t?this.table:("isAlias"!==t||!this.ignoreColumnAlias)&&e[t]}},$=class{static [t.entityKind]="ViewSelectionAliasProxyHandler";constructor(e,t,i){this.view=e,this.selection=t,this.ignoreColumnAlias=i}get(e,s){let r=e[s];return(0,t.is)(r,g.Column)?new Proxy(r,new w(this.view,this.ignoreColumnAlias)):(0,t.is)(r,y.Subquery)||(0,t.is)(r,i.SQL)||(0,t.is)(r,i.SQL.Aliased)||(0,i.isSQLWrapper)(r)||"object"!=typeof r||null===r?r:new Proxy(r,this)}},v=class{static [t.entityKind]="TableAliasProxyHandler";constructor(e,t,i){this.alias=e,this.replaceOriginalName=t,this.ignoreColumnAlias=i}get(e,s){if(s===S.Table.Symbol.IsAlias)return!0;if(s===S.Table.Symbol.Name||this.replaceOriginalName&&s===S.Table.Symbol.OriginalName)return this.alias;if(s===b.ViewBaseConfig)return{...e[b.ViewBaseConfig],name:this.alias,isAlias:!0,selectedFields:new Proxy(e[b.ViewBaseConfig].selectedFields,new $(new Proxy(e,this),e[b.ViewBaseConfig].selectedFields,this.ignoreColumnAlias))};if(s===S.Table.Symbol.Columns){let s=e[S.Table.Symbol.Columns];if(!s)return s;if((0,t.is)(e,i.View))return new Proxy(e[S.Table.Symbol.Columns],new $(new Proxy(e,this),e[S.Table.Symbol.Columns],this.ignoreColumnAlias));let r={};return Object.keys(s).map(t=>{r[t]=new Proxy(s[t],new w(new Proxy(e,this),this.ignoreColumnAlias))}),r}let r=e[s];return(0,t.is)(r,g.Column)?new Proxy(r,new w(new Proxy(e,this),this.ignoreColumnAlias)):r}},Q=class{static [t.entityKind]="ColumnAliasProxyHandler";constructor(e){this.alias=e}get(e,t){return"isAlias"===t||("name"===t?this.alias:"keyAsName"!==t&&(t===q.OriginalColumn?()=>e:e[t]))}};function x(e,t){return new Proxy(e,new v(t,!1,!1))}function N(e){return e[q.OriginalColumn]()}t.entityKind,g.Column.prototype.as=function(e){return new Proxy(this,new Q(e))};var L=class e{static [t.entityKind]="SelectionProxyHandler";config;constructor(e){this.config={...e}}get(s,r){if("_"===r)return{...s._,selectedFields:new Proxy(s._.selectedFields,this)};if(r===b.ViewBaseConfig)return{...s[b.ViewBaseConfig],selectedFields:new Proxy(s[b.ViewBaseConfig].selectedFields,this)};if("symbol"==typeof r)return s[r];let n=((0,t.is)(s,y.Subquery)?s._.selectedFields:(0,t.is)(s,i.View)?s[b.ViewBaseConfig].selectedFields:s)[r];if((0,t.is)(n,i.SQL.Aliased)){if("sql"===this.config.sqlAliasedBehavior&&!n.isSelectionField)return n.sql;let e=n.clone();return e.isSelectionField=!0,e.origin=this.config.alias,e}if((0,t.is)(n,i.SQL)){if("sql"===this.config.sqlBehavior)return n;throw Error(`You tried to reference "${r}" field from a subquery, which is a raw SQL field, but it doesn't have an alias declared. Please add an alias to the field using ".as('alias')" method.`)}return(0,t.is)(n,g.Column)?this.config.alias?new Proxy(n,new w(new Proxy(n.table,new v(this.config.alias,this.config.replaceOriginalName??!1,!0)),!0)):n:"object"!=typeof n||null===n?n:new Proxy(n,new e(this.config))}},T=e.i(75799);function C(e){return(0,t.is)(e,T.SQLiteTable)?[`${e[S.Table.Symbol.BaseName]}`]:(0,t.is)(e,y.Subquery)?e._.usedTables??[]:(0,t.is)(e,i.SQL)?e.usedTables??[]:[]}t.entityKind,t.entityKind,e.i(361328),e.i(646683),e.i(201440),e.i(616918);var _=class{static [t.entityKind]="SQLiteDelete";config;constructor(e,t,i,s){this.table=e,this.session=t,this.dialect=i,this.config={table:e,withList:s}}where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[S.Table.Symbol.Columns],new L({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.table[T.SQLiteTable.Symbol.Columns]){return this.config.returning=(0,l.orderSelectedFields)(e),this}getSQL(){return this.dialect.buildDeleteQuery(this.config)}toSQL(){return this.dialect.sqlToQuery(this.getSQL())}$dynamic(){return this}},A=class extends _{static [t.entityKind]="SQLiteAsyncDelete";_prepare(e=!1){return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),"arrays",e,this.config.returning?"all":"run",this.config.returning?this.dialect.mapperGenerators.rows(this.config.returning,void 0):void 0,{type:"delete",tables:C(this.config.table)})}prepare(){return this._prepare(!0)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(e){return this._prepare().execute(e)}};(0,l.applyMixins)(A,[a]);var j=i,B=class extends j.View{static [t.entityKind]="SQLiteViewBase"},F=class{static [t.entityKind]="TypedQueryBuilder";getSelectedFields(){return this._.selectedFields}withoutSelectionCastCodecs(){return this}},K=class{static [t.entityKind]="SQLiteSelectBuilder";fields;session;dialect;withList;distinct;constructor(e,t=D){this.builder=t,this.fields=e.fields,this.session=e.session,this.dialect=e.dialect,this.withList=e.withList,this.distinct=e.distinct}from(e){let s,r=!!this.fields;return s=this.fields?this.fields:(0,t.is)(e,y.Subquery)?Object.fromEntries(Object.keys(e._.selectedFields).map(t=>[t,e[t]])):(0,t.is)(e,B)?e[b.ViewBaseConfig].selectedFields:(0,t.is)(e,i.SQL)?{}:(0,l.getTableColumns)(e),new this.builder({table:e,fields:s,isPartialSelect:r,session:this.session,dialect:this.dialect,withList:this.withList??[],distinct:this.distinct})}},D=class extends F{static [t.entityKind]="SQLiteSelectQueryBuilder";_;config;joinsNotNullableMap;tableName;isPartialSelect;session;dialect;cacheConfig=void 0;usedTables=new Set;constructor({table:e,fields:t,isPartialSelect:i,session:s,dialect:r,withList:n,distinct:a}){for(const o of(super(),this.config={withList:n,table:e,fields:{...t},distinct:a,setOperators:[]},this.isPartialSelect=i,this.session=s,this.dialect=r,this._={selectedFields:t,config:this.config},this.tableName=(0,l.getTableLikeName)(e),this.joinsNotNullableMap="string"==typeof this.tableName?{[this.tableName]:!0}:{},C(e)))this.usedTables.add(o)}getUsedTables(){return[...this.usedTables]}createJoin(e){return(s,r)=>{let n=this.tableName,a=(0,l.getTableLikeName)(s);for(let e of C(s))this.usedTables.add(e);if("string"==typeof a&&this.config.joins?.some(e=>e.alias===a))throw Error(`Alias "${a}" is already used in this query`);if(!this.isPartialSelect&&(1===Object.keys(this.joinsNotNullableMap).length&&"string"==typeof n&&(this.config.fields={[n]:this.config.fields}),"string"==typeof a&&!(0,t.is)(s,i.SQL))){let e=(0,t.is)(s,y.Subquery)?s._.selectedFields:(0,t.is)(s,i.View)?s[b.ViewBaseConfig].selectedFields:s[S.Table.Symbol.Columns];this.config.fields[a]=e}if("function"==typeof r&&(r=r(new Proxy(this.config.fields,new L({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.joins||(this.config.joins=[]),this.config.joins.push({on:r,table:s,joinType:e,alias:a}),"string"==typeof a)switch(e){case"left":this.joinsNotNullableMap[a]=!1;break;case"right":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[a]=!0;break;case"cross":case"inner":this.joinsNotNullableMap[a]=!0;break;case"full":this.joinsNotNullableMap=Object.fromEntries(Object.entries(this.joinsNotNullableMap).map(([e])=>[e,!1])),this.joinsNotNullableMap[a]=!1}return this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");crossJoin=this.createJoin("cross");createSetOperator(e,t){return i=>{let s="function"==typeof i?i(O()):i;if(!(0,l.haveSameKeys)(this.getSelectedFields(),s.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return this.config.setOperators.push({type:e,isAll:t,rightSelect:s}),this}}union=this.createSetOperator("union",!1);unionAll=this.createSetOperator("union",!0);intersect=this.createSetOperator("intersect",!1);except=this.createSetOperator("except",!1);addSetOperators(e){return this.config.setOperators.push(...e),this}where(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new L({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.where=e,this}having(e){return"function"==typeof e&&(e=e(new Proxy(this.config.fields,new L({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))),this.config.having=e,this}groupBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new L({sqlAliasedBehavior:"alias",sqlBehavior:"sql"})));this.config.groupBy=Array.isArray(t)?t:[t]}else this.config.groupBy=e;return this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.fields,new L({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=i:this.config.orderBy=i}else this.config.setOperators.length>0?this.config.setOperators.at(-1).orderBy=e:this.config.orderBy=e;return this}limit(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).limit=e:this.config.limit=e,this}offset(e){return this.config.setOperators.length>0?this.config.setOperators.at(-1).offset=e:this.config.offset=e,this}$withCache(e){return this.cacheConfig=void 0===e?{config:{},enabled:!0,autoInvalidate:!0}:!1===e?{enabled:!1}:{enabled:!0,autoInvalidate:!0,...e},this}getSQL(){return this.config.fieldsFlat=(0,l.orderSelectedFields)(this.config.fields),this.dialect.buildSelectQuery(this.config)}toSQL(){return this.dialect.sqlToQuery(this.getSQL())}as(e){let t=[];if(t.push(...C(this.config.table)),this.config.joins)for(let e of this.config.joins)t.push(...C(e.table));return new Proxy(new y.Subquery(this.getSQL(),this.config.fields,e,!1,[...new Set(t)]),new L({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}getSelectedFields(){return new Proxy(this.config.fields,new L({alias:this.tableName,sqlAliasedBehavior:"alias",sqlBehavior:"error"}))}withoutSelectionCastCodecs(){return this}$dynamic(){return this}};function k(e,t){return(i,s,...r)=>{let n=[s,...r].map(i=>({type:e,isAll:t,rightSelect:i}));for(let e of n)if(!(0,l.haveSameKeys)(i.getSelectedFields(),e.rightSelect.getSelectedFields()))throw Error("Set operator error (union / intersect / except): selected fields are not the same or are in a different order");return i.addSetOperators(n)}}let O=()=>({union:P,unionAll:V,intersect:I,except:J}),P=k("union",!1),V=k("union",!0),I=k("intersect",!1),J=k("except",!1);var E=class extends Error{static [t.entityKind]="DrizzleError";constructor({message:e,cause:t}){super(e),this.name="DrizzleError",this.cause=t}},z=class e extends Error{static [t.entityKind]="DrizzleQueryError";constructor(t,i,s){super(`Failed query: ${t}
|
|
2
|
+
params: ${i}`),this.query=t,this.params=i,this.cause=s,this.name="DrizzleQueryError",Error.captureStackTrace(this,e),s&&(this.cause=s)}},U=class extends E{static [t.entityKind]="TransactionRollbackError";constructor(){super({message:"Rollback"}),this.name="TransactionRollbackError"}},M=e.i(875225),R=e.i(349129),W=class{static [t.entityKind]="RelationV2";fieldName;sourceColumns;targetColumns;alias;where;sourceTable;targetTable;through;throughTable;isReversed;sourceColumnTableNames=[];targetColumnTableNames=[];constructor(e,t){this.targetTableName=t,this.targetTable=e}},G=class extends W{static [t.entityKind]="OneV2";relationType="one";optional;constructor(e,t,i,s){super(t,i),this.alias=s?.alias,this.where=s?.where,s?.from&&(this.sourceColumns=(Array.isArray(s.from)?s.from:[s.from]).map(t=>(this.throughTable??=t._.through?e[t._.through._.tableName]:void 0,this.sourceColumnTableNames.push(t._.tableName),t._.column))),s?.to&&(this.targetColumns=(Array.isArray(s.to)?s.to:[s.to]).map(t=>(this.throughTable??=t._.through?e[t._.through._.tableName]:void 0,this.targetColumnTableNames.push(t._.tableName),t._.column))),this.throughTable&&(this.through={source:(Array.isArray(s?.from)?s.from:s?.from?[s.from]:[]).map(e=>e._.through),target:(Array.isArray(s?.to)?s.to:s?.to?[s.to]:[]).map(e=>e._.through)}),this.optional=s?.optional??!0}},H=(t.entityKind,class{static [t.entityKind]="AggregatedField";table;onTable(e){return this.table=e,this}});t.entityKind;let Z={and:M.and,between:M.between,eq:M.eq,exists:M.exists,gt:M.gt,gte:M.gte,ilike:M.ilike,inArray:M.inArray,arrayContains:M.arrayContains,arrayContained:M.arrayContained,arrayOverlaps:M.arrayOverlaps,isNull:M.isNull,isNotNull:M.isNotNull,like:M.like,lt:M.lt,lte:M.lte,ne:M.ne,not:M.not,notBetween:M.notBetween,notExists:M.notExists,notLike:M.notLike,notIlike:M.notIlike,notInArray:M.notInArray,or:M.or,sql:i.sql},Y={sql:i.sql,asc:R.asc,desc:R.desc};function X(e,s,r,n=!1,l=!1,a=!0){let o=s?1:e.length,u=r.map(({field:e,codec:s,arrayDimensions:r})=>{let n;return(n=(0,t.is)(e,g.Column)?e:(0,t.is)(e,i.SQL)?e.decoder:(0,t.is)(e,i.SQL.Aliased)?e.sql.decoder:(0,t.is)(e,S.Table)||(0,t.is)(e,i.View)?i.noopDecoder:e.getSQL().decoder,a&&e.mapFromJsonValue)?t=>e.mapFromJsonValue(t):n.mapFromDriverValue.isNoop?s?e=>s(e,r):void 0:s?e=>n.mapFromDriverValue(s(e,r)):e=>n.mapFromDriverValue(e)});for(let t=0;t<o;++t){let i=s?e:e[t];for(let e=0;e<r.length;++e){let t=r[e];if(t.selection){if(null===i[t.key])continue;if(n){if(i[t.key]=JSON.parse(i[t.key]),null===i[t.key])continue}else l&&"string"==typeof i[t.key]&&(i[t.key]=JSON.parse(i[t.key]));if(t.isArray){X(i[t.key],!1,t.selection,!1,l);continue}X(i[t.key],!0,t.selection,!1,l);continue}if(null===i[t.key])continue;let s=u[e];s&&(i[t.key]=s(i[t.key]))}}return e}function ee({selection:e,isFirst:s,parseJson:r,parseJsonIfString:n,rootJsonMappers:l,arrayModeRoot:a}){return o=>s&&!o[0]?o[0]:a?function(e,s,r,n=!1,l=!1){let a=s?1:e.length,o=r.map(({field:e,codec:s,arrayDimensions:r})=>{let n;return(n=(0,t.is)(e,g.Column)?e:(0,t.is)(e,i.SQL)?e.decoder:(0,t.is)(e,i.SQL.Aliased)?e.sql.decoder:(0,t.is)(e,S.Table)||(0,t.is)(e,i.View)?i.noopDecoder:e.getSQL().decoder).mapFromDriverValue.isNoop?s?e=>s(e,r):void 0:s?e=>n.mapFromDriverValue(s(e,r)):e=>n.mapFromDriverValue(e)}),u=Array.from({length:a});for(let t=0;t<a;++t){let i=s?e:e[t],a={};for(let e=0;e<r.length;++e){let t=r[e],s=i[e];if(t.selection){if(null===s){a[t.key]=null;continue}if(n){if(null===(s=JSON.parse(s))){a[t.key]=null;continue}}else l&&"string"==typeof s&&(s=JSON.parse(s));t.isArray?X(s,!1,t.selection,!1,l):X(s,!0,t.selection,!1,l),a[t.key]=s;continue}if(null===s){a[t.key]=null;continue}let u=o[e];a[t.key]=u?u(s):s}u[t]=a}return s?u[0]:u}(s?o[0]:o,s,e,r,n):X(s?o[0]:o,s,e,r,n,l)}function et({selection:e,isFirst:s,parseJson:r,parseJsonIfString:n,rootJsonMappers:a,arrayModeRoot:o}){let u=[],c=function e(s,r,n,l,a,o,u,c,d){let h=[],f=[],m=!1,p=s.map(()=>`c${c.n++}`),y=s.map((e,t)=>d?p[t]:`${JSON.stringify(e.key)}: ${p[t]}`);for(let[b,{field:q,key:w,codec:$,isArray:v,selection:Q,arrayDimensions:x}]of(h.push(d?`let [ ${y.join(", ")} ] = ${r};`:`let { ${y.join(", ")} } = ${r};`),s.entries())){let s=`${n}[${b}]`,r=JSON.stringify(w),d=p[b];if(Q){l?(h.push(`if (${d} !== null) ${d} = JSON.parse(${d});`),m=!0):a&&(h.push(`if (typeof ${d} === 'string') ${d} = JSON.parse(${d});`),m=!0);let t=`s${c.n++}`,i=u.length;if(u.push(`const { selection: ${t} } = ${s};`),v){let s=`j${c.n++}`,r=e(Q,`${d}[${s}]`,t,!1,a,!0,u,c,!1);if(r.hasWork){for(let e of(m=!0,h.push(`if (${d} !== null) {`),h.push(` for (let ${s} = 0; ${s} < ${d}.length; ++${s}) {`),r.bodyStmts))h.push(` ${e}`);h.push(` ${d}[${s}] = ${r.literal};`),h.push(" }"),h.push("}")}else u.splice(i,1)}else{let s=e(Q,d,t,!1,a,!0,u,c,!1);if(s.hasWork){for(let e of(m=!0,h.push(`if (${d} !== null) {`),s.bodyStmts))h.push(` ${e}`);h.push(` ${d} = ${s.literal};`),h.push("}")}else u.splice(i,1)}f.push(`${r}: ${d}`);continue}let y="",N="",L=!1;if((0,t.is)(q,g.Column)){if(o&&q.mapFromJsonValue){L=!0;let e=c.n++;N=`field: dec${e}`,y=`dec${e}.mapFromJsonValue`}else if(!q.mapFromDriverValue.isNoop){let e=c.n++;N=`field: dec${e}`,y=`dec${e}.mapFromDriverValue`}}else if((0,t.is)(q,i.SQL)){if(o&&q.decoder.mapFromJsonValue){L=!0;let e=c.n++;N=`field: { decoder: dec${e} }`,y=`dec${e}.mapFromJsonValue`}else if(!q.decoder.mapFromDriverValue.isNoop){let e=c.n++;N=`field: { decoder: dec${e} }`,y=`dec${e}.mapFromDriverValue`}}else if((0,t.is)(q,i.SQL.Aliased)){if(o&&q.sql.decoder.mapFromJsonValue){L=!0;let e=c.n++;N=`field: { sql: { decoder: dec${e} } }`,y=`dec${e}.mapFromJsonValue`}else if(!q.sql.decoder.mapFromDriverValue.isNoop){let e=c.n++;N=`field: { sql: { decoder: dec${e} } }`,y=`dec${e}.mapFromDriverValue`}}else if((0,t.is)(q,S.Table)||(0,t.is)(q,i.View));else{let e=q.getSQL();if(o&&e.decoder.mapFromJsonValue){L=!0;let e=c.n++;u.push(`const dec${e} = ${s}.field.getSQL().decoder;`),y=`dec${e}.mapFromJsonValue`}else if(!e.decoder.mapFromDriverValue.isNoop){let e=c.n++;u.push(`const dec${e} = ${s}.field.getSQL().decoder;`),y=`dec${e}.mapFromDriverValue`}}let T="";if(!L&&$&&(T=`codec${c.n++}`),N||T){let e=[];N&&e.push(N),T&&e.push(`codec: ${T}`),u.push(`const { ${e.join(", ")} } = ${s};`)}if(y||T){m=!0;let e=d;T&&(e=`${T}(${e}, ${x})`),y&&(e=`${y}(${e})`),f.push(`${r}: ${d} === null ? null : ${e}`)}else f.push(`${r}: ${d}`)}return{bodyStmts:h,literal:`{ ${f.join(", ")} }`,hasWork:m}}(e,"row","selection",r,n,!o&&a,u,{n:0},!!o),d=[];for(let e of(d.push(` "use strict";
|
|
3
|
+
const { selection } = this;`),u))d.push(` ${e}`);if(o)if(s){for(let e of(d.push(" const row = rows[0];"),d.push(" if (!row) return undefined;"),c.bodyStmts))d.push(` ${e}`);d.push(` return ${c.literal};`)}else{for(let e of(d.push(" const { length } = rows;"),d.push(" const mapped = Array.from({ length });"),d.push(" for (let i = 0; i < length; ++i) {"),d.push(" const row = rows[i];"),c.bodyStmts))d.push(` ${e}`);d.push(` mapped[i] = ${c.literal};`),d.push(" }"),d.push(" return mapped;")}else if(c.hasWork)if(s){for(let e of(d.push(" const row = rows[0];"),d.push(" if (!row) return undefined;"),c.bodyStmts))d.push(` ${e}`);d.push(` rows[0] = ${c.literal};`),d.push(" return rows[0];")}else{for(let e of(d.push(" for (let i = 0; i < rows.length; ++i) {"),d.push(" const row = rows[i];"),c.bodyStmts))d.push(` ${e}`);d.push(` rows[i] = ${c.literal};`),d.push(" }"),d.push(" return rows;")}else d.push(s?" return rows[0];":" return rows;");d.push(" //# sourceURL=drizzle:jit-relational-query-mapper");let h=d.join("\n");return Object.assign(new l.FnConstructor("rows",h).bind({selection:e}),{body:`function jitRqbMapper (rows) {
|
|
4
|
+
${h}
|
|
5
|
+
}`})}function ei(e,s){let r=e[S.TableColumns][s];return r?(0,t.is)(r,g.Column)?r:(0,t.is)(r,i.SQL.Aliased)?i.sql`${e}.${i.sql.identifier(r.fieldAlias)}`:i.sql`${e}.${i.sql.identifier(s)}`:i.sql`${e}.${i.sql.identifier(s)}`}function es(e,s,r={},n={},l=0){let a=Object.entries(s);if(!a.length)return;let o=[];for(let[s,u]of a)if(void 0!==u)switch(s){case"RAW":{let t="function"==typeof u?u(e,Z):u.getSQL();o.push(t);continue}case"OR":if(!u?.length)continue;o.push((0,M.or)(...u.map(t=>es(e,t,r,n,l))));continue;case"AND":if(!u?.length)continue;o.push((0,M.and)(...u.map(t=>es(e,t,r,n,l))));continue;case"NOT":{if(void 0===u)continue;let t=es(e,u,r,n,l);if(!t)continue;o.push((0,M.not)(t));continue}default:{if(e[S.TableColumns][s]){let r=function e(s,r){if("object"!=typeof r||(0,t.is)(r,i.Placeholder))return(0,M.eq)(s,r);let n=Object.entries(r);if(!n.length)return;let l=[];for(let[t,i]of n)if(void 0!==i)switch(t){case"NOT":{let t=e(s,i);if(!t)continue;l.push((0,M.not)(t));continue}case"OR":if(!i.length)continue;l.push((0,M.or)(...i.map(t=>e(s,t))));continue;case"AND":if(!i.length)continue;l.push((0,M.and)(...i.map(t=>e(s,t))));continue;case"isNotNull":case"isNull":if(!i)continue;l.push(Z[t](s));continue;case"in":l.push(Z.inArray(s,i));continue;case"notIn":l.push(Z.notInArray(s,i));continue;default:l.push(Z[t](s,i));continue}if(l.length)return(0,M.and)(...l)}(ei(e,s),u);r&&o.push(r);continue}let a=r[s];if(!a)throw new E({message:`Unknown relational filter field: "${s}"`});let c=x(a.targetTable,`f${l}`),d=a.throughTable?x(a.throughTable,`ft${l}`):void 0,h=n[a.targetTableName],{filter:f,joinCondition:m}=er(a,e,c,d),p=(0,M.and)(f,"boolean"==typeof u?void 0:es(c,u,h.relations,n,l+1)),y=d?i.sql`(select * from ${en(c)} inner join ${en(d)} on ${m}${i.sql` where ${p}`.if(p)} limit 1)`:i.sql`(select * from ${en(c)}${i.sql` where ${p}`.if(p)} limit 1)`;p&&o.push((u?M.exists:M.notExists)(y))}}return(0,M.and)(...o)}function er(e,s,r,n){if(e.through){let l=e.sourceColumns.map((r,l)=>{let a=e.through.source[l];return(0,M.eq)(i.sql`${s}.${i.sql.identifier(r.name)}`,i.sql`${n}.${i.sql.identifier((0,t.is)(a._.column,g.Column)?a._.column.name:a._.key)}`)}),a=e.targetColumns.map((s,l)=>{let a=e.through.target[l];return(0,M.eq)(i.sql`${n}.${i.sql.identifier((0,t.is)(a._.column,g.Column)?a._.column.name:a._.key)}`,i.sql`${r}.${i.sql.identifier(s.name)}`)});return{filter:(0,M.and)(e.where?es(e.isReversed?s:r,e.where):void 0,...l),joinCondition:(0,M.and)(...a)}}return{filter:(0,M.and)(...e.sourceColumns.map((t,n)=>{let l=e.targetColumns[n];return(0,M.eq)(i.sql`${s}.${i.sql.identifier(t.name)}`,i.sql`${r}.${i.sql.identifier(l.name)}`)}),e.where?es(e.isReversed?s:r,e.where):void 0)}}function en(e){return i.sql`${e[S.IsAlias]?i.sql`${i.sql`${i.sql.identifier(e[S.TableSchema]??"")}.`.if(e[S.TableSchema])}${i.sql.identifier(e[S.OriginalName])} as ${e}`:e}`}t.entityKind,t.entityKind,t.entityKind,t.entityKind;var el=e.i(100849),ea=class{static [t.entityKind]="SQLiteDialect";mapperGenerators;constructor(e){this.mapperGenerators=e?.useJitMappers?{rows:l.makeJitQueryMapper,relationalRows:et}:{rows:l.makeDefaultQueryMapper,relationalRows:ee}}escapeName(e){return`"${e.replace(/"/g,'""')}"`}escapeParam(e){return"?"}escapeString(e){return`'${e.replace(/'/g,"''")}'`}buildWithCTE(e){if(!e?.length)return;let t=[i.sql`with `];for(let[s,r]of e.entries())t.push(i.sql`${i.sql.identifier(r._.alias)} as (${r._.sql})`),s<e.length-1&&t.push(i.sql`, `);return t.push(i.sql` `),i.sql.join(t)}buildDeleteQuery({table:e,where:t,returning:s,withList:r,limit:n,orderBy:l}){let a=this.buildWithCTE(r),o=s?i.sql` returning ${this.buildSelection(s,{isSingleTable:!0})}`:void 0;return i.sql`${a}delete from ${e}${t?i.sql` where ${t}`:void 0}${o}${this.buildOrderBy(l)}${this.buildLimit(n)}`}buildUpdateSet(e,s){let r=e[S.Table.Symbol.Columns],n=Object.keys(r).filter(e=>void 0!==s[e]||r[e]?.onUpdateFn!==void 0),l=n.length;return i.sql.join(n.flatMap((e,n)=>{let a=r[e],o=a.onUpdateFn?.(),u=s[e]??((0,t.is)(o,i.SQL)?o:i.sql.param(o,a)),c=i.sql`${i.sql.identifier(a.name)} = ${u}`;return n<l-1?[c,i.sql.raw(", ")]:[c]}))}buildUpdateQuery({table:e,set:t,where:s,returning:r,withList:n,joins:l,from:a,limit:o,orderBy:u}){let c=this.buildWithCTE(n),d=this.buildUpdateSet(e,t),h=a&&i.sql.join([i.sql.raw(" from "),this.buildFromTable(a)]),f=this.buildJoins(l),m=r?i.sql` returning ${this.buildSelection(r,{isSingleTable:!0})}`:void 0;return i.sql`${c}update ${e} set ${d}${h}${f}${s?i.sql` where ${s}`:void 0}${m}${this.buildOrderBy(u)}${this.buildLimit(o)}`}buildSelection(e,{isSingleTable:s=!1}={}){let r=e.length,n=e.flatMap(({field:e},n)=>{let l=[];if((0,t.is)(e,i.SQL.Aliased))if(e.isSelectionField)s||void 0===e.origin||l.push(i.sql.identifier(e.origin),i.sql.raw(".")),l.push(i.sql.identifier(e.fieldAlias));else{let r=e.sql;if(s){let e=new i.SQL(r.queryChunks.map(e=>(0,t.is)(e,g.Column)?i.sql.identifier(e.name):e));l.push(r.shouldInlineParams?e.inlineParams():e)}else l.push(r);l.push(i.sql` as ${i.sql.identifier(e.fieldAlias)}`)}else if((0,t.is)(e,i.SQL))if(s){let s=new i.SQL(e.queryChunks.map(e=>(0,t.is)(e,g.Column)?i.sql.identifier(e.name):e));l.push(e.shouldInlineParams?s.inlineParams():s)}else l.push(e);else(0,t.is)(e,g.Column)?"SQLiteNumericBigInt"===e.columnType||"SQLiteNumeric"===e.columnType?s?l.push(e.isAlias?i.sql`cast(${i.sql.identifier(N(e).name)} as text) as ${e}`:i.sql`cast(${i.sql.identifier(e.name)} as text)`):l.push(e.isAlias?i.sql`cast(${N(e)} as text) as ${e}`:i.sql`cast(${e} as text)`):s?l.push(e.isAlias?i.sql`${i.sql.identifier(N(e).name)} as ${e}`:i.sql.identifier(e.name)):l.push(e.isAlias?i.sql`${N(e)} as ${e}`:e):(0,t.is)(e,y.Subquery)&&(e._.isWith?l.push(e):l.push(i.sql`(${e._.sql}) ${i.sql.identifier(e._.alias)}`));return n<r-1&&l.push(i.sql`, `),l});return i.sql.join(n)}buildJoins(e){if(!e||0===e.length)return;let s=[];if(e)for(let[r,n]of e.entries()){0===r&&s.push(i.sql` `);let l=n.table,a=n.on?i.sql` on ${n.on}`:void 0;if((0,t.is)(l,T.SQLiteTable)){let e=l[T.SQLiteTable.Symbol.Name],t=l[T.SQLiteTable.Symbol.Schema],r=l[T.SQLiteTable.Symbol.OriginalName],o=e===r?void 0:n.alias;s.push(i.sql`${i.sql.raw(n.joinType)} join ${t?i.sql`${i.sql.identifier(t)}.`:void 0}${i.sql.identifier(r)}${o&&i.sql` ${i.sql.identifier(o)}`}${a}`)}else s.push(i.sql`${i.sql.raw(n.joinType)} join ${l}${a}`);r<e.length-1&&s.push(i.sql` `)}return i.sql.join(s)}buildLimit(e){return"object"==typeof e||"number"==typeof e&&e>=0?i.sql` limit ${e}`:void 0}buildOrderBy(e){let t=[];if(e)for(let[s,r]of e.entries())t.push(r),s<e.length-1&&t.push(i.sql`, `);return t.length>0?i.sql` order by ${i.sql.join(t)}`:void 0}buildFromTable(e){if((0,t.is)(e,S.Table)&&e[S.Table.Symbol.IsAlias])return i.sql`${i.sql`${i.sql.identifier(e[S.Table.Symbol.Schema]??"")}.`.if(e[S.Table.Symbol.Schema])}${i.sql.identifier(e[S.Table.Symbol.OriginalName])} ${i.sql.identifier(e[S.Table.Symbol.Name])}`;if((0,t.is)(e,i.View)&&e[b.ViewBaseConfig].isAlias){let t=i.sql`${i.sql.identifier(e[b.ViewBaseConfig].originalName)}`;return e[b.ViewBaseConfig].schema&&(t=i.sql`${i.sql.identifier(e[b.ViewBaseConfig].schema)}.${t}`),i.sql`${t} ${i.sql.identifier(e[b.ViewBaseConfig].name)}`}return e}buildSelectQuery({withList:e,fields:s,fieldsFlat:r,where:n,having:a,table:o,joins:u,orderBy:c,groupBy:d,limit:h,offset:f,distinct:m,setOperators:p}){let q=r??(0,l.orderSelectedFields)(s);for(let e of q){let s;if((0,t.is)(e.field,g.Column)&&(0,S.getTableName)(e.field.table)!==((0,t.is)(o,y.Subquery)?o._.alias:(0,t.is)(o,B)?o[b.ViewBaseConfig].name:(0,t.is)(o,i.SQL)?void 0:(0,S.getTableName)(o))&&(s=e.field.table,!u?.some(({alias:e})=>e===(s[S.Table.Symbol.IsAlias]?(0,S.getTableName)(s):s[S.Table.Symbol.BaseName])))){let t=(0,S.getTableName)(e.field.table);throw Error(`Your "${e.path.join("->")}" field references a column "${t}"."${e.field.name}", but the table "${t}" is not part of the query! Did you forget to join it?`)}}let w=!u||0===u.length,$=this.buildWithCTE(e),v=m?i.sql` distinct`:void 0,Q=this.buildSelection(q,{isSingleTable:w}),x=this.buildFromTable(o),N=this.buildJoins(u),L=n?i.sql` where ${n}`:void 0,T=a?i.sql` having ${a}`:void 0,C=[];if(d)for(let[e,t]of d.entries())C.push(t),e<d.length-1&&C.push(i.sql`, `);let _=i.sql`${$}select${v} ${Q} from ${x}${N}${L}${C.length>0?i.sql` group by ${i.sql.join(C)}`:void 0}${T}${this.buildOrderBy(c)}${this.buildLimit(h)}${f?i.sql` offset ${f}`:void 0}`;return p.length>0?this.buildSetOperations(_,p):_}buildSetOperations(e,t){let[i,...s]=t;if(!i)throw Error("Cannot pass undefined values to any set operator");return 0===s.length?this.buildSetOperationQuery({leftSelect:e,setOperator:i}):this.buildSetOperations(this.buildSetOperationQuery({leftSelect:e,setOperator:i}),s)}buildSetOperationQuery({leftSelect:e,setOperator:{type:s,isAll:r,rightSelect:n,limit:l,orderBy:a,offset:o}}){let u,c=i.sql`${e.getSQL()} `,d=i.sql`${n.getSQL()}`;if(a&&a.length>0){let e=[];for(let s of a)if((0,t.is)(s,el.SQLiteColumn))e.push(i.sql.identifier(s.name));else if((0,t.is)(s,i.SQL)){for(let e=0;e<s.queryChunks.length;e++){let r=s.queryChunks[e];(0,t.is)(r,el.SQLiteColumn)&&(s.queryChunks[e]=i.sql.identifier(r.name))}e.push(i.sql`${s}`)}else e.push(i.sql`${s}`);u=i.sql` order by ${i.sql.join(e,i.sql`, `)}`}let h="object"==typeof l||"number"==typeof l&&l>=0?i.sql` limit ${l}`:void 0,f=i.sql.raw(`${s} ${r?"all ":""}`),m=o?i.sql` offset ${o}`:void 0;return i.sql`${c}${f}${d}${u}${h}${m}`}buildInsertQuery({table:e,values:s,onConflict:r,returning:n,withList:l,select:a}){let o=[],u=e[S.Table.Symbol.Columns],c=Object.entries(u),d=a&&!(0,t.is)(s,i.SQL)?Object.keys(s.getSelectedFields()).map(e=>[e,u[e]]):c.filter(([e,t])=>!t.shouldDisableInsert()),h=d.map(([,e])=>i.sql.identifier(e.name));if(a)(0,t.is)(s,i.SQL)?o.push(s):o.push(s.getSQL());else for(let[e,r]of(o.push(i.sql.raw("values ")),s.entries())){let n=[];for(let[e,s]of d){let l=r[e];if(void 0===l||(0,t.is)(l,i.Param)&&void 0===l.value){let e;if(null!==s.default&&void 0!==s.default)e=(0,t.is)(s.default,i.SQL)?s.default:i.sql.param(s.default,s);else if(void 0!==s.defaultFn){let r=s.defaultFn();e=(0,t.is)(r,i.SQL)?r:i.sql.param(r,s)}else if(s.default||void 0===s.onUpdateFn)e=i.sql`null`;else{let r=s.onUpdateFn();e=(0,t.is)(r,i.SQL)?r:i.sql.param(r,s)}n.push(e)}else n.push(l)}o.push(n),e<s.length-1&&o.push(i.sql`, `)}let f=this.buildWithCTE(l),m=i.sql.join(o),p=n?i.sql` returning ${this.buildSelection(n,{isSingleTable:!0})}`:void 0;return i.sql`${f}insert into ${e} ${h} ${m}${r?.length?i.sql.join(r):void 0}${p}`}sqlToQuery(e,t){return e.toQuery({escapeName:this.escapeName,escapeParam:this.escapeParam,escapeString:this.escapeString,invokeSource:t})}nestedSelectionerror(){throw new E({message:"Views with nested selections are not supported by the relational query builder"})}buildRqbColumn(e,s,r,n){if((0,t.is)(s,g.Column)){let t=i.sql`${e}.${i.sql.identifier(s.name)}`;switch(s.columnType){case"SQLiteBigInt":case"SQLiteBlobJson":case"SQLiteBlobBuffer":if(!n)return i.sql`${t} as ${i.sql.identifier(r)}`;return i.sql`hex(${t}) as ${i.sql.identifier(r)}`;case"SQLiteNumeric":case"SQLiteNumericNumber":case"SQLiteNumericBigInt":return i.sql`cast(${t} as text) as ${i.sql.identifier(r)}`;case"SQLiteCustomColumn":if(!n)return i.sql`${t} as ${i.sql.identifier(r)}`;return i.sql`${s.jsonSelectIdentifier(t,i.sql)} as ${i.sql.identifier(r)}`;default:return i.sql`${t} as ${i.sql.identifier(r)}`}}return i.sql`${e}.${(0,t.is)(s,i.SQL.Aliased)?i.sql.identifier(s.fieldAlias):(0,i.isSQLWrapper)(s)?i.sql.identifier(r):this.nestedSelectionerror()} as ${i.sql.identifier(r)}`}unwrapAllColumns=(e,t,s)=>i.sql.join(Object.entries(e[S.TableColumns]).map(([i,r])=>(t.push({key:i,field:r}),this.buildRqbColumn(e,r,i,s))),i.sql`, `);getSelectedTableColumns=(e,t)=>{let i,s=[],r=e[S.TableColumns];for(let[e,n]of Object.entries(t))if(void 0!==n&&(i=i||n,n)){let t=r[e];s.push({column:t,tsName:e})}if(!1===i)for(let[e,i]of Object.entries(r))!1!==t[e]&&s.push({column:i,tsName:e});return s};buildColumns=(e,t,s,r)=>r?.columns?(()=>{let n=[];for(let{column:i,tsName:l}of this.getSelectedTableColumns(e,r?.columns))n.push(this.buildRqbColumn(e,i,l,s)),t.push({key:l,field:i});return n.length?i.sql.join(n,i.sql`, `):void 0})():this.unwrapAllColumns(e,t,s);buildRelationalQuery({schema:e,table:s,tableConfig:r,queryConfig:n,relationWhere:l,mode:a,isNested:o,errorPath:u,depth:c,throughJoin:d,jsonb:h}){let f=[],m=!0===n?void 0:n,p=u??"",y=c??0;y||(s=x(s,`d${y}`));let b="first"===a?1:m?.limit,q=m?.offset,S=this.buildColumns(s,f,!!o,m),w=m?.where&&l?(0,M.and)(es(s,m.where,r.relations,e),l):m?.where?es(s,m.where,r.relations,e):l,$=m?.orderBy?function(e,s){if("function"==typeof s){let r=s(e,Y);return(0,t.is)(r,i.SQL)?r:Array.isArray(r)?r.length?i.sql.join(r.map(e=>(0,t.is)(e,i.SQL)?e:(0,R.asc)(e)),i.sql`, `):void 0:(0,t.is)(r,g.Column)?(0,R.asc)(r):void 0}let r=Object.entries(s).filter(([e,t])=>t);if(r.length)return i.sql.join(r.map(([t,i])=>("asc"===i?R.asc:R.desc)(ei(e,t))),i.sql`, `)}(s,m.orderBy):void 0,v=m?.extras?function(e,t){let s=[],r=[];for(let[n,l]of Object.entries(t)){if(!l)continue;let t=("function"==typeof l?l(e,{sql:Z.sql}):l).getSQL(),a,o=a?i.sql`${(void 0).apply(a,"cast",i.sql`(${t})`)} as ${i.sql.identifier(n)}`:i.sql`(${t}) as ${i.sql.identifier(n)}`;o.decoder=t.decoder,s.push(o),r.push(a?{key:n,field:o,codec:(void 0).get(a,"normalize"),arrayDimensions:a.dimensions}:{key:n,field:o})}return{sql:s.length?i.sql.join(s,i.sql`, `):void 0,selection:r}}(s,m.extras):void 0;v&&f.push(...v.selection);let Q=m?(()=>{let{with:n}=m;if(!n)return;let l=Object.entries(n).filter(([e,t])=>t);if(l.length)return i.sql.join(l.map(([n,l])=>{let a=r.relations[n],u=(0,t.is)(a,G),c=x(a.targetTable,`d${y+1}`),d=a.throughTable?x(a.throughTable,`tr${y}`):void 0,{filter:m,joinCondition:g}=er(a,s,c,d),b=d?i.sql` inner join ${en(d)} on ${g}`:void 0,q=this.buildRelationalQuery({table:c,mode:u?"first":"many",schema:e,queryConfig:l,tableConfig:e[a.targetTableName],relationWhere:m,isNested:!0,errorPath:`${p.length?`${p}.`:""}${n}`,depth:y+1,throughJoin:b,jsonb:h});f.push({field:c,key:n,selection:q.selection,isArray:!u,isOptional:(a.optional??!1)||!0!==l&&!!l.where});let S=i.sql.join(q.selection.map(e=>i.sql`${i.sql.raw(this.escapeString(e.key))}, ${e.selection?i.sql`${h}(${i.sql.identifier(e.key)})`:i.sql.identifier(e.key)}`),i.sql`, `),w=o?h:i.sql`json`;return u?i.sql`(select ${w}_object(${S}) as ${i.sql.identifier("r")} from (${q.sql}) as ${i.sql.identifier("t")}) as ${i.sql.identifier(n)}`:i.sql`coalesce((select ${w}_group_array(json_object(${S})) as ${i.sql.identifier("r")} from (${q.sql}) as ${i.sql.identifier("t")}), ${h}_array()) as ${i.sql.identifier(n)}`}),i.sql`, `)})():void 0,N=[S,v?.sql,Q].filter(e=>void 0!==e);if(!N.length)throw new E({message:`No fields selected for table "${r.name}"${p?` ("${p}")`:""}`});return{sql:i.sql`select ${i.sql.join(N,i.sql`, `)} from ${en(s)}${d}${i.sql` where ${w}`.if(w)}${i.sql` order by ${$}`.if($)}${i.sql` limit ${b}`.if(void 0!==b)}${i.sql` offset ${q}`.if(void 0!==q)}`,selection:f}}},eo=class{static [t.entityKind]="SQLiteQueryBuilder";dialect;dialectConfig;constructor(e){this.dialect=(0,t.is)(e,ea)?e:void 0,this.dialectConfig=(0,t.is)(e,ea)?void 0:e}$with=(e,t)=>{let i=this;return{as:s=>("function"==typeof s&&(s=s(i)),new Proxy(new y.WithSubquery(s.getSQL(),t??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new L({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};with(...e){let t=this;return{select:function(i){return new K({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e})},selectDistinct:function(i){return new K({fields:i??void 0,session:void 0,dialect:t.getDialect(),withList:e,distinct:!0})}}}select(e){return new K({fields:e??void 0,session:void 0,dialect:this.getDialect()})}selectDistinct(e){return new K({fields:e??void 0,session:void 0,dialect:this.getDialect(),distinct:!0})}getDialect(){return this.dialect||(this.dialect=new ea(this.dialectConfig)),this.dialect}},eu=class{static [t.entityKind]="SQLiteInsertBuilder";constructor(e,t,i,s,r=ec){this.table=e,this.session=t,this.dialect=i,this.withList=s,this.builder=r}values(e){if(0===(e=Array.isArray(e)?e:[e]).length)throw Error("values() must be called with at least one value");let s=e.map(e=>{let s={},r=this.table[S.Table.Symbol.Columns];for(let n of Object.keys(e)){let l=e[n];s[n]=(0,t.is)(l,i.SQL)?l:new i.Param(l,r[n])}return s});return new this.builder(this.table,s,this.session,this.dialect,this.withList)}select(e){let s="function"==typeof e?e(new eo):e;if(!(0,t.is)(s,i.SQL)){let e=Object.keys(this.table[S.Table.Symbol.Columns]);for(let t of Object.keys(s._.selectedFields))if(!e.includes(t))throw Error(`Insert select error: column "${t}" does not exist in table "${this.table[S.Table.Symbol.Name]}"`)}return new this.builder(this.table,s,this.session,this.dialect,this.withList,!0)}},ec=class{static [t.entityKind]="SQLiteInsert";config;constructor(e,t,i,s,r,n){this.session=i,this.dialect=s,this.config={table:e,values:t,withList:r,select:n}}returning(e=this.config.table[T.SQLiteTable.Symbol.Columns]){return this.config.returning=(0,l.orderSelectedFields)(e),this}onConflictDoNothing(e={}){if(this.config.onConflict||(this.config.onConflict=[]),void 0===e.target)this.config.onConflict.push(i.sql` on conflict do nothing`);else{let t=Array.isArray(e.target)?i.sql`${e.target}`:i.sql`${[e.target]}`,s=e.where?i.sql` where ${e.where}`:i.sql``;this.config.onConflict.push(i.sql` on conflict ${t} do nothing${s}`)}return this}onConflictDoUpdate(e){if(e.where&&(e.targetWhere||e.setWhere))throw Error('You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.');this.config.onConflict||(this.config.onConflict=[]);let t=e.where?i.sql` where ${e.where}`:void 0,s=e.targetWhere?i.sql` where ${e.targetWhere}`:void 0,r=e.setWhere?i.sql` where ${e.setWhere}`:void 0,n=Array.isArray(e.target)?i.sql`${e.target}`:i.sql`${[e.target]}`,a=this.dialect.buildUpdateSet(this.config.table,(0,l.mapUpdateSet)(this.config.table,e.set));return this.config.onConflict.push(i.sql` on conflict ${n}${s} do update set ${a}${t}${r}`),this}getSQL(){return this.dialect.buildInsertQuery(this.config)}toSQL(){return this.dialect.sqlToQuery(this.getSQL())}$dynamic(){return this}},ed=class extends ec{static [t.entityKind]="SQLiteAsyncInsert";_prepare(e=!1){return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),"arrays",e,this.config.returning?"all":"run",this.config.returning?this.dialect.mapperGenerators.rows(this.config.returning,void 0):void 0,{type:"insert",tables:C(this.config.table)})}prepare(){return this._prepare(!0)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this._prepare().execute()}};(0,l.applyMixins)(ed,[a]);var eh=class{static [t.entityKind]="SQLiteRaw";constructor(e,t,i){this.prepared=e,this.sql=t,this.query=i}getSQL(){return this.sql}getQuery(){return this.query}_prepare(){return this.prepared}},ef=class extends eh{static [t.entityKind]="SQLiteAsyncRaw";constructor(e,t,i){super(e,t,i)}execute(e){return this.prepared.execute(e)}};(0,l.applyMixins)(ef,[a]);var em=class extends D{static [t.entityKind]="SQLiteAsyncSelect";_prepare(e=!1){let t=this.dialect.sqlToQuery(this.getSQL()),i=this.config.fieldsFlat,s=this.dialect.mapperGenerators.rows(i,this.joinsNotNullableMap);return this.session.prepareQuery(t,"arrays",e,"all",s,{type:"select",tables:[...this.usedTables]},this.cacheConfig)}prepare(){return this._prepare(!0)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this._prepare().execute()}};(0,l.applyMixins)(em,[a]);var ep=class{static [t.entityKind]="SQLiteUpdateBuilder";constructor(e,t,i,s,r=ey){this.table=e,this.session=t,this.dialect=i,this.withList=s,this.builder=r}set(e){return new this.builder(this.table,(0,l.mapUpdateSet)(this.table,e),this.session,this.dialect,this.withList)}},ey=class{static [t.entityKind]="SQLiteUpdate";config;constructor(e,t,i,s,r){this.session=i,this.dialect=s,this.config={set:t,table:e,withList:r,joins:[]}}from(e){return this.config.from=e,this}createJoin(e){return(i,s)=>{let r=(0,l.getTableLikeName)(i);if("string"==typeof r&&this.config.joins.some(e=>e.alias===r))throw Error(`Alias "${r}" is already used in this query`);if("function"==typeof s){let e=this.config.from?(0,t.is)(i,T.SQLiteTable)?i[S.Table.Symbol.Columns]:(0,t.is)(i,y.Subquery)?i._.selectedFields:(0,t.is)(i,B)?i[b.ViewBaseConfig].selectedFields:void 0:void 0;s=s(new Proxy(this.config.table[S.Table.Symbol.Columns],new L({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})),e&&new Proxy(e,new L({sqlAliasedBehavior:"sql",sqlBehavior:"sql"})))}return this.config.joins.push({on:s,table:i,joinType:e,alias:r}),this}}leftJoin=this.createJoin("left");rightJoin=this.createJoin("right");innerJoin=this.createJoin("inner");fullJoin=this.createJoin("full");where(e){return this.config.where=e,this}orderBy(...e){if("function"==typeof e[0]){let t=e[0](new Proxy(this.config.table[S.Table.Symbol.Columns],new L({sqlAliasedBehavior:"alias",sqlBehavior:"sql"}))),i=Array.isArray(t)?t:[t];this.config.orderBy=i}else this.config.orderBy=e;return this}limit(e){return this.config.limit=e,this}returning(e=this.config.table[T.SQLiteTable.Symbol.Columns]){return this.config.returning=(0,l.orderSelectedFields)(e),this}getSQL(){return this.dialect.buildUpdateQuery(this.config)}toSQL(){return this.dialect.sqlToQuery(this.getSQL())}$dynamic(){return this}},eg=class extends ey{static [t.entityKind]="SQLiteAsyncUpdate";_prepare(e=!1){return this.session.prepareQuery(this.dialect.sqlToQuery(this.getSQL()),"arrays",e,this.config.returning?"all":"run",this.config.returning?this.dialect.mapperGenerators.rows(this.config.returning,void 0):void 0,{type:"update",tables:C(this.config.table)})}prepare(){return this._prepare(!0)}run=e=>this._prepare().run(e);all=e=>this._prepare().all(e);get=e=>this._prepare().get(e);values=e=>this._prepare().values(e);async execute(){return this.config.returning?this.all():this.run()}};(0,l.applyMixins)(eg,[a]);var eb=class{static [t.entityKind]="BaseSQLiteDatabase";query;constructor(e,t,i,s,r){for(const[n,l]of(this.resultKind=e,this.dialect=t,this.session=i,this.forbidJsonb=r,this._={relations:s,session:i,resultKind:e},this.query={},Object.entries(s)))this.query[n]=new h(e,s,s[l.name].table,l,t,i,r,"sync"===e?p:m);this.$cache={invalidate:async e=>{}}}$with=(e,t)=>{let i=this;return{as:s=>("function"==typeof s&&(s=s(new eo(i.dialect))),new Proxy(new y.WithSubquery(s.getSQL(),t??("getSelectedFields"in s?s.getSelectedFields()??{}:{}),e,!0),new L({alias:e,sqlAliasedBehavior:"alias",sqlBehavior:"error"})))}};$count(e,t){return"async"===this.resultKind?new c({source:e,filters:t,session:this.session,dialect:this.dialect}):new d({source:e,filters:t,session:this.session,dialect:this.dialect})}with(...e){let t=this;return{select:function(i){return new K({fields:i??void 0,session:t.session,dialect:t.dialect,withList:e},em)},selectDistinct:function(i){return new K({fields:i??void 0,session:t.session,dialect:t.dialect,withList:e,distinct:!0},em)},update:function(i){return new ep(i,t.session,t.dialect,e,eg)},insert:function(i){return new eu(i,t.session,t.dialect,e,ed)},delete:function(i){return new A(i,t.session,t.dialect,e)}}}select(e){return new K({fields:e??void 0,session:this.session,dialect:this.dialect},em)}selectDistinct(e){return new K({fields:e??void 0,session:this.session,dialect:this.dialect,distinct:!0},em)}update(e){return new ep(e,this.session,this.dialect,void 0,eg)}$cache;insert(e){return new eu(e,this.session,this.dialect,void 0,ed)}delete(e){return new A(e,this.session,this.dialect)}run(e){let t="string"==typeof e?i.sql.raw(e):e.getSQL(),s=this.dialect.sqlToQuery(t),r=this.session.prepareQuery(s,"raw",!1,"run");return"async"===this.resultKind?new ef(r,t,s):this.session.run(t)}all(e){let t="string"==typeof e?i.sql.raw(e):e.getSQL(),s=this.dialect.sqlToQuery(t),r=this.session.prepareQuery(s,"objects",!1,"all");return"async"===this.resultKind?new ef(r,t,s):this.session.objects(t)}get(e){let t="string"==typeof e?i.sql.raw(e):e.getSQL(),s=this.dialect.sqlToQuery(t),r=this.session.prepareQuery(s,"objects",!1,"get");return"async"===this.resultKind?new ef(r,t,s):this.session.object(t)}values(e){let t="string"==typeof e?i.sql.raw(e):e.getSQL(),s=this.dialect.sqlToQuery(t),r=this.session.prepareQuery(s,"objects",!1,"values");return"async"===this.resultKind?new ef(r,t,s):this.session.arrays(t)}transaction(e,t){return this.session.transaction(e,t)}},eq=class{static [t.entityKind]="Cache"},eS=class extends eq{static [t.entityKind]="NoopCache";strategy(){return"all"}async get(e){}async put(e,t,i,s){}async onMutate(e){}};let ew=async(e,t,i,s)=>{if(!i)return{type:"skip"};let{type:r,tables:n}=i;return("insert"===r||"update"===r||"delete"===r)&&n.length>0?{type:"invalidate",tables:n}:s&&s.enabled&&"select"===r?{type:"try",key:s.tag??await e$(e,t),isTag:void 0!==s.tag,autoInvalidate:s.autoInvalidate,tables:i.tables,config:s.config}:{type:"skip"}};async function e$(e,t){let i=`${e}-${JSON.stringify(t,(e,t)=>"bigint"==typeof t?`${t}n`:t)}`,s=new TextEncoder().encode(i);return[...new Uint8Array(await crypto.subtle.digest("SHA-256",s))].map(e=>e.toString(16).padStart(2,"0")).join("")}var ev=class{static [t.entityKind]="SQLiteBasePreparedQuery";mapper;executeMethod;constructor(e,t,i,s){this.query=t,this.mode=s,this.mapper=i,this.executeMethod=e}getQuery(){return this.query}},eQ=class{static [t.entityKind]="SQLiteSession";constructor(e){this.dialect=e}},ex=class extends a{static [t.entityKind]="ExecuteResultSync";constructor(e){super(),this.resultCb=e}async execute(){return this.resultCb()}sync(){return this.resultCb()}},eN=class extends ev{static [t.entityKind]="SQLiteAsyncPreparedQuery";fastPath;constructor(e,i="all",s,r,n,l,a,o,u,c){super(i,r,n,l),this.resultKind=e,this.executors=s,this.logger=a,this.cache=o,this.queryMetadata=u,this.cacheConfig=c,o&&"all"===o.strategy()&&void 0===c&&(this.cacheConfig={enabled:!0,autoInvalidate:!0}),this.cacheConfig?.enabled||(this.cacheConfig=void 0),this.fastPath=void 0===c&&(void 0===o||(0,t.is)(o,eS))}async queryWithCache(e,i,s,r){let n=void 0===this.cache||(0,t.is)(this.cache,eS)?{type:"skip"}:await ew(e,i,this.queryMetadata,this.cacheConfig);if("skip"===n.type)return r().catch(t=>{throw new z(e,i,t)});let a=this.cache;if("invalidate"===n.type)return Promise.all([r(),a.onMutate({tables:n.tables})]).then(e=>e[0]).catch(t=>{throw new z(e,i,t)});if("try"===n.type){let{tables:t,key:l,isTag:o,autoInvalidate:u,config:c}=n,d=`${s}_${l}`,h=await a.get(d,t,o,u);if(void 0===h){let s=await r().catch(t=>{throw new z(e,i,t)});return await a.put(d,s,u?t:[],o,c),s}return h}(0,l.assertUnreachable)(n)}run(e={}){let{query:t,logger:s,executors:r,fastPath:n,resultKind:l}=this,a=t._sql?t._sql.join(" "):t.sql,o=0===t.params.length?t.params:(0,i.fillPlaceholders)(t.params,e);if(s.logQuery(a,o),"sync"===l)try{return r.run(o)}catch(e){throw new z(a,o,e)}return n?r.run(o).catch(e=>{throw new z(a,o,e)}):this.queryWithCache(a,o,"run",()=>r.run(o))}all(e={}){let{query:t,logger:s,executors:r,mapper:n,fastPath:l,resultKind:a}=this,o=t._sql?t._sql.join(" "):t.sql,u=0===t.params.length?t.params:(0,i.fillPlaceholders)(t.params,e);if(s.logQuery(o,u),"sync"===a){let e;try{e=r.all(u)}catch(e){throw new z(o,u,e)}return n?n(e):e}let c=l?r.all(u).catch(e=>{throw new z(o,u,e)}):this.queryWithCache(o,u,"all",()=>r.all(u));return n?c.then(e=>n(e)):c}get(e={}){let{query:t,logger:s,executors:r,mapper:n,fastPath:l,resultKind:a}=this,o=t._sql?t._sql.join(" "):t.sql,u=0===t.params.length?t.params:(0,i.fillPlaceholders)(t.params,e);if(s.logQuery(o,u),"sync"===a){let e;try{e=r.get(u)}catch(e){throw new z(o,u,e)}return e?n?n([e])[0]:e:void 0}let c=l?r.get(u).catch(e=>{throw new z(o,u,e)}):this.queryWithCache(o,u,"get",()=>r.get(u));return n?c.then(e=>e?n([e])[0]:void 0):c.then(e=>e||void 0)}values(e={}){let{query:t,logger:s,executors:r,fastPath:n,resultKind:l}=this,a=t._sql?t._sql.join(" "):t.sql,o=0===t.params.length?t.params:(0,i.fillPlaceholders)(t.params,e);if(s.logQuery(a,o),"sync"===l)try{return r.values(o)}catch(e){throw new z(a,o,e)}return n?r.values(o).catch(e=>{throw new z(a,o,e)}):this.queryWithCache(a,o,"values",()=>r.values(o))}execute(e){return"async"===this.resultKind?this[this.executeMethod](e):new ex(()=>this[this.executeMethod](e))}},eL=class extends eQ{static [t.entityKind]="SQLiteAsyncSession";constructor(e,t){super(e),this.resultKind=t}run(e){return this.prepareQuery(this.dialect.sqlToQuery(e),"raw",!1).run()}objects(e){return this.prepareQuery(this.dialect.sqlToQuery(e),"objects",!1).all()}object(e){return this.prepareQuery(this.dialect.sqlToQuery(e),"objects",!1).get()}arrays(e){return this.prepareQuery(this.dialect.sqlToQuery(e),"arrays",!1).all()}array(e){return this.prepareQuery(this.dialect.sqlToQuery(e),"arrays",!1).get()}},eT=class extends eb{static [t.entityKind]="SQLiteAsyncTransaction";constructor(e,t,i,s,r=0,n){super(e,t,i,s,n),this.nestedIndex=r}rollback(){throw new U}},eC=class e extends eL{static [t.entityKind]="LibSQLSession";logger;cache;constructor(e,t,i,s,r){super(t,"async"),this.client=e,this.relations=i,this.options=s,this.tx=r,this.logger=s.logger??new n,this.cache=s.cache??new eS}prepareQuery(e,t,i,s,r,n,l){let a=this.tx??this.client;return new eN("async",s,{all:i=>a.execute({sql:e.sql,args:i}).then(({rows:e})=>"arrays"===t?e.map(eA):e.map(ej)),get:i=>a.execute({sql:e.sql,args:i}).then(({rows:e})=>e[0]?"arrays"===t?eA(e[0]):ej(e[0]):void 0),run:t=>a.execute({sql:e.sql,args:t}),values:t=>a.execute({sql:e.sql,args:t}).then(({rows:e})=>e.map(eA))},e,r,t,this.logger,this.cache,n,l)}async batch(e,t){let i=[],s=[];for(let t of e){let e=t._prepare(),r=e.getQuery();i.push(e),s.push({sql:r.sql,args:r.params})}return(await (t?this.client.migrate(s):(this.tx??this.client).batch(s))).map((e,t)=>{let{executeMethod:s,mapper:r,mode:n}=i[t];if("run"===s)return e;if("values"===s)return e.rows;if("get"===s){let t=e.rows[0];if(!t)return;let i="arrays"===n?eA(t):ej(t);return r?r([i])[0]:i}let{rows:l}=e,a="arrays"===n?l.map(eA):l.map(ej);return r?r(a):a})}async migrate(e){return this.batch(e,!0)}async transaction(t,i){let s=await this.client.transaction(),r=new e(this.client,this.dialect,this.relations,this.options,s),n=new e_("async",this.dialect,r,this.relations);try{let e=await t(n);return await s.commit(),e}catch(e){throw await s.rollback(),e}}},e_=class e extends eT{static [t.entityKind]="LibSQLTransaction";async transaction(t){let s=`sp${this.nestedIndex}`,r=new e("async",this.dialect,this.session,this._.relations,this.nestedIndex+1);await this.session.run(i.sql.raw(`savepoint ${s}`));try{let e=await t(r);return await this.session.run(i.sql.raw(`release savepoint ${s}`)),e}catch(e){throw await this.session.run(i.sql.raw(`rollback to savepoint ${s}`)),e}}};function eA(e){return Array.prototype.slice.call(e)}function ej(e){return Object.keys(e).reduce((t,i)=>(Object.prototype.propertyIsEnumerable.call(e,i)&&(t[i]=e[i]),t),{})}var eB=class extends eb{static [t.entityKind]="LibSQLDatabase";async batch(e){return this.session.batch(e)}};e.s(["LibSQLDatabase",0,eB,"construct",0,function(e,t={}){let i,s=new ea({useJitMappers:(0,l.jitCompatCheck)(t.jit)});!0===t.logger?i=new r:!1!==t.logger&&(i=t.logger);let n=t.relations??{},a=new eB("async",s,new eC(e,s,n,{logger:i,cache:t.cache},void 0),n);return a.$client=e,a.$cache=t.cache,a.$cache&&(a.$cache.invalidate=t.cache?.onMutate),a}],999884)},219756,e=>e.a(async(t,i)=>{try{var s=e.i(999884),r=e.i(418520),n=t([r]);function l(...e){if("string"==typeof e[0])return(0,s.construct)((0,r.createClient)({url:e[0]}),e[1]);let{connection:t,client:i,...n}=e[0];return i?(0,s.construct)(i,n):(0,s.construct)("string"==typeof t?(0,r.createClient)({url:t}):(0,r.createClient)(t),n)}[r]=n.then?(await n)():n,(l||(l={})).mock=function(e){return(0,s.construct)({},e)},e.s(["drizzle",0,l]),i()}catch(e){i(e)}},!1),875225,e=>{"use strict";var t=e.i(518899),i=e.i(844988),s=e.i(369e3),r=e.i(156325);function n(e,n){return!(0,t.isDriverValueEncoder)(n)||(0,t.isSQLWrapper)(e)||(0,i.is)(e,t.Param)||(0,i.is)(e,t.Placeholder)||(0,i.is)(e,r.Column)||(0,i.is)(e,s.Table)||(0,i.is)(e,t.View)?e:new t.Param(e,n)}e.s(["and",0,function(...e){let i=e.filter(e=>void 0!==e);if(0!==i.length)return new t.SQL(1===i.length?i:[new t.StringChunk("("),t.sql.join(i.map(e=>t.sql`(${e})`),new t.StringChunk(" and ")),new t.StringChunk(")")])},"arrayContained",0,function(e,i){if(Array.isArray(i)){if(0===i.length)throw Error("arrayContained requires at least one value");let s=n(i,e);return t.sql`${e} <@ ${t.sql`${Array.isArray(s)?new t.Param(s):s}`}`}return t.sql`${e} <@ ${n(i,e)}`},"arrayContains",0,function(e,i){if(Array.isArray(i)){if(0===i.length)throw Error("arrayContains requires at least one value");let s=n(i,e);return t.sql`${e} @> ${t.sql`${Array.isArray(s)?new t.Param(s):s}`}`}return t.sql`${e} @> ${n(i,e)}`},"arrayOverlaps",0,function(e,i){if(Array.isArray(i)){if(0===i.length)throw Error("arrayOverlaps requires at least one value");let s=n(i,e);return t.sql`${e} && ${t.sql`${Array.isArray(s)?new t.Param(s):s}`}`}return t.sql`${e} && ${n(i,e)}`},"between",0,function(e,i,s){return t.sql`${e} between ${n(i,e)} and ${n(s,e)}`},"eq",0,(e,i)=>t.sql`${e} = ${n(i,e)}`,"exists",0,function(e){return t.sql`exists ${e}`},"gt",0,(e,i)=>t.sql`${e} > ${n(i,e)}`,"gte",0,(e,i)=>t.sql`${e} >= ${n(i,e)}`,"ilike",0,function(e,i){return t.sql`${e} ilike ${i}`},"inArray",0,function(e,i){return Array.isArray(i)?0===i.length?t.sql`false`:t.sql`${e} in ${i.map(t=>n(t,e))}`:t.sql`${e} in ${n(i,e)}`},"isNotNull",0,function(e){return t.sql`(${e} is not null)`},"isNull",0,function(e){return t.sql`(${e} is null)`},"like",0,function(e,i){return t.sql`${e} like ${i}`},"lt",0,(e,i)=>t.sql`${e} < ${n(i,e)}`,"lte",0,(e,i)=>t.sql`${e} <= ${n(i,e)}`,"ne",0,(e,i)=>t.sql`${e} <> ${n(i,e)}`,"not",0,function(e){return(0,i.is)(e,t.SQL)?t.sql`not (${e})`:t.sql`not ${e}`},"notBetween",0,function(e,i,s){return t.sql`${e} not between ${n(i,e)} and ${n(s,e)}`},"notExists",0,function(e){return t.sql`not exists ${e}`},"notIlike",0,function(e,i){return t.sql`${e} not ilike ${i}`},"notInArray",0,function(e,i){return Array.isArray(i)?0===i.length?t.sql`true`:t.sql`${e} not in ${i.map(t=>n(t,e))}`:t.sql`${e} not in ${n(i,e)}`},"notLike",0,function(e,i){return t.sql`${e} not like ${i}`},"or",0,function(...e){let i=e.filter(e=>void 0!==e);if(0!==i.length)return new t.SQL(1===i.length?i:[new t.StringChunk("("),t.sql.join(i.map(e=>t.sql`(${e})`),new t.StringChunk(" or ")),new t.StringChunk(")")])}])},349129,e=>{"use strict";var t=e.i(518899);e.s(["asc",0,function(e){return t.sql`${e} asc`},"desc",0,function(e){return t.sql`${e} desc`}])},518899,844988,923277,156325,500833,369e3,792352,88274,e=>{"use strict";let t=Symbol.for("drizzle:entityKind");function i(e,i){if(!e||"object"!=typeof e)return!1;if(e instanceof i)return!0;if(!Object.prototype.hasOwnProperty.call(i,t))throw Error(`Class "${i.name??"<unknown>"}" doesn't look like a Drizzle entity. If this is incorrect and the class is provided by Drizzle, please report this as a bug.`);let s=Object.getPrototypeOf(e)?.constructor;if(s)for(;s;){if(t in s&&s[t]===i[t])return!0;s=Object.getPrototypeOf(s)}return!1}Symbol.for("drizzle:hasOwnEntityKind"),e.s(["entityKind",0,t,"is",0,i],844988);let s=Symbol.for("drizzle:OriginalColumn");e.s(["OriginalColumn",0,s],923277);let r=e=>e;r.isNoop=!0;var n,l=class{static [t]="Column";codec;name;keyAsName;primary;notNull;default;defaultFn;onUpdateFn;hasDefault;isUnique;uniqueName;uniqueType;dataType;columnType;enumValues=void 0;generated=void 0;generatedIdentity=void 0;length;isLengthExact;isAlias;config;table;onInit(){}constructor(e,t){this.config=t,this.onInit(),this.table=e,this.name=t.name,this.isAlias=!1,this.keyAsName=t.keyAsName,this.notNull=t.notNull,this.default=t.default,this.defaultFn=t.defaultFn,this.onUpdateFn=t.onUpdateFn,this.hasDefault=t.hasDefault,this.primary=t.primaryKey,this.isUnique=t.isUnique,this.uniqueName=t.uniqueName,this.uniqueType=t.uniqueType,this.dataType=t.dataType,this.columnType=t.columnType,this.generated=t.generated,this.generatedIdentity=t.generatedIdentity,this.length=t.length,this.isLengthExact=t.isLengthExact}mapFromDriverValue=r;mapToDriverValue=r;postBuild(){return this}shouldDisableInsert(){return void 0!==this.config.generated&&"byDefault"!==this.config.generated.type}[s](){return this}};e.s(["Column",0,l],156325);let a=Symbol.for("drizzle:Name");e.s(["TableName",0,a],500833);let o=Symbol.for("drizzle:Schema"),u=Symbol.for("drizzle:Columns"),c=Symbol.for("drizzle:ExtraConfigColumns"),d=Symbol.for("drizzle:OriginalName"),h=Symbol.for("drizzle:BaseName"),f=Symbol.for("drizzle:IsAlias"),m=Symbol.for("drizzle:ExtraConfigBuilder"),p=Symbol.for("drizzle:IsDrizzleTable");var y=class{static [t]="Table";static Symbol={Name:a,Schema:o,OriginalName:d,Columns:u,ExtraConfigColumns:c,BaseName:h,IsAlias:f,ExtraConfigBuilder:m};[a];[d];[o];[u];[c];[h];[f]=!1;[p]=!0;[m]=void 0;constructor(e,t,i){this[a]=this[d]=e,this[o]=t,this[h]=i}};e.s(["IsAlias",0,f,"OriginalName",0,d,"Table",0,y,"TableColumns",0,u,"TableSchema",0,o,"getTableName",0,function(e){return e[a]}],369e3);var g=class{static [t]="Subquery";constructor(e,t,i,s=!1,r=[]){this._={brand:"Subquery",sql:e,selectedFields:t,alias:i,isWith:s,usedTables:r}}},b=class extends g{static [t]="WithSubquery"};e.s(["Subquery",0,g,"WithSubquery",0,b],792352);let q=Symbol.for("drizzle:ViewBaseConfig");function S(e){return null!=e&&"function"==typeof e.getSQL}e.s(["ViewBaseConfig",0,q],88274);var w=class{static [t]="StringChunk";value;constructor(e){this.value=Array.isArray(e)?e:[e]}getSQL(){return new $([this])}},$=class e{static [t]="SQL";decoder=Q;shouldInlineParams=!1;usedTables=[];constructor(e){for(const t of(this.queryChunks=e,e))if(i(t,y)){const e=t[y.Symbol.Schema];this.usedTables.push(void 0===e?t[y.Symbol.Name]:e+"."+t[y.Symbol.Name])}}append(e){return this.queryChunks.push(...e.queryChunks),this}toQuery(e){return(t=>{let i=this.buildQueryFromSourceParams(this.queryChunks,e);return t?.setAttributes({"drizzle.query.text":i.sql,"drizzle.query.params":JSON.stringify(i.params)}),i})()}buildQueryFromSourceParams(t,s){let r=Object.assign({},s,{inlineParams:s.inlineParams||this.shouldInlineParams,paramStartIndex:s.paramStartIndex||{value:0}}),{escapeName:n,escapeParam:a,codecs:o,inlineParams:u,paramStartIndex:c,invokeSource:d}=r,h=t.map(t=>{if(i(t,w))return{sql:t.value.join(""),params:[]};if(i(t,v))return{sql:n(t.value),params:[]};if(void 0===t)return{sql:"",params:[]};if(Array.isArray(t)){let e=[new w("(")];for(let[i,s]of t.entries())e.push(s),i<t.length-1&&e.push(new w(", "));return e.push(new w(")")),this.buildQueryFromSourceParams(e,r)}if(i(t,e))return this.buildQueryFromSourceParams(t.queryChunks,{...r,inlineParams:u||t.shouldInlineParams});if(i(t,y)){let e=t[y.Symbol.Schema],i=t[y.Symbol.Name];return"mssql-view-with-schemabinding"===d?{sql:(void 0===e?n("dbo"):n(e))+"."+n(i),params:[]}:{sql:void 0===e||t[f]?n(i):n(e)+"."+n(i),params:[]}}if(i(t,l)){let e=t.name;if("indexes"===s.invokeSource)return{sql:n(e),params:[]};let i="mssql-check"===d?void 0:t.table[y.Symbol.Schema];return{sql:t.isAlias?n(t.name):t.table[f]||void 0===i?n(t.table[y.Symbol.Name])+"."+n(e):n(i)+"."+n(t.table[y.Symbol.Name])+"."+n(e),params:[]}}if(i(t,A)){let e=t[q].schema,i=t[q].name;return{sql:void 0===e||t[q].isAlias?n(i):n(e)+"."+n(i),params:[]}}if(i(t,N)){let s;if(i(t.value,e))return this.buildQueryFromSourceParams([t.value],r);let n=o&&i(t.encoder,l);if(i(t.value,C)){let e=a(c.value++,t);return t.codec=n?e=>o.apply(t.encoder,"normalizeParam",e):void 0,{sql:n?o.apply(t.encoder,"castParam",e):e,params:[t]}}if(null===t.value)s=t.value;else{if(i(s=t.encoder.mapToDriverValue.isNoop?t.value:t.encoder.mapToDriverValue(t.value),e))return this.buildQueryFromSourceParams([s],r);n&&(s=o.apply(t.encoder,"normalizeParam",s))}if(u)return{sql:this.mapInlineParam(s,r),params:[]};let d=a(c.value++,s);return{sql:n?o.apply(t.encoder,"castParam",d):d,params:[s]}}return i(t,C)?{sql:a(c.value++,t),params:[t]}:i(t,e.Aliased)&&void 0!==t.fieldAlias?{sql:(void 0!==t.origin?n(t.origin)+".":"")+n(t.fieldAlias),params:[]}:i(t,g)?t._.isWith?{sql:n(t._.alias),params:[]}:this.buildQueryFromSourceParams([new w("("),t._.sql,new w(") "),new v(t._.alias)],r):"function"==typeof t&&"enumName"in t?"schema"in t&&t.schema?{sql:n(t.schema)+"."+n(t.enumName),params:[]}:{sql:n(t.enumName),params:[]}:S(t)?t.shouldOmitSQLParens?.()?this.buildQueryFromSourceParams([t.getSQL()],r):this.buildQueryFromSourceParams([new w("("),t.getSQL(),new w(")")],r):u?{sql:this.mapInlineParam(t,r),params:[]}:{sql:a(c.value++,t),params:[t]}});if(s.tagged){let e={sql:"",params:[]},t=[];for(let i of h)t.push(i.sql),e.params.push(...i.params);return e._sql=Object.assign(t,{raw:t}),e}let m={sql:"",params:[]};for(let e of h)m.sql+=e.sql,m.params.push(...e.params);return m}mapInlineParam(e,{escapeString:t}){if(null===e)return"null";if("number"==typeof e||"boolean"==typeof e||"bigint"==typeof e)return e.toString();if("string"==typeof e)return t(e);if("object"==typeof e){let i=e.toString();return"[object Object]"===i?t(JSON.stringify(e)):t(i)}throw Error("Unexpected param value: "+e)}getSQL(){return this}as(t){return void 0===t?this:new e.Aliased(this,t)}mapWith(e){return this.decoder="function"==typeof e?{mapFromDriverValue:e}:e,this}nullable(){return this}inlineParams(){return this.shouldInlineParams=!0,this}if(e){return e?this:void 0}},v=class{static [t]="Name";brand;constructor(e){this.value=e}getSQL(){return new $([this])}};let Q={mapFromDriverValue:e=>e};Q.mapFromDriverValue.isNoop=!0;let x={mapToDriverValue:e=>e};x.mapToDriverValue.isNoop=!0;var N=class{static [t]="Param";brand;constructor(e,t=x,i){this.value=e,this.encoder=t,this.codec=i}getSQL(){return new $([this])}};function L(e,...t){let i=[];for(let[s,r]of((t.length>0||e.length>0&&""!==e[0])&&i.push(new w(e[0])),t.entries()))i.push(r,new w(e[s+1]));return new $(i)}function T(e){let t=T.encodeInput(e);return t.length?`/*${t}*/`:""}(n=L||(L={})).empty=function(){return new $([])},n.fromList=function(e){return new $(e)},n.raw=function(e){return new $([new w(e)])},n.join=function(e,t){let i=[];for(let[s,r]of e.entries())s>0&&void 0!==t&&i.push(t),i.push(r);return new $(i)},n.identifier=function(e){return new v(e)},n.placeholder=function(e){return new C(e)},n.param=function(e,t){return new N(e,t)},n.comment=function(e){let t=T(e);if(t.length)return L.raw(t)},function(e){function t(e){if("string"==typeof e)return e.length?s(e):e;let t=[];for(let[s,r]of Object.entries(e)){if(null==r||""===r)continue;let e=i(s),n=i(String(r));t.push(`${e}='${n}'`)}return t.length?t.sort().join(","):""}function i(e){return encodeURIComponent(e).replace(/'/g,"\\'")}function s(e){return e.replace(/\/\*/g,"/ *").replace(/\*\//g,"* /")}e.merge=function(e,i){let s;if("object"==typeof e&&"object"==typeof i)s=t({...e,...i});else if(e&&i)s=[t(e),t(i)].filter(e=>e.length).join(",");else if(i)s=t(i);else{if(!e)return"";s=t(e)}return s.length?`/*${s}*/`:""},e.encodeInput=t,e.sanitizeObjectElement=i,e.sanitizeStringInput=s}(T||(T={})),($||($={})).Aliased=class e{static [t]="SQL.Aliased";isSelectionField=!1;origin;constructor(e,t){this.sql=e,this.fieldAlias=t}getSQL(){return this.sql}clone(){return new e(this.sql,this.fieldAlias)}};var C=class{static [t]="Placeholder";constructor(e){this.name=e}getSQL(){return new $([this])}};let _=Symbol.for("drizzle:IsDrizzleView");var A=class{static [t]="View";[q];[_]=!0;get[a](){return this[q].name}get[o](){return this[q].schema}get[f](){return this[q].isAlias}get[d](){return this[q].originalName}get[u](){return this[q].selectedFields}constructor({name:e,schema:t,selectedFields:i,query:s}){this[q]={name:e,originalName:e,schema:t,selectedFields:i,query:s,isExisting:!s,isAlias:!1}}};l.prototype.getSQL=function(){return new $([this])},g.prototype.getSQL=function(){return new $([this])},e.s(["Param",0,N,"Placeholder",0,C,"SQL",0,$,"StringChunk",0,w,"View",0,A,"fillPlaceholders",0,function(e,t){return e.map(e=>{if(i(e,C)){if(!(e.name in t))throw Error(`No value for placeholder "${e.name}" was provided`);return t[e.name]}if(i(e,N)&&i(e.value,C)){if(!(e.value.name in t))throw Error(`No value for placeholder "${e.value.name}" was provided`);let i=t[e.value.name];if(null===i)return i;let s=e.encoder.mapToDriverValue.isNoop?i:e.encoder.mapToDriverValue(i);return e.codec?e.codec(s):s}return e})},"isDriverValueEncoder",0,function(e){return"object"==typeof e&&null!==e&&"mapToDriverValue"in e&&"function"==typeof e.mapToDriverValue},"isSQLWrapper",0,S,"noopDecoder",0,Q,"sql",0,L],518899)},704313,361328,100849,937540,380568,75799,646683,201440,616918,e=>{"use strict";var t,i=e.i(844988),s=e.i(156325),r=e.i(369e3),n=e.i(518899),l=e.i(792352),a=e.i(88274);let o=Object.getPrototypeOf(()=>null).constructor;function u(e){let t=e.getSQL();if((0,i.is)(t.decoder,s.Column))return t.decoder}function c(e,t){return{name:"string"==typeof e&&e.length>0?e:"",config:"object"==typeof e?e:t}}let d="u"<typeof TextDecoder?null:new TextDecoder;e.s(["FnConstructor",0,o,"applyMixins",0,function(e,t){for(let i of t)for(let t of Object.getOwnPropertyNames(i.prototype))"constructor"!==t&&Object.defineProperty(e.prototype,t,Object.getOwnPropertyDescriptor(i.prototype,t)||Object.create(null))},"assertUnreachable",0,function(e){throw Error("Didn't expect to get here")},"getColumnFromDecoder",0,u,"getColumnNameAndConfig",0,c,"getTableColumns",0,function(e){return e[r.Table.Symbol.Columns]},"getTableLikeName",0,function(e){return(0,i.is)(e,l.Subquery)?e._.alias:(0,i.is)(e,n.View)?e[a.ViewBaseConfig].name:(0,i.is)(e,n.SQL)?void 0:e[r.Table.Symbol.IsAlias]?e[r.Table.Symbol.Name]:e[r.Table.Symbol.BaseName]},"haveSameKeys",0,function(e,t){let i=Object.keys(e),s=Object.keys(t);if(i.length!==s.length)return!1;for(let[e,t]of i.entries())if(t!==s[e])return!1;return!0},"jitCompatCheck",0,function(e){if(!e)return!1;try{let e=new o("input",'"use strict"; return input;')(!0);return!0!==e&&(console.warn("Unable to use jit mappers due to incompatibility: corrupted jit function output.\nFalling back to premade mappers.\nError details:"),console.error(`Expected to receive \`true\`, got: ${e}`)),!0}catch(e){return console.warn("Unable to use jit mappers due to incompatibility.\nFalling back to premade mappers.\nError details:"),console.error(e),!1}},"makeDefaultQueryMapper",0,function(e,t){let a=e.map(({field:e,codec:a,arrayDimensions:o,path:u})=>{let c,d;if((0,i.is)(e,s.Column)){if(d=e,t&&2===u.length){let t=u[0];c=(i,s)=>{t in i?"string"==typeof i[t]&&i[t]!==(0,r.getTableName)(e.table)&&(i[t]=!1):i[t]=null===s&&(0,r.getTableName)(e.table)}}}else d=(0,i.is)(e,n.SQL)?e.decoder:(0,i.is)(e,l.Subquery)?e._.sql.decoder:e.sql.decoder;return[d.mapFromDriverValue.isNoop?a?e=>a(e,o):void 0:a?e=>d.mapFromDriverValue(a(e,o)):e=>d.mapFromDriverValue(e),c]});return i=>i.map(i=>{let s={},r=e.reduce((e,{path:t},r)=>{let n=e;for(let[e,l]of t.entries())if(e<t.length-1)l in n||(n[l]={}),n=n[l];else{let[e,t]=a[r],o=i[r],u=n[l]=null===o?null:e?e(o):o;t?.(s,u)}return e},{});if(t&&Object.keys(s).length>0)for(let[e,i]of Object.entries(s))"string"!=typeof i||t[i]||(r[e]=null);return r})},"makeJitQueryMapper",0,function(e,t){let a=` "use strict";
|
|
6
|
+
const { columns } = this;
|
|
7
|
+
const { length } = rows;
|
|
8
|
+
const mapped = Array.from({ length });
|
|
9
|
+
${function(e,t={}){let a=[],o=[];o.push(`const [ ${e.map((e,t)=>`c${t}`).join(", ")} ] = rows[i];`);let u={},c={},d=Array.from({length:e.length});for(let o=0;o<e.length;++o){let h,f,m,{field:p,path:y,codec:g,arrayDimensions:b}=e[o],q=!1;(0,i.is)(p,s.Column)?(q=!0,h=p,m=`field: decoder${o}`):(0,i.is)(p,n.SQL)?(h=p.decoder,m=`field: { decoder: decoder${o} }`):(0,i.is)(p,l.Subquery)?(h=p._.sql.decoder,m=`field: { _: { sql: { decoder: decoder${o} } } }`):(h=p.sql.decoder,m=`field: { sql: { decoder: decoder${o} } }`),f=`decoder${o}.mapFromDriverValue`,h.mapFromDriverValue.isNoop&&(f=""),f?a.push(`const { ${m}${g?`, codec: codec${o}`:""} } = columns[${o}];`):g&&a.push(`const { codec: codec${o} } = columns[${o}];`);let S=`c${o}`,w=S;if(g&&(w=`codec${o}(${w}, ${b})`),f&&(w=`${f}(${w})`),d[o]=S===w?`${S}`:`${S} === null ? ${S} : ${w}`,2!==y.length||!q)continue;void 0===c[y[0]]?c[y[0]]=[`c${o}`]:c[y[0]]?.push(`c${o}`);let[$]=y,v=(0,r.getTableName)(p.table);u[$]=!t[v]&&("string"==typeof u[$]?u[$]===v&&v:v)}o.push("mapped[i] = {");let h=[];for(let t=0;t<e.length;++t){let{path:i}=e[t],s=i.map(e=>JSON.stringify(e)),r=d[t],n=i.slice(0,-1),l=0;for(;l<h.length&&l<n.length&&h[l]===n[l];)l++;for(let e=h.length-1;e>=l;--e)o.push(`${" ".repeat(e+1)}},`);for(let e=l;e<n.length;++e)o.push(`${" ".repeat(e+1)}${s[e]}: ${0===e&&1===n.length&&"string"==typeof u[i[0]]?`${c[i[0]]?.map(e=>`${e} === null`).join(" && ")} ? null : {`:"{"}`);h=n,o.push(`${" ".repeat(i.length)}${s[i.length-1]}: ${r},`)}for(let e=h.length-1;e>=0;--e)o.push(`${" ".repeat(e+1)}},`);return o.push("};"),`${a.length?`${a.join("\n ")}
|
|
10
|
+
`:""}for (let i = 0; i < length; ++i) {
|
|
11
|
+
${o.join("\n ")}
|
|
12
|
+
}`}(e,t)}
|
|
13
|
+
return mapped;
|
|
14
|
+
//# sourceURL=drizzle:jit-query-mapper`;return Object.assign(new o("rows",a).bind({columns:e}),{body:`function jitQueryMapper (rows) {
|
|
15
|
+
${a}
|
|
16
|
+
}`})},"mapUpdateSet",0,function(e,t){let l=Object.entries(t).filter(([,e])=>void 0!==e).map(([t,l])=>(0,i.is)(l,n.SQL)||(0,i.is)(l,s.Column)?[t,l]:[t,new n.Param(l,e[r.Table.Symbol.Columns][t])]);if(0===l.length)throw Error("No values to set");return Object.fromEntries(l)},"orderSelectedFields",0,function e(t,a,o){return Object.entries(t).reduce((t,[c,d])=>{if("string"!=typeof c)return t;let h=a?[...a,c]:[c];if((0,i.is)(d,s.Column))t.push({path:h,field:d,codec:o?.get(d,"normalize"),arrayDimensions:d.dimensions,column:d});else if((0,i.is)(d,n.SQL)||(0,i.is)(d,n.SQL.Aliased)){let e=u(d);t.push(e?{path:h,field:d,codec:o?.get(e,"normalize"),arrayDimensions:e.dimensions,column:e}:{path:h,field:d})}else if((0,i.is)(d,l.Subquery)){let e,r,l=Object.values(d._.selectedFields)[0];(0,i.is)(l,s.Column)?(e=l,r=l):(0,i.is)(l,n.SQL)?(e=u(l),r=l.decoder):(e=u(l),r=l.sql.decoder),r&&(d._.sql.decoder=r),t.push(e?{path:h,field:d,codec:o?.get(e,"normalize"),arrayDimensions:e.dimensions,column:e}:{path:h,field:d})}else(0,i.is)(d,r.Table)?t.push(...e(d[r.Table.Symbol.Columns],h,o)):t.push(...e(d,h,o));return t},[])},"textDecoder",0,d],704313);var h=s,f=class{static [i.entityKind]="ColumnBuilder";config;constructor(e,t,i){this.config={name:e,keyAsName:""===e,notNull:!1,default:void 0,hasDefault:!1,primaryKey:!1,isUnique:!1,uniqueName:void 0,uniqueType:void 0,dataType:t,columnType:i,generated:void 0}}$type(){return this}notNull(){return this.config.notNull=!0,this}default(e){return this.config.default=e,this.config.hasDefault=!0,this}$defaultFn(e){return this.config.defaultFn=e,this.config.hasDefault=!0,this}$default=this.$defaultFn;$onUpdateFn(e){return this.config.onUpdateFn=e,this.config.hasDefault=!0,this}$onUpdate=this.$onUpdateFn;primaryKey(){return this.config.primaryKey=!0,this.config.notNull=!0,this}setName(e,t){""===this.config.name&&(this.config.name=t(e))}},m=e.i(500833),p=class{static [i.entityKind]="SQLiteForeignKeyBuilder";reference;_onUpdate;_onDelete;constructor(e,t){this.reference=()=>{let{name:t,columns:i,foreignColumns:s}=e();return{name:t,columns:i,foreignTable:s[0].table,foreignColumns:s}},t&&(this._onUpdate=t.onUpdate,this._onDelete=t.onDelete)}onUpdate(e){return this._onUpdate=e,this}onDelete(e){return this._onDelete=e,this}build(e){return new y(e,this)}},y=class{static [i.entityKind]="SQLiteForeignKey";reference;onUpdate;onDelete;constructor(e,t){this.table=e,this.reference=t.reference,this.onUpdate=t._onUpdate,this.onDelete=t._onDelete}getName(){let{name:e,columns:t,foreignColumns:i}=this.reference(),s=t.map(e=>e.name),r=i.map(e=>e.name),n=[this.table[m.TableName],...s,i[0].table[m.TableName],...r];return e??`${n.join("_")}_fk`}isNameExplicit(){return!!this.reference().name}};e.s(["ForeignKeyBuilder",0,p],361328);var g=class extends f{static [i.entityKind]="SQLiteColumnBuilder";foreignKeyConfigs=[];references(e,t={}){return this.foreignKeyConfigs.push({ref:e,actions:t}),this}unique(e){return this.config.isUnique=!0,this.config.uniqueName=e,this}generatedAlwaysAs(e,t){return this.config.generated={as:e,type:"always",mode:t?.mode??"virtual"},this}buildForeignKeys(e,t){return this.foreignKeyConfigs.map(({ref:i,actions:s})=>{let r;return r=new p(()=>({columns:[e],foreignColumns:[i()]})),s.onUpdate&&r.onUpdate(s.onUpdate),s.onDelete&&r.onDelete(s.onDelete),r.build(t)})}},b=class extends h.Column{static [i.entityKind]="SQLiteColumn";table;constructor(e,t){super(e,t),this.table=e}};function q(e){let t="";for(let i=0;i<e.length;i+=2)t+=String.fromCodePoint(Number.parseInt(e.slice(i,i+2),16));return t}e.s(["SQLiteColumn",0,b,"SQLiteColumnBuilder",0,g],100849);var S=class extends g{static [i.entityKind]="SQLiteBigIntBuilder";constructor(e){super(e,"bigint int64","SQLiteBigInt")}build(e){return new w(e,this.config)}},w=class extends b{static [i.entityKind]="SQLiteBigInt";getSQLType(){return"blob"}mapFromDriverValue=e=>"string"==typeof e?BigInt(q(e)):"u">typeof Buffer&&Buffer.from?BigInt((Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):e.buffer?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e)).toString("utf8")):BigInt(d.decode(e));mapToDriverValue=e=>Buffer.from(e.toString())},$=class extends g{static [i.entityKind]="SQLiteBlobJsonBuilder";constructor(e){super(e,"object json","SQLiteBlobJson")}build(e){return new v(e,this.config)}},v=class extends b{static [i.entityKind]="SQLiteBlobJson";getSQLType(){return"blob"}mapFromDriverValue=e=>"string"==typeof e?JSON.parse(q(e)):"u">typeof Buffer&&Buffer.from?JSON.parse((Buffer.isBuffer(e)?e:e instanceof ArrayBuffer?Buffer.from(e):e.buffer?Buffer.from(e.buffer,e.byteOffset,e.byteLength):Buffer.from(e)).toString("utf8")):JSON.parse(d.decode(e));mapToDriverValue=e=>Buffer.from(JSON.stringify(e))},Q=class extends g{static [i.entityKind]="SQLiteBlobBufferBuilder";constructor(e){super(e,"object buffer","SQLiteBlobBuffer")}build(e){return new x(e,this.config)}},x=class extends b{static [i.entityKind]="SQLiteBlobBuffer";mapFromDriverValue=e=>Buffer.isBuffer(e)?e:"string"==typeof e?Buffer.from(e,"hex"):Buffer.from(e);getSQLType(){return"blob"}};function N(e,t){let{name:i,config:s}=c(e,t);return s?.mode==="bigint"?new S(i):s?.mode==="buffer"?new Q(i):new $(i)}var L=class extends g{static [i.entityKind]="SQLiteCustomColumnBuilder";constructor(e,t,i){super(e,"custom","SQLiteCustomColumn"),this.config.fieldConfig=t,this.config.customTypeParams=i}build(e){return new T(e,this.config)}},T=class extends b{static [i.entityKind]="SQLiteCustomColumn";sqlName;mapTo;mapFrom;mapJson;forJsonSelect;constructor(e,t){super(e,t),this.sqlName=t.customTypeParams.dataType(t.fieldConfig),this.mapTo=t.customTypeParams.toDriver,this.mapFrom=t.customTypeParams.fromDriver,this.mapJson=t.customTypeParams.fromJson,this.forJsonSelect=t.customTypeParams.forJsonSelect}getSQLType(){return this.sqlName}mapFromDriverValue=e=>"function"==typeof this.mapFrom?this.mapFrom(e):e;mapFromJsonValue(e){return"function"==typeof this.mapJson?this.mapJson(e):this.mapFromDriverValue(e)}jsonSelectIdentifier(e,t){if("function"==typeof this.forJsonSelect)return this.forJsonSelect(e,t);let i=this.getSQLType().toLowerCase(),s=i.indexOf("(");switch(s+1?i.slice(0,s):i){case"numeric":case"decimal":case"bigint":return t`cast(${e} as text)`;case"blob":return t`hex(${e})`;default:return e}}mapToDriverValue=e=>"function"==typeof this.mapTo?this.mapTo(e):e};function C(e){return(t,i)=>{let{name:s,config:r}=c(t,i);return new L(s,r,e)}}var _=class extends g{static [i.entityKind]="SQLiteBaseIntegerBuilder";constructor(e,t,i){super(e,t,i),this.config.autoIncrement=!1}primaryKey(e){return e?.autoIncrement&&(this.config.autoIncrement=!0),this.config.hasDefault=!0,super.primaryKey()}},A=class extends b{static [i.entityKind]="SQLiteBaseInteger";autoIncrement=this.config.autoIncrement;getSQLType(){return"integer"}},j=class extends _{static [i.entityKind]="SQLiteIntegerBuilder";constructor(e){super(e,"number int53","SQLiteInteger")}build(e){return new B(e,this.config)}},B=class extends A{static [i.entityKind]="SQLiteInteger"},F=class extends _{static [i.entityKind]="SQLiteTimestampBuilder";constructor(e,t){super(e,"object date","SQLiteTimestamp"),this.config.mode=t}defaultNow(){return this.default(n.sql`(cast((julianday('now') - 2440587.5)*86400000 as integer))`)}build(e){return new K(e,this.config)}},K=class extends A{static [i.entityKind]="SQLiteTimestamp";mode=this.config.mode;mapFromDriverValue=e=>new Date("string"==typeof e?e.replaceAll('"',""):"timestamp"===this.config.mode?1e3*e:e);mapToDriverValue=e=>{if("number"==typeof e)return e;let t=e.getTime();return"timestamp"===this.config.mode?Math.floor(t/1e3):t}},D=class extends _{static [i.entityKind]="SQLiteBooleanBuilder";constructor(e,t){super(e,"boolean","SQLiteBoolean"),this.config.mode=t}build(e){return new k(e,this.config)}},k=class extends A{static [i.entityKind]="SQLiteBoolean";mode=this.config.mode;mapFromDriverValue=e=>1===Number(e);mapToDriverValue=e=>+!!e};function O(e,t){let{name:i,config:s}=c(e,t);return s?.mode==="timestamp"||s?.mode==="timestamp_ms"?new F(i,s.mode):s?.mode==="boolean"?new D(i,s.mode):new j(i)}e.s(["int",0,O,"integer",0,O],937540);var P=class extends g{static [i.entityKind]="SQLiteNumericBuilder";constructor(e){super(e,"string numeric","SQLiteNumeric")}build(e){return new V(e,this.config)}},V=class extends b{static [i.entityKind]="SQLiteNumeric";mapFromDriverValue=e=>"string"==typeof e?e:String(e);getSQLType(){return"numeric"}},I=class extends g{static [i.entityKind]="SQLiteNumericNumberBuilder";constructor(e){super(e,"number","SQLiteNumericNumber")}build(e){return new J(e,this.config)}},J=class extends b{static [i.entityKind]="SQLiteNumericNumber";mapFromDriverValue=e=>"number"==typeof e?e:Number(e);mapToDriverValue=String;getSQLType(){return"numeric"}},E=class extends g{static [i.entityKind]="SQLiteNumericBigIntBuilder";constructor(e){super(e,"bigint int64","SQLiteNumericBigInt")}build(e){return new z(e,this.config)}},z=class extends b{static [i.entityKind]="SQLiteNumericBigInt";mapFromDriverValue=BigInt;mapToDriverValue=String;getSQLType(){return"numeric"}};function U(e,t){let{name:i,config:s}=c(e,t),r=s?.mode;return"number"===r?new I(i):"bigint"===r?new E(i):new P(i)}var M=class extends g{static [i.entityKind]="SQLiteRealBuilder";constructor(e){super(e,"number double","SQLiteReal")}build(e){return new R(e,this.config)}},R=class extends b{static [i.entityKind]="SQLiteReal";getSQLType(){return"real"}};function W(e){return new M(e??"")}var G=class extends g{static [i.entityKind]="SQLiteTextBuilder";constructor(e,t){super(e,t.enum?.length?"string enum":"string","SQLiteText"),this.config.enumValues=t.enum,this.config.length=t.length}build(e){return new H(e,this.config)}},H=class extends b{static [i.entityKind]="SQLiteText";enumValues=this.config.enumValues;constructor(e,t){super(e,t)}getSQLType(){return`text${this.config.length?`(${this.config.length})`:""}`}},Z=class extends g{static [i.entityKind]="SQLiteTextJsonBuilder";constructor(e){super(e,"object json","SQLiteTextJson")}build(e){return new Y(e,this.config)}},Y=class extends b{static [i.entityKind]="SQLiteTextJson";getSQLType(){return"text"}mapFromDriverValue=e=>JSON.parse(e);mapToDriverValue=e=>JSON.stringify(e)};function X(e,t={}){let{name:i,config:s}=c(e,t);return"json"===s.mode?new Z(i):new G(i,s)}e.s(["text",0,X],380568);var ee=r;function et(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).map(e=>e.toLowerCase()).join("_")}function ei(e){return(e.replace(/['\u2019]/g,"").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g)??[]).reduce((e,t,i)=>e+(0===i?t.toLowerCase():`${t[0].toUpperCase()}${t.slice(1)}`),"")}let es=Symbol.for("drizzle:SQLiteInlineForeignKeys");var er=class extends ee.Table{static [i.entityKind]="SQLiteTable";static Symbol=Object.assign({},ee.Table.Symbol,{InlineForeignKeys:es});[ee.Table.Symbol.Columns];[es]=[];[ee.Table.Symbol.ExtraConfigBuilder]=void 0};let en=(t=void 0,(e,i,s)=>(function(e,t,i,s,r,n=e){let l="snake_case"===r?et:"camelCase"===r?ei:e=>e,a=new er(e,s,n),o=Object.fromEntries(Object.entries("function"==typeof t?t({blob:N,customType:C,integer:O,numeric:U,real:W,text:X}):t).map(([e,t])=>{t.setName(e,l);let i=t.build(a).postBuild();return a[es].push(...t.buildForeignKeys(i,a)),[e,i]})),u=Object.assign(a,o);return u[ee.Table.Symbol.Columns]=o,u[ee.Table.Symbol.ExtraConfigColumns]=o,i&&(u[er.Symbol.ExtraConfigBuilder]=i),u})(e,i,s,void 0,t));e.s(["SQLiteTable",0,er,"sqliteTable",0,en],75799);var el=class{static [i.entityKind]="SQLiteIndexBuilderOn";constructor(e,t){this.name=e,this.unique=t}on(...e){return new ea(this.name,e,this.unique)}},ea=class{static [i.entityKind]="SQLiteIndexBuilder";config;constructor(e,t,i){this.config={name:e,columns:t,unique:i,where:void 0}}where(e){return this.config.where=e,this}build(e){return new eo(this.config,e)}},eo=class{static [i.entityKind]="SQLiteIndex";config;isNameExplicit;constructor(e,t){this.config={...e,table:t},this.isNameExplicit=!!e.name}};e.s(["IndexBuilder",0,ea,"index",0,function(e){return new el(e,!1)}],646683);var eu=class{static [i.entityKind]="SQLitePrimaryKeyBuilder";columns;name;constructor(e,t){this.columns=e,this.name=t}build(e){return new ec(e,this.columns,this.name)}},ec=class{static [i.entityKind]="SQLitePrimaryKey";columns;name;isNameExplicit;constructor(e,t,i){this.table=e,this.columns=t,this.name=i,this.isNameExplicit=!!i}getName(){return this.name??`${this.table[er.Symbol.Name]}_${this.columns.map(e=>e.name).join("_")}_pk`}};e.s(["PrimaryKeyBuilder",0,eu,"primaryKey",0,function(...e){return e[0].columns?new eu(e[0].columns,e[0].name):new eu(e)}],201440);var ed=class{static [i.entityKind]="SQLiteUniqueConstraintBuilder";columns;constructor(e,t){this.name=t,this.columns=e}build(e){return new ef(e,this.columns,this.name)}},eh=class{static [i.entityKind]="SQLiteUniqueOnConstraintBuilder";name;constructor(e){this.name=e}on(...e){return new ed(e,this.name)}},ef=class{static [i.entityKind]="SQLiteUniqueConstraint";columns;name;isNameExplicit;constructor(e,t,i){this.table=e,this.columns=t,this.isNameExplicit=!!i,this.name=i??function(e,t){return`${e[m.TableName]}_${t.join("_")}_unique`}(this.table,this.columns.map(e=>e.name))}getName(){return this.name}};e.s(["UniqueConstraintBuilder",0,ed,"unique",0,function(e){return new eh(e)}],616918)}];
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=_1_5mnq4._.js.map
|