better-supabase 0.49.0 → 0.51.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/README.md +14 -0
- package/dist/{activities-C2v_Sq4w.d.ts → activities-CL253DEv.d.ts} +2 -2
- package/dist/{adapter-BzeH7ffo.js → adapter-DBO28HF_.js} +1 -1
- package/dist/{agents-Cekdx8Bz.d.ts → agents-C3l31Csq.d.ts} +33 -2
- package/dist/agents-Cf59iYaF.d.ts +290 -0
- package/dist/agents-lkuM-m6i.js +380 -0
- package/dist/{ai-cache-Pchr6Y4y.js → ai-cache-CnmJIQZG.js} +2 -2
- package/dist/{ai-chat-D2o3jqZ5.d.ts → ai-chat-DwVklsNR.d.ts} +88 -7
- package/dist/{ai-files-B2BWwPoj.js → ai-files-CMDsogDg.js} +3 -2
- package/dist/ai-guardrails-Ckbf-cmW.d.ts +216 -0
- package/dist/{ai-schedules-BOiaFIva.d.ts → ai-schedules-D68hvDoZ.d.ts} +1 -1
- package/dist/ai-sdk/agents/index.d.ts +68 -212
- package/dist/ai-sdk/agents/index.js +103 -300
- package/dist/ai-sdk/batches/index.js +1 -1
- package/dist/ai-sdk/cache/index.js +1 -1
- package/dist/ai-sdk/chat/index.d.ts +2 -2
- package/dist/ai-sdk/chat/index.js +5 -2
- package/dist/ai-sdk/embeddings/index.d.ts +52 -3
- package/dist/ai-sdk/embeddings/index.js +69 -1
- package/dist/ai-sdk/files/index.d.ts +38 -4
- package/dist/ai-sdk/files/index.js +100 -4
- package/dist/ai-sdk/index.d.ts +166 -16
- package/dist/ai-sdk/index.js +394 -21
- package/dist/ai-sdk/mcp/index.d.ts +49 -2
- package/dist/ai-sdk/mcp/index.js +108 -6
- package/dist/ai-sdk/memory/index.d.ts +2 -2
- package/dist/ai-sdk/memory/index.js +7 -2
- package/dist/ai-sdk/react/index.js +2 -2
- package/dist/ai-sdk/react/server.js +1 -1
- package/dist/ai-sdk/workflow/index.d.ts +87 -23
- package/dist/ai-sdk/workflow/index.js +275 -28
- package/dist/ai-sdk/workflow/react/index.d.ts +25 -4
- package/dist/ai-sdk/workflow/react/index.js +71 -16
- package/dist/ai-sdk/workflow/react/server.d.ts +4 -4
- package/dist/{api-CWeCh_j2.d.ts → api-3I8ucZF2.d.ts} +1 -1
- package/dist/{api-DXZh-j0l.js → api-CZGUgEVr.js} +1 -1
- package/dist/{app-tables-D6Na4nwb.d.ts → app-tables-qa0wvhw0.d.ts} +1 -1
- package/dist/{approvals-B-WgN6Mf.d.ts → approvals-C7DjllLP.d.ts} +84 -1
- package/dist/{approvals-CMkvP9kT.js → approvals-CfQuk-lJ.js} +84 -8
- package/dist/{assistant-DcxV_seb.js → assistant-BBN9KJPi.js} +108 -26
- package/dist/{assistant-Dy9zwENt.d.ts → assistant-VF3vhPZo.d.ts} +68 -25
- package/dist/astro/index.js +2 -2
- package/dist/{attachments-gjSYzlsQ.js → attachments-Da24yVTB.js} +4 -4
- package/dist/audit-files/index.js +2 -2
- package/dist/{authorization-N4bh4KQS.d.ts → authorization-fXe0XyzB.d.ts} +1 -1
- package/dist/{automations-Ce0jNNIe.js → automations-BKxKPkhr.js} +2 -2
- package/dist/{automations-CCc5RUw-.js → automations-CkwKi84L.js} +2 -1
- package/dist/{bind-ChYzUApb.d.ts → bind-CimlbjXB.d.ts} +3 -3
- package/dist/{block-authors-CjI5VcQz.js → block-authors-Dt82LpCs.js} +1 -1
- package/dist/{block-env-buLS8m9m.d.ts → block-env-D0JCpFzh.d.ts} +4 -4
- package/dist/{block-helpers-CCl3V9ku.js → block-helpers-DApvw3n9.js} +5 -2
- package/dist/{block-hooks-C2_d17_b.js → block-hooks-mazaapv5.js} +1 -1
- package/dist/{block-subjects-ok-uZ1UU.js → block-subjects-CFDmtXvr.js} +1 -1
- package/dist/{block-subjects-rv7V0R6O.js → block-subjects-D3r2SfCb.js} +10 -10
- package/dist/{block-tables-Pd7nOPv3.d.ts → block-tables-CdXRHb2v.d.ts} +1 -1
- package/dist/blocks/access-requests/index.d.ts +1 -1
- package/dist/blocks/access-requests/index.js +2 -2
- package/dist/blocks/accounting/index.d.ts +1 -1
- package/dist/blocks/accounting/index.js +3 -3
- package/dist/blocks/acknowledgements/index.d.ts +1 -1
- package/dist/blocks/acknowledgements/index.js +2 -2
- package/dist/blocks/activities/index.d.ts +5 -13
- package/dist/blocks/activities/index.js +3 -3
- package/dist/blocks/advisories/index.d.ts +1 -1
- package/dist/blocks/advisories/index.js +2 -2
- package/dist/blocks/agent-checkout/index.d.ts +1 -1
- package/dist/blocks/agent-checkout/index.js +2 -2
- package/dist/blocks/agents/index.d.ts +4 -4
- package/dist/blocks/agents/index.js +47 -8
- package/dist/blocks/ai-cache/index.d.ts +1 -1
- package/dist/blocks/ai-cache/index.js +2 -2
- package/dist/blocks/ai-chat/index.d.ts +4 -4
- package/dist/blocks/ai-chat/index.js +76 -8
- package/dist/blocks/ai-evals/index.d.ts +1 -1
- package/dist/blocks/ai-evals/index.js +2 -2
- package/dist/blocks/ai-files/index.d.ts +2 -2
- package/dist/blocks/ai-files/index.js +2 -2
- package/dist/blocks/ai-guardrails/index.d.ts +3 -216
- package/dist/blocks/ai-guardrails/index.js +4 -4
- package/dist/blocks/ai-keys/index.d.ts +1 -1
- package/dist/blocks/ai-keys/index.js +4 -4
- package/dist/blocks/ai-schedules/index.d.ts +2 -2
- package/dist/blocks/ai-schedules/index.js +2 -2
- package/dist/blocks/announcements/index.d.ts +4 -4
- package/dist/blocks/announcements/index.js +2 -2
- package/dist/blocks/api-keys/index.d.ts +1 -1
- package/dist/blocks/api-keys/index.js +2 -2
- package/dist/blocks/appraisals/index.d.ts +1 -1
- package/dist/blocks/appraisals/index.js +2 -2
- package/dist/blocks/approvals/index.d.ts +2 -2
- package/dist/blocks/approvals/index.js +3 -3
- package/dist/blocks/assets/index.d.ts +2 -2
- package/dist/blocks/assets/index.js +3 -3
- package/dist/blocks/assignment/index.d.ts +1 -1
- package/dist/blocks/assignment/index.js +3 -3
- package/dist/blocks/attachments/index.d.ts +5 -5
- package/dist/blocks/attachments/index.js +3 -3
- package/dist/blocks/audit/index.d.ts +2 -2
- package/dist/blocks/audit/index.js +2 -2
- package/dist/blocks/automations/index.d.ts +4 -4
- package/dist/blocks/automations/index.js +3 -3
- package/dist/blocks/banking/index.d.ts +1 -1
- package/dist/blocks/banking/index.js +3 -3
- package/dist/blocks/billable-time/index.d.ts +1 -1
- package/dist/blocks/billable-time/index.js +3 -3
- package/dist/blocks/billing/index.d.ts +2 -2
- package/dist/blocks/billing/index.js +2 -2
- package/dist/blocks/bookings/index.d.ts +2 -2
- package/dist/blocks/bookings/index.js +2 -2
- package/dist/blocks/bulk/index.d.ts +1 -1
- package/dist/blocks/bulk/index.js +2 -2
- package/dist/blocks/calendar/index.d.ts +3 -3
- package/dist/blocks/calendar/index.js +1 -1
- package/dist/blocks/care/index.d.ts +27 -27
- package/dist/blocks/care/index.js +27 -27
- package/dist/blocks/care-plans/index.d.ts +3 -3
- package/dist/blocks/care-plans/index.js +3 -3
- package/dist/blocks/cases/index.d.ts +3 -3
- package/dist/blocks/cases/index.js +3 -3
- package/dist/blocks/catalog/index.d.ts +2 -2
- package/dist/blocks/catalog/index.js +3 -3
- package/dist/blocks/channels/index.d.ts +1 -1
- package/dist/blocks/channels/index.js +2 -2
- package/dist/blocks/clinical-decision-support/index.d.ts +1 -1
- package/dist/blocks/clinical-decision-support/index.js +2 -2
- package/dist/blocks/cms/index.d.ts +5 -5
- package/dist/blocks/cms/index.js +5 -5
- package/dist/blocks/collaboration/index.d.ts +6 -6
- package/dist/blocks/collaboration/index.js +6 -6
- package/dist/blocks/collections/index.d.ts +1 -1
- package/dist/blocks/collections/index.js +2 -2
- package/dist/blocks/comments/index.d.ts +2 -2
- package/dist/blocks/comments/index.js +3 -3
- package/dist/blocks/commerce/index.d.ts +5 -5
- package/dist/blocks/commerce/index.js +5 -5
- package/dist/blocks/commissions/index.d.ts +1 -1
- package/dist/blocks/commissions/index.js +2 -2
- package/dist/blocks/compliance/index.d.ts +1 -1
- package/dist/blocks/compliance/index.js +2 -2
- package/dist/blocks/connectors/index.d.ts +1 -1
- package/dist/blocks/connectors/index.js +3 -3
- package/dist/blocks/consents/index.d.ts +2 -2
- package/dist/blocks/consents/index.js +3 -3
- package/dist/blocks/contacts/index.d.ts +3 -3
- package/dist/blocks/contacts/index.js +4 -4
- package/dist/blocks/content/index.d.ts +2 -2
- package/dist/blocks/content/index.js +3 -3
- package/dist/blocks/contracts/index.d.ts +1 -1
- package/dist/blocks/contracts/index.js +4 -4
- package/dist/blocks/courses/index.d.ts +3 -3
- package/dist/blocks/courses/index.js +3 -3
- package/dist/blocks/created-by/index.d.ts +2 -2
- package/dist/blocks/crm/index.d.ts +16 -16
- package/dist/blocks/crm/index.js +16 -16
- package/dist/blocks/custom-fields/index.d.ts +1 -1
- package/dist/blocks/custom-fields/index.js +2 -2
- package/dist/blocks/dam/index.d.ts +2 -2
- package/dist/blocks/dam/index.js +4 -4
- package/dist/blocks/data-lifecycle/index.d.ts +2 -2
- package/dist/blocks/data-lifecycle/index.js +3 -3
- package/dist/blocks/deals/index.d.ts +1 -1
- package/dist/blocks/deals/index.js +3 -3
- package/dist/blocks/dispatch/index.d.ts +2 -2
- package/dist/blocks/dispatch/index.js +4 -4
- package/dist/blocks/document-templates/index.d.ts +1 -1
- package/dist/blocks/document-templates/index.js +2 -2
- package/dist/blocks/documents/index.d.ts +1 -1
- package/dist/blocks/documents/index.js +2 -2
- package/dist/blocks/domains/index.d.ts +1 -1
- package/dist/blocks/domains/index.js +3 -3
- package/dist/blocks/donations/index.d.ts +1 -1
- package/dist/blocks/donations/index.js +4 -4
- package/dist/blocks/drive/index.d.ts +5 -5
- package/dist/blocks/drive/index.js +5 -5
- package/dist/blocks/e-prescribing/index.d.ts +1 -1
- package/dist/blocks/e-prescribing/index.js +2 -2
- package/dist/blocks/employees/index.d.ts +1 -1
- package/dist/blocks/employees/index.js +3 -3
- package/dist/blocks/enrichment/index.d.ts +1 -1
- package/dist/blocks/enrichment/index.js +3 -3
- package/dist/blocks/enrollments/index.d.ts +2 -2
- package/dist/blocks/enrollments/index.js +3 -3
- package/dist/blocks/entitlements/index.d.ts +3 -3
- package/dist/blocks/entitlements/index.js +3 -3
- package/dist/blocks/events/index.d.ts +3 -3
- package/dist/blocks/events/index.js +3 -3
- package/dist/blocks/expenses/index.d.ts +1 -1
- package/dist/blocks/expenses/index.js +3 -3
- package/dist/blocks/field-history/index.d.ts +1 -1
- package/dist/blocks/field-history/index.js +3 -3
- package/dist/blocks/filespace/index.d.ts +8 -8
- package/dist/blocks/filespace/index.js +7 -7
- package/dist/blocks/finance/index.d.ts +5 -5
- package/dist/blocks/finance/index.js +5 -5
- package/dist/blocks/flags/index.d.ts +1 -1
- package/dist/blocks/flags/index.js +3 -3
- package/dist/blocks/forecasts/index.d.ts +1 -1
- package/dist/blocks/forecasts/index.js +3 -3
- package/dist/blocks/forms/index.d.ts +3 -3
- package/dist/blocks/forms/index.js +2 -2
- package/dist/blocks/funding/index.d.ts +2 -2
- package/dist/blocks/funding/index.js +3 -3
- package/dist/blocks/goals/index.d.ts +1 -1
- package/dist/blocks/goals/index.js +3 -3
- package/dist/blocks/governance/index.d.ts +4 -4
- package/dist/blocks/governance/index.js +4 -4
- package/dist/blocks/guests/index.d.ts +1 -1
- package/dist/blocks/guests/index.js +3 -3
- package/dist/blocks/hiring/index.d.ts +1 -1
- package/dist/blocks/hiring/index.js +3 -3
- package/dist/blocks/identities/index.d.ts +1 -1
- package/dist/blocks/identities/index.js +2 -2
- package/dist/blocks/imports/index.d.ts +2 -2
- package/dist/blocks/imports/index.js +2 -2
- package/dist/blocks/inbox/index.d.ts +8 -8
- package/dist/blocks/inbox/index.js +3 -3
- package/dist/blocks/incidents/index.d.ts +1 -1
- package/dist/blocks/incidents/index.js +2 -2
- package/dist/blocks/index.d.ts +8 -8
- package/dist/blocks/index.js +4 -4
- package/dist/blocks/inspections/index.d.ts +2 -2
- package/dist/blocks/inspections/index.js +2 -2
- package/dist/blocks/inventory/index.d.ts +1 -1
- package/dist/blocks/inventory/index.js +3 -3
- package/dist/blocks/invoices/index.d.ts +1 -1
- package/dist/blocks/invoices/index.js +3 -3
- package/dist/blocks/knowledge/index.d.ts +3 -3
- package/dist/blocks/knowledge/index.js +4 -4
- package/dist/blocks/lead-scoring/index.d.ts +2 -2
- package/dist/blocks/lead-scoring/index.js +3 -3
- package/dist/blocks/learning/index.d.ts +3 -3
- package/dist/blocks/learning/index.js +3 -3
- package/dist/blocks/leases/index.d.ts +1 -1
- package/dist/blocks/leases/index.js +3 -3
- package/dist/blocks/leave/index.d.ts +1 -1
- package/dist/blocks/leave/index.js +3 -3
- package/dist/blocks/ledger/index.d.ts +1 -1
- package/dist/blocks/ledger/index.js +2 -2
- package/dist/blocks/legal-entities/index.d.ts +2 -2
- package/dist/blocks/legal-entities/index.js +2 -2
- package/dist/blocks/lims/index.d.ts +2 -2
- package/dist/blocks/lims/index.js +2 -2
- package/dist/blocks/mail-sync/index.d.ts +3 -3
- package/dist/blocks/mail-sync/index.js +3 -3
- package/dist/blocks/maintenance/index.d.ts +2 -2
- package/dist/blocks/maintenance/index.js +3 -3
- package/dist/blocks/manufacturing/index.d.ts +2 -2
- package/dist/blocks/manufacturing/index.js +3 -3
- package/dist/blocks/medications/index.d.ts +1 -1
- package/dist/blocks/medications/index.js +3 -3
- package/dist/blocks/meetings/index.d.ts +3 -3
- package/dist/blocks/meetings/index.js +3 -3
- package/dist/blocks/memberships/index.d.ts +2 -2
- package/dist/blocks/memory/index.d.ts +3 -3
- package/dist/blocks/memory/index.js +7 -7
- package/dist/blocks/messaging/index.d.ts +5 -5
- package/dist/blocks/messaging/index.js +3 -3
- package/dist/blocks/metrics/index.d.ts +1 -1
- package/dist/blocks/metrics/index.js +2 -2
- package/dist/blocks/mfa/index.d.ts +2 -2
- package/dist/blocks/moderation/index.d.ts +2 -2
- package/dist/blocks/moderation/index.js +2 -2
- package/dist/blocks/notifications/index.d.ts +5 -5
- package/dist/blocks/notifications/index.js +3 -3
- package/dist/blocks/numbering/index.d.ts +1 -1
- package/dist/blocks/numbering/index.js +1 -1
- package/dist/blocks/oauth-server/index.d.ts +1 -1
- package/dist/blocks/oauth-server/index.js +2 -2
- package/dist/blocks/observations/index.d.ts +2 -2
- package/dist/blocks/observations/index.js +3 -3
- package/dist/blocks/onboarding/index.d.ts +2 -2
- package/dist/blocks/onboarding/index.js +2 -2
- package/dist/blocks/orders/index.d.ts +1 -1
- package/dist/blocks/orders/index.js +4 -4
- package/dist/blocks/organizations/index.d.ts +2 -2
- package/dist/blocks/organizations/index.js +3 -3
- package/dist/blocks/outbox/index.d.ts +1 -1
- package/dist/blocks/outbox/index.js +2 -2
- package/dist/blocks/passes/index.d.ts +2 -2
- package/dist/blocks/passes/index.js +3 -3
- package/dist/blocks/payroll-export/index.d.ts +2 -2
- package/dist/blocks/payroll-export/index.js +3 -3
- package/dist/blocks/people/index.d.ts +7 -7
- package/dist/blocks/people/index.js +7 -7
- package/dist/blocks/periods/index.d.ts +1 -1
- package/dist/blocks/periods/index.js +2 -2
- package/dist/blocks/permissions/index.d.ts +3 -3
- package/dist/blocks/permissions/index.js +2 -2
- package/dist/blocks/pipelines/index.d.ts +1 -1
- package/dist/blocks/pipelines/index.js +3 -3
- package/dist/blocks/posts/index.d.ts +2 -2
- package/dist/blocks/posts/index.js +2 -2
- package/dist/blocks/procurement/index.d.ts +5 -5
- package/dist/blocks/procurement/index.js +5 -5
- package/dist/blocks/profiles/index.d.ts +1 -1
- package/dist/blocks/profiles/index.js +3 -3
- package/dist/blocks/projects/index.d.ts +7 -7
- package/dist/blocks/projects/index.js +7 -7
- package/dist/blocks/promotions/index.d.ts +1 -1
- package/dist/blocks/promotions/index.js +4 -4
- package/dist/blocks/prompts/index.d.ts +1 -1
- package/dist/blocks/prompts/index.js +2 -2
- package/dist/blocks/push/index.d.ts +2 -2
- package/dist/blocks/push/index.js +3 -3
- package/dist/blocks/qualifications/index.d.ts +2 -2
- package/dist/blocks/qualifications/index.js +3 -3
- package/dist/blocks/queue/index.d.ts +96 -3
- package/dist/blocks/queue/index.js +149 -7
- package/dist/blocks/quotes/index.d.ts +1 -1
- package/dist/blocks/quotes/index.js +3 -3
- package/dist/blocks/rank/index.d.ts +1 -1
- package/dist/blocks/rank/index.js +2 -2
- package/dist/blocks/reactions/index.d.ts +4 -4
- package/dist/blocks/reactions/index.js +3 -3
- package/dist/blocks/recruiting/index.d.ts +4 -4
- package/dist/blocks/recruiting/index.js +4 -4
- package/dist/blocks/referrals/index.d.ts +1 -1
- package/dist/blocks/referrals/index.js +2 -2
- package/dist/blocks/relations/index.d.ts +1 -1
- package/dist/blocks/relations/index.js +4 -4
- package/dist/blocks/reminders/index.d.ts +1 -1
- package/dist/blocks/reminders/index.js +1 -1
- package/dist/blocks/reviews/index.d.ts +1 -1
- package/dist/blocks/reviews/index.js +2 -2
- package/dist/blocks/rfqs/index.d.ts +2 -2
- package/dist/blocks/rfqs/index.js +3 -3
- package/dist/blocks/risks/index.d.ts +2 -2
- package/dist/blocks/risks/index.js +2 -2
- package/dist/blocks/saas/index.d.ts +12 -12
- package/dist/blocks/saas/index.js +12 -12
- package/dist/blocks/sales/index.d.ts +1 -1
- package/dist/blocks/sales/index.js +1 -1
- package/dist/blocks/saved-views/index.d.ts +2 -2
- package/dist/blocks/saved-views/index.js +2 -2
- package/dist/blocks/scheduling/index.d.ts +4 -4
- package/dist/blocks/scheduling/index.js +4 -4
- package/dist/blocks/scores/index.d.ts +2 -2
- package/dist/blocks/scores/index.js +3 -3
- package/dist/blocks/search/index.d.ts +4 -4
- package/dist/blocks/search/index.js +2 -2
- package/dist/blocks/security-events/index.d.ts +1 -1
- package/dist/blocks/security-events/index.js +2 -2
- package/dist/blocks/segments/index.d.ts +2 -2
- package/dist/blocks/segments/index.js +3 -3
- package/dist/blocks/sequences/index.d.ts +3 -3
- package/dist/blocks/sequences/index.js +3 -3
- package/dist/blocks/service/index.d.ts +7 -7
- package/dist/blocks/service/index.js +7 -7
- package/dist/blocks/service-accounts/index.d.ts +1 -1
- package/dist/blocks/service-accounts/index.js +2 -2
- package/dist/blocks/sessions/index.d.ts +2 -2
- package/dist/blocks/sessions/index.js +2 -2
- package/dist/blocks/settings/index.d.ts +2 -2
- package/dist/blocks/settings/index.js +3 -3
- package/dist/blocks/share-links/index.d.ts +1 -1
- package/dist/blocks/share-links/index.js +1 -1
- package/dist/blocks/shifts/index.d.ts +2 -2
- package/dist/blocks/shifts/index.js +3 -3
- package/dist/blocks/shipments/index.d.ts +2 -2
- package/dist/blocks/shipments/index.js +4 -4
- package/dist/blocks/signatures/index.d.ts +2 -2
- package/dist/blocks/signatures/index.js +2 -2
- package/dist/blocks/signing-keys/index.d.ts +1 -1
- package/dist/blocks/signing-keys/index.js +2 -2
- package/dist/blocks/sla/index.d.ts +1 -1
- package/dist/blocks/sla/index.js +3 -3
- package/dist/blocks/sso/index.d.ts +1 -1
- package/dist/blocks/sso/index.js +2 -2
- package/dist/blocks/state-machine/index.d.ts +1 -1
- package/dist/blocks/state-machine/index.js +1 -1
- package/dist/blocks/subjects/index.d.ts +2 -2
- package/dist/blocks/subjects/index.js +3 -3
- package/dist/blocks/support/index.d.ts +5 -5
- package/dist/blocks/support/index.js +5 -5
- package/dist/blocks/tags/index.d.ts +2 -2
- package/dist/blocks/tags/index.js +1 -1
- package/dist/blocks/tasks/index.d.ts +2 -2
- package/dist/blocks/tasks/index.js +3 -3
- package/dist/blocks/tax/index.d.ts +2 -2
- package/dist/blocks/tax/index.js +3 -3
- package/dist/blocks/teams/index.d.ts +1 -1
- package/dist/blocks/teams/index.js +1 -1
- package/dist/blocks/templates/index.d.ts +3 -3
- package/dist/blocks/templates/index.js +2 -2
- package/dist/blocks/tills/index.d.ts +1 -1
- package/dist/blocks/tills/index.js +3 -3
- package/dist/blocks/time-tracking/index.d.ts +2 -2
- package/dist/blocks/time-tracking/index.js +2 -2
- package/dist/blocks/timeline/index.d.ts +1 -1
- package/dist/blocks/timeline/index.js +2 -2
- package/dist/blocks/trash/index.d.ts +1 -1
- package/dist/blocks/trash/index.js +2 -2
- package/dist/blocks/undo/index.d.ts +2 -2
- package/dist/blocks/undo/index.js +2 -2
- package/dist/blocks/updated-at/index.d.ts +2 -2
- package/dist/blocks/usage/index.d.ts +3 -3
- package/dist/blocks/usage/index.js +15 -3
- package/dist/blocks/vercel-marketplace/index.d.ts +1 -1
- package/dist/blocks/vercel-marketplace/index.js +2 -2
- package/dist/blocks/versions/index.d.ts +1 -1
- package/dist/blocks/versions/index.js +2 -2
- package/dist/blocks/waitlist/index.d.ts +1 -1
- package/dist/blocks/waitlist/index.js +2 -2
- package/dist/blocks/warehouse/index.d.ts +1 -1
- package/dist/blocks/warehouse/index.js +3 -3
- package/dist/blocks/webhooks/index.d.ts +1 -1
- package/dist/blocks/webhooks/index.js +6 -6
- package/dist/blocks/workflow-editor/index.d.ts +7 -7
- package/dist/blocks/workflow-editor/index.js +3 -3
- package/dist/blocks/workflows/index.d.ts +5 -5
- package/dist/blocks/workflows/index.js +51 -12
- package/dist/{blocks-ERs7xZ7E.d.ts → blocks-DbarkJe1.d.ts} +43 -19
- package/dist/{channel-iJrqCvKh.js → channel-HoCqE6Xb.js} +1 -1
- package/dist/chat-sdk/index.d.ts +549 -131
- package/dist/chat-sdk/index.js +881 -245
- package/dist/claims/index.d.ts +3 -3
- package/dist/cli/{account-D7u3LvNN.js → account-CVomaGBV.js} +1 -1
- package/dist/cli/{account-BGMPSKJs.js → account-Co53476L.js} +1 -1
- package/dist/cli/add-CGR3mLgc.js +1 -0
- package/dist/cli/{add-BXfK7N0H.js → add-Cbuj3vBk.js} +2 -2
- package/dist/cli/{add-Ca3FNbhm.js → add-ymWkkPNw.js} +13 -13
- package/dist/cli/{app-table-files-BR0zwJ7T.js → app-table-files-DoPmytoG.js} +3 -3
- package/dist/cli/{app-tables-DAHcDTFh.js → app-tables-D1rjtFmq.js} +2 -2
- package/dist/cli/{automations-DKKuC8MW.js → automations-DAMWU5je.js} +1 -1
- package/dist/cli/{backfill-DHD9e6XO.js → backfill-DgHzYvi5.js} +162 -6
- package/dist/cli/bin.js +1 -1
- package/dist/cli/{blocks-C4J4d_Jx.js → blocks-CzCYyx9N.js} +2 -2
- package/dist/cli/{blocks-DtEsw6CG.js → blocks-DmIQd43q.js} +1 -1
- package/dist/cli/{cache-DyhfGbUV.js → cache-dmC65uMm.js} +1 -1
- package/dist/cli/{codemod-B7EdR7Fu.js → codemod-CzRpopTy.js} +3 -3
- package/dist/cli/{command-bvbsvYpo.js → command-CLlRvLN9.js} +14 -7
- package/dist/cli/{completion-C8zJwfzA.js → completion-4Ta2j6uu.js} +2 -2
- package/dist/cli/{completion-CsGpvIuo.js → completion-BeyJYbyT.js} +2 -2
- package/dist/cli/{completion-GgZmb_t7.js → completion-DwUZqnou.js} +1 -1
- package/dist/cli/{config-C-DXllAX.js → config-DDzGKmmT.js} +32 -1
- package/dist/cli/{config-DyGupd-1.js → config-DPKOp4D5.js} +1 -1
- package/dist/cli/{config-CWQesy6K.js → config-lZB85ksj.js} +1 -1
- package/dist/cli/{content-mapper-BM9asZuL.js → content-mapper-B6JGZZ-x.js} +2 -2
- package/dist/cli/{db-CVoN3aLl.js → db-XUHrXei6.js} +3 -3
- package/dist/cli/{doctor-BuE0Ry7T.js → doctor-Be-y8dsz.js} +240 -20
- package/dist/cli/{env-Bco8UGR3.js → env-49B92Izr.js} +1 -1
- package/dist/cli/env-BNeYZxBV.js +1 -0
- package/dist/cli/{gen-DMAd__D1.js → gen-CMppeGNK.js} +16 -16
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +8 -8
- package/dist/cli/{init-BfpkhVgY.js → init-qbw1o0Dd.js} +10 -10
- package/dist/cli/{keys-CRf_wOFs.js → keys-DPHVpbjn.js} +1 -1
- package/dist/cli/{live-XBM0kzT3.js → live-RZhHZRFj.js} +2 -2
- package/dist/cli/{mcp-C9HqqPIV.js → mcp-DudhybBp.js} +3 -3
- package/dist/cli/{metadata-dYoVRApT.js → metadata-O2AJ-PDA.js} +3 -3
- package/dist/cli/{migrate-DLWnaHNN.js → migrate-CiGCX8KP.js} +2 -2
- package/dist/cli/{migration-safety-Bh7VzARh.js → migration-safety-Cn2z7UC-.js} +11 -2
- package/dist/cli/{migrations-Cq5hkJsa.js → migrations-6KOIDi_b.js} +2 -2
- package/dist/cli/{module-migration-BUd_MAbE.js → module-migration-XPQbFJib.js} +2 -2
- package/dist/cli/{moved-btVl2MAQ.js → moved-DV_Edueb.js} +1 -1
- package/dist/cli/{parse-ThNFQ1hP.js → parse-CX-x-r5L.js} +1 -1
- package/dist/cli/powersync-BNWYxuB0.js +1 -0
- package/dist/cli/{powersync-Cb8xtLDc.js → powersync-CFOmXWSv.js} +4 -4
- package/dist/cli/{print-BVeE5vr_.js → print-BgO62egM.js} +2 -2
- package/dist/cli/{providers-xmyaROnG.js → providers-Ciss4nHV.js} +1 -1
- package/dist/cli/{prune-workflows-DUOBOuHp.js → prune-workflows-eAi-3R9F.js} +4 -4
- package/dist/cli/{remove-BuasHmdF.js → remove-B-vjuw8U.js} +7 -7
- package/dist/cli/{render-Hvu_ZKtr.js → render-eYxq_mwL.js} +4 -4
- package/dist/cli/{run-1ZTOS-gb.js → run-CLLVkt9B.js} +2 -2
- package/dist/cli/{run-DMZQUy5b.js → run-Cn0Ay_l6.js} +51 -51
- package/dist/cli/{run-KdsUN7Qj.js → run-VHRy6vLi.js} +9 -9
- package/dist/cli/seed-BqsY5MlO.js +1 -0
- package/dist/cli/{seed-C7eiVpBy.js → seed-DNaRUG_M.js} +4 -4
- package/dist/cli/{shared-3cetvs_N.js → shared-CL-Gg-tZ.js} +1 -1
- package/dist/cli/{skills-wZ94Fa8G.js → skills-Bfx3HM5e.js} +1 -1
- package/dist/cli/{snapshot-D7h2oWfS.js → snapshot-BDeHrbby.js} +3 -3
- package/dist/cli/{source-ENOc1zZ9.js → source-BPCSkEGq.js} +1 -1
- package/dist/cli/{source-args-Deg53QHe.js → source-args-DowOyFq5.js} +1 -1
- package/dist/cli/{spec-DGaKqtfR.js → spec-BN7JlljA.js} +3 -3
- package/dist/cli/{spec-CfKQ2Xxd.js → spec-CEiZkG-g.js} +1 -1
- package/dist/cli/{sql-layout-CGlyhvQ1.js → sql-layout-oPEsvcMQ.js} +2 -2
- package/dist/cli/{stack-Dr_oEfmw.js → stack-CwBH6-o8.js} +1 -1
- package/dist/cli/{sync-DFJfT7dH.js → sync-CgpA7QSy.js} +4 -4
- package/dist/cli/{table-DJiZ_PJP.js → table-BEiSh604.js} +1 -1
- package/dist/cli/{upgrade-C2Kdvrj-.js → upgrade-CWx1Pdz2.js} +5 -5
- package/dist/cli/{upgrade-DSi7r0MG.js → upgrade-DPDYkDat.js} +3 -3
- package/dist/cli/{version-AGe2VWGm.js → version-XN1WDU-l.js} +1 -1
- package/dist/client/index.d.ts +5 -5
- package/dist/client/native/index.d.ts +4 -4
- package/dist/{codecs-jdyv13IU.js → codecs-BSDJw_Fn.js} +2 -2
- package/dist/commerce/index.js +2 -2
- package/dist/{compose-DUitDAa_.js → compose-Be6lxp05.js} +1 -1
- package/dist/{composite-CQjoTPwv.js → composite-qffn948S.js} +1 -1
- package/dist/config/index.d.ts +5 -5
- package/dist/config/index.js +4 -4
- package/dist/{config-DYtSlwsi.js → config-DVRBLGIK.js} +3 -3
- package/dist/{config-gJ9FX0jc.js → config-DwPO3Dcs.js} +1 -1
- package/dist/{context-DNwBlpKo.d.ts → context-NgBzQFD8.d.ts} +61 -4
- package/dist/contract/index.d.ts +3 -3
- package/dist/{controller-DfgxFNFx.d.ts → controller-XiTA4O2z.d.ts} +1 -1
- package/dist/{conversion-BzVxeYqk.d.ts → conversion-BYSDK6_r.d.ts} +1 -1
- package/dist/create/index.d.ts +4 -4
- package/dist/create/index.js +3 -3
- package/dist/create/lite/index.d.ts +2 -2
- package/dist/create/lite/index.js +3 -3
- package/dist/{create-blocks-DupJA8Lw.js → create-blocks-X59FRi6t.js} +2 -2
- package/dist/credentials/index.js +3 -3
- package/dist/{deal-forecast-CgzuxYtf.js → deal-forecast-DWwQ_ZL6.js} +2 -2
- package/dist/{define-block-DiW9g10_.d.ts → define-block-DLqYhrYF.d.ts} +3 -3
- package/dist/{delivery-events-DUiTctdo.js → delivery-events-BNBvla4y.js} +1 -1
- package/dist/{drive-CvgLTJA9.d.ts → drive-CnOz5P5H.d.ts} +2 -2
- package/dist/e-invoicing/index.js +1 -1
- package/dist/edge/index.js +3 -3
- package/dist/embeddings-CCPghrsU.js +249 -0
- package/dist/{embeddings-Dm-GSHAi.d.ts → embeddings-DoNwEveb.d.ts} +52 -4
- package/dist/{entitlements-5nbdIitJ.d.ts → entitlements-7iVfWIy8.d.ts} +1 -1
- package/dist/{entitlements-BxZpcgcb.js → entitlements-CE-fFbUR.js} +2 -2
- package/dist/{errors-DCJMVeY7.js → errors-B3EJToP_.js} +72 -19
- package/dist/eve/index.d.ts +4 -4
- package/dist/eve/index.js +2 -2
- package/dist/{eve-DRYPT58Y.d.ts → eve-UQ0RZX-K.d.ts} +2 -2
- package/dist/{executor-COn2O4fg.d.ts → executor-mRSXEFIB.d.ts} +1 -1
- package/dist/expo/index.js +2 -2
- package/dist/{extract-DpiLKlbp.d.ts → extract-4SajsgPj.d.ts} +2 -2
- package/dist/fhir/index.js +1 -1
- package/dist/{field-errors-BCX7RCEc.d.ts → field-errors-B6sHzfiG.d.ts} +5 -5
- package/dist/{flags-oS3Mbyfc.js → flags-CtmDvszx.js} +1 -1
- package/dist/flags-sdk/index.js +5 -3
- package/dist/{framework-D8eW-nTX.js → framework-CD0tHWLN.js} +1 -1
- package/dist/{gateway-DjJYyq6h.d.ts → gateway-BsE1qacd.d.ts} +2 -2
- package/dist/{history-6KiVNWdH.js → history-CoX8QoXr.js} +21 -6
- package/dist/hono/index.js +2 -2
- package/dist/{inbox-BnELyPRZ.d.ts → inbox-i3nEfNHG.d.ts} +21 -1
- package/dist/{index-B8Mjb-KA.d.ts → index---6uF_J0.d.ts} +1 -1
- package/dist/{index-CFT7e_HH.d.ts → index-7-mAsoAB.d.ts} +2 -2
- package/dist/{index-CakXRuAZ.d.ts → index-B2HOIiNe.d.ts} +2 -2
- package/dist/{index-DMlTXcWp.d.ts → index-B9sdIEmz.d.ts} +2 -2
- package/dist/{index-ZI4sMVPT.d.ts → index-BEyOO6xN.d.ts} +2 -2
- package/dist/{index-BB5n8R_s.d.ts → index-BHlGYVat.d.ts} +1 -1
- package/dist/{index-D48wVmDj.d.ts → index-BUGFN7Lu.d.ts} +1 -1
- package/dist/{index-DHwPGqLY.d.ts → index-BaI1DFjU.d.ts} +2 -2
- package/dist/{index-BMYIwvDA.d.ts → index-BjMlZ2la.d.ts} +1 -1
- package/dist/{index-D6y6ojUX.d.ts → index-BpW3Kn-H.d.ts} +2 -2
- package/dist/{index-CurH6bgW.d.ts → index-C35Mxkfj.d.ts} +1 -1
- package/dist/{index-Bn5v6soX.d.ts → index-CA5xzl6j.d.ts} +1 -1
- package/dist/{index-D5LnplxJ.d.ts → index-CBTA4Hus.d.ts} +6 -6
- package/dist/{index-EHczIYa7.d.ts → index-CFfFev2y.d.ts} +72 -5
- package/dist/{index-BolFrOMw.d.ts → index-CaUkbhw7.d.ts} +2 -2
- package/dist/{index-BGgGwWcn.d.ts → index-Cfft6iUs.d.ts} +1 -1
- package/dist/{index-BW0aDURc.d.ts → index-CsngKWje.d.ts} +1 -1
- package/dist/{index-BNBFiyOR.d.ts → index-D89tUktw.d.ts} +1 -1
- package/dist/{index-BK8zPigx.d.ts → index-DDIZwUK-.d.ts} +1 -1
- package/dist/{index-BZ1Akcrg.d.ts → index-D_JS5FYo.d.ts} +1 -1
- package/dist/{index-BLL45v55.d.ts → index-Dh-CE1YF.d.ts} +1 -1
- package/dist/{index-DkWXofPH.d.ts → index-Dk039ZLg.d.ts} +1 -1
- package/dist/{index-DZTavebO.d.ts → index-Do2iK7pF.d.ts} +1 -1
- package/dist/{index-IKK8zWTN.d.ts → index-DpQ1JuKa.d.ts} +2 -2
- package/dist/{index-S6axmDQL.d.ts → index-Drjrj8Y5.d.ts} +2 -2
- package/dist/{index-7UV0pNYj.d.ts → index-Dvu6MySL.d.ts} +2 -2
- package/dist/{index-B2C1NczA.d.ts → index-LnDm58TV.d.ts} +4 -4
- package/dist/{index-D25Ry5R9.d.ts → index-P5Xhtrzo.d.ts} +1 -1
- package/dist/{index-CRSNN2v9.d.ts → index-PV91A2_J.d.ts} +8 -8
- package/dist/{index-B1NcZsVD.d.ts → index-VaTlShTa.d.ts} +7 -7
- package/dist/{index-iaMOudmP.d.ts → index-aNW_fYBI.d.ts} +1 -1
- package/dist/{index-Bdg6ee4m.d.ts → index-b5FUPI-5.d.ts} +1 -1
- package/dist/{index-1001GtVL.d.ts → index-hkFhFgRv.d.ts} +1 -1
- package/dist/{index-kidoYhB8.d.ts → index-jaxdP0Qe.d.ts} +1 -1
- package/dist/index-nFxtUFQv.d.ts +11 -0
- package/dist/{index-Bopuqb8z.d.ts → index-oR-iOHLT.d.ts} +4 -4
- package/dist/{index-DplKvjCs.d.ts → index-qPP3ja-K.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/{instances-ukDFg8oN.js → instances-CAzvtvlH.js} +119 -8
- package/dist/json-render/index.d.ts +91 -0
- package/dist/json-render/index.js +233 -0
- package/dist/{knowledge-DL1ZnEe7.d.ts → knowledge-CjrMiSnp.d.ts} +59 -9
- package/dist/{knowledge-CQl9LXaZ.js → knowledge-m3IJobAw.js} +22 -10
- package/dist/{manifest-DKY9HGin.js → manifest-12CvUHma.js} +3 -3
- package/dist/{manifest-DI_Vz152.d.ts → manifest-1CNHDf-P.d.ts} +2 -2
- package/dist/{manifest-D8JpSvuE.js → manifest-1X1rpQ-5.js} +3 -3
- package/dist/{manifest-BSQh5dw2.js → manifest-1qVuPpg1.js} +2 -2
- package/dist/{manifest-Cxz4_mWy.d.ts → manifest-279mgqK2.d.ts} +1 -1
- package/dist/{manifest-Cu_4X5Rm.js → manifest-3mRZEFbA.js} +2 -2
- package/dist/{manifest-ppItbSA5.d.ts → manifest-4-J2cBhl.d.ts} +1 -1
- package/dist/{manifest-BhBqFYV4.d.ts → manifest-4Ei8W6XJ.d.ts} +1 -1
- package/dist/{manifest-BEZ8HltH.js → manifest-638tYNw7.js} +2 -2
- package/dist/{manifest-BXNDl7bx.js → manifest-AFBjJxrJ.js} +2 -2
- package/dist/{manifest-B_3_99xa.js → manifest-AI6u-id7.js} +3 -3
- package/dist/{manifest-C95-cClh.js → manifest-B1Xj7ObD.js} +1 -1
- package/dist/{manifest-_qzN4kUG.js → manifest-B2G5B8ty.js} +2 -2
- package/dist/{manifest-CPYEEX6u.js → manifest-B3Fs0ZeU.js} +8 -3
- package/dist/{manifest-DJRHzb6v.js → manifest-B5c8gqof.js} +2 -2
- package/dist/{manifest-Dagm1cVO.d.ts → manifest-BAEYvNSN.d.ts} +1 -1
- package/dist/{manifest-CJByGKJ_.d.ts → manifest-BBCFaNss.d.ts} +1 -1
- package/dist/{manifest-CRXxYu5L.js → manifest-BEyhZ8sV.js} +3 -3
- package/dist/{manifest-ycsWja2O.d.ts → manifest-BFXftMd7.d.ts} +1 -1
- package/dist/{manifest--eIzr9Tj.js → manifest-BFbZ2mZA.js} +2 -2
- package/dist/{manifest-C0f5YJ7x.d.ts → manifest-BFi8-A1w.d.ts} +1 -1
- package/dist/{manifest-DeCjklgV.js → manifest-BHaR8iYx.js} +2 -2
- package/dist/{manifest-BKD8DbQT.js → manifest-BI65KPyR.js} +4 -4
- package/dist/{manifest-DHYr9yD1.js → manifest-BIOzNAsT.js} +2 -2
- package/dist/{manifest-CKxnGCVY.d.ts → manifest-BJ7XyLlV.d.ts} +1 -1
- package/dist/{manifest-DM2T_dN2.js → manifest-BKvawy3P.js} +3 -3
- package/dist/{manifest-C-_0WkGx.d.ts → manifest-BNR_72jF.d.ts} +4 -3
- package/dist/{manifest-BcdRITPc.d.ts → manifest-BOQOTepZ.d.ts} +1 -1
- package/dist/{manifest-DqwQmPZb.js → manifest-BP7YQERu.js} +3 -3
- package/dist/{manifest-C_hIU5kk.js → manifest-BPeoWfAO.js} +3 -3
- package/dist/{manifest-DHt1h5GN.js → manifest-BPpt2s0a.js} +3 -3
- package/dist/{manifest-6MuVEQnP.js → manifest-BQobHp4x.js} +5 -5
- package/dist/{manifest-BgMjraZw.js → manifest-BRgWZzVn.js} +3 -3
- package/dist/{manifest-CCXaDWdN.d.ts → manifest-BS1QA4mT.d.ts} +1 -1
- package/dist/{manifest-JvgqqKRq.js → manifest-BW6RRJXm.js} +2 -2
- package/dist/{manifest-K_42e50M.d.ts → manifest-BWIcNHVs.d.ts} +1 -1
- package/dist/{manifest-Hx3FBHKX.js → manifest-BXIL-A7I.js} +1 -1
- package/dist/{manifest-C3VB7-hM.d.ts → manifest-BaQ-A5Jy.d.ts} +2 -2
- package/dist/{manifest-D3HTgmR3.d.ts → manifest-BaR4cYwY.d.ts} +1 -1
- package/dist/{manifest-DjVqN_iK.d.ts → manifest-Bc1-GptG.d.ts} +1 -1
- package/dist/{manifest-C8Boo7Ps.js → manifest-Bea2AWYl.js} +4 -4
- package/dist/{manifest-1Xiu6zqs.js → manifest-BgKbxGVp.js} +2 -2
- package/dist/{manifest-Dbq6t-bI.d.ts → manifest-BhhX6xjo.d.ts} +1 -1
- package/dist/{manifest-Dm_5DTyx.js → manifest-BhpXYw_3.js} +2 -2
- package/dist/{manifest-BHNrIQ8X.d.ts → manifest-BieAORBI.d.ts} +1 -1
- package/dist/{manifest-D2qeEjrC.d.ts → manifest-Bk69YFI3.d.ts} +1 -1
- package/dist/{manifest-gCNbUW-X.js → manifest-BnJ_9tgk.js} +2 -2
- package/dist/{manifest-1lzhOO0z.d.ts → manifest-BqCQrbSP.d.ts} +2 -2
- package/dist/{manifest-DnZw4JWP.js → manifest-Brv_Pss2.js} +2 -2
- package/dist/{manifest-D7y9_k5i.d.ts → manifest-BuEIqayB.d.ts} +1 -1
- package/dist/{manifest-OS0pwPRn.d.ts → manifest-BxRL6XuJ.d.ts} +1 -1
- package/dist/{manifest-qb_YXiWK.js → manifest-BydKYd32.js} +2 -2
- package/dist/{manifest-FkY_rpfH.js → manifest-C-ROCYHF.js} +5 -5
- package/dist/{manifest-BfAXsd-X.d.ts → manifest-C1JGYvR-.d.ts} +1 -1
- package/dist/{manifest-gGOpzRmJ.d.ts → manifest-C3d7DJiE.d.ts} +1 -1
- package/dist/{manifest-D84UV5p6.js → manifest-C5NzuW_p.js} +2 -2
- package/dist/{manifest-A_VPz6fq.js → manifest-C75gu7oi.js} +2 -2
- package/dist/{manifest-BdmDmQtx.js → manifest-CBj4zlpo.js} +4 -4
- package/dist/{manifest-BKDSuS3x.d.ts → manifest-CFb---rO.d.ts} +2 -2
- package/dist/{manifest-BHhBqtFw.js → manifest-CFq6WJJO.js} +4 -4
- package/dist/{manifest-Bbtt8mb1.d.ts → manifest-CGJ2xLRu.d.ts} +1 -1
- package/dist/{manifest-DpwaOTir.js → manifest-CHheBZjl.js} +3 -3
- package/dist/{manifest-B83YpMlz.d.ts → manifest-CJzK3H3h.d.ts} +1 -1
- package/dist/{manifest-ClbUuESE.js → manifest-CKT1bZoZ.js} +2 -2
- package/dist/{manifest-Cj5IjsCB.js → manifest-CLFmOMSQ.js} +2 -2
- package/dist/{manifest-B9KmOzmT.d.ts → manifest-CMmfdgAG.d.ts} +1 -1
- package/dist/{manifest-Bx_0qkBP.js → manifest-COnvr04R.js} +2 -2
- package/dist/{manifest-mu_UflgB.d.ts → manifest-CR_RHsHu.d.ts} +1 -1
- package/dist/{manifest-BTC6dWdq.d.ts → manifest-CSLqw5qE.d.ts} +1 -1
- package/dist/{manifest-BDGVge5o.js → manifest-CWkdEugm.js} +2 -2
- package/dist/{manifest-DS2PjAgW.js → manifest-CXTVwg4s.js} +3 -3
- package/dist/{manifest-CX8DVTzn.js → manifest-CY-bInzt.js} +3 -3
- package/dist/{manifest-BZP0wKpE.js → manifest-CaZnTLGe.js} +3 -3
- package/dist/{manifest-B4CVN-Kx.js → manifest-CbdezcLS.js} +2 -2
- package/dist/{manifest-B3QwQDTx.js → manifest-Ccjdt-zG.js} +3 -3
- package/dist/{manifest-BW7wdKXA.js → manifest-CdDdPHbV.js} +4 -4
- package/dist/{manifest-cqfeLW8g.js → manifest-CeN-ohYP.js} +2 -2
- package/dist/{manifest-B7MpuCmz.d.ts → manifest-Cge4urPD.d.ts} +1 -1
- package/dist/{manifest-DsYIWD--.js → manifest-CiAp3lJg.js} +2 -2
- package/dist/{manifest-BFJvys4-.js → manifest-CmtXDmOP.js} +3 -3
- package/dist/{manifest-CJb0PtMj.d.ts → manifest-Cq3zIydP.d.ts} +1 -1
- package/dist/{manifest-DLv_WaSF.d.ts → manifest-Cs5-Vi9X.d.ts} +1 -1
- package/dist/{manifest-DwVl4YC4.d.ts → manifest-CsVTMa-G.d.ts} +1 -1
- package/dist/{manifest-DBsPHetA.js → manifest-Ct3CZB2E.js} +2 -2
- package/dist/{manifest--M7GmEPg.d.ts → manifest-CyKD7Hyx.d.ts} +1 -1
- package/dist/{manifest-DNaSpmZ3.js → manifest-Cytb-iJk.js} +2 -2
- package/dist/{manifest-Cj_ZnW6k.js → manifest-D-sJpAJB.js} +3 -3
- package/dist/{manifest-Bpzxyvxc.js → manifest-D0ceE9Zm.js} +3 -3
- package/dist/{manifest-CIJTIKo3.d.ts → manifest-D1FhVaUw.d.ts} +1 -1
- package/dist/{manifest-CLphqjtj.d.ts → manifest-D2URJ82u.d.ts} +1 -1
- package/dist/{manifest-Czv_oJ77.js → manifest-D2r45JYc.js} +2 -2
- package/dist/{manifest-DBJ5nBG9.d.ts → manifest-D3V8Ngw3.d.ts} +1 -1
- package/dist/{manifest-B709eXLx.js → manifest-D5UYH-l1.js} +2 -2
- package/dist/{manifest-DVnOUxy4.js → manifest-D5gmrL5j.js} +6 -6
- package/dist/{manifest-BQwqV6dQ.js → manifest-D6k-MFrE.js} +4 -4
- package/dist/{manifest-BoSzgLUl.js → manifest-D72opuEP.js} +3 -3
- package/dist/{manifest-DJ5nCW5K.js → manifest-D8ljY6Fz.js} +4 -4
- package/dist/{manifest-DemyeI_z.js → manifest-D96KwsqD.js} +4 -4
- package/dist/{manifest-Bz3xNPJL.d.ts → manifest-D9B8QIWz.d.ts} +1 -1
- package/dist/{manifest-BkS073Py.d.ts → manifest-DA0Q62es.d.ts} +1 -1
- package/dist/{manifest-CYNC6a1d.js → manifest-DAu2qpOy.js} +2 -2
- package/dist/{manifest-0vrTq9Uf.d.ts → manifest-DB6dSXpw.d.ts} +1 -1
- package/dist/{manifest-Db-GUsLH.d.ts → manifest-DKY1mHtE.d.ts} +1 -1
- package/dist/{manifest-CQFlAwfU.d.ts → manifest-DOIRQHB8.d.ts} +2 -2
- package/dist/{manifest-0PDfKdtc.js → manifest-DR8po1OZ.js} +4 -4
- package/dist/{manifest-ITF-BpEi.js → manifest-D_RCNlv9.js} +4 -4
- package/dist/{manifest-CR-6QDLZ.d.ts → manifest-D_gWI_Xp.d.ts} +1 -1
- package/dist/{manifest-BR_uGpTd.js → manifest-DaZ7LEOi.js} +2 -2
- package/dist/{manifest-Dz2IkqqY.d.ts → manifest-DfaKFvmO.d.ts} +1 -1
- package/dist/{manifest-DPFn2x18.d.ts → manifest-Dg4rFnjr.d.ts} +1 -1
- package/dist/{manifest-n9XQtQXA.d.ts → manifest-DhYiWMYQ.d.ts} +1 -1
- package/dist/{manifest-BfOHwSNK.js → manifest-DjIq3ZJf.js} +7 -7
- package/dist/{manifest-D7yeYU0f.d.ts → manifest-DnSrbZuv.d.ts} +1 -1
- package/dist/{manifest-D7slgR5H.d.ts → manifest-Do4TvdNR.d.ts} +1 -1
- package/dist/{manifest-DdFl3BYM.d.ts → manifest-Do7f1k9C.d.ts} +1 -1
- package/dist/{manifest--qnXa2lK.js → manifest-Dr-wuvfR.js} +4 -4
- package/dist/{manifest-yPcrAK5N.d.ts → manifest-Dr5yltSj.d.ts} +10 -3
- package/dist/{manifest-CbxMRPGY.js → manifest-DunhKI5K.js} +4 -4
- package/dist/{manifest-C3RDEoAr.d.ts → manifest-Duq5aCrY.d.ts} +1 -1
- package/dist/{manifest-J6kJX8YL.js → manifest-DuwJ7Ya_.js} +3 -3
- package/dist/{manifest-FJi1pYoB.js → manifest-Dxob7J6V.js} +6 -6
- package/dist/{manifest-Dj9AIgTy.d.ts → manifest-DzNmDhoS.d.ts} +1 -1
- package/dist/{manifest-CHsjS47_.d.ts → manifest-FqJtbN5n.d.ts} +1 -1
- package/dist/{manifest-roKO06Ko.d.ts → manifest-I7nR1vhO.d.ts} +1 -1
- package/dist/{manifest-o-EzlFwZ.js → manifest-N-vJi36T.js} +2 -2
- package/dist/{manifest-FAVN8Bg9.js → manifest-UHMLAfCl.js} +2 -2
- package/dist/{manifest-BKegpJgn.d.ts → manifest-VoN5Ae-i.d.ts} +1 -1
- package/dist/{manifest-DDkncgRB.d.ts → manifest-XRDA_p9P.d.ts} +1 -1
- package/dist/{manifest-Di0UrbTw.d.ts → manifest-ZQvywRBI.d.ts} +1 -1
- package/dist/{manifest-COZUTRxz.js → manifest-aWO0h4lZ.js} +3 -3
- package/dist/{manifest-D7R4sM8L.d.ts → manifest-hpPeciuH.d.ts} +1 -1
- package/dist/{manifest-CkYNs6PX.js → manifest-iNt_0t6h.js} +4 -4
- package/dist/{manifest-BAgqRR7p.js → manifest-j5YiEWqV.js} +2 -2
- package/dist/{manifest-D_iJU__f.d.ts → manifest-jRpt7muB.d.ts} +1 -1
- package/dist/{manifest-xD290bNh.js → manifest-jU8fwfLu.js} +3 -3
- package/dist/{manifest-DCC3phPq.js → manifest-nR_d-Ivi.js} +1 -1
- package/dist/{manifest-BRd1q660.d.ts → manifest-nyksTa_6.d.ts} +1 -1
- package/dist/{manifest-CWaCXYgf.js → manifest-p4Yvamix.js} +2 -2
- package/dist/{manifest-BQJV63RV.js → manifest-pKQ4z-dv.js} +1 -1
- package/dist/{manifest-DbjDYuCE.js → manifest-q62slcP6.js} +2 -2
- package/dist/{manifest-UbBXSkXn.d.ts → manifest-uDAAzAlQ.d.ts} +1 -1
- package/dist/{manifest-CtOwRTvP.js → manifest-upxzRaY-.js} +2 -2
- package/dist/{manifest-DW2_P6AT.js → manifest-vaCUz3Wa.js} +3 -3
- package/dist/{manifest-Dqgqm1Zo.js → manifest-vabt4x2a.js} +3 -3
- package/dist/{manifest-Cfvr-BhF.js → manifest-wSbIcOln.js} +19 -7
- package/dist/mapper/bin.js +7 -7
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/sdk/index.js +1 -1
- package/dist/{mcp-Bx9wzQw6.js → mcp-D1d_uDNE.js} +2 -2
- package/dist/{message-Cc4bkdNw.d.ts → message-Chvocrom.d.ts} +27 -4
- package/dist/{model-messages-OmbNNuN2.js → model-messages-BgSCTojd.js} +1 -1
- package/dist/{model-messages-CGSUU450.d.ts → model-messages-CK7L1_hV.d.ts} +1 -1
- package/dist/{money-codec-CvUy3_Ep.js → money-codec-lrXaOqi7.js} +1 -1
- package/dist/next/index.d.ts +7 -7
- package/dist/next/index.js +5 -5
- package/dist/{operations-Di203azT.d.ts → operations-BSsNQ81h.d.ts} +1 -1
- package/dist/{options-CyYZvdSy.js → options-BNtLQZrG.js} +2 -1
- package/dist/{options-SOjQVgfS.js → options-BYlcrVVf.js} +1 -0
- package/dist/options-BxOFSs-u.js +4 -0
- package/dist/orpc/index.d.ts +1 -1
- package/dist/orpc/index.js +1 -1
- package/dist/otel/index.d.ts +1 -1
- package/dist/otel/index.js +5 -5
- package/dist/{parse-H3g3kyZa.js → parse-Iz0DTVot.js} +2 -2
- package/dist/{payments-D89SVEgj.js → payments-DjrRAHBY.js} +1 -1
- package/dist/{permissions-C7GgjgTA.d.ts → permissions-CrPkD5Ik.d.ts} +1 -1
- package/dist/{ports-6EMtxwGE.d.ts → ports-Z6S_jGD7.d.ts} +1 -1
- package/dist/powersync/index.d.ts +3 -3
- package/dist/preset/index.d.ts +4 -4
- package/dist/preset/index.js +3 -3
- package/dist/{preset-Be8m6-PH.js → preset-D2dg-EVp.js} +3 -2
- package/dist/{preview-DCndUjk9.js → preview-B7OjoABd.js} +3 -3
- package/dist/{preview-Dlc_7tMK.d.ts → preview-Bgwwuvc9.d.ts} +2 -2
- package/dist/{project-CwZtBezd.js → project-Dhm0C7OR.js} +5 -5
- package/dist/{provider-DRGTjcBY.js → provider-Bkh8zSHN.js} +1 -1
- package/dist/{push-token-CQnqTZrb.d.ts → push-token-hDDp188w.d.ts} +1 -1
- package/dist/query/index.d.ts +1 -1
- package/dist/rate-limit/index.d.ts +1 -1
- package/dist/rate-limit/index.js +1 -1
- package/dist/{rate-limit-Bl_jNyAg.d.ts → rate-limit-A_ngDsV_.d.ts} +17 -0
- package/dist/{rate-limit-Df913_w3.js → rate-limit-Jl-5e7s8.js} +30 -10
- package/dist/react/index.d.ts +5 -5
- package/dist/react/index.js +1 -1
- package/dist/react/native/index.d.ts +1 -1
- package/dist/react/server.d.ts +5 -5
- package/dist/react/server.js +1 -1
- package/dist/{react-CsgcTKRk.js → react-DIfKgdfV.js} +2 -2
- package/dist/{react-CqOVutZj.js → react-DnOu9xsi.js} +3 -3
- package/dist/react-router/index.js +2 -2
- package/dist/realtime/index.d.ts +3 -3
- package/dist/realtime/index.js +2 -2
- package/dist/{record-form-DqGcUu0C.d.ts → record-form-Bye6v7Sg.d.ts} +1 -1
- package/dist/{recordings-CiYHdFPa.d.ts → recordings-16Flkx9W.d.ts} +1 -1
- package/dist/records/index.d.ts +7 -7
- package/dist/{route-optimizer-DqUyDP78.js → route-optimizer-Ds11cQyM.js} +1 -1
- package/dist/{rows-Ccg381fF.js → rows-DidUYmOx.js} +1 -1
- package/dist/{rows-CTzeKlaI.js → rows-kSV-CDYA.js} +2 -2
- package/dist/runs-CEm5AFQk.js +91 -0
- package/dist/{sales-C8o3E5U3.js → sales-DNuk5v36.js} +7 -7
- package/dist/{sales-lines-COFwijz1.js → sales-lines-mwRnIC9p.js} +3 -3
- package/dist/{sales-shared-DGSptcqA.js → sales-shared-Ca2ZDF6a.js} +1 -1
- package/dist/{sales-variants-D0oxdF-6.js → sales-variants-QTgChYXJ.js} +1 -1
- package/dist/{scores-CQt_G6T-.js → scores-Opsegupn.js} +2 -2
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +4 -4
- package/dist/{settings-B4NApcY7.js → settings-Bf5nmbl-.js} +2 -2
- package/dist/{sign-in-Dd5ljzNG.js → sign-in-BYJboUBW.js} +1 -1
- package/dist/{signing-keys-B2bpJ3eJ.js → signing-keys-sYy92dAx.js} +2 -2
- package/dist/solid/index.d.ts +5 -5
- package/dist/solid-start/index.js +2 -2
- package/dist/spec/index.d.ts +2 -2
- package/dist/spec/index.js +2 -2
- package/dist/{spec-pins-D2Q41RiK.d.ts → spec-pins-Bb6V8nR2.d.ts} +1 -1
- package/dist/{spec-pins-BtVFN8wA.js → spec-pins-Dlz8OVqi.js} +1 -1
- package/dist/sql/index.d.ts +6 -6
- package/dist/sql/index.js +3 -3
- package/dist/{sql-BPU70zf9.js → sql-DrlapNYO.js} +3365 -788
- package/dist/{sso-gMj8CIpe.js → sso-RsAYRs9q.js} +2 -2
- package/dist/ssr/index.d.ts +1 -1
- package/dist/{store-DHoKrWYZ.d.ts → store-CGXNwUwi.d.ts} +6 -1
- package/dist/streams/index.d.ts +59 -2
- package/dist/streams/index.js +111 -22
- package/dist/streams/redis/index.d.ts +8 -1
- package/dist/streams/redis/index.js +12 -4
- package/dist/streams/resumable/index.d.ts +68 -0
- package/dist/streams/resumable/index.js +71 -0
- package/dist/{subject-readers-B5YcD7CO.js → subject-readers-DhXR7Tdk.js} +1 -1
- package/dist/svelte/index.d.ts +5 -5
- package/dist/sveltekit/index.js +2 -2
- package/dist/tanstack-start/index.js +2 -2
- package/dist/{tax-D_M90sFh.js → tax-Deg3udmG.js} +1 -1
- package/dist/{tee-eneLXtYJ.js → tee-CHLXLuvg.js} +2 -1
- package/dist/{tenant-DHLx2ZkL.d.ts → tenant-DYOUVE8r.d.ts} +1 -1
- package/dist/testing/index.d.ts +13 -12
- package/dist/testing/index.js +60 -15
- package/dist/{timeline-9mP3m30L.d.ts → timeline-DTE4-6Hq.d.ts} +2 -2
- package/dist/{topic-DVr01uhB.js → topic-CLEQ3t6o.js} +25 -2
- package/dist/{topic-BKsRT4gu.d.ts → topic-DrN4Af8U.d.ts} +16 -1
- package/dist/{transport-CS4cVH4S.js → transport-CZBRg-9e.js} +7 -3
- package/dist/{types-Y1Oa950J.d.ts → types-BKtpHTHc.d.ts} +8 -0
- package/dist/{types-B2y4HmKY.d.ts → types-C941lZYk.d.ts} +1 -1
- package/dist/{types-D9r3axee.d.ts → types-DTNDqdyT.d.ts} +2 -2
- package/dist/{types-zYtQ5JDy.d.ts → types-D_o60OcA.d.ts} +1 -1
- package/dist/{types-DlG6Uj4P.d.ts → types-DeKSApwU.d.ts} +2 -2
- package/dist/{undo-DNRfstwk.js → undo-BXeYO6gy.js} +2 -2
- package/dist/{usage-CFVOHbUu.d.ts → usage-D7CYIk1m.d.ts} +22 -0
- package/dist/vue/index.d.ts +5 -5
- package/dist/{watch-topic-M1yL9NiW.d.ts → watch-topic-ClQWiVZ1.d.ts} +1 -1
- package/dist/{webhook-inbox-BamK2_Vw.js → webhook-inbox-B36XJ2eY.js} +25 -2
- package/dist/webmcp/index.d.ts +1 -1
- package/dist/webmcp/index.js +1 -1
- package/dist/workflow-sdk/builder/index.d.ts +3 -3
- package/dist/workflow-sdk/builder/index.js +1 -1
- package/dist/workflow-sdk/index.d.ts +7 -3
- package/dist/workflow-sdk/index.js +16 -74
- package/dist/workflow-sdk/world/index.d.ts +48 -3
- package/dist/workflow-sdk/world/index.js +326 -31
- package/dist/{workflow-sdk-BCNusk7Y.d.ts → workflow-sdk-Bdp_VQ3Q.d.ts} +37 -3
- package/dist/{workflow-sdk-cHlpMyLV.js → workflow-sdk-ID8eoPMe.js} +108 -7
- package/dist/{workflow-sdk-CcoFSLFn.js → workflow-sdk-j7xorOLf.js} +230 -60
- package/dist/{workflows-DjVrHu22.d.ts → workflows-C6fR7YGm.d.ts} +56 -15
- package/dist/yjs/index.d.ts +1 -1
- package/dist/yjs/index.js +1 -1
- package/package.json +41 -11
- package/schemas/ai-message-v2.json +290 -0
- package/schemas/config-v1.json +29 -1
- package/schemas/design-v1.json +45 -0
- package/schemas/doctor-report-v1.json +5 -0
- package/skills/better-supabase/references/ui-recipes.md +77 -0
- package/skills/better-supabase-api/SKILL.md +2 -2
- package/skills/better-supabase-api/references/ai.md +56 -0
- package/skills/better-supabase-api/references/streams-credentials.md +5 -0
- package/dist/cli/add-4-omCrbh.js +0 -1
- package/dist/cli/env-C9HRYvnX.js +0 -1
- package/dist/cli/powersync-ZBM_emZL.js +0 -1
- package/dist/cli/seed-Ki7TgmY1.js +0 -1
- package/dist/embeddings-bZWDJ5yx.js +0 -129
package/dist/chat-sdk/index.js
CHANGED
|
@@ -1,8 +1,52 @@
|
|
|
1
|
+
import { n as dbError } from "../errors-CXPerGIl.js";
|
|
1
2
|
import { n as isRecord } from "../guards-CsRa6v57.js";
|
|
2
3
|
import { s as nowInstant } from "../temporal-DKTdGK9i.js";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { a as ok, r as err, t as AsyncResult } from "../result-DrBaeIVt.js";
|
|
5
|
+
import { t as importOptionalPeer } from "../optional-peer-5SOYr3lL.js";
|
|
6
|
+
import { B as textOf, F as run, H as toInstant, K as rpcTransport, T as optionalText, W as dbTransport, f as errorText, k as randomToken, o as blockCall, q as sqlTransport } from "../block-helpers-DApvw3n9.js";
|
|
7
|
+
import { r as writeToStore } from "../tee-CHLXLuvg.js";
|
|
5
8
|
import { BaseFormatConverter, ChatError, Message, NotImplementedError, RateLimitError, defaultEmojiResolver, parseMarkdown, stringifyMarkdown } from "chat";
|
|
9
|
+
// src/chat-sdk/capabilities.ts
|
|
10
|
+
/** The error code `capabilitiesOf` returns when the catalog peer is missing. */
|
|
11
|
+
const CHAT_CATALOG_MISSING = "CHAT_CATALOG_MISSING";
|
|
12
|
+
const isCatalog = (value) => isRecord(value) && typeof value["getCatalogEntry"] === "function";
|
|
13
|
+
const text = (value, fallback) => typeof value === "string" ? value : fallback;
|
|
14
|
+
function supportOf(value) {
|
|
15
|
+
if (typeof value === "string") return { status: value === "yes" || value === "partial" ? value : "no" };
|
|
16
|
+
if (!isRecord(value)) return { status: "no" };
|
|
17
|
+
const status = value["status"];
|
|
18
|
+
const label = value["label"];
|
|
19
|
+
return {
|
|
20
|
+
status: status === "yes" || status === "partial" ? status : "no",
|
|
21
|
+
...typeof label === "string" ? { label } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const missing = () => dbError("unsupported", "capabilitiesOf needs the @chat-adapter/catalog package: pnpm add @chat-adapter/catalog", { code: CHAT_CATALOG_MISSING });
|
|
25
|
+
/**
|
|
26
|
+
* What the Chat SDK catalog lists for an adapter (`slack`, `whatsapp`, ...):
|
|
27
|
+
* its package, type and capability matrix, so an app can pick a fallback before
|
|
28
|
+
* it posts a card or a file. `@chat-adapter/catalog` is an optional peer loaded
|
|
29
|
+
* on first use; without it the result is an `unsupported` error with the code
|
|
30
|
+
* `CHAT_CATALOG_MISSING`. It never imports `chat/adapters`. An unknown name is
|
|
31
|
+
* a `not_found` error. Pass `load` to supply the module yourself.
|
|
32
|
+
*/
|
|
33
|
+
function capabilitiesOf(adapterName, options = {}) {
|
|
34
|
+
return AsyncResult.from(async () => {
|
|
35
|
+
const module = await (options.load ?? (() => importOptionalPeer("@chat-adapter/catalog")))();
|
|
36
|
+
if (!isCatalog(module)) return err(missing());
|
|
37
|
+
const entry = module.getCatalogEntry(adapterName);
|
|
38
|
+
if (!isRecord(entry)) return err(dbError("not_found", `The Chat SDK catalog has no "${adapterName}"`));
|
|
39
|
+
const features = isRecord(entry["features"]) ? entry["features"] : {};
|
|
40
|
+
return ok({
|
|
41
|
+
slug: text(entry["slug"], adapterName),
|
|
42
|
+
name: text(entry["name"], adapterName),
|
|
43
|
+
type: text(entry["type"], "platform"),
|
|
44
|
+
group: text(entry["group"], "community"),
|
|
45
|
+
packageName: text(entry["packageName"], ""),
|
|
46
|
+
features: Object.fromEntries(Object.entries(features).map(([key, value]) => [key, supportOf(value)]))
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
6
50
|
// src/chat-sdk/delivery.ts
|
|
7
51
|
const STATUSES = {
|
|
8
52
|
accepted: "queued",
|
|
@@ -17,30 +61,30 @@ const STATUSES = {
|
|
|
17
61
|
canceled: "failed"
|
|
18
62
|
};
|
|
19
63
|
const statusOf = (value) => typeof value === "string" ? STATUSES[value.toLowerCase()] : void 0;
|
|
20
|
-
function json(body) {
|
|
64
|
+
function json$1(body) {
|
|
21
65
|
try {
|
|
22
66
|
return JSON.parse(body);
|
|
23
67
|
} catch {
|
|
24
68
|
return;
|
|
25
69
|
}
|
|
26
70
|
}
|
|
27
|
-
const list = (value) => Array.isArray(value) ? value : [];
|
|
71
|
+
const list$1 = (value) => Array.isArray(value) ? value : [];
|
|
28
72
|
/** WhatsApp Cloud API: `entry[].changes[].value.statuses[]`. */
|
|
29
73
|
const whatsappDeliveries = ({ body }) => {
|
|
30
|
-
const payload = json(body);
|
|
74
|
+
const payload = json$1(body);
|
|
31
75
|
if (!isRecord(payload) || payload["object"] !== "whatsapp_business_account") return null;
|
|
32
76
|
const updates = [];
|
|
33
77
|
let other = false;
|
|
34
|
-
for (const entry of list(payload["entry"])) for (const change of list(isRecord(entry) ? entry["changes"] : void 0)) {
|
|
78
|
+
for (const entry of list$1(payload["entry"])) for (const change of list$1(isRecord(entry) ? entry["changes"] : void 0)) {
|
|
35
79
|
const value = isRecord(change) ? change["value"] : void 0;
|
|
36
80
|
if (!isRecord(value)) continue;
|
|
37
|
-
if (list(value["messages"]).length > 0) other = true;
|
|
38
|
-
for (const item of list(value["statuses"])) {
|
|
81
|
+
if (list$1(value["messages"]).length > 0) other = true;
|
|
82
|
+
for (const item of list$1(value["statuses"])) {
|
|
39
83
|
if (!isRecord(item)) continue;
|
|
40
84
|
const status = statusOf(item["status"]);
|
|
41
85
|
const id = optionalText(item["id"]);
|
|
42
86
|
if (!status || id === void 0) continue;
|
|
43
|
-
const first = list(item["errors"])[0];
|
|
87
|
+
const first = list$1(item["errors"])[0];
|
|
44
88
|
const error = isRecord(first) ? optionalText(first["title"]) ?? optionalText(first["message"]) : void 0;
|
|
45
89
|
updates.push({
|
|
46
90
|
externalId: id,
|
|
@@ -59,14 +103,14 @@ const whatsappDeliveries = ({ body }) => {
|
|
|
59
103
|
* carry no ids and are skipped.
|
|
60
104
|
*/
|
|
61
105
|
const messengerDeliveries = ({ body }) => {
|
|
62
|
-
const payload = json(body);
|
|
106
|
+
const payload = json$1(body);
|
|
63
107
|
if (!isRecord(payload) || payload["object"] !== "page" && payload["object"] !== "instagram") return null;
|
|
64
|
-
const events = list(payload["entry"]).flatMap((entry) => list(isRecord(entry) ? entry["messaging"] : void 0).filter(isRecord));
|
|
108
|
+
const events = list$1(payload["entry"]).flatMap((entry) => list$1(isRecord(entry) ? entry["messaging"] : void 0).filter(isRecord));
|
|
65
109
|
const receipts = events.filter((event) => isRecord(event["delivery"]) || isRecord(event["read"]));
|
|
66
110
|
return {
|
|
67
111
|
updates: receipts.flatMap((event) => {
|
|
68
112
|
const delivery = event["delivery"];
|
|
69
|
-
return isRecord(delivery) ? list(delivery["mids"]).flatMap((mid) => typeof mid === "string" ? [{
|
|
113
|
+
return isRecord(delivery) ? list$1(delivery["mids"]).flatMap((mid) => typeof mid === "string" ? [{
|
|
70
114
|
externalId: mid,
|
|
71
115
|
status: "delivered"
|
|
72
116
|
}] : []) : [];
|
|
@@ -102,6 +146,301 @@ const DELIVERY_PARSERS = {
|
|
|
102
146
|
twilio: twilioDeliveries,
|
|
103
147
|
sms: twilioDeliveries
|
|
104
148
|
};
|
|
149
|
+
// src/chat-sdk/identity.ts
|
|
150
|
+
/**
|
|
151
|
+
* The `IdentityRef` of a Chat SDK author: `kind: "chat"`, the adapter name as
|
|
152
|
+
* the provider and the platform's user id. Pass `workspace` (a Slack team id)
|
|
153
|
+
* when one app serves several workspaces.
|
|
154
|
+
*/
|
|
155
|
+
function chatIdentityOf(author, adapter, workspace) {
|
|
156
|
+
return {
|
|
157
|
+
kind: "chat",
|
|
158
|
+
provider: adapter.name,
|
|
159
|
+
value: author.userId,
|
|
160
|
+
...workspace === void 0 ? {} : { workspace }
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The user or contact `identity` is linked to; `null` without a resolver or a
|
|
165
|
+
* link.
|
|
166
|
+
*/
|
|
167
|
+
async function resolveChatAuthor(identity, options) {
|
|
168
|
+
const resolve = options.principalByIdentity ?? options.server?.authorization?.identities?.principalByIdentity;
|
|
169
|
+
return resolve ? await resolve(identity) ?? null : null;
|
|
170
|
+
}
|
|
171
|
+
/** Enqueues bot jobs that run as the chat author's linked user. */
|
|
172
|
+
function botJobs(options) {
|
|
173
|
+
return { async enqueue(identity, payload) {
|
|
174
|
+
const author = await resolveChatAuthor(identity, options);
|
|
175
|
+
if (author?.kind !== "user") return {
|
|
176
|
+
result: await options.enqueue(payload, {}),
|
|
177
|
+
author
|
|
178
|
+
};
|
|
179
|
+
const ticket = await options.ticketFor(author.userId);
|
|
180
|
+
if (typeof ticket !== "string" || ticket === "") throw new TypeError("botJobs: ticketFor returned an empty ticket");
|
|
181
|
+
return {
|
|
182
|
+
result: await options.enqueue(payload, { ticket }),
|
|
183
|
+
author
|
|
184
|
+
};
|
|
185
|
+
} };
|
|
186
|
+
}
|
|
187
|
+
/** A Chat SDK `ActionEvent` as the `ChatAction` the provider decides. */
|
|
188
|
+
function chatActionOf(event, workspace) {
|
|
189
|
+
return {
|
|
190
|
+
id: event.actionId,
|
|
191
|
+
...event.value === void 0 ? {} : { value: event.value },
|
|
192
|
+
author: chatIdentityOf(event.user, event.adapter, workspace)
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Decides a chat button press through the provider: the author is resolved,
|
|
197
|
+
* then `onAction(action, author)` runs. Everything but `allowed: true` refuses,
|
|
198
|
+
* and an unlinked author is refused before the hook runs. Act on the decision,
|
|
199
|
+
* never on the button alone.
|
|
200
|
+
*/
|
|
201
|
+
function chatActions(options) {
|
|
202
|
+
return async (action) => {
|
|
203
|
+
const hook = options.onAction ?? options.server?.authorization?.chat?.onAction;
|
|
204
|
+
let author;
|
|
205
|
+
try {
|
|
206
|
+
author = await resolveChatAuthor(action.author, options);
|
|
207
|
+
} catch {
|
|
208
|
+
return {
|
|
209
|
+
allowed: false,
|
|
210
|
+
reason: "error"
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
if (author === null) return {
|
|
214
|
+
allowed: false,
|
|
215
|
+
reason: "unlinked"
|
|
216
|
+
};
|
|
217
|
+
if (!hook) return {
|
|
218
|
+
allowed: false,
|
|
219
|
+
reason: "unhandled"
|
|
220
|
+
};
|
|
221
|
+
let decision;
|
|
222
|
+
try {
|
|
223
|
+
decision = await hook(action, author);
|
|
224
|
+
} catch {
|
|
225
|
+
return {
|
|
226
|
+
allowed: false,
|
|
227
|
+
reason: "error"
|
|
228
|
+
};
|
|
229
|
+
}
|
|
230
|
+
if (decision === void 0) return {
|
|
231
|
+
allowed: false,
|
|
232
|
+
reason: "unhandled"
|
|
233
|
+
};
|
|
234
|
+
if (!decision.allowed) return {
|
|
235
|
+
allowed: false,
|
|
236
|
+
reason: "refused"
|
|
237
|
+
};
|
|
238
|
+
switch (author.kind) {
|
|
239
|
+
case "user": return decision.userId === void 0 || decision.userId === author.userId ? {
|
|
240
|
+
allowed: true,
|
|
241
|
+
author,
|
|
242
|
+
userId: author.userId
|
|
243
|
+
} : {
|
|
244
|
+
allowed: false,
|
|
245
|
+
reason: "refused"
|
|
246
|
+
};
|
|
247
|
+
case "contact": return decision.userId === void 0 ? {
|
|
248
|
+
allowed: true,
|
|
249
|
+
author
|
|
250
|
+
} : {
|
|
251
|
+
allowed: true,
|
|
252
|
+
author,
|
|
253
|
+
userId: decision.userId
|
|
254
|
+
};
|
|
255
|
+
default: throw new TypeError(`unknown identity target ${String(author)}`);
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* The approval page URL for `request`, with `kind` and `subject` as query
|
|
261
|
+
* parameters. Opening it approves nothing: the signed-in approver decides on
|
|
262
|
+
* the page, and the page's server action or POST route checks them.
|
|
263
|
+
*/
|
|
264
|
+
function approvalLink(page, request) {
|
|
265
|
+
const url = new URL(page);
|
|
266
|
+
url.searchParams.set("kind", request.kind);
|
|
267
|
+
url.searchParams.set("subject", request.subject);
|
|
268
|
+
return url.toString();
|
|
269
|
+
}
|
|
270
|
+
const escapeLabel = (label) => label.replaceAll(/[[\]\\]/g, (char) => `\\${char}`);
|
|
271
|
+
/** A chat message that links to the approval page, for `thread.post`. */
|
|
272
|
+
function approvalPrompt(options) {
|
|
273
|
+
const link = `[${escapeLabel(options.label ?? "Review the request")}](${approvalLink(options.page, options.request).replaceAll(")", "%29")})`;
|
|
274
|
+
return { markdown: options.text === void 0 ? link : `${options.text}\n\n${link}` };
|
|
275
|
+
}
|
|
276
|
+
// src/chat-sdk/interactive.ts
|
|
277
|
+
function json(body) {
|
|
278
|
+
try {
|
|
279
|
+
return JSON.parse(body);
|
|
280
|
+
} catch {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const list = (value) => Array.isArray(value) ? value : [];
|
|
285
|
+
/** What the contact picked in one WhatsApp message, or `null`. */
|
|
286
|
+
function replyOf(message) {
|
|
287
|
+
const interactive = message["interactive"];
|
|
288
|
+
if (message["type"] === "interactive" && isRecord(interactive)) {
|
|
289
|
+
const button = interactive["button_reply"];
|
|
290
|
+
const row = interactive["list_reply"];
|
|
291
|
+
if (isRecord(button)) {
|
|
292
|
+
const id = optionalText(button["id"]);
|
|
293
|
+
const title = optionalText(button["title"]);
|
|
294
|
+
return id === void 0 ? null : {
|
|
295
|
+
kind: "button_reply",
|
|
296
|
+
actionId: id,
|
|
297
|
+
...title === void 0 ? {} : { title }
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
if (isRecord(row)) {
|
|
301
|
+
const id = optionalText(row["id"]);
|
|
302
|
+
const title = optionalText(row["title"]);
|
|
303
|
+
const description = optionalText(row["description"]);
|
|
304
|
+
return id === void 0 ? null : {
|
|
305
|
+
kind: "list_reply",
|
|
306
|
+
actionId: id,
|
|
307
|
+
...title === void 0 ? {} : { title },
|
|
308
|
+
...description === void 0 ? {} : { description }
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
const quick = message["button"];
|
|
314
|
+
if (message["type"] === "button" && isRecord(quick)) {
|
|
315
|
+
const text = optionalText(quick["text"]);
|
|
316
|
+
const id = optionalText(quick["payload"]) ?? text;
|
|
317
|
+
return id === void 0 ? null : {
|
|
318
|
+
kind: "quick_reply",
|
|
319
|
+
actionId: id,
|
|
320
|
+
...text === void 0 ? {} : { title: text }
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* The button and list replies in a WhatsApp Cloud API webhook body (a string or
|
|
327
|
+
* its parsed JSON): `interactive.button_reply`, `interactive.list_reply` and a
|
|
328
|
+
* template's quick reply (`type: "button"`). Other messages and status
|
|
329
|
+
* callbacks are skipped.
|
|
330
|
+
*/
|
|
331
|
+
function whatsappInteractiveOf(payload) {
|
|
332
|
+
return readWhatsapp(payload)?.actions ?? [];
|
|
333
|
+
}
|
|
334
|
+
function readWhatsapp(payload) {
|
|
335
|
+
const body = typeof payload === "string" ? json(payload) : payload;
|
|
336
|
+
if (!isRecord(body) || body["object"] !== "whatsapp_business_account") return null;
|
|
337
|
+
const actions = [];
|
|
338
|
+
let messages = 0;
|
|
339
|
+
for (const entry of list(body["entry"])) for (const change of list(isRecord(entry) ? entry["changes"] : void 0)) {
|
|
340
|
+
const value = isRecord(change) ? change["value"] : void 0;
|
|
341
|
+
if (!isRecord(value)) continue;
|
|
342
|
+
const names = /* @__PURE__ */ new Map();
|
|
343
|
+
for (const contact of list(value["contacts"])) {
|
|
344
|
+
if (!isRecord(contact)) continue;
|
|
345
|
+
const id = optionalText(contact["wa_id"]);
|
|
346
|
+
const profile = contact["profile"];
|
|
347
|
+
const name = isRecord(profile) ? optionalText(profile["name"]) : void 0;
|
|
348
|
+
if (id !== void 0 && name !== void 0) names.set(id, name);
|
|
349
|
+
}
|
|
350
|
+
for (const item of list(value["messages"])) {
|
|
351
|
+
if (!isRecord(item)) continue;
|
|
352
|
+
messages += 1;
|
|
353
|
+
const reply = replyOf(item);
|
|
354
|
+
const from = optionalText(item["from"]);
|
|
355
|
+
const messageId = optionalText(item["id"]);
|
|
356
|
+
if (reply === null || from === void 0 || messageId === void 0) continue;
|
|
357
|
+
const context = item["context"];
|
|
358
|
+
const contextMessageId = isRecord(context) ? optionalText(context["id"]) : void 0;
|
|
359
|
+
const name = names.get(from);
|
|
360
|
+
actions.push({
|
|
361
|
+
...reply,
|
|
362
|
+
from,
|
|
363
|
+
messageId,
|
|
364
|
+
...name === void 0 ? {} : { name },
|
|
365
|
+
...contextMessageId === void 0 ? {} : { contextMessageId }
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return {
|
|
370
|
+
actions,
|
|
371
|
+
only: actions.length > 0 && actions.length === messages
|
|
372
|
+
};
|
|
373
|
+
}
|
|
374
|
+
/** `whatsappInteractiveOf` as an `InteractiveParser`. */
|
|
375
|
+
const whatsappInteractive = ({ body }) => readWhatsapp(body);
|
|
376
|
+
/** The parsers `inboundHandler` uses by default, keyed by adapter name. */
|
|
377
|
+
const INTERACTIVE_PARSERS = { whatsapp: whatsappInteractive };
|
|
378
|
+
// src/chat-sdk/store.ts
|
|
379
|
+
/**
|
|
380
|
+
* The replayable event in a webhook inbox message's `payload`, or `null`. The
|
|
381
|
+
* message's `attempts` becomes the event's `attempt`.
|
|
382
|
+
*/
|
|
383
|
+
function chatEventOf(message) {
|
|
384
|
+
const { payload } = message;
|
|
385
|
+
if (!isRecord(payload) || typeof payload["adapter"] !== "string" || typeof payload["body"] !== "string") return null;
|
|
386
|
+
const headers = {};
|
|
387
|
+
if (isRecord(payload["headers"])) {
|
|
388
|
+
for (const [key, value] of Object.entries(payload["headers"])) if (typeof value === "string") headers[key] = value;
|
|
389
|
+
}
|
|
390
|
+
return {
|
|
391
|
+
id: String(message.id),
|
|
392
|
+
adapter: payload["adapter"],
|
|
393
|
+
body: payload["body"],
|
|
394
|
+
headers,
|
|
395
|
+
...message.attempts === void 0 ? {} : { attempt: message.attempts }
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
/** The store an `Inbox` or a store argument stands for. */
|
|
399
|
+
function isInboundStore(value) {
|
|
400
|
+
return "apiVersion" in value;
|
|
401
|
+
}
|
|
402
|
+
/** Adapts an `Inbox` on a service transport to `ChatInboundStore`. */
|
|
403
|
+
function inboxStore(inbox) {
|
|
404
|
+
return {
|
|
405
|
+
apiVersion: 1,
|
|
406
|
+
recordInbound: (input) => inbox.inbound.record(input).orThrow(),
|
|
407
|
+
recordOutbound: (input) => inbox.deliveries.record({
|
|
408
|
+
messageId: input.messageId,
|
|
409
|
+
channel: input.channel,
|
|
410
|
+
externalId: input.externalId,
|
|
411
|
+
status: "sent"
|
|
412
|
+
}).orThrow(),
|
|
413
|
+
recordDeliveryAttempt: (input) => inbox.deliveries.record({
|
|
414
|
+
messageId: input.messageId,
|
|
415
|
+
channel: input.channel,
|
|
416
|
+
status: input.status,
|
|
417
|
+
...input.externalId === void 0 ? {} : { externalId: input.externalId },
|
|
418
|
+
...input.error === void 0 ? {} : { error: input.error }
|
|
419
|
+
}).orThrow(),
|
|
420
|
+
updateDeliveryStatus: (input) => inbox.deliveries.setStatus(input).orThrow(),
|
|
421
|
+
lastInboundAt: async (conversationId) => {
|
|
422
|
+
return (await inbox.conversations.get(conversationId).orThrow())?.lastInboundAt ?? null;
|
|
423
|
+
},
|
|
424
|
+
outbound: async (messageId) => {
|
|
425
|
+
const message = await inbox.messages.get(messageId).orThrow();
|
|
426
|
+
if (message?.kind !== "message" || message.deletedAt !== void 0) return null;
|
|
427
|
+
const conversation = await inbox.conversations.get(message.conversationId).orThrow();
|
|
428
|
+
return conversation ? {
|
|
429
|
+
message,
|
|
430
|
+
conversation
|
|
431
|
+
} : null;
|
|
432
|
+
},
|
|
433
|
+
maintain: async (options) => ({
|
|
434
|
+
woken: await inbox.wakeSnoozed().orThrow(),
|
|
435
|
+
published: await inbox.publishDue().orThrow(),
|
|
436
|
+
purgedEvents: await inbox.inbound.purge({ olderThan: options.keepEvents ?? "7 days" }).orThrow()
|
|
437
|
+
})
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
/** The store for an `Inbox` or a store. */
|
|
441
|
+
function storeOf(value) {
|
|
442
|
+
return isInboundStore(value) ? value : inboxStore(value);
|
|
443
|
+
}
|
|
105
444
|
// src/chat-sdk/channels.ts
|
|
106
445
|
const APP$1 = { type: "app" };
|
|
107
446
|
const ECHO_TTL_MS = 864e5;
|
|
@@ -121,6 +460,26 @@ const DROPPED_HEADERS = /* @__PURE__ */ new Set([
|
|
|
121
460
|
"authorization",
|
|
122
461
|
"x-forwarded-for"
|
|
123
462
|
]);
|
|
463
|
+
async function storeInInbox(inbox, event) {
|
|
464
|
+
if (inbox === void 0) return null;
|
|
465
|
+
const stored = await inbox.inbound.store(event);
|
|
466
|
+
return stored.ok ? stored.data : null;
|
|
467
|
+
}
|
|
468
|
+
/** Reads what a sink's `store` answers: a value, or a block's `Result`. */
|
|
469
|
+
async function storeInSink(sink, event) {
|
|
470
|
+
let outcome;
|
|
471
|
+
try {
|
|
472
|
+
outcome = await sink.store(event);
|
|
473
|
+
} catch {
|
|
474
|
+
return null;
|
|
475
|
+
}
|
|
476
|
+
if (isRecord(outcome) && outcome["ok"] === false) return null;
|
|
477
|
+
const data = isRecord(outcome) && "data" in outcome ? outcome["data"] : outcome;
|
|
478
|
+
return {
|
|
479
|
+
id: isRecord(data) && data["id"] !== void 0 ? String(data["id"]) : event.id,
|
|
480
|
+
duplicate: isRecord(data) && data["duplicate"] === true
|
|
481
|
+
};
|
|
482
|
+
}
|
|
124
483
|
const defaultPassthrough = (request, body) => request.method === "GET" || body.includes("\"type\":\"url_verification\"");
|
|
125
484
|
/**
|
|
126
485
|
* A route handler that verifies a channel webhook, stores the raw event in the
|
|
@@ -128,6 +487,7 @@ const defaultPassthrough = (request, body) => request.method === "GET" || body.i
|
|
|
128
487
|
* into Chat SDK later, so a slow bot never makes the platform retry.
|
|
129
488
|
*/
|
|
130
489
|
function webhook(options) {
|
|
490
|
+
if (options.inbox === void 0 && options.sink === void 0) throw new TypeError("webhook needs an `inbox` or a `sink`");
|
|
131
491
|
const passthrough = options.passthrough ?? defaultPassthrough;
|
|
132
492
|
return async (request) => {
|
|
133
493
|
const body = await request.clone().text();
|
|
@@ -141,7 +501,17 @@ function webhook(options) {
|
|
|
141
501
|
const headers = {};
|
|
142
502
|
for (const [key, value] of request.headers.entries()) if (!DROPPED_HEADERS.has(key)) headers[key] = value;
|
|
143
503
|
const externalId = options.externalId?.(body, request);
|
|
144
|
-
const stored = await options.
|
|
504
|
+
const stored = options.sink ? await storeInSink(options.sink, {
|
|
505
|
+
id: externalId ?? crypto.randomUUID(),
|
|
506
|
+
payload: {
|
|
507
|
+
adapter: options.adapter,
|
|
508
|
+
body,
|
|
509
|
+
headers,
|
|
510
|
+
...options.inboxId === void 0 ? {} : { inboxId: options.inboxId }
|
|
511
|
+
},
|
|
512
|
+
headers,
|
|
513
|
+
...options.tenant === void 0 ? {} : { tenant: options.tenant }
|
|
514
|
+
}) : await storeInInbox(options.inbox, {
|
|
145
515
|
adapter: options.adapter,
|
|
146
516
|
body,
|
|
147
517
|
headers,
|
|
@@ -149,8 +519,8 @@ function webhook(options) {
|
|
|
149
519
|
...options.inboxId === void 0 ? {} : { inboxId: options.inboxId },
|
|
150
520
|
...options.tenant === void 0 ? {} : { tenant: options.tenant }
|
|
151
521
|
});
|
|
152
|
-
if (
|
|
153
|
-
options.after?.(stored
|
|
522
|
+
if (stored === null) return new Response("could not store the event", { status: 503 });
|
|
523
|
+
options.after?.(stored);
|
|
154
524
|
return new Response("ok", { status: 200 });
|
|
155
525
|
};
|
|
156
526
|
}
|
|
@@ -168,39 +538,73 @@ async function readSource(file) {
|
|
|
168
538
|
* or let `webhook` verify and give the adapter a check that accepts replays.
|
|
169
539
|
*/
|
|
170
540
|
function inboundHandler(options) {
|
|
171
|
-
const { chat
|
|
541
|
+
const { chat } = options;
|
|
542
|
+
const store = storeOf(options.inbox);
|
|
543
|
+
const inbox = isInboundStore(options.inbox) ? void 0 : options.inbox;
|
|
172
544
|
const parsers = options.parsers ?? DELIVERY_PARSERS;
|
|
173
545
|
const baseUrl = options.baseUrl ?? "https://inbox.local";
|
|
546
|
+
const interactiveParsers = options.interactive ?? INTERACTIVE_PARSERS;
|
|
547
|
+
const dedupe = options.deduplicate ?? "first-attempt";
|
|
174
548
|
const applyDeliveries = async (adapter, parsed) => {
|
|
175
|
-
for (const update of parsed.updates) await
|
|
549
|
+
for (const update of parsed.updates) await store.updateDeliveryStatus({
|
|
176
550
|
channel: channelFor(adapter),
|
|
177
551
|
externalId: update.externalId,
|
|
178
552
|
status: update.status,
|
|
179
553
|
...update.error === void 0 ? {} : { error: update.error }
|
|
180
|
-
})
|
|
554
|
+
});
|
|
181
555
|
};
|
|
182
|
-
const
|
|
556
|
+
const mark = async (event, status, error) => {
|
|
557
|
+
if (inbox === void 0) return;
|
|
183
558
|
await inbox.inbound.setStatus({
|
|
184
559
|
id: event.id,
|
|
185
|
-
status
|
|
560
|
+
status,
|
|
561
|
+
...error === void 0 ? {} : { error }
|
|
186
562
|
}).orThrow();
|
|
563
|
+
};
|
|
564
|
+
const deduplicates = (event) => {
|
|
565
|
+
switch (dedupe) {
|
|
566
|
+
case "always": return true;
|
|
567
|
+
case "never": return false;
|
|
568
|
+
case "first-attempt": return (event.attempt ?? 1) <= 1;
|
|
569
|
+
default: return dedupe;
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
const applyActions = async (event) => {
|
|
573
|
+
if (options.onAction === void 0) return false;
|
|
574
|
+
const parsed = interactiveParsers[event.adapter]?.(event) ?? null;
|
|
575
|
+
if (parsed === null || parsed.actions.length === 0) return false;
|
|
576
|
+
for (const action of parsed.actions) {
|
|
577
|
+
const decision = options.actions ? await options.actions(chatActionOf({
|
|
578
|
+
actionId: action.actionId,
|
|
579
|
+
...action.title === void 0 ? {} : { value: action.title },
|
|
580
|
+
user: { userId: action.from },
|
|
581
|
+
adapter: { name: event.adapter }
|
|
582
|
+
})) : void 0;
|
|
583
|
+
if (decision !== void 0 && !decision.allowed) continue;
|
|
584
|
+
await options.onAction(action, {
|
|
585
|
+
adapter: event.adapter,
|
|
586
|
+
event,
|
|
587
|
+
...decision === void 0 ? {} : { decision }
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
return parsed.only;
|
|
591
|
+
};
|
|
592
|
+
const process = async (event) => {
|
|
593
|
+
await mark(event, "processing");
|
|
187
594
|
try {
|
|
188
595
|
const parsed = parsers[event.adapter]?.(event) ?? null;
|
|
189
596
|
if (parsed) await applyDeliveries(event.adapter, parsed);
|
|
190
597
|
if (parsed?.only) {
|
|
191
|
-
await
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
598
|
+
await mark(event, "processed");
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
if (await applyActions(event)) {
|
|
602
|
+
await mark(event, "processed");
|
|
195
603
|
return;
|
|
196
604
|
}
|
|
197
605
|
const handle = chat.webhooks[event.adapter];
|
|
198
606
|
if (!handle) {
|
|
199
|
-
await
|
|
200
|
-
id: event.id,
|
|
201
|
-
status: "ignored",
|
|
202
|
-
error: `no adapter named ${event.adapter}`
|
|
203
|
-
}).orThrow();
|
|
607
|
+
await mark(event, "ignored", `no adapter named ${event.adapter}`);
|
|
204
608
|
return;
|
|
205
609
|
}
|
|
206
610
|
const tasks = [];
|
|
@@ -210,20 +614,14 @@ function inboundHandler(options) {
|
|
|
210
614
|
body: event.body
|
|
211
615
|
}), {
|
|
212
616
|
waitUntil: (task) => void tasks.push(task),
|
|
213
|
-
...options.propagateHandlerErrors === true ? { propagateHandlerErrors: true } : {}
|
|
617
|
+
...options.propagateHandlerErrors === true ? { propagateHandlerErrors: true } : {},
|
|
618
|
+
...deduplicates(event) ? {} : { deduplicate: false }
|
|
214
619
|
});
|
|
215
620
|
await Promise.all(tasks);
|
|
216
621
|
if (response.status >= 400) throw new Error(`${event.adapter} answered ${String(response.status)}`);
|
|
217
|
-
await
|
|
218
|
-
id: event.id,
|
|
219
|
-
status: "processed"
|
|
220
|
-
}).orThrow();
|
|
622
|
+
await mark(event, "processed");
|
|
221
623
|
} catch (error) {
|
|
222
|
-
await
|
|
223
|
-
id: event.id,
|
|
224
|
-
status: "failed",
|
|
225
|
-
error: errorText(error)
|
|
226
|
-
});
|
|
624
|
+
await mark(event, "failed", errorText(error)).catch(() => void 0);
|
|
227
625
|
throw error;
|
|
228
626
|
}
|
|
229
627
|
};
|
|
@@ -246,6 +644,7 @@ function inboundHandler(options) {
|
|
|
246
644
|
return {
|
|
247
645
|
process,
|
|
248
646
|
drain: async (drainOptions = {}) => {
|
|
647
|
+
if (inbox === void 0) throw new TypeError("drain reads the Inbox's webhook store: pass the Inbox, or replay events with process()");
|
|
249
648
|
const events = await inbox.inbound.pending({
|
|
250
649
|
limit: drainOptions.limit ?? 50,
|
|
251
650
|
...drainOptions.maxAttempts === void 0 ? {} : { maxAttempts: drainOptions.maxAttempts }
|
|
@@ -253,7 +652,10 @@ function inboundHandler(options) {
|
|
|
253
652
|
let processed = 0;
|
|
254
653
|
let failed = 0;
|
|
255
654
|
for (const event of events) try {
|
|
256
|
-
await process(
|
|
655
|
+
await process({
|
|
656
|
+
...event,
|
|
657
|
+
attempt: event.attempts + 1
|
|
658
|
+
});
|
|
257
659
|
processed += 1;
|
|
258
660
|
} catch {
|
|
259
661
|
failed += 1;
|
|
@@ -270,7 +672,7 @@ function inboundHandler(options) {
|
|
|
270
672
|
const inboxId = options.inboxes[adapter];
|
|
271
673
|
if (inboxId === void 0) throw new Error(`inboundHandler: no inbox for adapter "${adapter}"`);
|
|
272
674
|
const sources = await files(message, adapter, thread.id);
|
|
273
|
-
return
|
|
675
|
+
return store.recordInbound({
|
|
274
676
|
inboxId,
|
|
275
677
|
threadId: thread.id,
|
|
276
678
|
contact: {
|
|
@@ -283,9 +685,10 @@ function inboundHandler(options) {
|
|
|
283
685
|
externalId: message.id,
|
|
284
686
|
...sources.length > 0 ? { files: sources } : {}
|
|
285
687
|
}
|
|
286
|
-
})
|
|
688
|
+
});
|
|
287
689
|
},
|
|
288
690
|
importFiles: async (importOptions) => {
|
|
691
|
+
if (inbox === void 0) throw new TypeError("importFiles needs the Inbox, not a store");
|
|
289
692
|
const read = importOptions.read ?? readSource;
|
|
290
693
|
const pending = await inbox.files.pending(importOptions.limit ?? 50).orThrow();
|
|
291
694
|
let processed = 0;
|
|
@@ -308,6 +711,7 @@ function inboundHandler(options) {
|
|
|
308
711
|
}
|
|
309
712
|
};
|
|
310
713
|
}
|
|
714
|
+
const fromText = (message) => message.format === "markdown" ? { markdown: message.body } : message.body;
|
|
311
715
|
const CHANNELS = { twilio: "sms" };
|
|
312
716
|
const channelFor = (adapter) => CHANNELS[adapter] ?? adapter;
|
|
313
717
|
/**
|
|
@@ -329,11 +733,8 @@ const sleep$1 = (ms) => new Promise((resolve) => {
|
|
|
329
733
|
* contact's last message.
|
|
330
734
|
*/
|
|
331
735
|
async function whatsappWindowOpen(inbox, conversationId, now = nowInstant()) {
|
|
332
|
-
const last =
|
|
333
|
-
|
|
334
|
-
limit: 200
|
|
335
|
-
}).orThrow()).findLast((message) => message.direction === "inbound" && message.kind === "message");
|
|
336
|
-
return last !== void 0 && last.createdAt.add({ hours: 24 }).epochMilliseconds > now.epochMilliseconds;
|
|
736
|
+
const last = await storeOf(inbox).lastInboundAt(conversationId);
|
|
737
|
+
return last !== null && last.add({ hours: 24 }).epochMilliseconds > now.epochMilliseconds;
|
|
337
738
|
}
|
|
338
739
|
/**
|
|
339
740
|
* Posts a staff reply the `inbox` module queued on its channel, records the
|
|
@@ -343,7 +744,8 @@ async function whatsappWindowOpen(inbox, conversationId, now = nowInstant()) {
|
|
|
343
744
|
* retries.
|
|
344
745
|
*/
|
|
345
746
|
function deliver(options) {
|
|
346
|
-
const { chat
|
|
747
|
+
const { chat } = options;
|
|
748
|
+
const store = storeOf(options.inbox);
|
|
347
749
|
const retries = options.rateLimitRetries ?? 2;
|
|
348
750
|
const maxWait = options.maxRetryWaitMs ?? 1e4;
|
|
349
751
|
const postWithRetry = async (post) => {
|
|
@@ -356,36 +758,44 @@ function deliver(options) {
|
|
|
356
758
|
}
|
|
357
759
|
};
|
|
358
760
|
return async (job) => {
|
|
359
|
-
const
|
|
360
|
-
if (
|
|
361
|
-
const conversation =
|
|
362
|
-
if (!conversation) return null;
|
|
761
|
+
const found = await store.outbound(job.message_id);
|
|
762
|
+
if (!found) return null;
|
|
763
|
+
const { message, conversation } = found;
|
|
363
764
|
const name = options.adapterFor?.(conversation) ?? (conversation.inbox?.channel === "sms" ? "twilio" : conversation.inbox?.channel);
|
|
364
765
|
const adapter = name === void 0 ? void 0 : chat.getAdapter(name);
|
|
365
766
|
if (!adapter || name === void 0) throw new Error(`deliver: no adapter for conversation ${conversation.id}`);
|
|
366
767
|
const channel = conversation.inbox?.channel ?? name;
|
|
367
768
|
try {
|
|
368
|
-
const
|
|
769
|
+
const template = await options.template?.({
|
|
369
770
|
conversation,
|
|
370
771
|
message,
|
|
371
772
|
adapter
|
|
372
|
-
})
|
|
773
|
+
});
|
|
774
|
+
const files = [];
|
|
775
|
+
for (const attachment of template ? [] : message.attachments) {
|
|
776
|
+
const file = await options.download?.(attachment);
|
|
777
|
+
if (file) files.push(file);
|
|
778
|
+
}
|
|
779
|
+
const text = message.format === "markdown" ? { markdown: message.body } : { raw: message.body };
|
|
780
|
+
const content = template ?? (files.length > 0 ? {
|
|
781
|
+
...text,
|
|
782
|
+
files
|
|
783
|
+
} : fromText(message));
|
|
373
784
|
const raw = await postWithRetry(() => adapter.postMessage(conversation.threadId, content));
|
|
374
785
|
await chat.getState().set(echoKey(name, raw.id), true, ECHO_TTL_MS);
|
|
375
|
-
await
|
|
786
|
+
await store.recordOutbound({
|
|
376
787
|
messageId: message.id,
|
|
377
788
|
channel,
|
|
378
|
-
externalId: raw.id
|
|
379
|
-
|
|
380
|
-
}).orThrow();
|
|
789
|
+
externalId: raw.id
|
|
790
|
+
});
|
|
381
791
|
return raw;
|
|
382
792
|
} catch (error) {
|
|
383
|
-
await
|
|
793
|
+
await store.recordDeliveryAttempt({
|
|
384
794
|
messageId: message.id,
|
|
385
795
|
channel,
|
|
386
796
|
status: "failed",
|
|
387
797
|
error: errorText(error)
|
|
388
|
-
});
|
|
798
|
+
}).catch(() => void 0);
|
|
389
799
|
throw error;
|
|
390
800
|
}
|
|
391
801
|
};
|
|
@@ -396,151 +806,171 @@ function deliver(options) {
|
|
|
396
806
|
* post the bot's due scheduled messages. Run it from a cron job.
|
|
397
807
|
*/
|
|
398
808
|
async function maintain(options) {
|
|
399
|
-
const
|
|
400
|
-
|
|
809
|
+
const own = await storeOf(options.inbox).maintain?.({ ...options.keepEvents === void 0 ? {} : { keepEvents: options.keepEvents } }) ?? {
|
|
810
|
+
woken: 0,
|
|
811
|
+
published: 0,
|
|
812
|
+
purgedEvents: 0
|
|
813
|
+
};
|
|
401
814
|
const replayed = options.handler ? await options.handler.drain() : {
|
|
402
815
|
processed: 0,
|
|
403
816
|
failed: 0
|
|
404
817
|
};
|
|
818
|
+
const purgedState = options.state ? await options.state.purge() : 0;
|
|
819
|
+
const posted = options.scheduled ? (await options.scheduled.scheduler.publishDue(options.scheduled.chat)).published : 0;
|
|
405
820
|
return {
|
|
406
|
-
|
|
407
|
-
published,
|
|
408
|
-
purgedEvents: await options.inbox.inbound.purge({ olderThan: options.keepEvents ?? "7 days" }).orThrow(),
|
|
821
|
+
...own,
|
|
409
822
|
replayed,
|
|
410
|
-
purgedState
|
|
411
|
-
posted
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
// src/chat-sdk/identity.ts
|
|
415
|
-
/**
|
|
416
|
-
* The `IdentityRef` of a Chat SDK author: `kind: "chat"`, the adapter name as
|
|
417
|
-
* the provider and the platform's user id. Pass `workspace` (a Slack team id)
|
|
418
|
-
* when one app serves several workspaces.
|
|
419
|
-
*/
|
|
420
|
-
function chatIdentityOf(author, adapter, workspace) {
|
|
421
|
-
return {
|
|
422
|
-
kind: "chat",
|
|
423
|
-
provider: adapter.name,
|
|
424
|
-
value: author.userId,
|
|
425
|
-
...workspace === void 0 ? {} : { workspace }
|
|
823
|
+
purgedState,
|
|
824
|
+
posted
|
|
426
825
|
};
|
|
427
826
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
*/
|
|
432
|
-
async function resolveChatAuthor(identity, options) {
|
|
433
|
-
const resolve = options.principalByIdentity ?? options.server?.authorization?.identities?.principalByIdentity;
|
|
434
|
-
return resolve ? await resolve(identity) ?? null : null;
|
|
827
|
+
// src/chat-sdk/inbox-adapter-parts.ts
|
|
828
|
+
function aiGeneratedOf(message) {
|
|
829
|
+
return typeof message === "object" && "aiGenerated" in message && message.aiGenerated;
|
|
435
830
|
}
|
|
436
|
-
/**
|
|
437
|
-
function
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
831
|
+
/** The files and attachments a postable message carries, with their bytes. */
|
|
832
|
+
async function outgoingFilesOf(message) {
|
|
833
|
+
if (typeof message !== "object") return [];
|
|
834
|
+
const out = [];
|
|
835
|
+
if ("files" in message) for (const file of message.files) out.push({
|
|
836
|
+
name: file.filename,
|
|
837
|
+
mimeType: file.mimeType,
|
|
838
|
+
data: file.data
|
|
839
|
+
});
|
|
840
|
+
if ("attachments" in message) for (const attachment of message.attachments) {
|
|
841
|
+
const data = attachment.data ?? await attachment.fetchData?.();
|
|
842
|
+
if (data !== void 0) out.push({
|
|
843
|
+
name: attachment.name ?? "file",
|
|
844
|
+
mimeType: attachment.mimeType,
|
|
845
|
+
data
|
|
846
|
+
});
|
|
847
|
+
}
|
|
848
|
+
return out;
|
|
451
849
|
}
|
|
452
|
-
|
|
453
|
-
|
|
850
|
+
const byteLength = (data) => data instanceof Blob ? data.size : data.byteLength;
|
|
851
|
+
const SHORT_EMOJI_NAME = /^[\w+-]+$/;
|
|
852
|
+
const emojiFromRaw = (emoji) => SHORT_EMOJI_NAME.test(emoji) ? defaultEmojiResolver.fromSlack(emoji) : defaultEmojiResolver.fromGChat(emoji);
|
|
853
|
+
/** What `stream` answers for an empty stream: nothing was posted. */
|
|
854
|
+
function emptyMessage(conversationId, inboxId) {
|
|
855
|
+
const now = nowInstant();
|
|
454
856
|
return {
|
|
455
|
-
id:
|
|
456
|
-
|
|
457
|
-
|
|
857
|
+
id: `empty:${randomToken(9)}`,
|
|
858
|
+
organizationId: "",
|
|
859
|
+
conversationId,
|
|
860
|
+
parentId: void 0,
|
|
861
|
+
threadId: void 0,
|
|
862
|
+
authorId: void 0,
|
|
863
|
+
author: void 0,
|
|
864
|
+
kind: "message",
|
|
865
|
+
body: "",
|
|
866
|
+
document: void 0,
|
|
867
|
+
anchor: void 0,
|
|
868
|
+
mentionIds: [],
|
|
869
|
+
mentionScope: void 0,
|
|
870
|
+
broadcast: false,
|
|
871
|
+
replyCount: 0,
|
|
872
|
+
lastReplyAt: void 0,
|
|
873
|
+
replyUserIds: [],
|
|
874
|
+
pinnedAt: void 0,
|
|
875
|
+
pinnedBy: void 0,
|
|
876
|
+
resolvedAt: void 0,
|
|
877
|
+
resolvedBy: void 0,
|
|
878
|
+
scheduledFor: void 0,
|
|
879
|
+
sentAt: void 0,
|
|
880
|
+
editedAt: void 0,
|
|
881
|
+
deletedAt: void 0,
|
|
882
|
+
createdAt: now,
|
|
883
|
+
attachments: [],
|
|
884
|
+
reactions: [],
|
|
885
|
+
fields: {},
|
|
886
|
+
direction: "outbound",
|
|
887
|
+
authorType: "bot",
|
|
888
|
+
format: "text",
|
|
889
|
+
externalId: null,
|
|
890
|
+
replyTo: null,
|
|
891
|
+
metadata: {
|
|
892
|
+
empty: true,
|
|
893
|
+
inbox_id: inboxId
|
|
894
|
+
}
|
|
458
895
|
};
|
|
459
896
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
allowed: false,
|
|
475
|
-
reason: "error"
|
|
476
|
-
};
|
|
477
|
-
}
|
|
478
|
-
if (author === null) return {
|
|
479
|
-
allowed: false,
|
|
480
|
-
reason: "unlinked"
|
|
481
|
-
};
|
|
482
|
-
if (!hook) return {
|
|
483
|
-
allowed: false,
|
|
484
|
-
reason: "unhandled"
|
|
897
|
+
// src/chat-sdk/inbox-adapter-events.ts
|
|
898
|
+
/** The actions and reactions `inboxAdapter` hands to the Chat SDK. */
|
|
899
|
+
function eventDispatchers(deps) {
|
|
900
|
+
const { remember, stopActionId } = deps;
|
|
901
|
+
const threadIdFor = deps.threadFor;
|
|
902
|
+
const adapterOf = deps.adapter;
|
|
903
|
+
const actorOf = (actor) => {
|
|
904
|
+
const name = actor?.name ?? "visitor";
|
|
905
|
+
return {
|
|
906
|
+
userId: actor?.id ?? "visitor",
|
|
907
|
+
userName: name,
|
|
908
|
+
fullName: name,
|
|
909
|
+
isBot: false,
|
|
910
|
+
isMe: false
|
|
485
911
|
};
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
912
|
+
};
|
|
913
|
+
const settle = (instance, work, webhook, what) => {
|
|
914
|
+
const { waitUntil, ...rest } = webhook;
|
|
915
|
+
const task = work(rest);
|
|
916
|
+
if (waitUntil === void 0) return task;
|
|
917
|
+
waitUntil(rest.propagateHandlerErrors === true ? task : task.catch((error) => {
|
|
918
|
+
instance.getLogger("inbox").error(`inbox ${what} failed`, { error });
|
|
919
|
+
}));
|
|
920
|
+
return Promise.resolve();
|
|
921
|
+
};
|
|
922
|
+
const dispatchAction = (event, webhook = {}) => {
|
|
923
|
+
const chat = deps.chat();
|
|
924
|
+
if (!chat) return Promise.reject(new ChatError("inboxAdapter: initialize() has not run", "NOT_READY"));
|
|
925
|
+
const instance = chat;
|
|
926
|
+
const task = async (handlerOptions) => {
|
|
927
|
+
const threadId = await threadIdFor(event.conversation_id, event.inbox_id);
|
|
928
|
+
if (threadId === void 0) return;
|
|
929
|
+
remember(threadId);
|
|
930
|
+
if (event.action_id === stopActionId) {
|
|
931
|
+
await instance.abortTurn(threadId);
|
|
932
|
+
return;
|
|
933
|
+
}
|
|
934
|
+
await instance.processAction({
|
|
935
|
+
adapter: adapterOf(),
|
|
936
|
+
actionId: event.action_id,
|
|
937
|
+
messageId: event.message_id,
|
|
938
|
+
threadId,
|
|
939
|
+
raw: event,
|
|
940
|
+
user: actorOf(event.user),
|
|
941
|
+
...event.value === void 0 ? {} : { value: event.value }
|
|
942
|
+
}, handlerOptions);
|
|
498
943
|
};
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
944
|
+
return settle(instance, task, webhook, "action");
|
|
945
|
+
};
|
|
946
|
+
const dispatchReaction = (event, webhook = {}) => {
|
|
947
|
+
const chat = deps.chat();
|
|
948
|
+
if (!chat) return Promise.reject(new ChatError("inboxAdapter: initialize() has not run", "NOT_READY"));
|
|
949
|
+
const instance = chat;
|
|
950
|
+
const task = async (handlerOptions) => {
|
|
951
|
+
const threadId = await threadIdFor(event.conversation_id, event.inbox_id);
|
|
952
|
+
if (threadId === void 0) return;
|
|
953
|
+
remember(threadId);
|
|
954
|
+
await instance.processReaction({
|
|
955
|
+
adapter: adapterOf(),
|
|
956
|
+
added: event.added,
|
|
957
|
+
emoji: emojiFromRaw(event.emoji),
|
|
958
|
+
rawEmoji: event.emoji,
|
|
959
|
+
messageId: event.message_id,
|
|
960
|
+
threadId,
|
|
961
|
+
raw: event,
|
|
962
|
+
user: actorOf(event.user)
|
|
963
|
+
}, handlerOptions);
|
|
502
964
|
};
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
} : {
|
|
509
|
-
allowed: false,
|
|
510
|
-
reason: "refused"
|
|
511
|
-
};
|
|
512
|
-
case "contact": return decision.userId === void 0 ? {
|
|
513
|
-
allowed: true,
|
|
514
|
-
author
|
|
515
|
-
} : {
|
|
516
|
-
allowed: true,
|
|
517
|
-
author,
|
|
518
|
-
userId: decision.userId
|
|
519
|
-
};
|
|
520
|
-
default: throw new TypeError(`unknown identity target ${String(author)}`);
|
|
521
|
-
}
|
|
965
|
+
return settle(instance, task, webhook, "reaction");
|
|
966
|
+
};
|
|
967
|
+
return {
|
|
968
|
+
dispatchAction,
|
|
969
|
+
dispatchReaction
|
|
522
970
|
};
|
|
523
971
|
}
|
|
524
|
-
|
|
525
|
-
* The approval page URL for `request`, with `kind` and `subject` as query
|
|
526
|
-
* parameters. Opening it approves nothing: the signed-in approver decides on
|
|
527
|
-
* the page, and the page's server action or POST route checks them.
|
|
528
|
-
*/
|
|
529
|
-
function approvalLink(page, request) {
|
|
530
|
-
const url = new URL(page);
|
|
531
|
-
url.searchParams.set("kind", request.kind);
|
|
532
|
-
url.searchParams.set("subject", request.subject);
|
|
533
|
-
return url.toString();
|
|
534
|
-
}
|
|
535
|
-
const escapeLabel = (label) => label.replaceAll(/[[\]\\]/g, (char) => `\\${char}`);
|
|
536
|
-
/** A chat message that links to the approval page, for `thread.post`. */
|
|
537
|
-
function approvalPrompt(options) {
|
|
538
|
-
const link = `[${escapeLabel(options.label ?? "Review the request")}](${approvalLink(options.page, options.request).replaceAll(")", "%29")})`;
|
|
539
|
-
return { markdown: options.text === void 0 ? link : `${options.text}\n\n${link}` };
|
|
540
|
-
}
|
|
541
|
-
// src/chat-sdk/inbox-adapter.ts
|
|
972
|
+
// src/chat-sdk/inbox-adapter-helpers.ts
|
|
542
973
|
const PREFIX = "inbox:";
|
|
543
|
-
const KNOWN_THREADS = 1e3;
|
|
544
974
|
var MarkdownConverter = class extends BaseFormatConverter {
|
|
545
975
|
fromAst(ast) {
|
|
546
976
|
return stringifyMarkdown(ast).trimEnd();
|
|
@@ -550,38 +980,6 @@ var MarkdownConverter = class extends BaseFormatConverter {
|
|
|
550
980
|
}
|
|
551
981
|
};
|
|
552
982
|
const converter = new MarkdownConverter();
|
|
553
|
-
/**
|
|
554
|
-
* The `IdentityRef` of an inbox contact: `kind: "chat"`, `provider: "inbox"`
|
|
555
|
-
* and the contact id.
|
|
556
|
-
*/
|
|
557
|
-
function inboxIdentityOf(contactId) {
|
|
558
|
-
return {
|
|
559
|
-
kind: "chat",
|
|
560
|
-
provider: "inbox",
|
|
561
|
-
value: contactId
|
|
562
|
-
};
|
|
563
|
-
}
|
|
564
|
-
/** The thread id of an inbox conversation: `inbox:<inbox id>:<conversation id>`. */
|
|
565
|
-
function inboxThreadId(thread) {
|
|
566
|
-
return `${PREFIX}${thread.inboxId}:${thread.conversationId}`;
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* Splits an inbox thread id. Throws a `ChatError` with code `INVALID_THREAD_ID`
|
|
570
|
-
* for any other shape, including the older `inbox:<conversation id>` form.
|
|
571
|
-
*/
|
|
572
|
-
function decodeInboxThreadId(threadId) {
|
|
573
|
-
const rest = threadId.startsWith(PREFIX) ? threadId.slice(6) : "";
|
|
574
|
-
const split = rest.lastIndexOf(":");
|
|
575
|
-
if (split <= 0 || split === rest.length - 1) throw new ChatError(`"${threadId}" is not an inbox thread id`, "INVALID_THREAD_ID");
|
|
576
|
-
return {
|
|
577
|
-
inboxId: rest.slice(0, split),
|
|
578
|
-
conversationId: rest.slice(split + 1)
|
|
579
|
-
};
|
|
580
|
-
}
|
|
581
|
-
/** The conversation id of an inbox thread id. */
|
|
582
|
-
function conversationIdOf(threadId) {
|
|
583
|
-
return decodeInboxThreadId(threadId).conversationId;
|
|
584
|
-
}
|
|
585
983
|
const CHAT_ERROR_CODES = {
|
|
586
984
|
not_found: "NOT_FOUND",
|
|
587
985
|
unauthorized: "AUTH_FAILED",
|
|
@@ -650,7 +1048,7 @@ function bodyOf(message) {
|
|
|
650
1048
|
};
|
|
651
1049
|
}
|
|
652
1050
|
function inboxIdOfChannel(channelId) {
|
|
653
|
-
const inboxId = channelId.startsWith(
|
|
1051
|
+
const inboxId = channelId.startsWith("inbox:") ? channelId.slice(6) : "";
|
|
654
1052
|
if (inboxId.length === 0 || inboxId.includes(":")) throw new ChatError(`"${channelId}" is not an inbox channel id`, "INVALID_CHANNEL_ID");
|
|
655
1053
|
return inboxId;
|
|
656
1054
|
}
|
|
@@ -691,6 +1089,42 @@ async function* textOnly(source) {
|
|
|
691
1089
|
for await (const chunk of source) if (typeof chunk === "string") yield chunk;
|
|
692
1090
|
else if (chunk.type === "markdown_text") yield chunk.text;
|
|
693
1091
|
}
|
|
1092
|
+
// src/chat-sdk/inbox-adapter.ts
|
|
1093
|
+
const KNOWN_THREADS = 1e3;
|
|
1094
|
+
/** The action id `inboxAdapter` treats as "stop the bot" by default. */
|
|
1095
|
+
const INBOX_STOP_ACTION = "chat:stop";
|
|
1096
|
+
/**
|
|
1097
|
+
* The `IdentityRef` of an inbox contact: `kind: "chat"`, `provider: "inbox"`
|
|
1098
|
+
* and the contact id.
|
|
1099
|
+
*/
|
|
1100
|
+
function inboxIdentityOf(contactId) {
|
|
1101
|
+
return {
|
|
1102
|
+
kind: "chat",
|
|
1103
|
+
provider: "inbox",
|
|
1104
|
+
value: contactId
|
|
1105
|
+
};
|
|
1106
|
+
}
|
|
1107
|
+
/** The thread id of an inbox conversation: `inbox:<inbox id>:<conversation id>`. */
|
|
1108
|
+
function inboxThreadId(thread) {
|
|
1109
|
+
return `${PREFIX}${thread.inboxId}:${thread.conversationId}`;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Splits an inbox thread id. Throws a `ChatError` with code `INVALID_THREAD_ID`
|
|
1113
|
+
* for any other shape, including the older `inbox:<conversation id>` form.
|
|
1114
|
+
*/
|
|
1115
|
+
function decodeInboxThreadId(threadId) {
|
|
1116
|
+
const rest = threadId.startsWith("inbox:") ? threadId.slice(6) : "";
|
|
1117
|
+
const split = rest.lastIndexOf(":");
|
|
1118
|
+
if (split <= 0 || split === rest.length - 1) throw new ChatError(`"${threadId}" is not an inbox thread id`, "INVALID_THREAD_ID");
|
|
1119
|
+
return {
|
|
1120
|
+
inboxId: rest.slice(0, split),
|
|
1121
|
+
conversationId: rest.slice(split + 1)
|
|
1122
|
+
};
|
|
1123
|
+
}
|
|
1124
|
+
/** The conversation id of an inbox thread id. */
|
|
1125
|
+
function conversationIdOf(threadId) {
|
|
1126
|
+
return decodeInboxThreadId(threadId).conversationId;
|
|
1127
|
+
}
|
|
694
1128
|
/**
|
|
695
1129
|
* A Chat SDK adapter for the in-app inbox: the bot reads and writes the `inbox`
|
|
696
1130
|
* module's conversations, so one `Chat` instance answers the widget and the
|
|
@@ -762,7 +1196,7 @@ function inboxAdapter(options) {
|
|
|
762
1196
|
raw: message,
|
|
763
1197
|
threadId
|
|
764
1198
|
});
|
|
765
|
-
const post = async (threadId, body, format, metadata, replyTo) => rawOf(await must(inbox.messages.send({
|
|
1199
|
+
const post = async (threadId, body, format, metadata, replyTo, attachments) => rawOf(await must(inbox.messages.send({
|
|
766
1200
|
conversationId: remember(threadId).conversationId,
|
|
767
1201
|
input: {
|
|
768
1202
|
body,
|
|
@@ -772,14 +1206,57 @@ function inboxAdapter(options) {
|
|
|
772
1206
|
author_name: userName,
|
|
773
1207
|
...metadata
|
|
774
1208
|
},
|
|
775
|
-
...replyTo === void 0 ? {} : { replyTo }
|
|
1209
|
+
...replyTo === void 0 ? {} : { replyTo },
|
|
1210
|
+
...attachments === void 0 || attachments.length === 0 ? {} : { attachments }
|
|
776
1211
|
}
|
|
777
1212
|
})), threadId);
|
|
778
|
-
const
|
|
1213
|
+
const uploadAll = async (conversationId, files) => {
|
|
1214
|
+
if (files.length === 0) return [];
|
|
1215
|
+
if (options.upload === void 0) throw new NotImplementedError("inboxAdapter: posting files needs the `upload` option", "upload");
|
|
1216
|
+
const ids = [];
|
|
1217
|
+
for (const file of files) {
|
|
1218
|
+
const target = await must(inbox.messages.createUpload({
|
|
1219
|
+
conversationId,
|
|
1220
|
+
file: {
|
|
1221
|
+
name: file.name,
|
|
1222
|
+
size: byteLength(file.data),
|
|
1223
|
+
...file.mimeType === void 0 ? {} : { mimeType: file.mimeType }
|
|
1224
|
+
}
|
|
1225
|
+
}));
|
|
1226
|
+
await options.upload(target, file);
|
|
1227
|
+
await must(inbox.messages.confirmUpload(target.id));
|
|
1228
|
+
ids.push(target.id);
|
|
1229
|
+
}
|
|
1230
|
+
return ids;
|
|
1231
|
+
};
|
|
1232
|
+
const postMessage = async (threadId, message, replyTo) => {
|
|
779
1233
|
const { body, format } = bodyOf(message);
|
|
780
1234
|
const card = cardOf(message);
|
|
781
|
-
|
|
1235
|
+
const { conversationId } = remember(threadId);
|
|
1236
|
+
const attachments = await uploadAll(conversationId, await outgoingFilesOf(message));
|
|
1237
|
+
const metadata = {
|
|
1238
|
+
...card === void 0 ? {} : { card },
|
|
1239
|
+
...aiGeneratedOf(message) ? { ai_generated: true } : {}
|
|
1240
|
+
};
|
|
1241
|
+
return post(threadId, body, format, Object.keys(metadata).length === 0 ? void 0 : metadata, replyTo, attachments);
|
|
782
1242
|
};
|
|
1243
|
+
/** The thread id of a conversation: the cache, the event's inbox or a read. */
|
|
1244
|
+
const threadIdFor = async (conversationId, inboxId) => {
|
|
1245
|
+
const known = threads.get(conversationId);
|
|
1246
|
+
if (known !== void 0) return known;
|
|
1247
|
+
const owner = inboxId ?? (await must(inbox.conversations.get(conversationId)))?.inboxId;
|
|
1248
|
+
return owner === void 0 ? void 0 : inboxThreadId({
|
|
1249
|
+
inboxId: owner,
|
|
1250
|
+
conversationId
|
|
1251
|
+
});
|
|
1252
|
+
};
|
|
1253
|
+
const { dispatchAction, dispatchReaction } = eventDispatchers({
|
|
1254
|
+
chat: () => chat,
|
|
1255
|
+
adapter: () => adapter,
|
|
1256
|
+
threadFor: threadIdFor,
|
|
1257
|
+
remember,
|
|
1258
|
+
stopActionId: options.stopActionId ?? "chat:stop"
|
|
1259
|
+
});
|
|
783
1260
|
const summaryOf = async (conversation) => {
|
|
784
1261
|
const threadId = inboxThreadId({
|
|
785
1262
|
inboxId: conversation.inboxId,
|
|
@@ -865,6 +1342,25 @@ function inboxAdapter(options) {
|
|
|
865
1342
|
renderFormatted: (content) => converter.fromAst(content),
|
|
866
1343
|
dispatch,
|
|
867
1344
|
ticketOf: (message) => tickets.get(message.id),
|
|
1345
|
+
dispatchAction,
|
|
1346
|
+
dispatchReaction,
|
|
1347
|
+
supportsTurnCancellation: true,
|
|
1348
|
+
rehydrateAttachment: (attachment) => {
|
|
1349
|
+
const attachmentId = attachment.fetchMetadata?.["attachmentId"];
|
|
1350
|
+
const { download } = options;
|
|
1351
|
+
if (download === void 0 || typeof attachmentId !== "string") return attachment;
|
|
1352
|
+
const file = {
|
|
1353
|
+
id: attachmentId,
|
|
1354
|
+
name: attachment.name ?? "file",
|
|
1355
|
+
mimeType: attachment.mimeType,
|
|
1356
|
+
size: attachment.size,
|
|
1357
|
+
status: "clean"
|
|
1358
|
+
};
|
|
1359
|
+
return {
|
|
1360
|
+
...attachment,
|
|
1361
|
+
fetchData: () => download(file)
|
|
1362
|
+
};
|
|
1363
|
+
},
|
|
868
1364
|
handleWebhook: async (request, webhook) => {
|
|
869
1365
|
if (!options.verify || !await options.verify(request)) return new Response("unauthorized", { status: 401 });
|
|
870
1366
|
let job;
|
|
@@ -874,6 +1370,33 @@ function inboxAdapter(options) {
|
|
|
874
1370
|
return new Response("invalid JSON", { status: 400 });
|
|
875
1371
|
}
|
|
876
1372
|
if (!isRecord(job) || typeof job["conversation_id"] !== "string" || typeof job["message_id"] !== "string") return new Response("expected conversation_id and message_id", { status: 400 });
|
|
1373
|
+
const inboxId = typeof job["inbox_id"] === "string" ? { inbox_id: job["inbox_id"] } : {};
|
|
1374
|
+
const user = isRecord(job["user"]) && typeof job["user"]["id"] === "string" ? { user: {
|
|
1375
|
+
id: job["user"]["id"],
|
|
1376
|
+
...typeof job["user"]["name"] === "string" ? { name: job["user"]["name"] } : {}
|
|
1377
|
+
} } : {};
|
|
1378
|
+
if (job["type"] === "action" && typeof job["action_id"] === "string") {
|
|
1379
|
+
await dispatchAction({
|
|
1380
|
+
conversation_id: job["conversation_id"],
|
|
1381
|
+
message_id: job["message_id"],
|
|
1382
|
+
action_id: job["action_id"],
|
|
1383
|
+
...typeof job["value"] === "string" ? { value: job["value"] } : {},
|
|
1384
|
+
...inboxId,
|
|
1385
|
+
...user
|
|
1386
|
+
}, webhook);
|
|
1387
|
+
return new Response("ok", { status: 200 });
|
|
1388
|
+
}
|
|
1389
|
+
if (job["type"] === "reaction" && typeof job["emoji"] === "string" && typeof job["added"] === "boolean") {
|
|
1390
|
+
await dispatchReaction({
|
|
1391
|
+
conversation_id: job["conversation_id"],
|
|
1392
|
+
message_id: job["message_id"],
|
|
1393
|
+
emoji: job["emoji"],
|
|
1394
|
+
added: job["added"],
|
|
1395
|
+
...inboxId,
|
|
1396
|
+
...user
|
|
1397
|
+
}, webhook);
|
|
1398
|
+
return new Response("ok", { status: 200 });
|
|
1399
|
+
}
|
|
877
1400
|
await dispatch({
|
|
878
1401
|
conversation_id: job["conversation_id"],
|
|
879
1402
|
message_id: job["message_id"],
|
|
@@ -989,12 +1512,7 @@ function inboxAdapter(options) {
|
|
|
989
1512
|
};
|
|
990
1513
|
},
|
|
991
1514
|
stream: async (threadId, source, streamOptions) => {
|
|
992
|
-
const { conversationId } = remember(threadId);
|
|
993
|
-
await inbox.conversations.typing({
|
|
994
|
-
conversationId,
|
|
995
|
-
typing: true,
|
|
996
|
-
actor: userName
|
|
997
|
-
});
|
|
1515
|
+
const { conversationId, inboxId } = remember(threadId);
|
|
998
1516
|
let text = "";
|
|
999
1517
|
const chunks = textOnly(source);
|
|
1000
1518
|
const store = options.streams;
|
|
@@ -1007,18 +1525,29 @@ function inboxAdapter(options) {
|
|
|
1007
1525
|
}
|
|
1008
1526
|
controller.close();
|
|
1009
1527
|
} });
|
|
1010
|
-
if (store && streamId) await writeToStore(store, streamId, readable);
|
|
1011
|
-
else {
|
|
1012
|
-
const reader = readable.getReader();
|
|
1013
|
-
while (!(await reader.read()).done);
|
|
1014
|
-
}
|
|
1015
1528
|
await inbox.conversations.typing({
|
|
1016
1529
|
conversationId,
|
|
1017
|
-
typing:
|
|
1530
|
+
typing: true,
|
|
1018
1531
|
actor: userName
|
|
1019
1532
|
});
|
|
1020
|
-
|
|
1021
|
-
|
|
1533
|
+
try {
|
|
1534
|
+
if (store && streamId) await writeToStore(store, streamId, readable);
|
|
1535
|
+
else {
|
|
1536
|
+
const reader = readable.getReader();
|
|
1537
|
+
while (!(await reader.read()).done);
|
|
1538
|
+
}
|
|
1539
|
+
} finally {
|
|
1540
|
+
await inbox.conversations.typing({
|
|
1541
|
+
conversationId,
|
|
1542
|
+
typing: false,
|
|
1543
|
+
actor: userName
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
if (text.trim().length === 0) return rawOf(emptyMessage(conversationId, inboxId), threadId);
|
|
1547
|
+
return post(threadId, text, "markdown", {
|
|
1548
|
+
...streamId === void 0 ? {} : { stream_id: streamId },
|
|
1549
|
+
...options.aiGeneratedStreams === false ? {} : { ai_generated: true }
|
|
1550
|
+
});
|
|
1022
1551
|
}
|
|
1023
1552
|
};
|
|
1024
1553
|
return adapter;
|
|
@@ -1103,6 +1632,7 @@ function createChatInstallations(options) {
|
|
|
1103
1632
|
};
|
|
1104
1633
|
}
|
|
1105
1634
|
// src/chat-sdk/scheduler.ts
|
|
1635
|
+
const LEGACY_KEY = "chat:scheduled";
|
|
1106
1636
|
const LOCK_TTL_MS = 1e4;
|
|
1107
1637
|
const LOCK_POLL_MS = 25;
|
|
1108
1638
|
const sleep = (ms) => new Promise((resolve) => {
|
|
@@ -1115,10 +1645,19 @@ const byPostAt = (a, b) => Date.parse(a.postAt) - Date.parse(b.postAt);
|
|
|
1115
1645
|
* changed under the state's lock, so it suits hundreds of posts, not millions.
|
|
1116
1646
|
*/
|
|
1117
1647
|
function stateScheduler(state, options = {}) {
|
|
1118
|
-
const key = options.key ?? "
|
|
1648
|
+
const key = options.key ?? "better-supabase:scheduled";
|
|
1649
|
+
const legacyKey = options.key === void 0 ? LEGACY_KEY : void 0;
|
|
1119
1650
|
const maxAttempts = options.maxAttempts ?? 3;
|
|
1120
1651
|
const lockWait = options.lockWaitMs ?? 2e3;
|
|
1121
|
-
const read = async () =>
|
|
1652
|
+
const read = async () => {
|
|
1653
|
+
const current = await state.get(key);
|
|
1654
|
+
if (current !== null || legacyKey === void 0) return current ?? [];
|
|
1655
|
+
return await state.get(legacyKey) ?? [];
|
|
1656
|
+
};
|
|
1657
|
+
const write = async (posts) => {
|
|
1658
|
+
await state.set(key, posts);
|
|
1659
|
+
if (legacyKey !== void 0) await state.delete(legacyKey);
|
|
1660
|
+
};
|
|
1122
1661
|
const locked = async (work) => {
|
|
1123
1662
|
const deadline = Date.now() + lockWait;
|
|
1124
1663
|
for (;;) {
|
|
@@ -1136,7 +1675,7 @@ function stateScheduler(state, options = {}) {
|
|
|
1136
1675
|
const posts = await read();
|
|
1137
1676
|
const rest = posts.filter((post) => post.id !== id);
|
|
1138
1677
|
if (rest.length === posts.length) return false;
|
|
1139
|
-
await
|
|
1678
|
+
await write(rest);
|
|
1140
1679
|
return true;
|
|
1141
1680
|
});
|
|
1142
1681
|
return {
|
|
@@ -1151,7 +1690,7 @@ function stateScheduler(state, options = {}) {
|
|
|
1151
1690
|
attempts: 0
|
|
1152
1691
|
};
|
|
1153
1692
|
await locked(async () => {
|
|
1154
|
-
await
|
|
1693
|
+
await write([...await read(), post]);
|
|
1155
1694
|
});
|
|
1156
1695
|
return {
|
|
1157
1696
|
scheduledMessageId: post.id,
|
|
@@ -1173,7 +1712,7 @@ function stateScheduler(state, options = {}) {
|
|
|
1173
1712
|
const taken = posts.filter((post) => Date.parse(post.postAt) <= now).toSorted(byPostAt).slice(0, limit);
|
|
1174
1713
|
if (taken.length > 0) {
|
|
1175
1714
|
const ids = new Set(taken.map((post) => post.id));
|
|
1176
|
-
await
|
|
1715
|
+
await write(posts.filter((post) => !ids.has(post.id)));
|
|
1177
1716
|
}
|
|
1178
1717
|
return taken;
|
|
1179
1718
|
});
|
|
@@ -1198,7 +1737,7 @@ function stateScheduler(state, options = {}) {
|
|
|
1198
1737
|
}
|
|
1199
1738
|
}
|
|
1200
1739
|
if (retry.length > 0) await locked(async () => {
|
|
1201
|
-
await
|
|
1740
|
+
await write([...await read(), ...retry]);
|
|
1202
1741
|
});
|
|
1203
1742
|
return {
|
|
1204
1743
|
published,
|
|
@@ -1223,6 +1762,94 @@ function scheduledAdapter(adapter, scheduler) {
|
|
|
1223
1762
|
});
|
|
1224
1763
|
return Object.assign(adapter, { scheduleMessage });
|
|
1225
1764
|
}
|
|
1765
|
+
// src/chat-sdk/pipeline.ts
|
|
1766
|
+
function prefixOf(chat) {
|
|
1767
|
+
const state = chat.getState();
|
|
1768
|
+
return typeof state === "object" && state !== null && "keyPrefix" in state && typeof state.keyPrefix === "string" ? state.keyPrefix : void 0;
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Splits a channel webhook into a receiving half and a processing half.
|
|
1772
|
+
* `receive` answers the platform from a handler-less Chat instance and stores
|
|
1773
|
+
* the raw event in the sink (or the inbox). `process` replays it later into the
|
|
1774
|
+
* Chat instance that has your handlers, once per queue attempt. Both instances
|
|
1775
|
+
* need their own state prefix: a shared one makes the replay look like a
|
|
1776
|
+
* duplicate. That throws a `TypeError` here, when the prefixes match.
|
|
1777
|
+
*/
|
|
1778
|
+
function chatWebhookPipeline(options) {
|
|
1779
|
+
const { chat, receiveChat, adapter, retry, inbox, ...rest } = options;
|
|
1780
|
+
if (chat === receiveChat || chat.getState() === receiveChat.getState() || prefixOf(chat) !== void 0 && prefixOf(chat) === prefixOf(receiveChat)) throw new TypeError("chatWebhookPipeline: `chat` and `receiveChat` share one state prefix, so the replay would be dropped as a duplicate; give the receiving state its own `keyPrefix` (for example \"chat-sdk:receive\")");
|
|
1781
|
+
const receiver = receiveChat.webhooks[adapter];
|
|
1782
|
+
if (receiver === void 0) throw new TypeError(`chatWebhookPipeline: \`receiveChat\` has no adapter named "${adapter}"`);
|
|
1783
|
+
const handler = inboundHandler({
|
|
1784
|
+
...rest,
|
|
1785
|
+
inbox,
|
|
1786
|
+
chat,
|
|
1787
|
+
propagateHandlerErrors: true,
|
|
1788
|
+
deduplicate: "never"
|
|
1789
|
+
});
|
|
1790
|
+
return {
|
|
1791
|
+
receive: webhook({
|
|
1792
|
+
...rest,
|
|
1793
|
+
...isInboundStore(inbox) ? {} : { inbox },
|
|
1794
|
+
adapter,
|
|
1795
|
+
passthroughHandler: receiver,
|
|
1796
|
+
verify: async (request, body) => {
|
|
1797
|
+
if (options.verify !== void 0 && !await options.verify(request, body)) return false;
|
|
1798
|
+
const tasks = [];
|
|
1799
|
+
const response = await receiver(new Request(request.url, {
|
|
1800
|
+
method: request.method,
|
|
1801
|
+
headers: request.headers,
|
|
1802
|
+
body
|
|
1803
|
+
}), { waitUntil: (task) => void tasks.push(task) });
|
|
1804
|
+
await Promise.all(tasks);
|
|
1805
|
+
return response.status < 400;
|
|
1806
|
+
}
|
|
1807
|
+
}),
|
|
1808
|
+
handler,
|
|
1809
|
+
process: async (event) => {
|
|
1810
|
+
try {
|
|
1811
|
+
await handler.process(event);
|
|
1812
|
+
return;
|
|
1813
|
+
} catch (error) {
|
|
1814
|
+
const decision = retry?.(error, event);
|
|
1815
|
+
if (decision === void 0) throw error;
|
|
1816
|
+
return decision;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
}
|
|
1821
|
+
// src/chat-sdk/whatsapp.ts
|
|
1822
|
+
/** Thrown when the window is closed and no template can be sent. */
|
|
1823
|
+
var ChatWindowClosedError = class extends Error {
|
|
1824
|
+
code = "CHAT_WINDOW_CLOSED";
|
|
1825
|
+
conversationId;
|
|
1826
|
+
constructor(conversationId, reason) {
|
|
1827
|
+
super(`The WhatsApp reply window of conversation ${conversationId} is closed: ${reason}`);
|
|
1828
|
+
this.name = "ChatWindowClosedError";
|
|
1829
|
+
this.conversationId = conversationId;
|
|
1830
|
+
}
|
|
1831
|
+
};
|
|
1832
|
+
const hasSendTemplate = (value) => typeof value === "object" && value !== null && "sendTemplate" in value && typeof value.sendTemplate === "function";
|
|
1833
|
+
/**
|
|
1834
|
+
* Posts `message` while the contact's 24-hour window is open (it reads
|
|
1835
|
+
* `conversations.last_inbound_at`), and the approved `template` through the
|
|
1836
|
+
* adapter's `sendTemplate` once it has closed. A closed window with no
|
|
1837
|
+
* template, or an adapter without `sendTemplate`, throws a
|
|
1838
|
+
* `ChatWindowClosedError` (`code: "CHAT_WINDOW_CLOSED"`) instead of letting
|
|
1839
|
+
* WhatsApp reject the post.
|
|
1840
|
+
*/
|
|
1841
|
+
async function sendWithinWindowOrTemplate(thread, message, options) {
|
|
1842
|
+
if (await whatsappWindowOpen(options.inbox, options.conversationId, options.now)) return {
|
|
1843
|
+
sent: "message",
|
|
1844
|
+
raw: await thread.post(message)
|
|
1845
|
+
};
|
|
1846
|
+
if (options.template === void 0) throw new ChatWindowClosedError(options.conversationId, "send an approved template");
|
|
1847
|
+
if (!hasSendTemplate(thread.adapter)) throw new ChatWindowClosedError(options.conversationId, "the adapter cannot send a template");
|
|
1848
|
+
return {
|
|
1849
|
+
sent: "template",
|
|
1850
|
+
raw: await thread.adapter.sendTemplate(thread.id, options.template)
|
|
1851
|
+
};
|
|
1852
|
+
}
|
|
1226
1853
|
// src/chat-sdk/state.ts
|
|
1227
1854
|
const wrap = (value) => ({ v: value === void 0 ? null : value });
|
|
1228
1855
|
const unwrap = (stored) => isRecord(stored) && "v" in stored ? stored["v"] : stored;
|
|
@@ -1263,7 +1890,16 @@ function createSupabaseState(options) {
|
|
|
1263
1890
|
}, then).orThrow();
|
|
1264
1891
|
return {
|
|
1265
1892
|
keyPrefix: prefix,
|
|
1266
|
-
connect: () =>
|
|
1893
|
+
connect: async () => {
|
|
1894
|
+
try {
|
|
1895
|
+
await call("chat_state_queue_depth", {
|
|
1896
|
+
prefix,
|
|
1897
|
+
thread_id: "__connect__"
|
|
1898
|
+
}, Number).orThrow();
|
|
1899
|
+
} catch (cause) {
|
|
1900
|
+
throw new Error("The chat-sdk-state module is missing or unreachable: add the chat-sdk-state module and run its migration.", { cause });
|
|
1901
|
+
}
|
|
1902
|
+
},
|
|
1267
1903
|
disconnect: () => Promise.resolve(),
|
|
1268
1904
|
subscribe: (threadId) => run("chat_state_subscribe", { thread_id: threadId }, () => void 0),
|
|
1269
1905
|
unsubscribe: (threadId) => run("chat_state_unsubscribe", { thread_id: threadId }, () => void 0),
|
|
@@ -1323,4 +1959,4 @@ function createSupabaseState(options) {
|
|
|
1323
1959
|
purge: (purgeOptions = {}) => call("purge_chat_state", { batch: purgeOptions.batch }, Number).orThrow()
|
|
1324
1960
|
};
|
|
1325
1961
|
}
|
|
1326
|
-
export { DELIVERY_PARSERS, approvalLink, approvalPrompt, botJobs, channelAdapter, chatActionOf, chatActions, chatErrorOf, chatIdentityOf, conversationIdOf, createChatInstallations, createSupabaseState, dbTransport, decodeInboxThreadId, deliver, inboundHandler, inboxAdapter, inboxIdentityOf, inboxThreadId, maintain, messengerDeliveries, resolveChatAuthor, rpcTransport, scheduledAdapter, sqlTransport, stateScheduler, twilioDeliveries, webhook, whatsappDeliveries, whatsappWindowOpen };
|
|
1962
|
+
export { CHAT_CATALOG_MISSING, ChatWindowClosedError, DELIVERY_PARSERS, INBOX_STOP_ACTION, INTERACTIVE_PARSERS, approvalLink, approvalPrompt, botJobs, capabilitiesOf, channelAdapter, chatActionOf, chatActions, chatErrorOf, chatEventOf, chatIdentityOf, chatWebhookPipeline, conversationIdOf, createChatInstallations, createSupabaseState, dbTransport, decodeInboxThreadId, deliver, inboundHandler, inboxAdapter, inboxIdentityOf, inboxStore, inboxThreadId, maintain, messengerDeliveries, resolveChatAuthor, rpcTransport, scheduledAdapter, sendWithinWindowOrTemplate, sqlTransport, stateScheduler, twilioDeliveries, webhook, whatsappDeliveries, whatsappInteractive, whatsappInteractiveOf, whatsappWindowOpen };
|