better-supabase 0.34.0 → 0.36.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/dist/{adapter-CWzyKepA.js → adapter-ddQ9Hzka.js} +126 -91
- package/dist/{agents-DXiOPB3V.d.ts → agents-BwUHtvD6.d.ts} +4 -4
- package/dist/{ai-cache-CLiAXCPH.d.ts → ai-cache-CPOP2PYz.d.ts} +4 -4
- package/dist/{ai-chat-DlcBdOhJ.d.ts → ai-chat-BZhfCHHr.d.ts} +106 -25
- package/dist/{ai-schedules-Drx2KRTn.d.ts → ai-schedules-BZPmySUa.d.ts} +5 -5
- package/dist/ai-sdk/agents/index.d.ts +6 -6
- package/dist/ai-sdk/batches/index.d.ts +3 -3
- package/dist/ai-sdk/cache/index.d.ts +1 -1
- package/dist/ai-sdk/chat/index.d.ts +2 -2
- package/dist/ai-sdk/chat/index.js +3 -272
- package/dist/ai-sdk/embeddings/index.d.ts +2 -2
- package/dist/ai-sdk/files/index.d.ts +1 -1
- package/dist/ai-sdk/index.d.ts +5 -5
- package/dist/ai-sdk/index.js +2 -3
- package/dist/ai-sdk/mcp/index.d.ts +3 -3
- package/dist/ai-sdk/memory/index.d.ts +3 -3
- package/dist/ai-sdk/workflow/index.d.ts +6 -5
- package/dist/ai-sdk/workflow/index.js +9 -9
- package/dist/{api-myq2e9t5.d.ts → api-XEaCJbgv.d.ts} +5 -5
- package/dist/{api-keys-DbIbkGxx.d.ts → api-keys-C82fMru4.d.ts} +4 -4
- package/dist/{app-tables-Don-aNOB.d.ts → app-tables-C0XVpQEJ.d.ts} +1 -1
- package/dist/{approvals-Da4uAANx.js → approvals-D8gR1R8R.js} +95 -11
- package/dist/{approvals-DZoGtNFv.d.ts → approvals-DqCv7f-G.d.ts} +101 -7
- package/dist/{assistant-BEbRPjhn.d.ts → assistant-5heV2GeR.d.ts} +7 -3
- package/dist/assistant-BHZ6fqBR.js +300 -0
- package/dist/astro/index.d.ts +7 -7
- package/dist/astro/index.js +5 -5
- package/dist/{auth-module-CqXdm8qD.js → auth-module-DkqapRZJ.js} +1 -1
- package/dist/{authorization-DpVtxuKM.d.ts → authorization-2Rv1AJQJ.d.ts} +151 -39
- package/dist/{authorization-hooks-CxwsRnfV.d.ts → authorization-hooks-C0GfMvFm.d.ts} +8 -2
- package/dist/authz-topic-D7fPUY4P.js +13 -0
- package/dist/{automations-Bw5cX7oj.js → automations-D4QTP8nI.js} +2 -1
- package/dist/{availability-CebEOfMN.d.ts → availability-CZlcrkqD.d.ts} +49 -8
- package/dist/{base64-CVyKHBBw.js → base64-CEBz6-Jj.js} +9 -2
- package/dist/better-result/index.d.ts +3 -3
- package/dist/{bind-BA05aoY9.d.ts → bind-C2XvMlfg.d.ts} +7 -7
- package/dist/{block-env-UX42PHLP.d.ts → block-env-BQrtLPyc.d.ts} +4 -4
- package/dist/{block-helpers-disoUWCp.d.ts → block-helpers-BNtM1tqy.d.ts} +1 -1
- package/dist/{block-hooks-DrA_d1dJ.d.ts → block-hooks-CtMsgLQr.d.ts} +2 -2
- package/dist/{block-subjects-Br2MQNFn.d.ts → block-subjects-Bkieh2Xk.d.ts} +1 -1
- package/dist/{block-tables-Bre1zjau.d.ts → block-tables-DPOgnT3y.d.ts} +1 -1
- package/dist/{block-transport-BEtC_Kis.d.ts → block-transport-CDmOUuLZ.d.ts} +2 -2
- package/dist/blocks/access-requests/index.d.ts +5 -5
- package/dist/blocks/activities/index.d.ts +9 -9
- package/dist/blocks/agents/index.d.ts +4 -4
- package/dist/blocks/ai-cache/index.d.ts +3 -3
- package/dist/blocks/ai-chat/index.d.ts +8 -8
- package/dist/blocks/ai-chat/index.js +80 -20
- package/dist/blocks/ai-files/index.d.ts +3 -3
- package/dist/blocks/ai-keys/index.d.ts +4 -4
- package/dist/blocks/ai-schedules/index.d.ts +3 -3
- package/dist/blocks/announcements/index.d.ts +8 -8
- package/dist/blocks/api-keys/index.d.ts +3 -3
- package/dist/blocks/approvals/index.d.ts +16 -5
- package/dist/blocks/approvals/index.js +7 -4
- package/dist/blocks/assets/index.d.ts +6 -6
- package/dist/blocks/assignment/index.d.ts +7 -7
- package/dist/blocks/attachments/index.d.ts +4 -4
- package/dist/blocks/audit/index.d.ts +13 -13
- package/dist/blocks/audit/index.js +1 -1
- package/dist/blocks/automations/index.d.ts +12 -12
- package/dist/blocks/billable-time/index.d.ts +6 -6
- package/dist/blocks/billing/index.d.ts +9 -9
- package/dist/blocks/billing/index.js +1 -1
- package/dist/blocks/bookings/index.d.ts +6 -6
- package/dist/blocks/bulk/index.d.ts +4 -4
- package/dist/blocks/calendar/index.d.ts +46 -8
- package/dist/blocks/calendar/index.js +306 -47
- package/dist/blocks/catalog/index.d.ts +52 -15
- package/dist/blocks/catalog/index.js +53 -18
- package/dist/blocks/channels/index.d.ts +7 -7
- package/dist/blocks/collections/index.d.ts +6 -6
- package/dist/blocks/comments/index.d.ts +10 -10
- package/dist/blocks/compliance/index.d.ts +5 -5
- package/dist/blocks/connectors/index.d.ts +4 -4
- package/dist/blocks/contacts/index.d.ts +6 -6
- package/dist/blocks/content/index.d.ts +5 -5
- package/dist/blocks/contracts/index.d.ts +6 -6
- package/dist/blocks/courses/index.d.ts +5 -5
- package/dist/blocks/created-by/index.d.ts +2 -2
- package/dist/blocks/custom-fields/index.d.ts +6 -6
- package/dist/blocks/data-lifecycle/index.d.ts +8 -8
- package/dist/blocks/deals/index.d.ts +6 -6
- package/dist/blocks/deals/index.js +1 -1
- package/dist/blocks/dispatch/index.d.ts +6 -6
- package/dist/blocks/documents/index.d.ts +4 -4
- package/dist/blocks/documents/index.js +1 -1
- package/dist/blocks/domains/index.d.ts +6 -6
- package/dist/blocks/donations/index.d.ts +6 -6
- package/dist/blocks/drive/index.d.ts +6 -6
- package/dist/blocks/employees/index.d.ts +8 -8
- package/dist/blocks/enrichment/index.d.ts +6 -6
- package/dist/blocks/enrollments/index.d.ts +74 -9
- package/dist/blocks/enrollments/index.js +67 -3
- package/dist/blocks/entitlements/index.d.ts +6 -6
- package/dist/blocks/expenses/index.d.ts +93 -6
- package/dist/blocks/expenses/index.js +95 -4
- package/dist/blocks/field-history/index.d.ts +4 -4
- package/dist/blocks/flags/index.d.ts +5 -5
- package/dist/blocks/forecasts/index.d.ts +6 -6
- package/dist/blocks/forms/index.d.ts +6 -6
- package/dist/blocks/goals/index.d.ts +4 -4
- package/dist/blocks/guests/index.d.ts +6 -6
- package/dist/blocks/hiring/index.d.ts +6 -6
- package/dist/blocks/identities/index.d.ts +5 -5
- package/dist/blocks/imports/index.d.ts +5 -5
- package/dist/blocks/inbox/index.d.ts +11 -11
- package/dist/blocks/inbox/index.js +56 -1
- package/dist/blocks/incidents/index.d.ts +5 -5
- package/dist/blocks/index.d.ts +9 -9
- package/dist/blocks/inventory/index.d.ts +6 -6
- package/dist/blocks/invoices/index.d.ts +30 -10
- package/dist/blocks/invoices/index.js +28 -9
- package/dist/blocks/knowledge/index.d.ts +4 -4
- package/dist/blocks/knowledge/index.js +1 -1
- package/dist/blocks/lead-scoring/index.d.ts +7 -7
- package/dist/blocks/leases/index.d.ts +6 -6
- package/dist/blocks/leave/index.d.ts +88 -15
- package/dist/blocks/leave/index.js +65 -14
- package/dist/blocks/ledger/index.d.ts +6 -6
- package/dist/blocks/mail-sync/index.d.ts +5 -5
- package/dist/blocks/memberships/index.d.ts +2 -2
- package/dist/blocks/memory/index.d.ts +5 -5
- package/dist/blocks/memory/index.js +30 -5
- package/dist/blocks/messaging/index.d.ts +11 -11
- package/dist/blocks/metrics/index.d.ts +6 -6
- package/dist/blocks/mfa/index.d.ts +2 -2
- package/dist/blocks/moderation/index.d.ts +6 -6
- package/dist/blocks/notifications/index.d.ts +11 -11
- package/dist/blocks/notifications/index.js +1 -1
- package/dist/blocks/numbering/index.d.ts +4 -4
- package/dist/blocks/oauth-server/index.d.ts +5 -5
- package/dist/blocks/oauth-server/index.js +1 -1
- package/dist/blocks/onboarding/index.d.ts +5 -5
- package/dist/blocks/orders/index.d.ts +7 -7
- package/dist/blocks/organizations/index.d.ts +8 -8
- package/dist/blocks/outbox/index.d.ts +4 -4
- package/dist/blocks/outbox/index.js +1 -1
- package/dist/blocks/passes/index.d.ts +8 -8
- package/dist/blocks/passes/index.js +2 -2
- package/dist/blocks/permissions/index.d.ts +7 -7
- package/dist/blocks/pipelines/index.d.ts +6 -6
- package/dist/blocks/posts/index.d.ts +5 -5
- package/dist/blocks/profiles/index.d.ts +4 -4
- package/dist/blocks/promotions/index.d.ts +5 -5
- package/dist/blocks/push/index.d.ts +7 -7
- package/dist/blocks/queue/index.d.ts +6 -6
- package/dist/blocks/queue/index.js +2 -2
- package/dist/blocks/quotes/index.d.ts +119 -27
- package/dist/blocks/quotes/index.js +112 -18
- package/dist/blocks/rank/index.d.ts +4 -4
- package/dist/blocks/reactions/index.d.ts +9 -9
- package/dist/blocks/relations/index.d.ts +7 -7
- package/dist/blocks/reminders/index.d.ts +78 -11
- package/dist/blocks/reminders/index.js +118 -6
- package/dist/blocks/reviews/index.d.ts +5 -5
- package/dist/blocks/saved-views/index.d.ts +6 -6
- package/dist/blocks/scores/index.d.ts +5 -5
- package/dist/blocks/search/index.d.ts +7 -7
- package/dist/blocks/security-events/index.d.ts +7 -7
- package/dist/blocks/security-events/index.js +1 -1
- package/dist/blocks/segments/index.d.ts +7 -7
- package/dist/blocks/sequences/index.d.ts +6 -6
- package/dist/blocks/service-accounts/index.d.ts +5 -5
- package/dist/blocks/sessions/index.d.ts +2 -2
- package/dist/blocks/sessions/index.js +1 -1
- package/dist/blocks/settings/index.d.ts +6 -6
- package/dist/blocks/share-links/index.d.ts +5 -5
- package/dist/blocks/shipments/index.d.ts +6 -6
- package/dist/blocks/shipments/index.js +1 -1
- package/dist/blocks/signatures/index.d.ts +5 -5
- package/dist/blocks/signing-keys/index.d.ts +4 -4
- package/dist/blocks/signing-keys/index.js +2 -2
- package/dist/blocks/sla/index.d.ts +7 -7
- package/dist/blocks/sso/index.d.ts +6 -6
- package/dist/blocks/state-machine/index.d.ts +27 -7
- package/dist/blocks/state-machine/index.js +7 -2
- package/dist/blocks/subjects/index.d.ts +6 -6
- package/dist/blocks/tags/index.d.ts +6 -6
- package/dist/blocks/tasks/index.d.ts +9 -9
- package/dist/blocks/teams/index.d.ts +4 -4
- package/dist/blocks/templates/index.d.ts +7 -7
- package/dist/blocks/time-tracking/index.d.ts +7 -7
- package/dist/blocks/time-tracking/index.js +1 -1
- package/dist/blocks/timeline/index.d.ts +8 -8
- package/dist/blocks/trash/index.d.ts +6 -6
- package/dist/blocks/undo/index.d.ts +4 -4
- package/dist/blocks/updated-at/index.d.ts +2 -2
- package/dist/blocks/usage/index.d.ts +4 -4
- package/dist/blocks/vercel-marketplace/index.d.ts +5 -5
- package/dist/blocks/vercel-marketplace/index.js +3 -3
- package/dist/blocks/versions/index.d.ts +6 -6
- package/dist/blocks/waitlist/index.d.ts +5 -5
- package/dist/blocks/waitlist/index.js +1 -1
- package/dist/blocks/webhooks/index.d.ts +13 -13
- package/dist/blocks/webhooks/index.js +5 -5
- package/dist/blocks/workflow-editor/index.d.ts +10 -10
- package/dist/blocks/workflow-editor/index.js +65 -2
- package/dist/blocks/workflows/index.d.ts +7 -7
- package/dist/{bookings-Br0VXzaf.d.ts → bookings-Dj5cvXKv.d.ts} +4 -4
- package/dist/{bucket-DvG66r5G.d.ts → bucket-CrsJNHzi.d.ts} +1 -1
- package/dist/chat-sdk/index.d.ts +6 -6
- package/dist/claims/index.d.ts +6 -6
- package/dist/claims/index.js +2 -2
- package/dist/cli/{add-DoEtJhZG.js → add-D2CH8t_B.js} +2 -2
- package/dist/cli/add-De73Ghlh.js +1 -0
- package/dist/cli/{add-THXE7juv.js → add-Duf1-19E.js} +16 -14
- package/dist/cli/{agent-59XWXsRi.js → agent-Tqq3MAqx.js} +26 -1
- package/dist/cli/{app-table-files-BqLd5TuX.js → app-table-files-ha8X0rRE.js} +2 -2
- package/dist/cli/app-tables-BIyQcsHH.js +42 -0
- package/dist/cli/{backfill-D-2W0fNT.js → backfill-CLgA6-ll.js} +3 -3
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-BVU_FoLo.js → blocks-9AeouX4h.js} +2 -2
- package/dist/cli/{blocks-XwUHeyUH.js → blocks-BVB1fMMj.js} +1 -1
- package/dist/cli/{cache-D4nwCBXc.js → cache-aMk9vF1_.js} +1 -1
- package/dist/cli/{codemod-Dh4lf_k4.js → codemod-B5wrcnF2.js} +113 -4
- package/dist/cli/{command-BpZ4AuhR.js → command-DM_x_yzZ.js} +6 -0
- package/dist/cli/{completion-DHTT6rjI.js → completion-CusuUJNn.js} +1 -1
- package/dist/cli/{completion-B08Q0xB3.js → completion-Cx2UYd-y.js} +2 -2
- package/dist/cli/{completion-CwL7e93t.js → completion-DbYb3N8e.js} +2 -2
- package/dist/cli/{config-D-Upz3jV.js → config-BeuImpav.js} +1 -1
- package/dist/cli/{content-mapper-CwFH_PEn.js → content-mapper-CEtdbshU.js} +2 -2
- package/dist/cli/{db-Diy1OebO.js → db-CeiQzhPq.js} +2 -2
- package/dist/cli/{doctor-CyAMbZ_s.js → doctor-DaOUWfRN.js} +391 -54
- package/dist/cli/env-BfWbheiC.js +1 -0
- package/dist/cli/{env-BAJn6wCA.js → env-DVV10l_r.js} +1 -1
- package/dist/cli/{gen-EAUNnUY7.js → gen-BO-2NF-G.js} +14 -14
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +7 -7
- package/dist/cli/{init-BRmmmGHJ.js → init-Xit9Hnbb.js} +9 -9
- package/dist/cli/{keys-CxajkV_7.js → keys-DJTN2Avl.js} +1 -1
- package/dist/cli/{live-CV9mn-xC.js → live-CuMpyRjF.js} +2 -2
- package/dist/cli/{mcp-CnaxcLWa.js → mcp-C7d4j5cq.js} +4 -4
- package/dist/cli/{metadata-CFQGBR5E.js → metadata-D2YvkY2D.js} +3 -3
- package/dist/cli/{migrate-z5oHDGNs.js → migrate-BCXxyTKt.js} +2 -2
- package/dist/cli/{migration-safety-BtAPMEZa.js → migration-safety-DfwTOBQ4.js} +1 -1
- package/dist/cli/{migrations-CNa62JSi.js → migrations-nomh4TBo.js} +2 -2
- package/dist/cli/{module-migration-CKJ8kRm1.js → module-migration--9T_T-zt.js} +2 -2
- package/dist/cli/{moved-BAFPdJz_.js → moved-CT6i1csY.js} +1 -1
- package/dist/cli/{parse-BueItuNJ.js → parse-qgJylE_A.js} +1 -1
- package/dist/cli/{powersync-BgoAWeRT.js → powersync-DB9WZsIv.js} +4 -4
- package/dist/cli/powersync-IBM_v_eJ.js +1 -0
- package/dist/cli/{print-CoqKHoy0.js → print-S6IF5rZm.js} +2 -2
- package/dist/cli/{providers-CfbFxUOQ.js → providers-BDTcal71.js} +1 -1
- package/dist/cli/{prune-workflows-BigCoXLw.js → prune-workflows-Zr2DjByi.js} +3 -3
- package/dist/cli/{remove-C9zwn-Kk.js → remove-CPX5Tg5s.js} +6 -6
- package/dist/cli/{render-DQCU_kBW.js → render-Bp7a7XQ9.js} +18 -4
- package/dist/cli/{run-DOD00FFl.js → run-BclCFEyP.js} +13 -41
- package/dist/cli/{run-dY9uOC3W.js → run-BlVaLnt_.js} +2 -2
- package/dist/cli/{run-CVaBuT18.js → run-kgG50x_Z.js} +44 -43
- package/dist/cli/{seed-BpaqqyO8.js → seed-Cn2R91cd.js} +2 -2
- package/dist/cli/seed-DGGjReq4.js +1 -0
- package/dist/cli/{shared-COtj7l3r.js → shared-D60W9NS-.js} +1 -1
- package/dist/cli/{skills-jZThjL3B.js → skills-DH-yPDny.js} +1 -1
- package/dist/cli/{snapshot-BvlEmTB0.js → snapshot-C3_eQUgY.js} +2 -2
- package/dist/cli/{source-BhZRCitG.js → source-Bk6XwIAK.js} +1 -1
- package/dist/cli/{spec-Bo2wIViH.js → spec-BDTpcBns.js} +1 -1
- package/dist/cli/{spec-DsMWuJLv.js → spec-C8ydQwZC.js} +3 -3
- package/dist/cli/{sql-layout-CA7xgRjR.js → sql-layout-DVQ20UMi.js} +3 -3
- package/dist/cli/{stack-147NqctC.js → stack-CmhSfY5V.js} +3 -2
- package/dist/cli/{sync-D9xSGdzO.js → sync-D-WO4Yvl.js} +4 -4
- package/dist/cli/{table-D9FbJS8h.js → table-k5OABwy3.js} +1 -1
- package/dist/cli/{upgrade-Ykf0LLEB.js → upgrade-DGe5Pv6v.js} +5 -5
- package/dist/cli/{upgrade-XK_CQKVJ.js → upgrade-XdhMuHAu.js} +3 -3
- package/dist/cli/{version-Dfdz7KSh.js → version-DKfeme2I.js} +1 -1
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js +1 -1
- package/dist/client/native/index.d.ts +5 -5
- package/dist/client/native/index.js +2 -2
- package/dist/{client-Bky2z09B.js → client-DrejIxsu.js} +1 -1
- package/dist/{cloud-event-DXWmXrus.d.ts → cloud-event-BEmAUdl1.d.ts} +1 -1
- package/dist/commerce/index.js +1 -1
- package/dist/{compiler-qlXlokKn.d.ts → compiler-BOW4yPcW.d.ts} +2 -2
- package/dist/{composite-CIxjVcL1.d.ts → composite-B-oAH16L.d.ts} +7 -7
- package/dist/{composite-D2JnIiHt.js → composite-BidYZWZY.js} +3 -3
- package/dist/config/index.d.ts +3 -3
- package/dist/config/index.js +4 -4
- package/dist/{config-Bu6pwqcO.js → config-BKxjItQ-.js} +3 -3
- package/dist/{config-MDRA2sre.js → config-BrRlSxhx.js} +1 -1
- package/dist/{connectors-Cf2LeAuZ.d.ts → connectors-CrLRW4Ol.d.ts} +4 -4
- package/dist/{context-BGC0J3t9.d.ts → context-yfOlyAqb.d.ts} +3 -3
- package/dist/contract/index.d.ts +9 -9
- package/dist/{controller-CQrkLoRX.d.ts → controller-CAcLEndc.d.ts} +1 -1
- package/dist/{conversion-C9rndpEI.d.ts → conversion-s1NtB6S-.d.ts} +1 -1
- package/dist/create/index.d.ts +3 -3
- package/dist/create/index.js +3 -3
- package/dist/create/lite/index.d.ts +4 -4
- package/dist/create/lite/index.js +2 -2
- package/dist/credentials/index.d.ts +4 -4
- package/dist/credentials/index.js +1 -1
- package/dist/{cron-route-DSITg1yC.js → cron-route-uTsC2BD0.js} +1 -1
- package/dist/{data-engine-CMENsp3d.d.ts → data-engine-CX1oYDZl.d.ts} +1 -1
- package/dist/{define-ITQA71fw.d.ts → define-BvkaC3Oh.d.ts} +5 -5
- package/dist/{define-B6D55cO0.js → define-Duh2mMYk.js} +1 -1
- package/dist/{define-block-COmMkx2x.d.ts → define-block-Ds3aLZwz.d.ts} +12 -12
- package/dist/{documents-DeZw83ue.d.ts → documents-Btk0MhC0.d.ts} +3 -3
- package/dist/edge/index.d.ts +9 -9
- package/dist/edge/index.js +7 -7
- package/dist/elysia/index.d.ts +1 -1
- package/dist/elysia/index.js +1 -1
- package/dist/{embeddings-rVR2AKVz.d.ts → embeddings-CI6P_mtD.d.ts} +1 -1
- package/dist/{ended-NC_ZesY4.d.ts → ended-iq2wp8fc.d.ts} +8 -3
- package/dist/{entitlements-BOWTZaRf.d.ts → entitlements-Dhu-4vlH.d.ts} +2 -2
- package/dist/env/index.d.ts +1 -1
- package/dist/{messages-CRk1g6oe.js → errors-0Qid9fGz.js} +107 -3
- package/dist/eve/index.d.ts +9 -9
- package/dist/eve/index.js +3 -3
- package/dist/{eve-DIKjuPp5.d.ts → eve-DleYrhwj.d.ts} +2 -2
- package/dist/{event-calendar-DUtFyRrv.d.ts → event-calendar-DPMcqy7Q.d.ts} +1 -1
- package/dist/events/index.d.ts +3 -3
- package/dist/{events-DVt3Z9hw.d.ts → events-DCw3c6pj.d.ts} +1 -1
- package/dist/{executor-DqNRrFxx.d.ts → executor-B-o7QMPp.d.ts} +16 -2
- package/dist/{executor-CFmee_nV.d.ts → executor-DoSNec_H.d.ts} +1 -1
- package/dist/{executor-CHnoKOxk.d.ts → executor-H8ZLkeHj.d.ts} +4 -4
- package/dist/{executor-BDMqPbVU.js → executor-RYiR4z47.js} +71 -37
- package/dist/expo/index.d.ts +4 -4
- package/dist/expo/index.js +7 -7
- package/dist/{field-errors-DxPZYw2m.d.ts → field-errors-DXZk9Qjt.d.ts} +10 -10
- package/dist/{fields-CAVk9dxX.d.ts → fields-CP46SPNE.d.ts} +1 -1
- package/dist/{filter-evaluate-Bz3Fzhz2.d.ts → filter-evaluate-Bkbb0nuQ.d.ts} +1 -1
- package/dist/{filter-query-DV-x8fio.d.ts → filter-query-Xj40B5KT.d.ts} +1 -1
- package/dist/{flags-6emyAXly.d.ts → flags-Cuew4tGx.d.ts} +2 -2
- package/dist/flags-sdk/index.d.ts +2 -2
- package/dist/{framework-BFlaPuvv.d.ts → framework-Byr_j8G-.d.ts} +8 -8
- package/dist/{framework-ChzJYkJW.js → framework-z3KTPRjk.js} +4 -4
- package/dist/{gateway-DaekJ_Me.d.ts → gateway-B9k89AC4.d.ts} +3 -3
- package/dist/h3/index.d.ts +1 -1
- package/dist/h3/index.js +1 -1
- package/dist/h3/v1/index.d.ts +1 -1
- package/dist/h3/v1/index.js +1 -1
- package/dist/hono/index.d.ts +9 -10
- package/dist/hono/index.js +8 -8
- package/dist/{inbox-DavCzW7b.d.ts → inbox-yGfUVQr2.d.ts} +61 -6
- package/dist/{index-Dvpu22CJ.d.ts → index-1uV69AZq.d.ts} +1 -1
- package/dist/{index-CJB50jzQ.d.ts → index-6H-8Ib1w.d.ts} +6 -6
- package/dist/{index-M1izbwbN.d.ts → index-Ag-T51Jl.d.ts} +1 -1
- package/dist/{index-DNAkWDXc.d.ts → index-BUluRi0b.d.ts} +6 -6
- package/dist/{index-QTZIopQj.d.ts → index-C78VPlXW.d.ts} +1 -1
- package/dist/{index-D18su_r5.d.ts → index-CY612vAg.d.ts} +10 -5
- package/dist/{index-BfU0KR0X.d.ts → index-CnzGRpeH.d.ts} +5 -5
- package/dist/{index-BIAtapnD.d.ts → index-Dbd1E5Au.d.ts} +5 -5
- package/dist/{index-Bhkag9ZE.d.ts → index-Dv6lfL5p.d.ts} +14 -14
- package/dist/{index-8w4OB5En.d.ts → index-F6lsRlsr.d.ts} +1 -1
- package/dist/{index-CeUwyJ3Z.d.ts → index-kkZwp5M1.d.ts} +6 -6
- package/dist/{index-Bz0WLuh_.d.ts → index-lMApFSAd.d.ts} +5 -5
- package/dist/index.d.ts +7 -7
- package/dist/index.js +1 -1
- package/dist/{instances-D31jrmKh.js → instances-xQ2lupVE.js} +246 -12
- package/dist/jwks-cache-CBKtICNV.js +114 -0
- package/dist/{jws-B8p0ppgh.js → jws-De9qjIPV.js} +1 -1
- package/dist/{kit-9pZP5iLU.js → kit-D5rRAKWJ.js} +2 -2
- package/dist/{kit-OgFOW9rX.d.ts → kit-DCuO1ZhB.d.ts} +4 -4
- package/dist/{knowledge-DdZzUTQ-.js → knowledge-CJnZOaix.js} +67 -7
- package/dist/{knowledge-BBC2sfAY.d.ts → knowledge-DWXAxvkN.d.ts} +82 -11
- package/dist/lint/index.d.ts +1 -1
- package/dist/list/index.d.ts +3 -3
- package/dist/{list-query-C7V8kUaD.d.ts → list-query-D1h3Dmnk.d.ts} +3 -3
- package/dist/mapper/bin.js +5 -5
- package/dist/mcp/index.d.ts +3 -3
- package/dist/mcp/index.js +5 -5
- package/dist/mcp/sdk/index.d.ts +6 -6
- package/dist/mcp/sdk/index.js +2 -2
- package/dist/{messaging-D5z2TR37.d.ts → messaging-Bfe4p9Pm.d.ts} +4 -4
- package/dist/{model-messages-BcrkjsPE.js → model-messages-CIHqP7Z3.js} +1 -1
- package/dist/nestjs/index.d.ts +2 -2
- package/dist/nestjs/index.js +1 -1
- package/dist/next/client/index.d.ts +1 -1
- package/dist/next/index.d.ts +331 -79
- package/dist/next/index.js +520 -105
- package/dist/node/index.d.ts +2 -2
- package/dist/node/index.js +1 -1
- package/dist/{operations-BG6prEnh.d.ts → operations-SWpzGC_K.d.ts} +1 -1
- package/dist/{options-D4dxMGHF.js → options-Bgnm4pTD.js} +1 -0
- package/dist/{options-C13-dVMH.js → options-D-jiqb0l.js} +2 -0
- package/dist/{options-DjFbIRgV.js → options-DjdxZgHi.js} +2 -1
- package/dist/{options-CgMiQGOF.js → options-DqmTs2nv.js} +4 -1
- package/dist/{options-C-NFS6e3.js → options-DxgZ8tVc.js} +2 -1
- package/dist/{options-CuPWezcV.js → options-RYbyaVhv.js} +3 -1
- package/dist/options-SOjQVgfS.js +37 -0
- package/dist/{options-JnPEVbBJ.js → options-ScQ6Hnxo.js} +2 -1
- package/dist/{options-Sq4bYbf5.js → options-X61tvckX.js} +4 -1
- package/dist/orpc/index.d.ts +8 -8
- package/dist/orpc/index.js +6 -6
- package/dist/otel/index.d.ts +2 -2
- package/dist/otel/index.js +4 -4
- package/dist/{outbox-7zgh-7nw.d.ts → outbox-BFZS6Kvz.d.ts} +4 -4
- package/dist/{permissions-CoHsUtZS.d.ts → permissions-2UlVQDzY.d.ts} +1 -1
- package/dist/{pool-D-4HyhuW.d.ts → pool-yO-LzZAd.d.ts} +3 -3
- package/dist/{ports-CmEXVqhg.js → ports-CkygVOeE.js} +2 -2
- package/dist/{ports-XvgCe7ey.d.ts → ports-prqYrReN.d.ts} +1 -1
- package/dist/postgres/index.d.ts +4 -4
- package/dist/{postgrest-DZtM2nIS.d.ts → postgrest-Bjain6nf.d.ts} +1 -1
- package/dist/powersync/index.d.ts +6 -6
- package/dist/preset/index.d.ts +3 -3
- package/dist/preset/index.js +3 -3
- package/dist/{preset-om2rbdYw.js → preset-BvHNleCo.js} +2 -2
- package/dist/{project-B7nqCzn5.js → project-CBvowdKY.js} +5 -5
- package/dist/{provider-BI0KC4u5.d.ts → provider-bIAzxVMB.d.ts} +1 -1
- package/dist/{push-token-kcc04ZaS.d.ts → push-token-DtqJeg8w.d.ts} +1 -1
- package/dist/query/index.d.ts +1 -1
- package/dist/{rate-limit-CRhlLFhP.js → rate-limit-BJ4EMdAy.js} +1 -1
- package/dist/react/index.d.ts +9 -9
- package/dist/react/index.js +3 -3
- package/dist/react/native/index.d.ts +1 -1
- package/dist/react/native/index.js +1 -1
- package/dist/react/server.d.ts +9 -9
- package/dist/react/server.js +2 -2
- package/dist/react/session.d.ts +2 -32
- package/dist/react/session.js +1 -37
- package/dist/{react-COIov1yC.js → react-DZ7AW2yf.js} +2 -2
- package/dist/react-router/index.d.ts +6 -6
- package/dist/react-router/index.js +5 -5
- package/dist/realtime/index.d.ts +6 -6
- package/dist/{record-form-DU2EoVsv.d.ts → record-form-BQA-lawE.d.ts} +1 -1
- package/dist/{recordings-D69Va7gP.d.ts → recordings-Bw5LoocX.d.ts} +1 -1
- package/dist/records/index.d.ts +9 -9
- package/dist/{refusal-CGi-0Q18.d.ts → refusal-BX1EvmpJ.d.ts} +3 -3
- package/dist/{refusal-5c6UMpUP.js → refusal-rnbr6RZD.js} +2 -2
- package/dist/{refresh-B8t_KE3s.js → request-kind-tNDM5Z_o.js} +15 -31
- package/dist/{resolve--LfVoOMg.d.ts → resolve-BIpQRhvF.d.ts} +97 -36
- package/dist/{resolve-FW8oeXvh.js → resolve-CZV31iCm.js} +402 -392
- package/dist/{resolved-names-DYYyh35i.js → resolved-names-b6P2--jK.js} +1 -1
- package/dist/{resource-BbWk4hoP.js → resource-COaS9_i8.js} +1 -1
- package/dist/{resource-DWllVW8k.d.ts → resource-CaYpB07K.d.ts} +1 -1
- package/dist/{resource-execute-DUBYKTYU.d.ts → resource-execute-A1NbR-sd.d.ts} +2 -2
- package/dist/{resource-types-RgaljPs0.d.ts → resource-types-CTcc37WL.d.ts} +4 -4
- package/dist/{resources-Bki1J4jy.d.ts → resources-13ZFX1G6.d.ts} +2 -2
- package/dist/{resources-DYSx9NYM.js → resources-DhiK3yLO.js} +1 -1
- package/dist/{respond-DLH4tD2d.js → respond-8A3EOo61.js} +1 -1
- package/dist/{respond-BYOV7KZp.d.ts → respond-CAxhkwAi.d.ts} +15 -19
- package/dist/{sales-lines-DuNVoKHA.d.ts → sales-lines-wQHuL-pa.d.ts} +1 -1
- package/dist/{sandboxes-B2hBoBvJ.d.ts → sandboxes-BF9RxxCU.d.ts} +1 -1
- package/dist/{scores-FAORS4qU.d.ts → scores-Ce8MxQX9.d.ts} +5 -5
- package/dist/server/index.d.ts +58 -36
- package/dist/server/index.js +35 -41
- package/dist/{server-types-C2hlvhP4.d.ts → server-types-DEjva0MW.d.ts} +19 -17
- package/dist/{session-B4VasaAA.d.ts → session-BA0YDmjt.d.ts} +11 -12
- package/dist/session-BjPYE4dT.js +180 -0
- package/dist/session-CeYL3EPm.d.ts +77 -0
- package/dist/{session-status-D8CBxCqv.d.ts → session-status-Df6tuKY9.d.ts} +4 -3
- package/dist/{sign-in-CX1a5i2P.d.ts → sign-in-4u4vLtXG.d.ts} +16 -4
- package/dist/{sign-in-CxdoTEp5.js → sign-in-djgvab1X.js} +3 -3
- package/dist/{sign-in-BMm1xhKq.js → sign-in-k2lXELeC.js} +2 -2
- package/dist/{signatures-CBn7w4VR.js → signatures-DK01D2S7.js} +1 -1
- package/dist/{signers-6ih6i9aq.d.ts → signers-Dw9DBZjJ.d.ts} +4 -4
- package/dist/{signing-keys-De09WNJ3.d.ts → signing-keys-FglIQ6iL.d.ts} +2 -2
- package/dist/{signing-keys-BC5_hJN5.js → signing-keys-sGaXklwD.js} +1 -1
- package/dist/{snapshot-CVMSyTHH.js → snapshot-BOA7lkRg.js} +9 -17
- package/dist/solid/index.d.ts +10 -10
- package/dist/solid/index.js +1 -1
- package/dist/solid-start/index.d.ts +6 -6
- package/dist/solid-start/index.js +5 -5
- package/dist/spec/index.d.ts +2 -2
- package/dist/sql/index.d.ts +5 -5
- package/dist/sql/index.js +3 -3
- package/dist/{sql-DdtukoIm.js → sql-BChN3Hxv.js} +7594 -2269
- package/dist/sqlite/index.d.ts +3 -3
- package/dist/{sso-CuzAjsc8.d.ts → sso-B7w7h8RJ.d.ts} +3 -3
- package/dist/ssr/index.d.ts +5 -6
- package/dist/ssr/index.js +3 -3
- package/dist/storage/index.d.ts +3 -3
- package/dist/storage/index.js +1 -1
- package/dist/streams/index.d.ts +1 -1
- package/dist/{subject-readers-BlD8tALG.d.ts → subject-readers-YL8H9G8X.d.ts} +2 -2
- package/dist/{subjects-Bv2dPflD.d.ts → subjects-CVjAE7nz.d.ts} +3 -3
- package/dist/{support-DxYI6sDM.d.ts → support-BwtMgjVg.d.ts} +4 -4
- package/dist/{support-view-DSmCett7.d.ts → support-view-GykHOIQ2.d.ts} +1 -1
- package/dist/svelte/index.d.ts +9 -9
- package/dist/svelte/index.js +1 -1
- package/dist/sveltekit/index.d.ts +7 -7
- package/dist/sveltekit/index.js +5 -5
- package/dist/{tags--k2fbPfO.d.ts → tags-CAfvzA1U.d.ts} +1 -1
- package/dist/tanstack-db/index.d.ts +3 -3
- package/dist/tanstack-start/index.d.ts +6 -6
- package/dist/tanstack-start/index.js +5 -5
- package/dist/{tenant-DkKbvK5T.d.ts → tenant-lBgoqg9T.d.ts} +1 -1
- package/dist/testing/index.d.ts +27 -28
- package/dist/testing/index.js +5 -5
- package/dist/{timeline-Bq658xsi.d.ts → timeline-CrO48Qa6.d.ts} +5 -5
- package/dist/{topic-B6zuexk7.d.ts → topic-x-mrN_Ff.d.ts} +5 -5
- package/dist/{types-C8UyJOPJ.d.ts → types-6PMaLIyw.d.ts} +3 -3
- package/dist/{types-Dh2OGEW5.d.ts → types-BdhE7I8Z.d.ts} +5 -5
- package/dist/{types-BkYEUWdz.d.ts → types-BzIYSSWK.d.ts} +16 -1
- package/dist/{types-DCoqai8o.d.ts → types-C7K8mu9B.d.ts} +45 -15
- package/dist/{types-d0JBRTAg.d.ts → types-C9XfFGmA.d.ts} +128 -13
- package/dist/{types-BvHw2cCS.d.ts → types-CJqNGQKb.d.ts} +2 -2
- package/dist/{types-TH3zlMiM.d.ts → types-D5uf0l4_.d.ts} +1 -1
- package/dist/{types-BBqP9H6w.d.ts → types-auvHrNWC.d.ts} +4 -4
- package/dist/{undo-22ofP6Zp.d.ts → undo-CdKp5_2X.d.ts} +2 -2
- package/dist/{usage-CNCT6_3D.d.ts → usage-DZ8j5Tm_.d.ts} +4 -4
- package/dist/{vault-yGQD5Rdl.d.ts → vault-DjbG4XQS.d.ts} +2 -2
- package/dist/vercel-connect/index.d.ts +1 -1
- package/dist/vercel-sandbox/index.d.ts +2 -2
- package/dist/{verify-DY_j4GPZ.js → verify-96j8d5ps.js} +1 -1
- package/dist/{verify-BQu3eBNW.d.ts → verify-HOiu3lRR.d.ts} +2 -2
- package/dist/{view-BfEqjZJ_.js → view-Ch0Qtr36.js} +1 -1
- package/dist/{view-Cy2XxYp1.d.ts → view-DdDY88SC.d.ts} +1 -1
- package/dist/vue/index.d.ts +10 -10
- package/dist/vue/index.js +1 -1
- package/dist/{watch-topic-YYSVJGDY.d.ts → watch-topic-D6bcqOrJ.d.ts} +1 -1
- package/dist/workflow-sdk/builder/index.d.ts +29 -5
- package/dist/workflow-sdk/builder/index.js +39 -12
- package/dist/workflow-sdk/index.d.ts +1 -1
- package/dist/workflow-sdk/index.js +2 -2
- package/dist/workflow-sdk/world/index.d.ts +1 -1
- package/dist/workflow-sdk/world/index.js +1 -1
- package/dist/{workflow-sdk-BL3wzkdp.js → workflow-sdk-CBS8L2Ku.js} +5 -0
- package/dist/{workflow-sdk-yIkECybp.d.ts → workflow-sdk-D3H10W5h.d.ts} +3 -3
- package/dist/{workflows-BljkWRxE.d.ts → workflows-BI4yKqFh.d.ts} +3 -3
- package/dist/yjs/index.d.ts +2 -2
- package/dist/yjs/index.js +1 -1
- package/package.json +1 -1
- package/schemas/config-v1.json +162 -0
- package/schemas/doctor-report-v1.json +4 -0
- package/skills/better-supabase-auth/SKILL.md +45 -11
- package/dist/cli/add-C13ZqJ_N.js +0 -1
- package/dist/cli/env-UN6PJFX6.js +0 -1
- package/dist/cli/powersync-DoCruiOt.js +0 -1
- package/dist/cli/seed-ByLneY1H.js +0 -1
- package/dist/errors-D3-4c-XF.js +0 -102
- package/dist/http-BDC1IvBX.js +0 -27
- package/dist/jwks-cache-IZaiICAV.js +0 -48
- package/dist/options-Itq7QYoW.js +0 -20
- package/dist/refresh-BtbC2rZe.d.ts +0 -52
- package/dist/snapshot-BGsJw9xn.d.ts +0 -83
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
import { n as dbError } from "./errors-B7tCfCvX.js";
|
|
2
|
+
import { n as isRecord } from "./guards-CsRa6v57.js";
|
|
2
3
|
import { r as err, t as AsyncResult } from "./result-8xza7w5W.js";
|
|
3
|
-
import { A as recordsOf, L as textOf, O as recordOf, j as requiredInstant, n as applyTemporal, o as blockCall, w as optionalText } from "./block-helpers-I7UzjNEf.js";
|
|
4
|
+
import { A as recordsOf, L as textOf, O as recordOf, P as sha256Hex, j as requiredInstant, n as applyTemporal, o as blockCall, w as optionalText } from "./block-helpers-I7UzjNEf.js";
|
|
4
5
|
import { r as withBlockHooks } from "./block-hooks-CadxQ9-_.js";
|
|
5
6
|
import { c as withFields, n as blockFields, r as extraFieldsArg, t as allWithFields } from "./block-fields-Bjcv6_zc.js";
|
|
6
7
|
import { i as subjectRefOf } from "./block-subjects-cRlVtKDO.js";
|
|
7
8
|
import { t as requireTenant } from "./block-tenant-Bun03JuO.js";
|
|
8
9
|
// src/blocks/approvals/approvals.ts
|
|
10
|
+
/**
|
|
11
|
+
* Serializes `value` with object keys sorted and no whitespace. It is stable
|
|
12
|
+
* for JSON values; `undefined` members are dropped as `JSON.stringify` does.
|
|
13
|
+
*/
|
|
14
|
+
function canonicalJson(value) {
|
|
15
|
+
if (Array.isArray(value)) return `[${value.map((item) => item === void 0 ? "null" : canonicalJson(item)).join(",")}]`;
|
|
16
|
+
if (typeof value === "object" && value !== null) return `{${Object.entries(value).filter(([, item]) => item !== void 0).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => `${JSON.stringify(key)}:${canonicalJson(item)}`).join(",")}}`;
|
|
17
|
+
return value === void 0 ? "null" : JSON.stringify(value);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The hex SHA-256 of `value` as sorted-key JSON, for `request` and `consume`.
|
|
21
|
+
* Pass the exact operation the approval covers (for example the subject, the
|
|
22
|
+
* action and its arguments) so an approval for one change can't run another.
|
|
23
|
+
*/
|
|
24
|
+
function approvalFingerprint(value) {
|
|
25
|
+
return sha256Hex(canonicalJson(value));
|
|
26
|
+
}
|
|
9
27
|
const STATUSES = [
|
|
10
28
|
"pending",
|
|
11
29
|
"approved",
|
|
@@ -38,13 +56,20 @@ function approversOf(value) {
|
|
|
38
56
|
...permission === void 0 ? {} : { permission },
|
|
39
57
|
...role === void 0 ? {} : { role },
|
|
40
58
|
...team === void 0 ? {} : { team },
|
|
41
|
-
...Array.isArray(row["users"]) ? { users: row["users"].map((user) => textOf(user)) } : {}
|
|
59
|
+
...Array.isArray(row["users"]) ? { users: row["users"].map((user) => textOf(user)) } : {},
|
|
60
|
+
...row["manager"] === true ? { manager: true } : {}
|
|
42
61
|
};
|
|
43
62
|
}
|
|
63
|
+
const stepsOf = (value, fn) => recordsOf(value ?? [], fn).map((step) => ({
|
|
64
|
+
approvers: approversOf(step["approvers"]),
|
|
65
|
+
required: Number(step["required"] ?? 1)
|
|
66
|
+
}));
|
|
67
|
+
const modeOf = (value) => value === "confirm" ? "confirm" : "authorize";
|
|
44
68
|
function requestOf(value, fn) {
|
|
45
69
|
const row = recordOf(value, fn);
|
|
46
70
|
const requestedBy = optionalText(row["requestedBy"]);
|
|
47
71
|
const reason = optionalText(row["reason"]);
|
|
72
|
+
const fingerprint = optionalText(row["fingerprint"]);
|
|
48
73
|
const payload = row["payload"];
|
|
49
74
|
return {
|
|
50
75
|
id: textOf(row["id"]),
|
|
@@ -52,17 +77,55 @@ function requestOf(value, fn) {
|
|
|
52
77
|
subject: subjectRefOf(row["subjectType"], row["subjectId"]),
|
|
53
78
|
action: textOf(row["action"]),
|
|
54
79
|
status: statusOf(row["status"]),
|
|
80
|
+
mode: modeOf(row["mode"]),
|
|
55
81
|
step: Number(row["step"]),
|
|
56
|
-
steps:
|
|
57
|
-
approvers: approversOf(step["approvers"]),
|
|
58
|
-
required: Number(step["required"])
|
|
59
|
-
})),
|
|
82
|
+
steps: stepsOf(row["steps"], fn),
|
|
60
83
|
payload: typeof payload === "object" && payload !== null && !Array.isArray(payload) ? recordOf(payload, fn) : {},
|
|
61
84
|
createdAt: requiredInstant(row["createdAt"], "createdAt"),
|
|
62
85
|
...requestedBy === void 0 ? {} : { requestedBy },
|
|
63
86
|
...reason === void 0 ? {} : { reason },
|
|
87
|
+
...fingerprint === void 0 ? {} : { fingerprint },
|
|
64
88
|
...instant(row["expiresAt"], "expiresAt"),
|
|
65
|
-
...instant(row["decidedAt"], "decidedAt")
|
|
89
|
+
...instant(row["decidedAt"], "decidedAt"),
|
|
90
|
+
...instant(row["consumedAt"], "consumedAt")
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function requirementOf(value) {
|
|
94
|
+
if (value === null || value === void 0) return null;
|
|
95
|
+
const row = recordOf(value, "approval_requirement");
|
|
96
|
+
const expiresIn = optionalText(row["expiresIn"]);
|
|
97
|
+
return {
|
|
98
|
+
mode: modeOf(row["mode"]),
|
|
99
|
+
steps: stepsOf(row["steps"], "approval_requirement"),
|
|
100
|
+
selfApproval: row["selfApproval"] === true,
|
|
101
|
+
policies: Array.isArray(row["policies"]) ? row["policies"].map((id) => textOf(id)) : [],
|
|
102
|
+
...expiresIn === void 0 ? {} : { expiresIn }
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/** Save_approval_policy stores only trees `rule_check` accepts. */
|
|
106
|
+
const isFilterGroup = (value) => isRecord(value) && value["type"] === "group" && Array.isArray(value["rules"]);
|
|
107
|
+
function conditionsOf(value) {
|
|
108
|
+
if (!isFilterGroup(value)) throw new TypeError(`approval conditions are ${JSON.stringify(value)}`);
|
|
109
|
+
return value;
|
|
110
|
+
}
|
|
111
|
+
function tenantPolicyOf(value, fn) {
|
|
112
|
+
const row = recordOf(value, fn);
|
|
113
|
+
const expiresIn = optionalText(row["expiresIn"]);
|
|
114
|
+
const conditions = row["conditions"];
|
|
115
|
+
return {
|
|
116
|
+
id: textOf(row["id"]),
|
|
117
|
+
organizationId: textOf(row["organizationId"]),
|
|
118
|
+
subjectType: textOf(row["subjectType"]),
|
|
119
|
+
action: textOf(row["action"]),
|
|
120
|
+
name: textOf(row["name"]),
|
|
121
|
+
mode: modeOf(row["mode"]),
|
|
122
|
+
steps: stepsOf(row["steps"], fn),
|
|
123
|
+
selfApproval: row["selfApproval"] === true,
|
|
124
|
+
enabled: row["enabled"] !== false,
|
|
125
|
+
createdAt: requiredInstant(row["createdAt"], "createdAt"),
|
|
126
|
+
...conditions === null || conditions === void 0 ? {} : { conditions: conditionsOf(conditions) },
|
|
127
|
+
...expiresIn === void 0 ? {} : { expiresIn },
|
|
128
|
+
...instant(row["updatedAt"], "updatedAt")
|
|
66
129
|
};
|
|
67
130
|
}
|
|
68
131
|
function decisionOf(value) {
|
|
@@ -126,14 +189,15 @@ function createApprovals(options) {
|
|
|
126
189
|
comment: comment ?? null
|
|
127
190
|
}));
|
|
128
191
|
return withBlockHooks({
|
|
129
|
-
request: (subject, { action, reason, payload, ...extra }) => tenant().andThen((organizationId) => AsyncResult.from(() => extraFieldsArg(fields, extra)).andThen((more) => one("request_approval", {
|
|
192
|
+
request: (subject, { action, reason, payload, fingerprint, ...extra }) => tenant().andThen((organizationId) => AsyncResult.from(() => extraFieldsArg(fields, extra)).andThen((more) => one("request_approval", {
|
|
130
193
|
tenant: organizationId,
|
|
131
194
|
subject_type: subject.type,
|
|
132
195
|
subject_id: subject.id,
|
|
133
196
|
action,
|
|
134
197
|
reason: reason ?? null,
|
|
135
198
|
payload: payload ?? {},
|
|
136
|
-
...more
|
|
199
|
+
...more,
|
|
200
|
+
...fingerprint === void 0 ? {} : { fingerprint }
|
|
137
201
|
}))),
|
|
138
202
|
approve: (id, comment) => decide(id, "approved", comment),
|
|
139
203
|
reject: (id, comment) => decide(id, "rejected", comment),
|
|
@@ -157,10 +221,30 @@ function createApprovals(options) {
|
|
|
157
221
|
subject_type: subject.type,
|
|
158
222
|
subject_id: subject.id,
|
|
159
223
|
action
|
|
160
|
-
}, (value) => value === true)
|
|
224
|
+
}, (value) => value === true),
|
|
225
|
+
requirement: (subjectType, action, payload) => tenant().andThen((organizationId) => call("approval_requirement", {
|
|
226
|
+
tenant: organizationId,
|
|
227
|
+
subject_type: subjectType,
|
|
228
|
+
action,
|
|
229
|
+
subject: payload ?? {}
|
|
230
|
+
}, requirementOf)),
|
|
231
|
+
consume: (id, fingerprint) => one("consume_approval", {
|
|
232
|
+
request_id: id,
|
|
233
|
+
fingerprint: fingerprint ?? null
|
|
234
|
+
}),
|
|
235
|
+
listPolicies: (list = {}) => tenant().andThen((organizationId) => call("list_approval_policies", {
|
|
236
|
+
tenant: organizationId,
|
|
237
|
+
subject_type: list.subjectType ?? null,
|
|
238
|
+
page_size: list.pageSize ?? null
|
|
239
|
+
}, (value) => recordsOf(value, "list_approval_policies").map((row) => tenantPolicyOf(row, "list_approval_policies")))),
|
|
240
|
+
savePolicy: (input) => tenant().andThen((organizationId) => call("save_approval_policy", {
|
|
241
|
+
tenant: organizationId,
|
|
242
|
+
policy: input
|
|
243
|
+
}, (value) => tenantPolicyOf(value, "save_approval_policy"))),
|
|
244
|
+
removePolicy: (id) => call("remove_approval_policy", { policy_id: id }, (value) => value === true)
|
|
161
245
|
}, options.hooks, {
|
|
162
246
|
block: "approvals",
|
|
163
247
|
...options.logger ? { logger: options.logger } : {}
|
|
164
248
|
});
|
|
165
249
|
}
|
|
166
|
-
export { createApprovals as t };
|
|
250
|
+
export { createApprovals as n, approvalFingerprint as t };
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
import { T as ErrorMapper, t as AsyncResult } from "./result-DTOQRyGY.js";
|
|
3
3
|
import { t as StandardSchemaV1 } from "./standard-DRX6Ch1j.js";
|
|
4
4
|
import { r as FieldsOf } from "./block-fields-Puv5m5D3.js";
|
|
5
|
-
import {
|
|
5
|
+
import { et as RecordRef } from "./types-BzIYSSWK.js";
|
|
6
6
|
import { n as Logger } from "./logger-0LfhvwE4.js";
|
|
7
|
-
import { a as BlockTenantOptions, r as BlockTemporalOptions } from "./block-helpers-
|
|
8
|
-
import { t as BlockTransport } from "./block-transport-
|
|
9
|
-
import { n as BlockHooks } from "./block-hooks-
|
|
10
|
-
import {
|
|
7
|
+
import { a as BlockTenantOptions, r as BlockTemporalOptions } from "./block-helpers-BNtM1tqy.js";
|
|
8
|
+
import { t as BlockTransport } from "./block-transport-CDmOUuLZ.js";
|
|
9
|
+
import { n as BlockHooks } from "./block-hooks-CtMsgLQr.js";
|
|
10
|
+
import { h as FilterQuery } from "./filter-query-Xj40B5KT.js";
|
|
11
|
+
import { i as AuthorizationHooks, n as Approver } from "./authorization-hooks-C0GfMvFm.js";
|
|
11
12
|
interface ApprovalsOptions<S extends StandardSchemaV1 | undefined = undefined> extends BlockTemporalOptions, BlockTenantOptions {
|
|
12
13
|
readonly transport: BlockTransport;
|
|
13
14
|
/**
|
|
@@ -37,12 +38,19 @@ interface ApprovalsOptions<S extends StandardSchemaV1 | undefined = undefined> e
|
|
|
37
38
|
readonly approver?: Approver;
|
|
38
39
|
}
|
|
39
40
|
type ApprovalStatus = "pending" | "approved" | "rejected" | "cancelled" | "expired";
|
|
41
|
+
/**
|
|
42
|
+
* `confirm`: the requester may approve their own request, as a second look.
|
|
43
|
+
* `authorize`: someone else has to decide each step.
|
|
44
|
+
*/
|
|
45
|
+
type ApprovalMode = "confirm" | "authorize";
|
|
40
46
|
/** Who may decide a step. Any match is enough. */
|
|
41
47
|
interface ApprovalApprovers {
|
|
42
48
|
readonly permission?: string;
|
|
43
49
|
readonly role?: string;
|
|
44
50
|
readonly team?: string;
|
|
45
51
|
readonly users?: readonly string[];
|
|
52
|
+
/** The requester's manager, through the employees block. */
|
|
53
|
+
readonly manager?: boolean;
|
|
46
54
|
}
|
|
47
55
|
interface ApprovalStep {
|
|
48
56
|
readonly approvers: ApprovalApprovers;
|
|
@@ -54,6 +62,7 @@ interface ApprovalRequest {
|
|
|
54
62
|
readonly subject: RecordRef;
|
|
55
63
|
readonly action: string;
|
|
56
64
|
readonly status: ApprovalStatus;
|
|
65
|
+
readonly mode: ApprovalMode;
|
|
57
66
|
/** The current step, from 0. */
|
|
58
67
|
readonly step: number;
|
|
59
68
|
/** The policy's steps when the request was made. */
|
|
@@ -61,9 +70,59 @@ interface ApprovalRequest {
|
|
|
61
70
|
readonly requestedBy?: string;
|
|
62
71
|
readonly reason?: string;
|
|
63
72
|
readonly payload: Readonly<Record<string, unknown>>;
|
|
73
|
+
/** The hex SHA-256 `consume` checks, from `approvalFingerprint`. */
|
|
74
|
+
readonly fingerprint?: string;
|
|
64
75
|
readonly expiresAt?: Temporal.Instant;
|
|
65
76
|
readonly decidedAt?: Temporal.Instant;
|
|
77
|
+
/** When `consume` used the approval. */
|
|
78
|
+
readonly consumedAt?: Temporal.Instant;
|
|
79
|
+
readonly createdAt: Temporal.Instant;
|
|
80
|
+
}
|
|
81
|
+
/** What a request needs right now, from `requirement`. */
|
|
82
|
+
interface ApprovalRequirement {
|
|
83
|
+
readonly mode: ApprovalMode;
|
|
84
|
+
readonly steps: readonly ApprovalStep[];
|
|
85
|
+
readonly selfApproval: boolean;
|
|
86
|
+
/** The request lifetime as a Postgres interval, when one applies. */
|
|
87
|
+
readonly expiresIn?: string;
|
|
88
|
+
/** The tenant policies that matched, in order. */
|
|
89
|
+
readonly policies: readonly string[];
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* A tenant's approval policy. It tightens the config policy for the same
|
|
93
|
+
* subject type and action and can never loosen it.
|
|
94
|
+
*/
|
|
95
|
+
interface ApprovalTenantPolicy {
|
|
96
|
+
readonly id: string;
|
|
97
|
+
readonly organizationId: string;
|
|
98
|
+
readonly subjectType: string;
|
|
99
|
+
readonly action: string;
|
|
100
|
+
readonly name: string;
|
|
101
|
+
/** Applies only to requests whose payload matches; none applies always. */
|
|
102
|
+
readonly conditions?: FilterQuery;
|
|
103
|
+
readonly mode: ApprovalMode;
|
|
104
|
+
/** Added after the steps of the config policy and earlier tenant policies. */
|
|
105
|
+
readonly steps: readonly ApprovalStep[];
|
|
106
|
+
readonly selfApproval: boolean;
|
|
107
|
+
readonly expiresIn?: string;
|
|
108
|
+
readonly enabled: boolean;
|
|
66
109
|
readonly createdAt: Temporal.Instant;
|
|
110
|
+
readonly updatedAt?: Temporal.Instant;
|
|
111
|
+
}
|
|
112
|
+
/** A new policy needs `subjectType`, `action` and `name`; `id` changes one. */
|
|
113
|
+
interface ApprovalPolicyInput {
|
|
114
|
+
readonly id?: string;
|
|
115
|
+
readonly subjectType?: string;
|
|
116
|
+
readonly action?: string;
|
|
117
|
+
readonly name?: string;
|
|
118
|
+
/** `null` removes the conditions. */
|
|
119
|
+
readonly conditions?: FilterQuery | null;
|
|
120
|
+
readonly mode?: ApprovalMode;
|
|
121
|
+
readonly steps?: readonly ApprovalStep[];
|
|
122
|
+
readonly selfApproval?: boolean;
|
|
123
|
+
/** A Postgres interval such as `3 days`; `null` removes it. */
|
|
124
|
+
readonly expiresIn?: string | null;
|
|
125
|
+
readonly enabled?: boolean;
|
|
67
126
|
}
|
|
68
127
|
interface ApprovalDecision {
|
|
69
128
|
readonly id: string;
|
|
@@ -84,8 +143,16 @@ interface ApprovalRequestInput {
|
|
|
84
143
|
/** An action `options.policies` names for the subject type. */
|
|
85
144
|
readonly action: string;
|
|
86
145
|
readonly reason?: string;
|
|
87
|
-
/**
|
|
146
|
+
/**
|
|
147
|
+
* Passed to the job the final approval enqueues. Tenant policy conditions
|
|
148
|
+
* match against it.
|
|
149
|
+
*/
|
|
88
150
|
readonly payload?: Readonly<Record<string, unknown>>;
|
|
151
|
+
/**
|
|
152
|
+
* Binds the approval to one exact request: `consume` refuses a different
|
|
153
|
+
* fingerprint. Build it with `approvalFingerprint`.
|
|
154
|
+
*/
|
|
155
|
+
readonly fingerprint?: string;
|
|
89
156
|
}
|
|
90
157
|
interface ApprovalListOptions {
|
|
91
158
|
/** `null` lists every status. Default: `pending`. */
|
|
@@ -121,7 +188,34 @@ interface Approvals<F extends object = Record<never, never>> {
|
|
|
121
188
|
list(options?: ApprovalListOptions): AsyncResult<readonly (ApprovalRequest & F)[]>;
|
|
122
189
|
/** Whether the subject's latest request for the action was approved. */
|
|
123
190
|
isApproved(subject: RecordRef, action: string): AsyncResult<boolean>;
|
|
191
|
+
/**
|
|
192
|
+
* What a request would need for the subject type and action, with `payload`
|
|
193
|
+
* as the request payload tenant conditions read; `null` when nothing is
|
|
194
|
+
* required, so the action can run without a request.
|
|
195
|
+
*/
|
|
196
|
+
requirement(subjectType: string, action: string, payload?: Readonly<Record<string, unknown>>): AsyncResult<ApprovalRequirement | null>;
|
|
197
|
+
/**
|
|
198
|
+
* Uses an approved request once, before its action runs. A second call fails
|
|
199
|
+
* with `APPROVAL_CONSUMED`, and a fingerprint other than the request's with
|
|
200
|
+
* `APPROVAL_FINGERPRINT_MISMATCH`.
|
|
201
|
+
*/
|
|
202
|
+
consume(id: string, fingerprint?: string): AsyncResult<ApprovalRequest & F>;
|
|
203
|
+
/** The tenant's policies (`options.tenantPolicies`). */
|
|
204
|
+
listPolicies(options?: {
|
|
205
|
+
readonly subjectType?: string;
|
|
206
|
+
readonly pageSize?: number;
|
|
207
|
+
}): AsyncResult<readonly ApprovalTenantPolicy[]>;
|
|
208
|
+
/** Creates or changes a tenant policy. Needs `approvals.manage`. */
|
|
209
|
+
savePolicy(input: ApprovalPolicyInput): AsyncResult<ApprovalTenantPolicy>;
|
|
210
|
+
/** Deletes a tenant policy; `false` when it did not exist. */
|
|
211
|
+
removePolicy(id: string): AsyncResult<boolean>;
|
|
124
212
|
}
|
|
213
|
+
/**
|
|
214
|
+
* The hex SHA-256 of `value` as sorted-key JSON, for `request` and `consume`.
|
|
215
|
+
* Pass the exact operation the approval covers (for example the subject, the
|
|
216
|
+
* action and its arguments) so an approval for one change can't run another.
|
|
217
|
+
*/
|
|
218
|
+
declare function approvalFingerprint(value: unknown): Promise<string>;
|
|
125
219
|
/** The `approvals` SQL module as typed calls. */
|
|
126
220
|
declare function createApprovals<S extends StandardSchemaV1 | undefined = undefined>(options: ApprovalsOptions<S>): Approvals<FieldsOf<S>>;
|
|
127
|
-
export {
|
|
221
|
+
export { ApprovalPolicyInput as a, ApprovalRequestInput as c, ApprovalStep as d, ApprovalTenantPolicy as f, createApprovals as g, approvalFingerprint as h, ApprovalMode as i, ApprovalRequirement as l, ApprovalsOptions as m, ApprovalDecision as n, ApprovalRequest as o, Approvals as p, ApprovalListOptions as r, ApprovalRequestDetail as s, ApprovalApprovers as t, ApprovalStatus as u };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { b as DbError } from "./result-DTOQRyGY.js";
|
|
2
2
|
import { i as AiMessage } from "./message-Cc4bkdNw.js";
|
|
3
|
-
import {
|
|
3
|
+
import { A as AiRunStatus, m as AiChatRecord, t as AiChat, x as AiModerationAction, z as AiUserMessageTrigger } from "./ai-chat-BZhfCHHr.js";
|
|
4
4
|
import { n as GatewayOptions } from "./gateway-options-Mut8jih_.js";
|
|
5
5
|
import { o as StreamStore } from "./store-c7QxUHX-.js";
|
|
6
|
-
import { i as CostBackfillPayload, t as AiUsage } from "./gateway-
|
|
6
|
+
import { i as CostBackfillPayload, t as AiUsage } from "./gateway-B9k89AC4.js";
|
|
7
7
|
import { FinishReason, LanguageModelUsage, ModelMessage, TextStreamPart, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOnEndCallback, UIMessageStreamOptions, safeValidateUIMessages } from "ai";
|
|
8
8
|
/** Who asks, for one request. */
|
|
9
9
|
interface AssistantContext {
|
|
@@ -13,7 +13,11 @@ interface AssistantContext {
|
|
|
13
13
|
*/
|
|
14
14
|
readonly chats: AiChat;
|
|
15
15
|
readonly userId: string;
|
|
16
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The tenant a new chat is made in; `null` for a chat outside a tenant
|
|
18
|
+
* (`blocks.ai-chat.options.tenant: false`).
|
|
19
|
+
*/
|
|
20
|
+
readonly organizationId: string | null;
|
|
17
21
|
/**
|
|
18
22
|
* Keeps the function alive until the answer is stored, after the response is
|
|
19
23
|
* sent: `after` in Next.js, `ctx.waitUntil` on Workers and Vercel.
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import { n as dbError } from "./errors-B7tCfCvX.js";
|
|
2
|
+
import { n as isRecord } from "./guards-CsRa6v57.js";
|
|
3
|
+
import { o as problemResponse } from "./problem-C0SVHhd3.js";
|
|
4
|
+
import { n as pathToHistory, r as repairDanglingToolCalls } from "./history-6KiVNWdH.js";
|
|
5
|
+
import { t as gatewayOptions } from "./gateway-options-DQGQzdkD.js";
|
|
6
|
+
import { _ as usageOf, a as fromUIMessage, h as runRelease, l as toUIMessages, m as problem429, n as aiErrorToDbError, o as isUIMessage, r as AI_SDK_UI_FORMAT, t as aiErrorMessage } from "./errors-0Qid9fGz.js";
|
|
7
|
+
import { n as teeToStore, t as resumeFromStore } from "./tee-CVOMhEX-.js";
|
|
8
|
+
import { JsonToSseTransformStream, UI_MESSAGE_STREAM_HEADERS, convertToModelMessages, safeValidateUIMessages, toUIMessageStream } from "ai";
|
|
9
|
+
// src/ai-sdk/http.ts
|
|
10
|
+
/** A 400 problem response for a malformed chat request. */
|
|
11
|
+
function badRequest(message) {
|
|
12
|
+
return problemResponse(dbError("invalid_request", message, { code: "AI_CHAT_BAD_REQUEST" }));
|
|
13
|
+
}
|
|
14
|
+
/** The JSON body of a request, or `undefined` when it is not JSON. */
|
|
15
|
+
async function readJson(request) {
|
|
16
|
+
try {
|
|
17
|
+
return await request.json();
|
|
18
|
+
} catch {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A UI message stream as a response, with extra headers such as the workflow
|
|
24
|
+
* run id.
|
|
25
|
+
*/
|
|
26
|
+
function sse(stream, headers = {}) {
|
|
27
|
+
return new Response(stream.pipeThrough(new TextEncoderStream()), { headers: {
|
|
28
|
+
...UI_MESSAGE_STREAM_HEADERS,
|
|
29
|
+
...headers
|
|
30
|
+
} });
|
|
31
|
+
}
|
|
32
|
+
// src/ai-sdk/chat/assistant.ts
|
|
33
|
+
/**
|
|
34
|
+
* A `stream` option that sends the model and start time with the first chunk
|
|
35
|
+
* and the finish reason and usage with the last, as message metadata.
|
|
36
|
+
*/
|
|
37
|
+
function assistantMetadata(args) {
|
|
38
|
+
return { messageMetadata: ({ part }) => {
|
|
39
|
+
if (part.type === "start") return {
|
|
40
|
+
model: args.model,
|
|
41
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
42
|
+
};
|
|
43
|
+
if (part.type === "finish") return {
|
|
44
|
+
finishReason: part.finishReason,
|
|
45
|
+
usage: part.totalUsage
|
|
46
|
+
};
|
|
47
|
+
} };
|
|
48
|
+
}
|
|
49
|
+
/** The chat's tenant as an optional `organizationId`, for a spread. */
|
|
50
|
+
const tenantOf = (chat) => chat.organizationId === void 0 ? {} : { organizationId: chat.organizationId };
|
|
51
|
+
const TRIGGERS = /* @__PURE__ */ new Set(["submit-message", "regenerate-message"]);
|
|
52
|
+
function parseBody(value) {
|
|
53
|
+
if (!isRecord(value)) return "Expected a JSON object.";
|
|
54
|
+
const { id, trigger, messageId, model } = value;
|
|
55
|
+
if (typeof id !== "string" || id === "") return "Expected the chat id.";
|
|
56
|
+
const messages = value["messages"];
|
|
57
|
+
const last = Array.isArray(messages) ? messages.at(-1) : void 0;
|
|
58
|
+
const message = value["message"] ?? last;
|
|
59
|
+
if (!isUIMessage(message) || message.role !== "user") return "Expected the user's message.";
|
|
60
|
+
if (trigger !== void 0 && !TRIGGERS.has(trigger)) return "Expected submit-message or regenerate-message.";
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
message,
|
|
64
|
+
...trigger === "regenerate-message" ? { trigger } : {},
|
|
65
|
+
...typeof messageId === "string" ? { messageId } : {},
|
|
66
|
+
...typeof model === "string" ? { model } : {}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const settle = async (value) => {
|
|
70
|
+
try {
|
|
71
|
+
return await value;
|
|
72
|
+
} catch {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const uiChunksOf = (result, options) => {
|
|
77
|
+
if (result.stream !== void 0) return toUIMessageStream({
|
|
78
|
+
stream: result.stream,
|
|
79
|
+
...options
|
|
80
|
+
});
|
|
81
|
+
return result.toUIMessageStream?.(options);
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A chat route for the AI SDK on the `ai-chat` block: `respond` stores the
|
|
85
|
+
* user's message, picks an allowed model, checks the quota, claims the chat's
|
|
86
|
+
* answer, runs the model and streams it while keeping a copy in the stream
|
|
87
|
+
* store; the answer and its usage are stored when it ends, even after the
|
|
88
|
+
* client left. `resume` replays it after a reload, `stop` ends it.
|
|
89
|
+
*/
|
|
90
|
+
function createAssistant(options) {
|
|
91
|
+
const newId = options.generateId ?? (() => crypto.randomUUID());
|
|
92
|
+
async function chatOf(context, body) {
|
|
93
|
+
const found = await context.chats.chats.get(body.id);
|
|
94
|
+
if (found.ok) return found.data;
|
|
95
|
+
if (found.error.kind !== "not_found") return problemResponse(found.error);
|
|
96
|
+
const created = await context.chats.chats.create(context.organizationId, {
|
|
97
|
+
id: body.id,
|
|
98
|
+
...body.model === void 0 ? {} : { model: body.model }
|
|
99
|
+
});
|
|
100
|
+
return created.ok ? created.data : problemResponse(created.error);
|
|
101
|
+
}
|
|
102
|
+
async function modelOf(context, chat, requested) {
|
|
103
|
+
const allowed = await context.chats.models.allowed(chat.organizationId);
|
|
104
|
+
if (!allowed.ok) return problemResponse(allowed.error);
|
|
105
|
+
const ids = new Set(allowed.data.map((model) => model.id));
|
|
106
|
+
const fits = (id) => ids.size === 0 || ids.has(id);
|
|
107
|
+
if (requested !== void 0 && fits(requested)) return requested;
|
|
108
|
+
if (requested !== void 0) return problemResponse(dbError("forbidden", `The model ${requested} is not allowed.`, { code: "AI_MODEL_NOT_ALLOWED" }));
|
|
109
|
+
if (chat.model !== void 0 && fits(chat.model)) return chat.model;
|
|
110
|
+
if (fits(options.defaultModel)) return options.defaultModel;
|
|
111
|
+
const first = allowed.data[0];
|
|
112
|
+
return first === void 0 ? options.defaultModel : first.id;
|
|
113
|
+
}
|
|
114
|
+
async function moderated(context, chat, message) {
|
|
115
|
+
const verdict = await options.moderate?.({
|
|
116
|
+
message,
|
|
117
|
+
chat
|
|
118
|
+
});
|
|
119
|
+
if (verdict === void 0 || verdict.action === "allow") return;
|
|
120
|
+
await context.chats.moderation.record({
|
|
121
|
+
...tenantOf(chat),
|
|
122
|
+
chatId: chat.id,
|
|
123
|
+
messageId: message.id,
|
|
124
|
+
userId: context.userId,
|
|
125
|
+
stage: "input",
|
|
126
|
+
action: verdict.action,
|
|
127
|
+
category: verdict.category,
|
|
128
|
+
...verdict.score === void 0 ? {} : { score: verdict.score }
|
|
129
|
+
});
|
|
130
|
+
return verdict.action === "block" ? problemResponse(dbError("forbidden", "The message was blocked.", { code: "AI_MODERATION_BLOCKED" })) : void 0;
|
|
131
|
+
}
|
|
132
|
+
async function prepare(value, context) {
|
|
133
|
+
const body = parseBody(value);
|
|
134
|
+
if (typeof body === "string") return badRequest(body);
|
|
135
|
+
if (options.validate !== void 0) {
|
|
136
|
+
const checked = await safeValidateUIMessages({
|
|
137
|
+
messages: [body.message],
|
|
138
|
+
...options.validate
|
|
139
|
+
});
|
|
140
|
+
if (!checked.success) return problemResponse(dbError("validation", "The message did not match its schema.", {
|
|
141
|
+
code: "AI_MESSAGE_INVALID",
|
|
142
|
+
issues: [{ message: checked.error.message }]
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
const chat = await chatOf(context, body);
|
|
146
|
+
if (chat instanceof Response) return chat;
|
|
147
|
+
const model = await modelOf(context, chat, body.model);
|
|
148
|
+
if (model instanceof Response) return model;
|
|
149
|
+
const userMessage = fromUIMessage(body.message);
|
|
150
|
+
const blocked = await moderated(context, chat, userMessage);
|
|
151
|
+
if (blocked) return blocked;
|
|
152
|
+
if (options.quota && chat.organizationId !== void 0) {
|
|
153
|
+
const exceeded = await options.quota(chat.organizationId);
|
|
154
|
+
if (exceeded) return problem429(exceeded);
|
|
155
|
+
}
|
|
156
|
+
const appended = await context.chats.messages.appendUser(chat.id, userMessage, {
|
|
157
|
+
...body.trigger === void 0 ? {} : { trigger: body.trigger },
|
|
158
|
+
...body.messageId === void 0 ? {} : { messageId: body.messageId },
|
|
159
|
+
native: body.message
|
|
160
|
+
});
|
|
161
|
+
if (!appended.ok) return problemResponse(appended.error);
|
|
162
|
+
const parentId = appended.data.messageId;
|
|
163
|
+
const path = await context.chats.messages.path(chat.id, {
|
|
164
|
+
leafId: parentId,
|
|
165
|
+
native: true
|
|
166
|
+
});
|
|
167
|
+
if (!path.ok) return problemResponse(path.error);
|
|
168
|
+
const repaired = new Map(repairDanglingToolCalls(pathToHistory(path.data)).map((message) => [message.id, message]));
|
|
169
|
+
const uiMessages = toUIMessages(path.data.map((stored) => stored.format === "ai-sdk-ui" || stored.format === "native" ? stored : repaired.get(stored.id) ?? stored));
|
|
170
|
+
return {
|
|
171
|
+
chat,
|
|
172
|
+
model,
|
|
173
|
+
parentId,
|
|
174
|
+
uiMessages,
|
|
175
|
+
messages: await convertToModelMessages(uiMessages, { ignoreIncompleteToolCalls: true }),
|
|
176
|
+
providerOptions: gatewayOptions({
|
|
177
|
+
userId: context.userId,
|
|
178
|
+
...tenantOf(chat),
|
|
179
|
+
chatId: chat.id,
|
|
180
|
+
feature: options.feature ?? "chat"
|
|
181
|
+
})
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
async function respond(request, context) {
|
|
185
|
+
const turn = await prepare(await readJson(request), context);
|
|
186
|
+
if (turn instanceof Response) return turn;
|
|
187
|
+
const { chat, model, parentId, uiMessages } = turn;
|
|
188
|
+
const streamId = newId();
|
|
189
|
+
const assistantId = newId();
|
|
190
|
+
const claim = await context.chats.runs.claim(chat.id, streamId, {
|
|
191
|
+
model,
|
|
192
|
+
messageId: assistantId
|
|
193
|
+
});
|
|
194
|
+
if (!claim.ok) return problemResponse(claim.error);
|
|
195
|
+
if (!claim.data.claimed) return problemResponse(dbError("conflict", "An answer is already being written.", { code: "AI_CHAT_BUSY" }));
|
|
196
|
+
const runId = claim.data.runId;
|
|
197
|
+
const abort = new AbortController();
|
|
198
|
+
const release = (status, usage, error) => context.chats.runs.release(chat.id, streamId, runRelease(status, usage, error));
|
|
199
|
+
const runArgs = {
|
|
200
|
+
chat,
|
|
201
|
+
model,
|
|
202
|
+
messages: turn.messages,
|
|
203
|
+
uiMessages,
|
|
204
|
+
abortSignal: abort.signal,
|
|
205
|
+
providerOptions: turn.providerOptions,
|
|
206
|
+
context
|
|
207
|
+
};
|
|
208
|
+
let result;
|
|
209
|
+
try {
|
|
210
|
+
result = await options.run(runArgs);
|
|
211
|
+
} catch (cause) {
|
|
212
|
+
await release("failed", void 0, String(cause));
|
|
213
|
+
const mapped = aiErrorToDbError(cause);
|
|
214
|
+
return problemResponse(mapped.kind === "unexpected" ? dbError("unexpected", "The answer could not be started.", { code: "AI_CHAT_RUN_FAILED" }) : mapped);
|
|
215
|
+
}
|
|
216
|
+
let finished;
|
|
217
|
+
const onEnd = (event) => {
|
|
218
|
+
finished = (async () => {
|
|
219
|
+
const stopped = event.isAborted || abort.signal.aborted;
|
|
220
|
+
const status = stopped ? "cancelled" : "completed";
|
|
221
|
+
const saved = await context.chats.messages.saveAssistant(chat.id, fromUIMessage(event.responseMessage), {
|
|
222
|
+
parentId,
|
|
223
|
+
status: stopped ? "aborted" : "complete",
|
|
224
|
+
model,
|
|
225
|
+
format: AI_SDK_UI_FORMAT,
|
|
226
|
+
native: event.responseMessage,
|
|
227
|
+
runId
|
|
228
|
+
});
|
|
229
|
+
const usage = usageOf({
|
|
230
|
+
usage: await settle(result.usage ?? result.totalUsage),
|
|
231
|
+
finalStep: result.finalStep === void 0 ? { providerMetadata: await settle(result.providerMetadata) } : await settle(result.finalStep)
|
|
232
|
+
});
|
|
233
|
+
await release(saved.ok ? status : "failed", usage, saved.ok ? void 0 : saved.error.message);
|
|
234
|
+
if (usage.costMicroUsd === void 0 && usage.generationId !== void 0 && options.enqueueCostBackfill) await options.enqueueCostBackfill({
|
|
235
|
+
generationId: usage.generationId,
|
|
236
|
+
...tenantOf(chat)
|
|
237
|
+
});
|
|
238
|
+
await options.onFinish?.({
|
|
239
|
+
chat,
|
|
240
|
+
message: event.responseMessage,
|
|
241
|
+
status,
|
|
242
|
+
model,
|
|
243
|
+
usage,
|
|
244
|
+
context
|
|
245
|
+
});
|
|
246
|
+
})();
|
|
247
|
+
return finished;
|
|
248
|
+
};
|
|
249
|
+
const streamOptions = {
|
|
250
|
+
...typeof options.stream === "function" ? options.stream(runArgs) : options.stream ?? {},
|
|
251
|
+
originalMessages: uiMessages,
|
|
252
|
+
generateMessageId: () => assistantId,
|
|
253
|
+
onEnd,
|
|
254
|
+
onError: options.onError ?? aiErrorMessage
|
|
255
|
+
};
|
|
256
|
+
const chunks = uiChunksOf(result, streamOptions);
|
|
257
|
+
if (chunks === void 0) {
|
|
258
|
+
await release("failed", void 0, "The run returned no stream.");
|
|
259
|
+
return problemResponse(dbError("unexpected", "The answer could not be started.", { code: "AI_CHAT_RUN_FAILED" }));
|
|
260
|
+
}
|
|
261
|
+
const teed = teeToStore(options.streams, streamId, chunks.pipeThrough(new JsonToSseTransformStream()), {
|
|
262
|
+
owner: chat.ownerId,
|
|
263
|
+
...chat.organizationId === void 0 ? {} : { tenant: chat.organizationId },
|
|
264
|
+
kind: "chat",
|
|
265
|
+
...options.streamTtl === void 0 ? {} : { ttl: options.streamTtl },
|
|
266
|
+
onCancel: () => {
|
|
267
|
+
abort.abort();
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
context.waitUntil?.((async () => {
|
|
271
|
+
await teed.persisted;
|
|
272
|
+
await finished;
|
|
273
|
+
})());
|
|
274
|
+
return sse(teed.stream);
|
|
275
|
+
}
|
|
276
|
+
async function resume(chatId, context, resumeOptions = {}) {
|
|
277
|
+
const chat = await context.chats.chats.get(chatId);
|
|
278
|
+
if (!chat.ok) return chat.error.kind === "not_found" ? new Response(null, { status: 204 }) : problemResponse(chat.error);
|
|
279
|
+
const { activeStreamId } = chat.data;
|
|
280
|
+
if (activeStreamId === void 0) return new Response(null, { status: 204 });
|
|
281
|
+
const stream = await resumeFromStore(options.streams, activeStreamId, {
|
|
282
|
+
...resumeOptions.fromIdx === void 0 ? {} : { fromIdx: resumeOptions.fromIdx },
|
|
283
|
+
...resumeOptions.signal === void 0 ? {} : { signal: resumeOptions.signal }
|
|
284
|
+
});
|
|
285
|
+
if (!stream.ok) return problemResponse(stream.error);
|
|
286
|
+
return stream.data === void 0 ? new Response(null, { status: 204 }) : sse(stream.data);
|
|
287
|
+
}
|
|
288
|
+
async function stop(chatId, context) {
|
|
289
|
+
const stopped = await context.chats.runs.stop(chatId);
|
|
290
|
+
if (!stopped.ok) return problemResponse(stopped.error);
|
|
291
|
+
return new Response(null, { status: 204 });
|
|
292
|
+
}
|
|
293
|
+
return {
|
|
294
|
+
respond,
|
|
295
|
+
prepare,
|
|
296
|
+
resume,
|
|
297
|
+
stop
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
export { readJson as a, badRequest as i, createAssistant as n, sse as o, tenantOf as r, assistantMetadata as t };
|
package/dist/astro/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as BetterSupabase } from "../define-
|
|
3
|
-
import { P as StorageImageOptions } from "../index-
|
|
4
|
-
import { r as BetterServer } from "../server-types-
|
|
5
|
-
import { a as AuthorizedContext, l as Unwrapped, n as ActionParsed, o as BlockActionOptions, r as ActionResult, s as BlockRequireOptions } from "../kit-
|
|
6
|
-
import { t as RefusalRedirects } from "../refusal-
|
|
7
|
-
import { n as FrameworkOptions, r as LocalsResource, t as FrameworkLocals } from "../framework-
|
|
1
|
+
import { O as AnyFunctions, Ut as AnyAuthorizer, k as AnyModels, rn as PermissionRef } from "../types-BzIYSSWK.js";
|
|
2
|
+
import { t as BetterSupabase } from "../define-BvkaC3Oh.js";
|
|
3
|
+
import { P as StorageImageOptions } from "../index-1uV69AZq.js";
|
|
4
|
+
import { r as BetterServer } from "../server-types-DEjva0MW.js";
|
|
5
|
+
import { a as AuthorizedContext, l as Unwrapped, n as ActionParsed, o as BlockActionOptions, r as ActionResult, s as BlockRequireOptions } from "../kit-DCuO1ZhB.js";
|
|
6
|
+
import { t as RefusalRedirects } from "../refusal-BX1EvmpJ.js";
|
|
7
|
+
import { n as FrameworkOptions, r as LocalsResource, t as FrameworkLocals } from "../framework-Byr_j8G-.js";
|
|
8
8
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
9
9
|
/**
|
|
10
10
|
* The part of Astro's `APIContext` (middleware, pages, endpoints, actions) the
|